From patchwork Tue Aug 7 14:52:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 175667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A82EC2C009D for ; Wed, 8 Aug 2012 01:37:58 +1000 (EST) Received: from localhost ([::1]:40977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sylr2-0007QD-NX for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 11:37:56 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SylA8-0004wX-GR for qemu-devel@nongnu.org; Tue, 07 Aug 2012 10:53:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SylA6-0000LM-IP for qemu-devel@nongnu.org; Tue, 07 Aug 2012 10:53:36 -0400 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:43586) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SylA6-0000Kj-7v for qemu-devel@nongnu.org; Tue, 07 Aug 2012 10:53:34 -0400 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Aug 2012 15:53:33 +0100 Received: from d06nrmr1707.portsmouth.uk.ibm.com (9.149.39.225) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 7 Aug 2012 15:52:57 +0100 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q77Equ4l2248938 for ; Tue, 7 Aug 2012 15:52:57 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q77Equvd018494 for ; Tue, 7 Aug 2012 08:52:56 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q77EqrcI018343; Tue, 7 Aug 2012 08:52:55 -0600 From: Cornelia Huck To: KVM , linux-s390 , qemu-devel Date: Tue, 7 Aug 2012 16:52:53 +0200 Message-Id: <1344351173-2716-6-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1344351173-2716-1-git-send-email-cornelia.huck@de.ibm.com> References: <1344351173-2716-1-git-send-email-cornelia.huck@de.ibm.com> x-cbid: 12080714-2966-0000-0000-000004EF91BE X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.109 Cc: Carsten Otte , Anthony Liguori , Rusty Russell , Sebastian Ott , Marcelo Tosatti , Heiko Carstens , Alexander Graf , Christian Borntraeger , Avi Kivity , Martin Schwidefsky Subject: [Qemu-devel] [PATCH 5/5] [HACK] Handle multiple virtio aliases. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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");