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 10/13] scsi: include bus and device levels
Date: Mon,  6 Jun 2011 18:04:19 +0200	[thread overview]
Message-ID: <1307376262-1255-11-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com>

This gives each SCSIBus and SCSIDevice a position on the SCSI hierarchy:

- a SCSI_HOST dispatches on the "path" (aka "bus" aka "channel") axis.

- a SCSI_PATH dispatches on the target axis.

- a SCSI_TARGET dispatches on the LUN axis and handles requests for
  REPORT LUNS commands, invalid LUNs, and well-known LUNs.  It may
  also have children that are paths, though this is not very much
  supported by operating systems.

- a SCSI_LUN is at the bottom of the hierarchy.

This is used in the next patch to create missing layers in the
qdev representation.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/esp.c          |    2 +-
 hw/lsi53c895a.c   |    2 +-
 hw/scsi-bus.c     |    3 ++-
 hw/scsi-disk.c    |    3 +++
 hw/scsi-generic.c |    1 +
 hw/scsi-luns.c    |    6 ++++--
 hw/scsi.h         |   11 ++++++++++-
 hw/spapr_vscsi.c  |    2 +-
 hw/usb-msd.c      |    2 +-
 9 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/hw/esp.c b/hw/esp.c
index a821a0a..0f16dcf 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -751,7 +751,7 @@ static int esp_init1(SysBusDevice *dev)
 
     qdev_init_gpio_in(&dev->qdev, esp_gpio_demux, 2);
 
-    scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, &esp_scsi_ops);
+    scsi_bus_new(&s->bus, &dev->qdev, 0, ESP_MAX_DEVS, SCSI_PATH, &esp_scsi_ops);
     return scsi_bus_legacy_handle_cmdline(&s->bus);
 }
 
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index a908324..2e5dd42 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -2287,7 +2287,7 @@ static int lsi_scsi_init(PCIDevice *dev)
                            PCI_BASE_ADDRESS_SPACE_MEMORY, lsi_ram_mapfunc);
     QTAILQ_INIT(&s->queue);
 
-    scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, &lsi_scsi_ops);
+    scsi_bus_new(&s->bus, &dev->qdev, 1, LSI_MAX_DEVS, SCSI_PATH, &lsi_scsi_ops);
     if (!dev->qdev.hotplugged) {
         return scsi_bus_legacy_handle_cmdline(&s->bus);
     }
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 54f308d..43a1cd7 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -21,10 +21,11 @@ static int next_scsi_bus;
 
 /* Create a scsi bus, and attach devices to it.  */
 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
