public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: KVM <kvm@vger.kernel.org>,
	linux-s390 <linux-s390@vger.kernel.org>,
	qemu-devel <qemu-devel@nongnu.org>
Cc: Avi Kivity <avi@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	Carsten Otte <cotte@de.ibm.com>, Alexander Graf <agraf@suse.de>,
	Heiko Carstens <heiko.carstens@de.ibm.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Sebastian Ott <sebott@linux.vnet.ibm.com>
Subject: [PATCH 5/5] [HACK] Handle multiple virtio aliases.
Date: Tue,  7 Aug 2012 16:52:53 +0200	[thread overview]
Message-ID: <1344351173-2716-6-git-send-email-cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <1344351173-2716-1-git-send-email-cornelia.huck@de.ibm.com>

This patch enables using both virtio-xxx-s390 and virtio-xxx-ccw
by making the alias lookup code verify that a driver is actually
registered.

(Only included in order to allow testing of virtio-ccw; should be
replaced by cleaning up the virtio bus model.)

Not-signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 blockdev.c        |  6 +---
 hw/qdev-monitor.c | 85 +++++++++++++++++++++++++++++++++----------------------
 vl.c              |  6 +---
 3 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 8669142..7a8eb27 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -559,11 +559,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
     case IF_VIRTIO:
         /* add virtio block device */
         opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL);
-        if (arch_type == QEMU_ARCH_S390X) {
-            qemu_opt_set(opts, "driver", "virtio-blk-s390");
-        } else {
-            qemu_opt_set(opts, "driver", "virtio-blk-pci");
-        }
+        qemu_opt_set(opts, "driver", "virtio-blk");
         qemu_opt_set(opts, "drive", dinfo->id);
         if (devaddr)
             qemu_opt_set(opts, "addr", devaddr);
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 79f7e6b..6178b83 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -118,9 +118,53 @@ static int set_property(const char *name, const char *value, void *opaque)
     return 0;
 }
 
