Patchwork [RFC,v2,08/13] scsi: introduce the scsi-path device

login
register
mail settings
Submitter Paolo Bonzini
Date June 6, 2011, 4:04 p.m.
Message ID <1307376262-1255-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/98976/
State New
Headers show

Comments

Paolo Bonzini - June 6, 2011, 4:04 p.m.
This introduces a device that dispatches SCSI requests according to the
"target" field of a hierarchical LUN.  The device does not have to do
any processing: requests are always forwarded to a target.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 Makefile.objs  |    2 +-
 hw/scsi-luns.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletions(-)
 create mode 100644 hw/scsi-luns.c

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 90838f6..90940d3 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -85,7 +85,7 @@  common-obj-$(CONFIG_MAX111X) += max111x.o
 common-obj-$(CONFIG_DS1338) += ds1338.o
 common-obj-y += i2c.o smbus.o smbus_eeprom.o
 common-obj-y += eeprom93xx.o
-common-obj-y += scsi-disk.o cdrom.o
+common-obj-y += scsi-disk.o cdrom.o scsi-luns.o
 common-obj-y += scsi-generic.o scsi-bus.o
 common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
 common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o
diff --git a/hw/scsi-luns.c b/hw/scsi-luns.c
new file mode 100644
index 0000000..699e3c1
--- /dev/null
+++ b/hw/scsi-luns.c
@@ -0,0 +1,42 @@ 
+/*
+ * SCSI Device emulation
+ *
+ * Copyright (c) 2011 Red Hat, Inc.
+ *
+ * Author: Paolo Bonzini <pbonzini@redhat.com>.
+ *
+ * This code is licenced under the LGPL.
+ */
+
+#include "qemu-common.h"
+#include "qemu-error.h"
+#include "scsi.h"
+#include "sysemu.h"
+
+static struct SCSIBusOps path_scsi_ops = {
+    .decode_lun = scsi_decode_target_from_lun
+};
+
+static int scsi_path_initfn(SCSIDevice *s)
+{
+    s->children = qemu_mallocz(sizeof(SCSIBus));
+    scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS,
+                 &path_scsi_ops);
+    return 0;
+}
+
+static SCSIDeviceInfo scsi_path_info = {
+    .qdev.name    = "scsi-path",
+    .qdev.desc    = "SCSI initiator device connected to multiple targets",
+    .qdev.size    = sizeof(SCSIDevice),
+    .init         = scsi_path_initfn,
+    .qdev.props   = (Property[]) {
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void scsi_luns_register_devices(void)
+{
+    scsi_qdev_register(&scsi_path_info);
+}
+device_init(scsi_luns_register_devices)