From patchwork Fri Feb 26 14:50:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 46334 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 AE8FFB7CFA for ; Sat, 27 Feb 2010 01:54:45 +1100 (EST) Received: from localhost ([127.0.0.1]:40027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nl1aU-0005sy-PB for incoming@patchwork.ozlabs.org; Fri, 26 Feb 2010 09:54:42 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nl1Wv-0004tH-2I for qemu-devel@nongnu.org; Fri, 26 Feb 2010 09:51:01 -0500 Received: from [199.232.76.173] (port=59759 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nl1Wu-0004t3-ER for qemu-devel@nongnu.org; Fri, 26 Feb 2010 09:51:00 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nl1Wr-0001pn-6F for qemu-devel@nongnu.org; Fri, 26 Feb 2010 09:51:00 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:50074) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Nl1Wq-0001ol-53 for qemu-devel@nongnu.org; Fri, 26 Feb 2010 09:50:56 -0500 Received: from blackfin.pond.sub.org (pD9E3899F.dip.t-dialin.net [217.227.137.159]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 2389E276CAE for ; Fri, 26 Feb 2010 15:50:52 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 6F63474; Fri, 26 Feb 2010 15:50:51 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 26 Feb 2010 15:50:51 +0100 Message-Id: <1267195851-22244-3-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1267195851-22244-1-git-send-email-armbru@redhat.com> References: <1267195851-22244-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Mark McLoughlin , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH v2 2/2] 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 | 7 +++++++ net.c | 1 + 2 files changed, 8 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 438eaea..24671af 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 -ENOENT; + if ((*ptr)->peer) { + return -EEXIST; + } return 0; } @@ -557,6 +560,10 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value) ret = prop->info->parse(dev, prop, value); if (ret < 0) { switch (ret) { + case -EEXIST: + fprintf(stderr, "property \"%s.%s\": \"%s\" is already in use\n", + dev->info->name, name, value); + break; default: case -EINVAL: fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n", 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; }