qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/2] qdev: Catch attempt to attach more than one device to a netdev
Date: Fri, 26 Feb 2010 15:50:51 +0100	[thread overview]
Message-ID: <1267195851-22244-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1267195851-22244-1-git-send-email-armbru@redhat.com>

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 <armbru@redhat.com>
---
 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;
         }
-- 
1.6.6.1

  parent reply	other threads:[~2010-02-26 14:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-26 14:50 [Qemu-devel] [PATCH v2 0/2] Catch attempt to attach more than one device to a netdev Markus Armbruster
2010-02-26 14:50 ` [Qemu-devel] [PATCH v2 1/2] qdev: Improve diagnostics for bad property values Markus Armbruster
2010-03-09 15:02   ` Anthony Liguori
2010-03-09 15:02   ` Anthony Liguori
2010-02-26 14:50 ` Markus Armbruster [this message]
2010-02-26 14:52 ` [Qemu-devel] Re: [PATCH v2 0/2] Catch attempt to attach more than one device to a netdev Michael S. Tsirkin
2010-02-26 16:00 ` Gerd Hoffmann
2010-02-27  9:40 ` Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1267195851-22244-3-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=markmc@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).