From patchwork Thu Feb 25 10:10:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EE995B6EFF for ; Thu, 25 Feb 2010 21:11:39 +1100 (EST) Received: from localhost ([127.0.0.1]:58902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nkagx-0006ff-LQ for incoming@patchwork.ozlabs.org; Thu, 25 Feb 2010 05:11:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nkafp-0006fa-MX for qemu-devel@nongnu.org; Thu, 25 Feb 2010 05:10:25 -0500 Received: from [199.232.76.173] (port=52244 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nkafo-0006fS-At for qemu-devel@nongnu.org; Thu, 25 Feb 2010 05:10:24 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nkafm-0004Oz-PW for qemu-devel@nongnu.org; Thu, 25 Feb 2010 05:10:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22547) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nkafm-0004Oh-Dx for qemu-devel@nongnu.org; Thu, 25 Feb 2010 05:10:22 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1PAAJ07005065 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 25 Feb 2010 05:10:19 -0500 Received: from blackfin.pond.sub.org (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1PAAGpu022928; Thu, 25 Feb 2010 05:10:17 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 6C95254; Thu, 25 Feb 2010 11:10:15 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 25 Feb 2010 11:10:15 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin , Gerd Hoffmann Subject: [Qemu-devel] [PATCH] qdev: Catch attempt to attach more than one device to a netdev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Guest device and host netdev are peers, i.e. it's a 1:1 relation. However, we fail to enforce that: $ qemu -nodefaults --nographic -netdev user,id=net0 -device e1000,netdev=net0 -device virtio-net-pci,netdev=net0 -monitor stdio QEMU 0.12.50 monitor - type 'help' for more information (qemu) info network Devices not on any VLAN: net0: net=10.0.2.0, restricted=n peer=virtio-net-pci.0 e1000.0: model=e1000,macaddr=52:54:00:12:34:56 peer=net0 virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:57 peer=net0 It's all downhill from there. Signed-off-by: Markus Armbruster --- hw/qdev-properties.c | 3 +++ net.c | 1 + 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 277ff9e..89efd91 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -341,6 +341,9 @@ static int parse_netdev(DeviceState *dev, Property *prop, const char *str) *ptr = qemu_find_netdev(str); if (*ptr == NULL) return -1; + if ((*ptr)->peer) { + return -1; + } return 0; } diff --git a/net.c b/net.c index a1bf49f..e6c96d3 100644 --- a/net.c +++ b/net.c @@ -245,6 +245,7 @@ VLANClientState *qemu_new_net_client(NetClientInfo *info, QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next); } else { if (peer) { + assert(!peer->peer); vc->peer = peer; peer->peer = vc; }