aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Kagan <rkagan@virtuozzo.com>2017-04-26 17:18:03 +0300
committerKevin O'Connor <kevin@koconnor.net>2017-05-02 19:57:03 -0400
commit69ebdef9bdb7f0f4f7bd9b5f30ef0bf687d6c918 (patch)
tree890e3e178a65b0d99ee48512ad5115f68f7f1a80
parent750188dfb35f61f1533f1138d6972b19f36f1a2c (diff)
downloadseabios-69ebdef9bdb7f0f4f7bd9b5f30ef0bf687d6c918.tar.gz
virtio-scsi: enumerate luns with REPORT LUNS
Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
-rw-r--r--src/hw/virtio-scsi.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c
index 5fb9409f..7490ec08 100644
--- a/src/hw/virtio-scsi.c
+++ b/src/hw/virtio-scsi.c
@@ -94,15 +94,11 @@ virtio_scsi_process_op(struct disk_op_s *op)
return DISK_RET_EBADTRACK;
}
-static int
-virtio_scsi_add_lun(struct pci_device *pci, struct vp_device *vp,
- struct vring_virtqueue *vq, u16 target, u16 lun)
+static void
+virtio_scsi_init_lun(struct virtio_lun_s *vlun, struct pci_device *pci,
+ struct vp_device *vp, struct vring_virtqueue *vq,
+ u16 target, u16 lun)
{
- struct virtio_lun_s *vlun = malloc_fseg(sizeof(*vlun));
- if (!vlun) {
- warn_noalloc();
- return -1;
- }
memset(vlun, 0, sizeof(*vlun));
vlun->drive.type = DTYPE_VIRTIO_SCSI;
vlun->drive.cntl_id = pci->bdf;
@@ -111,8 +107,22 @@ virtio_scsi_add_lun(struct pci_device *pci, struct vp_device *vp,
vlun->vq = vq;
vlun->target = target;
vlun->lun = lun;
+}
- int prio = bootprio_find_scsi_device(pci, target, lun);
+static int
+virtio_scsi_add_lun(u32 lun, struct drive_s *tmpl_drv)
+{
+ struct virtio_lun_s *tmpl_vlun =
+ container_of(tmpl_drv, struct virtio_lun_s, drive);
+ struct virtio_lun_s *vlun = malloc_fseg(sizeof(*vlun));
+ if (!vlun) {
+ warn_noalloc();
+ return -1;
+ }
+ virtio_scsi_init_lun(vlun, tmpl_vlun->pci, tmpl_vlun->vp, tmpl_vlun->vq,
+ tmpl_vlun->target, lun);
+
+ int prio = bootprio_find_scsi_device(vlun->pci, vlun->target, vlun->lun);
int ret = scsi_drive_setup(&vlun->drive, "virtio-scsi", prio);
if (ret)
goto fail;
@@ -127,9 +137,13 @@ static int
virtio_scsi_scan_target(struct pci_device *pci, struct vp_device *vp,
struct vring_virtqueue *vq, u16 target)
{
- /* TODO: send REPORT LUNS. For now, only LUN 0 is recognized. */
- int ret = virtio_scsi_add_lun(pci, vp, vq, target, 0);
- return ret < 0 ? 0 : 1;
+
+ struct virtio_lun_s vlun0;
+
+ virtio_scsi_init_lun(&vlun0, pci, vp, vq, target, 0);
+
+ int ret = scsi_rep_luns_scan(&vlun0.drive, virtio_scsi_add_lun);
+ return ret < 0 ? 0 : ret;
}
static void