qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH v2 12/13] scsi: create scsi-path and scsi-target devices automatically
Date: Mon,  6 Jun 2011 18:04:21 +0200	[thread overview]
Message-ID: <1307376262-1255-13-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com>

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 <pbonzini@redhat.com>
---
 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

  parent reply	other threads:[~2011-06-06 16:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06 16:04 [Qemu-devel] [RFC PATCH v2 00/13] support hierarchical LUNs Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 01/13] scsi: cleanup reset and destroy callbacks Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 02/13] scsi: support parsing of SAM logical unit numbers Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 03/13] scsi: add initiator field to SCSIRequest Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 04/13] scsi: let a SCSIDevice have children devices Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 05/13] scsi: let the bus pick a LUN for the child device Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 06/13] scsi-generic: fix passthrough of devices with LUN != 0 Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 07/13] scsi: add walking of hierarchical LUNs Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 08/13] scsi: introduce the scsi-path device Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 09/13] scsi: introduce the scsi-target device Paolo Bonzini
2011-06-07  8:09   ` Stefan Hajnoczi
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 10/13] scsi: include bus and device levels Paolo Bonzini
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 11/13] qdev: introduce automatic creation of buses Paolo Bonzini
2011-06-06 16:04 ` Paolo Bonzini [this message]
2011-06-06 16:04 ` [Qemu-devel] [RFC PATCH v2 13/13] scsi: delete handling of REPORT LUNS and unknown LUNs outside scsi-target Paolo Bonzini

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=1307376262-1255-13-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@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).