diff mbox

[4/4] vhost-scsi: add an ioctl interface to get target id

Message ID 1421673818-11224-5-git-send-email-arei.gonglei@huawei.com
State New
Headers show

Commit Message

Gonglei (Arei) Jan. 19, 2015, 1:23 p.m. UTC
From: Gonglei <arei.gonglei@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.gonglei@huawei.com>
Signed-off-by: Bo Su <subo7@huawei.com>
---
 hw/scsi/vhost-scsi.c           | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/vhost-scsi.h |  1 +
 2 files changed, 40 insertions(+)

Comments

Michael S. Tsirkin Jan. 19, 2015, 9:51 p.m. UTC | #1
On Mon, Jan 19, 2015 at 09:23:38PM +0800, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@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.gonglei@huawei.com>
> Signed-off-by: Bo Su <subo7@huawei.com>

OK but let's see the kernel patch get accepted first.

> ---
>  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
>
Gonglei (Arei) Jan. 26, 2015, 8 a.m. UTC | #2
On 2015/1/20 5:51, Michael S. Tsirkin wrote:

> On Mon, Jan 19, 2015 at 09:23:38PM +0800, arei.gonglei@huawei.com wrote:
>> > From: Gonglei <arei.gonglei@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.gonglei@huawei.com>
>> > Signed-off-by: Bo Su <subo7@huawei.com>
> OK but let's see the kernel patch get accepted first.
> 

Hi, Michael & Paolo

Because Qemu only accept an wwpn argument for vhost-scsi, we
cannot assign a tpgt. That's say tpg is transparent for Qemu, Qemu
doesn't know which tpg can boot, but vhost-scsi driver module
doesn't know too for one assigned wwpn. At present, we assume that
the first tpg can boot only, and add an ioctl to get the first tpgt,
can we? Looking  forward to your reply for any suggestions.

Regards,
-Gonglei
Paolo Bonzini Jan. 26, 2015, 9:32 a.m. UTC | #3
On 26/01/2015 09:00, Gonglei wrote:
> Hi, Michael & Paolo
> 
> Because Qemu only accept an wwpn argument for vhost-scsi, we
> cannot assign a tpgt. That's say tpg is transparent for Qemu, Qemu
> doesn't know which tpg can boot, but vhost-scsi driver module
> doesn't know too for one assigned wwpn. At present, we assume that
> the first tpg can boot only, and add an ioctl to get the first tpgt,
> can we? Looking  forward to your reply for any suggestions.

That's okay, alternatively you could add a boot_tpgt argument that
defaults to 1 (is it correct that 0 is not a valid tpgt?).

Paolo
Gonglei (Arei) Jan. 26, 2015, 12:13 p.m. UTC | #4
On 2015/1/26 17:32, Paolo Bonzini wrote:

> 
> 
> On 26/01/2015 09:00, Gonglei wrote:
>> Hi, Michael & Paolo
>>
>> Because Qemu only accept an wwpn argument for vhost-scsi, we
>> cannot assign a tpgt. That's say tpg is transparent for Qemu, Qemu
>> doesn't know which tpg can boot, but vhost-scsi driver module
>> doesn't know too for one assigned wwpn. At present, we assume that
>> the first tpg can boot only, and add an ioctl to get the first tpgt,
>> can we? Looking  forward to your reply for any suggestions.
> 
> That's okay, alternatively you could add a boot_tpgt argument that
> defaults to 1 (is it correct that 0 is not a valid tpgt?).
> 

No, 0 is the minimize valid value. :)
Paolo, where do you think we should add a boot_tpgt argument?

Regards,
-Gonglei
Paolo Bonzini Jan. 26, 2015, 12:16 p.m. UTC | #5
On 26/01/2015 13:13, Gonglei wrote:
>> > 
>> > That's okay, alternatively you could add a boot_tpgt argument that
>> > defaults to 1 (is it correct that 0 is not a valid tpgt?).
>> > 
> No, 0 is the minimize valid value. :)
> Paolo, where do you think we should add a boot_tpgt argument?

To vhost-scsi-pci.  (Property, not argument).

Paolo
Gonglei (Arei) Jan. 26, 2015, 12:23 p.m. UTC | #6
On 2015/1/26 20:16, Paolo Bonzini wrote:

> 
> 
> On 26/01/2015 13:13, Gonglei wrote:
>>>>
>>>> That's okay, alternatively you could add a boot_tpgt argument that
>>>> defaults to 1 (is it correct that 0 is not a valid tpgt?).
>>>>
>> No, 0 is the minimize valid value. :)
>> Paolo, where do you think we should add a boot_tpgt argument?
> 
> To vhost-scsi-pci.  (Property, not argument).
> 

Got it. Thanks.

BTW, I will send the kernel patch later. :)

Regards,
-Gonglei
diff mbox

Patch

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) \