From: Gonglei <arei.gong...@huawei.com>

Because vhost-scsi module do not support VHOST_SCSI_GET_TPGT
at present, so I use "#if 0" handle it, and set the target
default to 1. In addition, channel and lun both are 0 for
bootable vhost-scsi device.

Signed-off-by: Gonglei <arei.gong...@huawei.com>
Signed-off-by: Bo Su <su...@huawei.com>
---
 hw/scsi/vhost-scsi.c           | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost-scsi.h |  1 +
 2 files changed, 40 insertions(+)

diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index dc9076e..a7cd420 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -201,6 +201,36 @@ static void vhost_dummy_handle_output(VirtIODevice *vdev, 
VirtQueue *vq)
 {
 }
 
+static int vhost_scsi_get_target_id(VHostSCSI *s, Error **errp)
+{
+    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
+    const VhostOps *vhost_ops = s->dev.vhost_ops;
+    struct vhost_scsi_target backend;
+    int ret;
+
+    memset(&backend, 0, sizeof(backend));
+    pstrcpy(backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs->conf.wwpn);
+    ret = vhost_ops->vhost_call(&s->dev, VHOST_SCSI_GET_TPGT, &backend);
+    /* Fixme: wait vhost-scsi module supporting VHOST_SCSI_GET_TPGT */
+#if 0
+    if (ret < 0) {
+        error_setg_errno(errp, -ret,
+                         "vhost-scsi: failed to get the target id");
+        return ret;
+    }
+#elseif
+    if (ret < 0) {
+        error_report("Warning: vhost-scsi failed to get the target id: %s",
+                     strerror(-ret));
+        /* set default target to 1 */
+        backend.vhost_tpgt = 1;
+    }
+#endif
+
+    s->target = backend.vhost_tpgt;
+    return 0;
+}
+
 static void vhost_scsi_realize(DeviceState *dev, Error **errp)
 {
     VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
@@ -251,6 +281,15 @@ static void vhost_scsi_realize(DeviceState *dev, Error 
**errp)
         return;
     }
 
+    /* At present, channel and lun both are 0 for bootable vhost-scsi disk */
+    s->channel = 0;
+    s->lun = 0;
+    if (vhost_scsi_get_target_id(s, &err)) {
+        error_propagate(errp, err);
+        close(vhostfd);
+        return;
+    }
+
     error_setg(&s->migration_blocker,
             "vhost-scsi does not support migration");
     migrate_add_blocker(s->migration_blocker);
diff --git a/include/hw/virtio/vhost-scsi.h b/include/hw/virtio/vhost-scsi.h
index c0056c2..a6bd031 100644
--- a/include/hw/virtio/vhost-scsi.h
+++ b/include/hw/virtio/vhost-scsi.h
@@ -49,6 +49,7 @@ enum vhost_scsi_vq_list {
 #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct 
vhost_scsi_target)
 #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct 
vhost_scsi_target)
 #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
+#define VHOST_SCSI_GET_TPGT _IOW(VHOST_VIRTIO, 0x45, struct vhost_scsi_target)
 
 #define TYPE_VHOST_SCSI "vhost-scsi"
 #define VHOST_SCSI(obj) \
-- 
1.7.12.4



Reply via email to