From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIr-00063f-Hq for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTcIp-0000Qr-RC for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:21 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:51045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIp-0000FC-FB for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:19 -0400 Received: by mail-pz0-f45.google.com with SMTP id 30so2107087pzk.4 for ; Mon, 06 Jun 2011 09:05:19 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 6 Jun 2011 18:04:21 +0200 Message-Id: <1307376262-1255-13-git-send-email-pbonzini@redhat.com> In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> References: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH v2 12/13] scsi: create scsi-path and scsi-target devices automatically List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This allows to specify a bus or target ID as the scsi-id, and automatically creates all the missing chains down to the LUN level. The given scsi-id is used for the first level; subsequent levels use id 0 as it should be for backward compatibility. Having to parse the number manually kind of sucks. :( Unfortunately qdev properties will not be parsed until after the device has been created. The right way to fix it is to wait for the QCFG fairies, or to otherwise make qdev use QObject rather than QemuOpts as the basis for its parsing. Not something I am going to do soon anyway. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 44 insertions(+), 1 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 43a1cd7..277bcc0 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -7,11 +7,14 @@ #include "trace.h" static char *scsibus_get_fw_dev_path(DeviceState *dev); +static BusState *scsibus_realize_topology(BusState *qbus, DeviceInfo *base, + QemuOpts *opts); static struct BusInfo scsi_bus_info = { .name = "SCSI", .size = sizeof(SCSIBus), - .get_fw_dev_path = scsibus_get_fw_dev_path, + .get_fw_dev_path = scsibus_get_fw_dev_path, + .realize_topology = scsibus_realize_topology, .props = (Property[]) { DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1), DEFINE_PROP_END_OF_LIST(), @@ -32,6 +35,46 @@ void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev, bus->qbus.allow_hotplug = 1; } +static BusState *scsibus_realize_topology(BusState *qbus, DeviceInfo *base, + QemuOpts *opts) +{ + SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base); + SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, qbus); + const char *scsi_id_str; + int scsi_id; + DeviceState *qdev; + SCSIDevice *dev; + + scsi_id_str = qemu_opt_get(opts, "scsi-id"); + if (scsi_id_str) { + char *end; + scsi_id = strtoul(scsi_id_str, &end, 0); + if ((*end != '\0') || (end == scsi_id_str)) { + /* We'll fail when parsing the property. */ + return &bus->qbus; + } + } else { + scsi_id = -1; + } + + if (bus->level >= info->level - 1) { + return &bus->qbus; + } + if (bus->level == SCSI_PATH) { + qdev = qdev_create(&bus->qbus, "scsi-target"); + } else { + qdev = qdev_create(&bus->qbus, "scsi-path"); + } + if (scsi_id != -1) { + qdev_prop_set_uint32(qdev, "scsi-id", scsi_id); + qemu_opt_set(opts, "scsi-id", "0"); + } + + qdev_init_nofail(qdev); + dev = DO_UPCAST(SCSIDevice, qdev, qdev); + return &dev->children->qbus; +} + static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) { SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev); -- 1.7.4.4