From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 35/55] scsi: allow arbitrary LUNs
Date: Mon, 31 Oct 2011 14:30:10 +0100 [thread overview]
Message-ID: <1320067830-12093-36-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1320067830-12093-1-git-send-email-kwolf@redhat.com>
From: Paolo Bonzini <pbonzini@redhat.com>
This only requires changes in two places: in SCSIBus, we need to look
for a free LUN if somebody creates a device with a pre-existing scsi-id
but the default LUN (-1, meaning "search for a free spot"); in vSCSI,
we need to actually parse the LUN according to the SCSI spec.
For vSCSI, max_target/max_lun are set according to the logical unit
addressing format in SAM.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
hw/esp.c | 3 ++-
hw/lsi53c895a.c | 3 ++-
hw/scsi-bus.c | 48 ++++++++++++++++++++++++++++++++----------------
hw/scsi.h | 3 ++-
hw/spapr_vscsi.c | 39 +++++++++++++++++++++++++++++++++++----
hw/usb-msd.c | 3 ++-
6 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/hw/esp.c b/hw/esp.c
index aad290f..5742bb3 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -724,7 +724,8 @@ void esp_init(target_phys_addr_t espaddr, int it_shift,
static const struct SCSIBusInfo esp_scsi_info = {
.tcq = false,
- .ndev = ESP_MAX_DEVS,
+ .max_target = ESP_MAX_DEVS,
+ .max_lun = 7,
.transfer_data = esp_transfer_data,
.complete = esp_command_complete,
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index c15f167..d26e442 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -2085,7 +2085,8 @@ static int lsi_scsi_uninit(PCIDevice *d)
static const struct SCSIBusInfo lsi_scsi_info = {
.tcq = true,
- .ndev = LSI_MAX_DEVS,
+ .max_target = LSI_MAX_DEVS,
+ .max_lun = 0, /* LUN support is buggy */
.transfer_data = lsi_transfer_data,
.complete = lsi_command_complete,
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index a2d57a7..cec06db 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -17,7 +17,7 @@ static struct BusInfo scsi_bus_info = {
.get_fw_dev_path = scsibus_get_fw_dev_path,
.props = (Property[]) {
DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
- DEFINE_PROP_UINT32("lun", SCSIDevice, lun, 0),
+ DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
DEFINE_PROP_END_OF_LIST(),
},
};
@@ -37,26 +37,42 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
- SCSIDevice *olddev;
+ SCSIDevice *d;
int rc = -1;
- if (dev->id == -1) {
- int id;
- for (id = 0; id < bus->info->ndev; id++) {
- if (!scsi_device_find(bus, id, 0)) {
- dev->id = id;
- break;
- }
- }
- }
- if (dev->id >= bus->info->ndev) {
+ if (dev->id != -1 && dev->id > bus->info->max_target) {
error_report("bad scsi device id: %d", dev->id);
goto err;
}
- olddev = scsi_device_find(bus, dev->id, dev->lun);
- if (olddev && dev->lun == olddev->lun) {
- qdev_free(&olddev->qdev);
+ if (dev->id == -1) {
+ int id = -1;
+ if (dev->lun == -1) {
+ dev->lun = 0;
+ }
+ do {
+ d = scsi_device_find(bus, ++id, dev->lun);
+ } while (d && d->lun == dev->lun && id <= bus->info->max_target);
+ if (id > bus->info->max_target) {
+ error_report("no free target");
+ goto err;
+ }
+ dev->id = id;
+ } else if (dev->lun == -1) {
+ int lun = -1;
+ do {
+ d = scsi_device_find(bus, dev->id, ++lun);
+ } while (d && d->lun == lun && lun < bus->info->max_lun);
+ if (lun > bus->info->max_lun) {
+ error_report("no free lun");
+ goto err;
+ }
+ dev->lun = lun;
+ } else {
+ d = scsi_device_find(bus, dev->id, dev->lun);
+ if (dev->lun == d->lun && dev != d) {
+ qdev_free(&d->qdev);
+ }
}
dev->info = info;
@@ -115,7 +131,7 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
int res = 0, unit;
loc_push_none(&loc);
- for (unit = 0; unit < bus->info->ndev; unit++) {
+ for (unit = 0; unit < bus->info->max_target; unit++) {
dinfo = drive_get(IF_SCSI, bus->busnr, unit);
if (dinfo == NULL) {
continue;
diff --git a/hw/scsi.h b/hw/scsi.h
index add3d2d..401d8d3 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -98,7 +98,8 @@ struct SCSIDeviceInfo {
};
struct SCSIBusInfo {
- int tcq, ndev;
+ int tcq;
+ int max_target, max_lun;
void (*transfer_data)(SCSIRequest *req, uint32_t arg);
void (*complete)(SCSIRequest *req, uint32_t arg);
void (*cancel)(SCSIRequest *req);
diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index ea3bb08..e6c3581 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -131,9 +131,39 @@ static void vscsi_put_req(vscsi_req *req)
static SCSIDevice *vscsi_device_find(SCSIBus *bus, uint64_t srp_lun, int *lun)
{
- /* XXX Figure that one out properly ! This is crackpot */
- int id = (srp_lun >> 56) & 0x7f;
- *lun = (srp_lun >> 48) & 0xff;
+ int channel = 0, id = 0;
+
+retry:
+ switch (srp_lun >> 62) {
+ case 0:
+ if ((srp_lun >> 56) != 0) {
+ channel = (srp_lun >> 56) & 0x3f;
+ id = (srp_lun >> 48) & 0xff;
+ srp_lun <<= 16;
+ goto retry;
+ }
+ *lun = (srp_lun >> 48) & 0xff;
+ break;
+
+ case 1:
+ *lun = (srp_lun >> 48) & 0x3fff;
+ break;
+ case 2:
+ channel = (srp_lun >> 53) & 0x7;
+ id = (srp_lun >> 56) & 0x3f;
+ *lun = (srp_lun >> 48) & 0x1f;
+ break;
+ case 3:
+ *lun = -1;
+ return NULL;
+ default:
+ abort();
+ }
+
+ if (channel) {
+ *lun = -1;
+ return NULL;
+ }
return scsi_device_find(bus, id, *lun);
}
@@ -862,7 +892,8 @@ static int vscsi_do_crq(struct VIOsPAPRDevice *dev, uint8_t *crq_data)
static const struct SCSIBusInfo vscsi_scsi_info = {
.tcq = true,
- .ndev = VSCSI_REQ_LIMIT,
+ .max_target = 63, /* logical unit addressing format */
+ .max_lun = 31,
.transfer_data = vscsi_transfer_data,
.complete = vscsi_command_complete,
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 2c047fa..1a0815a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -497,7 +497,8 @@ static void usb_msd_password_cb(void *opaque, int err)
static const struct SCSIBusInfo usb_msd_scsi_info = {
.tcq = false,
- .ndev = 1,
+ .max_target = 0,
+ .max_lun = 0,
.transfer_data = usb_msd_transfer_data,
.complete = usb_msd_command_complete,
--
1.7.6.4
next prev parent reply other threads:[~2011-10-31 13:28 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 13:29 [Qemu-devel] [PULL 00/55] Block patches Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 01/55] iSCSI block driver Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 02/55] Documentation: Add iSCSI section Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 03/55] Teach block/vdi about "discarded" (no longer allocated) blocks Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 04/55] qcow2: fix some errors and typo in qcow2.txt Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 05/55] block: Remove dead code Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 06/55] block: Fix bdrv_open use after free Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 07/55] qcow: Fix bdrv_write_compressed error handling Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 08/55] ide: Fix off-by-one error in array index check Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 09/55] vmdk: Fix use of uninitialised value Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 10/55] vmdk: Improve error handling Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 11/55] vmdk: Fix possible segfaults Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 12/55] Documentation: Describe NBD URL syntax Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 13/55] block: fix qcow2_co_flush deadlock Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 14/55] qemu-io: delete bs instead of leaking it Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 15/55] block: set bs->read_only before .bdrv_open() Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 16/55] block: reinitialize across bdrv_close()/bdrv_open() Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 17/55] Documentation: Add syntax for using sheepdog devices Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 18/55] scsi: pass correct sense code for ENOMEDIUM Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 19/55] atapi/scsi: unify definitions for MMC Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 20/55] atapi: move GESN definitions to scsi-defs.h Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 21/55] atapi: cleanup/fix mode sense results Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 22/55] scsi: notify the device when unit attention is reported Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 23/55] scsi-disk: report media changed via unit attention sense codes Kevin Wolf
2011-10-31 13:29 ` [Qemu-devel] [PATCH 24/55] scsi-disk: fix coding style issues (braces) Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 25/55] scsi-disk: add stubs for more MMC commands Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 26/55] scsi-disk: store valid mode pages in a table Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 27/55] atapi/scsi-disk: make mode page values coherent between the two Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 28/55] scsi-disk: support DVD profile in GET CONFIGURATION Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 29/55] scsi-disk: support READ DVD STRUCTURE Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 31/55] scsi: move tcq/ndev to SCSIBusOps (now SCSIBusInfo) Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 32/55] qdev: switch children device list to QTAILQ Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 33/55] scsi: remove devs array from SCSIBus Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 34/55] scsi: implement REPORT LUNS for arbitrary LUNs Kevin Wolf
2011-10-31 13:30 ` Kevin Wolf [this message]
2011-10-31 13:30 ` [Qemu-devel] [PATCH 36/55] scsi: add channel to addressing Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 37/55] scsi-disk: fail READ CAPACITY if LBA != 0 but PMI == 0 Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 38/55] scsi-disk: fix retrying a flush Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 39/55] scsi-generic: drop SCSIGenericState Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 40/55] scsi-generic: remove scsi_req_fixup Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 41/55] scsi-generic: check ioctl statuses when SG_IO succeeds Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 42/55] scsi-generic: look at host status Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 43/55] scsi-generic: snoop READ CAPACITY commands to get block size Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 44/55] scsi-disk: do not duplicate BlockDriverState member Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 45/55] scsi-disk: remove cluster_size Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 46/55] scsi-disk: small clean up to INQUIRY Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 48/55] scsi: make reqops const Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 49/55] scsi: export scsi_generic_reqops Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 50/55] scsi: pass cdb to alloc_req Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 51/55] scsi: do not call transfer_data after canceling a request Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 52/55] scsi-disk: bump SCSIRequest reference count until aio completion runs Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 53/55] scsi-generic: " Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 54/55] scsi: push request restart to SCSIDevice Kevin Wolf
2011-10-31 13:30 ` [Qemu-devel] [PATCH 55/55] scsi-disk: add scsi-block for device passthrough Kevin Wolf
2011-10-31 16:52 ` [Qemu-devel] [PULL 00/55] Block patches Anthony Liguori
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=1320067830-12093-36-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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).