-                  const SCSIBusOps *ops)
+		  enum SCSIDeviceLevel level, const SCSIBusOps *ops)
 {
     qbus_create_inplace(&bus->qbus, &scsi_bus_info, host, NULL);
     bus->busnr = next_scsi_bus++;
+    bus->level = level;
     bus->tcq = tcq;
     bus->ndev = ndev;
     bus->ops = ops;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index b2c8d6e..0a4fbee 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1263,6 +1263,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI disk",
         .qdev.size    = sizeof(SCSIDiskState),
+        .level        = SCSI_LUN,
         .reset        = scsi_disk_reset,
         .init         = scsi_hd_initfn,
         .destroy      = scsi_destroy,
@@ -1284,6 +1285,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI CD-ROM",
         .qdev.size    = sizeof(SCSIDiskState),
+        .level        = SCSI_LUN,
         .reset        = scsi_disk_reset,
         .init         = scsi_cd_initfn,
         .destroy      = scsi_destroy,
@@ -1304,6 +1306,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI disk or CD-ROM (legacy)",
         .qdev.size    = sizeof(SCSIDiskState),
+        .level        = SCSI_LUN,
         .reset        = scsi_disk_reset,
         .init         = scsi_disk_initfn,
         .destroy      = scsi_destroy,
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 1611023..e1f9d0e 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -561,6 +561,7 @@ static SCSIDeviceInfo scsi_generic_info = {
     .qdev.name    = "scsi-generic",
     .qdev.desc    = "pass through generic scsi device (/dev/sg*)",
     .qdev.size    = sizeof(SCSIGenericState),
+    .level        = SCSI_LUN,
     .init         = scsi_generic_initfn,
     .destroy      = scsi_destroy,
     .alloc_req    = scsi_new_request,
diff --git a/hw/scsi-luns.c b/hw/scsi-luns.c
index 4b158a9..2cf36f0 100644
--- a/hw/scsi-luns.c
+++ b/hw/scsi-luns.c
@@ -319,7 +319,7 @@ static struct SCSIBusOps path_scsi_ops = {
 static int scsi_path_initfn(SCSIDevice *s)
 {
     s->children = qemu_mallocz(sizeof(SCSIBus));
-    scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS,
+    scsi_bus_new(s->children, &s->qdev, 1, MAX_SCSI_DEVS, SCSI_PATH,
                  &path_scsi_ops);
     return 0;
 }
@@ -329,6 +329,7 @@ static SCSIDeviceInfo scsi_path_info = {
     .qdev.desc    = "SCSI initiator device connected to multiple targets",
     .qdev.size    = sizeof(SCSIDevice),
     .init         = scsi_path_initfn,
+    .level        = SCSI_PATH,
     .qdev.props   = (Property[]) {
         DEFINE_PROP_END_OF_LIST(),
     },
@@ -352,7 +353,7 @@ static int scsi_target_initfn(SCSIDevice *dev)
     }
 
     s->qdev.children = qemu_mallocz(sizeof(SCSIBus));
-    scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS,
+    scsi_bus_new(s->qdev.children, &dev->qdev, 1, MAX_SCSI_DEVS, SCSI_TARGET,
                  &target_scsi_ops);
     return 0;
 }
@@ -361,6 +362,7 @@ static SCSIDeviceInfo scsi_target_info = {
     .qdev.name    = "scsi-target",
     .qdev.desc    = "SCSI target device connected to multiple logical units",
     .qdev.size    = sizeof(SCSITargetState),
+    .level        = SCSI_TARGET,
     .init         = scsi_target_initfn,
     .alloc_req    = scsi_new_request,
     .free_req     = scsi_free_request,
diff --git a/hw/scsi.h b/hw/scsi.h
index 9f70771..f4fec61 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -27,6 +27,13 @@ enum SCSILun {
     LUN_WLUN_MASK = 255
 };
 
+enum SCSIDeviceLevel {
+    SCSI_HOST = 0,
+    SCSI_PATH = 1,
+    SCSI_TARGET = 2,
+    SCSI_LUN = 3
+};
+
 typedef struct SCSISense {
     uint8_t key;
     uint8_t asc;
@@ -73,6 +80,7 @@ int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num);
 /* scsi-bus.c */
 struct SCSIDeviceInfo {
     DeviceInfo qdev;
+    enum SCSIDeviceLevel level;
     int (*init)(SCSIDevice *dev);
     void (*destroy)(SCSIDevice *s);
     void (*reset)(SCSIDevice *s);
@@ -100,6 +108,7 @@ struct SCSIBus {
     BusState qbus;
     int busnr;
 
+    enum SCSIDeviceLevel level;
     int tcq, ndev;
     const SCSIBusOps *ops;
 
@@ -107,7 +116,7 @@ struct SCSIBus {
 };
 
 void scsi_bus_new(SCSIBus *bus, DeviceState *host, int tcq, int ndev,
-                  const SCSIBusOps *ops);
+		  enum SCSIDeviceLevel level, const SCSIBusOps *ops);
 void scsi_qdev_register(SCSIDeviceInfo *info);
 
 static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d, DeviceState *initiator)
diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index ace9dac..36dba40 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -935,7 +935,7 @@ static int spapr_vscsi_init(VIOsPAPRDevice *dev)
 
     dev->crq.SendFunc = vscsi_do_crq;
 
-    scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT,
+    scsi_bus_new(&s->bus, &dev->qdev, 1, VSCSI_REQ_LIMIT, SCSI_HOST,
                  &vscsi_scsi_ops);
     if (!dev->qdev.hotplugged) {
         scsi_bus_legacy_handle_cmdline(&s->bus);
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 195089c..5b34b7b 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -537,7 +537,7 @@ static int usb_msd_initfn(USBDevice *dev)
     }
 
     usb_desc_init(dev);
-    scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, &usb_msd_scsi_ops);
+    scsi_bus_new(&s->bus, &s->dev.qdev, 0, 1, SCSI_PATH, &usb_msd_scsi_ops);
     s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable);
     if (!s->scsi_dev) {
         return -1;
-- 
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 ` Paolo Bonzini [this message]
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 ` [Qemu-devel] [RFC PATCH v2 12/13] scsi: create scsi-path and scsi-target devices automatically Paolo Bonzini
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-11-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).