-static const char *find_typename_by_alias(const char *alias)
+static BusState *qbus_find_recursive(BusState *bus, const char *name,
+                                     const char *bus_typename)
+{
+    BusChild *kid;
+    BusState *child, *ret;
+    int match = 1;
+
+    if (name && (strcmp(bus->name, name) != 0)) {
+        match = 0;
+    }
+    if (bus_typename &&
+        (strcmp(object_get_typename(OBJECT(bus)), bus_typename) != 0)) {
+        match = 0;
+    }
+    if (match) {
+        return bus;
+    }
+
+    QTAILQ_FOREACH(kid, &bus->children, sibling) {
+        DeviceState *dev = kid->child;
+        QLIST_FOREACH(child, &dev->child_bus, sibling) {
+            ret = qbus_find_recursive(child, name, bus_typename);
+            if (ret) {
+                return ret;
+            }
+        }
+    }
+    return NULL;
+}
+
+static bool qdev_verify_bus(DeviceClass *dc)
+{
+    BusState *bus;
+
+    if (dc) {
+        bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type);
+        if (bus) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static const char *find_typename_by_alias(const char *alias, bool check_bus)
 {
     int i;
+    ObjectClass *oc;
 
     for (i = 0; qdev_alias_table[i].alias; i++) {
         if (qdev_alias_table[i].arch_mask &&
@@ -129,7 +173,10 @@ static const char *find_typename_by_alias(const char *alias)
         }
 
         if (strcmp(qdev_alias_table[i].alias, alias) == 0) {
-            return qdev_alias_table[i].typename;
+            oc = object_class_by_name(qdev_alias_table[i].typename);
+            if (oc && (!check_bus || qdev_verify_bus(DEVICE_CLASS(oc)))) {
+                return qdev_alias_table[i].typename;
+            }
         }
     }
 
@@ -155,7 +202,7 @@ int qdev_device_help(QemuOpts *opts)
 
     klass = object_class_by_name(driver);
     if (!klass) {
-        const char *typename = find_typename_by_alias(driver);
+        const char *typename = find_typename_by_alias(driver, false);
 
         if (typename) {
             driver = typename;
@@ -283,36 +330,6 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
     return NULL;
 }
 
-static BusState *qbus_find_recursive(BusState *bus, const char *name,
-                                     const char *bus_typename)
-{
-    BusChild *kid;
-    BusState *child, *ret;
-    int match = 1;
-
-    if (name && (strcmp(bus->name, name) != 0)) {
-        match = 0;
-    }
-    if (bus_typename &&
-        (strcmp(object_get_typename(OBJECT(bus)), bus_typename) != 0)) {
-        match = 0;
-    }
-    if (match) {
-        return bus;
-    }
-
-    QTAILQ_FOREACH(kid, &bus->children, sibling) {
-        DeviceState *dev = kid->child;
-        QLIST_FOREACH(child, &dev->child_bus, sibling) {
-            ret = qbus_find_recursive(child, name, bus_typename);
-            if (ret) {
-                return ret;
-            }
-        }
-    }
-    return NULL;
-}
-
 static BusState *qbus_find(const char *path)
 {
     DeviceState *dev;
@@ -417,7 +434,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
     /* find driver */
     obj = object_class_by_name(driver);
     if (!obj) {
-        const char *typename = find_typename_by_alias(driver);
+        const char *typename = find_typename_by_alias(driver, true);
 
         if (typename) {
             driver = typename;
diff --git a/vl.c b/vl.c
index 8d1f7f0..f04eb18 100644
--- a/vl.c
+++ b/vl.c
@@ -2029,11 +2029,7 @@ static int virtcon_parse(const char *devname)
     }
 
     bus_opts = qemu_opts_create(device, NULL, 0, NULL);
-    if (arch_type == QEMU_ARCH_S390X) {
-        qemu_opt_set(bus_opts, "driver", "virtio-serial-s390");
-    } else {
-        qemu_opt_set(bus_opts, "driver", "virtio-serial-pci");
-    } 
+    qemu_opt_set(bus_opts, "driver", "virtio-serial");
 
     dev_opts = qemu_opts_create(device, NULL, 0, NULL);
     qemu_opt_set(dev_opts, "driver", "virtconsole");
-- 
1.7.11.4

      parent reply	other threads:[~2012-08-07 14:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-07 14:52 [RFC PATCH 0/5] qemu: s390: virtual css and virtio-ccw Cornelia Huck
2012-08-07 14:52 ` [PATCH 1/5] Update headers for upcoming s390 changes Cornelia Huck
2012-08-07 14:52 ` [PATCH 2/5] s390: Virtual channel subsystem support Cornelia Huck
2012-08-07 21:00   ` [Qemu-devel] " Blue Swirl
2012-08-08  8:17     ` Cornelia Huck
2012-08-08 19:16       ` [Qemu-devel] " Blue Swirl
2012-08-08 19:34         ` Peter Maydell
2012-08-08 19:39           ` Blue Swirl
2012-08-09  7:19             ` Cornelia Huck
2012-08-08  8:27   ` Peter Maydell
2012-08-08  8:53     ` Cornelia Huck
2012-08-07 14:52 ` [PATCH 3/5] s390: Add new channel I/O based virtio transport Cornelia Huck
2012-08-07 20:47   ` [Qemu-devel] " Blue Swirl
2012-08-08  8:28     ` Cornelia Huck
2012-08-08 19:03       ` Blue Swirl
2012-08-09  7:21         ` Cornelia Huck
2012-08-09 11:34   ` Stefan Hajnoczi
2012-08-09 12:12     ` Cornelia Huck
2012-08-09 12:27       ` Stefan Hajnoczi
2012-08-07 14:52 ` [PATCH 4/5] s390: Virtual channel subsystem support for !KVM Cornelia Huck
2012-08-07 14:52 ` Cornelia Huck [this message]

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=1344351173-2716-6-git-send-email-cornelia.huck@de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=agraf@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cotte@de.ibm.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=schwidefsky@de.ibm.com \
    --cc=sebott@linux.vnet.ibm.com \
    /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