[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v2 12/13] scsi: create scsi-path and scsi-target
From: |
Paolo Bonzini |
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 |
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 <address@hidden>
---
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
- [Qemu-devel] [RFC PATCH v2 03/13] scsi: add initiator field to SCSIRequest, (continued)
- [Qemu-devel] [RFC PATCH v2 03/13] scsi: add initiator field to SCSIRequest, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 04/13] scsi: let a SCSIDevice have children devices, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 05/13] scsi: let the bus pick a LUN for the child device, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 06/13] scsi-generic: fix passthrough of devices with LUN != 0, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 07/13] scsi: add walking of hierarchical LUNs, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 08/13] scsi: introduce the scsi-path device, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 09/13] scsi: introduce the scsi-target device, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 10/13] scsi: include bus and device levels, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 11/13] qdev: introduce automatic creation of buses, Paolo Bonzini, 2011/06/06
- [Qemu-devel] [RFC PATCH v2 12/13] scsi: create scsi-path and scsi-target devices automatically,
Paolo Bonzini <=
- [Qemu-devel] [RFC PATCH v2 13/13] scsi: delete handling of REPORT LUNS and unknown LUNs outside scsi-target, Paolo Bonzini, 2011/06/06