qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] virtio-scsi: Implement fc_host feature
@ 2017-01-16 16:07 Fam Zheng
  2017-01-16 16:07 ` [Qemu-devel] [PATCH 1/2] manual update linux header for virtio scsi fc_host Fam Zheng
  2017-01-16 16:07 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature Fam Zheng
  0 siblings, 2 replies; 5+ messages in thread
From: Fam Zheng @ 2017-01-16 16:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, stefanha, Michael S. Tsirkin

This implements a WIP feature extention being proposed on virtio-scsi.

We assign a set of Fibre Channel properties, WWNN and WWPN (world wide node
name and port name, respectively) to the device so the virtual device presents
a FC transport in guest. They are useful to identify a host side virtual port
on an FC host, in a NPIV (N_Port ID Virtualization) senario.

The linux driver changes are submitted as:

https://lkml.org/lkml/2017/1/16/439

Fam Zheng (2):
  manual update linux header for virtio scsi fc_host
  virtio-scsi: Implement fc_host feature

 hw/scsi/virtio-scsi.c                        | 60 ++++++++++++++++++++++++++++
 include/hw/virtio/virtio-scsi.h              | 10 +++++
 include/standard-headers/linux/virtio_scsi.h |  6 +++
 3 files changed, 76 insertions(+)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/2] manual update linux header for virtio scsi fc_host
  2017-01-16 16:07 [Qemu-devel] [PATCH 0/2] virtio-scsi: Implement fc_host feature Fam Zheng
@ 2017-01-16 16:07 ` Fam Zheng
  2017-01-16 16:07 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature Fam Zheng
  1 sibling, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2017-01-16 16:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, stefanha, Michael S. Tsirkin

XXX: bring these changes in by syncing once it's added to linux.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 include/standard-headers/linux/virtio_scsi.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/standard-headers/linux/virtio_scsi.h b/include/standard-headers/linux/virtio_scsi.h
index ab66166..b37c395 100644
--- a/include/standard-headers/linux/virtio_scsi.h
+++ b/include/standard-headers/linux/virtio_scsi.h
@@ -113,6 +113,11 @@ struct virtio_scsi_config {
 	uint16_t max_channel;
 	uint16_t max_target;
 	uint32_t max_lun;
+	uint8_t  primary_wwpn[8];
+	uint8_t  primary_wwnn[8];
+	uint8_t  secondary_wwpn[8];
+	uint8_t  secondary_wwnn[8];
+	uint8_t  primary_active;
 } QEMU_PACKED;
 
 /* Feature Bits */
@@ -120,6 +125,7 @@ struct virtio_scsi_config {
 #define VIRTIO_SCSI_F_HOTPLUG                  1
 #define VIRTIO_SCSI_F_CHANGE                   2
 #define VIRTIO_SCSI_F_T10_PI                   3
+#define VIRTIO_SCSI_F_FC_HOST                  4
 
 /* Response codes */
 #define VIRTIO_SCSI_S_OK                       0
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature
  2017-01-16 16:07 [Qemu-devel] [PATCH 0/2] virtio-scsi: Implement fc_host feature Fam Zheng
  2017-01-16 16:07 ` [Qemu-devel] [PATCH 1/2] manual update linux header for virtio scsi fc_host Fam Zheng
@ 2017-01-16 16:07 ` Fam Zheng
  2017-01-17 10:54   ` Stefan Hajnoczi
  1 sibling, 1 reply; 5+ messages in thread
From: Fam Zheng @ 2017-01-16 16:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, stefanha, Michael S. Tsirkin

This patch add qdev properties to allow enabling the fc_host feature of
virtio-scsi, and fill config fields.

For migration, the destination QEMU should be started with the same
wwnn and wwpn, and a inverted primary_active. When migration is done,
the config change interrupt will allow guest to discover the toggling.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 hw/scsi/virtio-scsi.c           | 60 +++++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/virtio-scsi.h | 10 +++++++
 2 files changed, 70 insertions(+)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 204e14f..af9aa77 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -654,6 +654,11 @@ static void virtio_scsi_get_config(VirtIODevice *vdev,
     virtio_stw_p(vdev, &scsiconf->max_channel, VIRTIO_SCSI_MAX_CHANNEL);
     virtio_stw_p(vdev, &scsiconf->max_target, VIRTIO_SCSI_MAX_TARGET);
     virtio_stl_p(vdev, &scsiconf->max_lun, VIRTIO_SCSI_MAX_LUN);
+    virtio_stq_p(vdev, &scsiconf->primary_wwpn, s->conf.primary_wwpn);
+    virtio_stq_p(vdev, &scsiconf->primary_wwnn, s->conf.primary_wwnn);
+    virtio_stq_p(vdev, &scsiconf->secondary_wwpn, s->conf.secondary_wwpn);
+    virtio_stq_p(vdev, &scsiconf->secondary_wwnn, s->conf.secondary_wwnn);
+    scsiconf->primary_active =  s->conf.primary_active;
 }
 
 static void virtio_scsi_set_config(VirtIODevice *vdev,
@@ -868,12 +873,62 @@ void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
     }
 }
 
+static void virtio_scsi_vm_state_change(void *opaque, int running,
+                                        RunState state)
+{
+    VirtIOSCSI *s = opaque;
+    VirtIODevice *vdev = VIRTIO_DEVICE(s);
+
+    if (!running || !s->config_change_pending) {
+        return;
+    }
+    s->config_change_pending = false;
+    virtio_notify_config(vdev);
+}
+
 static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIOSCSI *s = VIRTIO_SCSI(dev);
+    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
     Error *err = NULL;
 
+    if (vs->conf.fc_host) {
+        if (!strcmp(vs->conf.fc_host, "off")) {
+            vs->conf.primary_wwpn = 0;
+            vs->conf.primary_wwnn = 0;
+            vs->conf.secondary_wwpn = 0;
+            vs->conf.secondary_wwnn = 0;
+        } else if (!strcmp(vs->conf.fc_host, "primary") ||
+                   !strcmp(vs->conf.fc_host, "secondary")) {
+            virtio_add_feature(&vdev->host_features, VIRTIO_SCSI_F_FC_HOST);
+            vs->conf.primary_active = !strcmp(vs->conf.fc_host, "primary");
+            if (!vs->conf.primary_wwpn) {
+                error_setg(errp, "fc_host enabled but primary_wwpn not set");
+                return;
+            }
+            if (!vs->conf.primary_wwnn) {
+                error_setg(errp, "fc_host enabled but primary_wwnn not set");
+                return;
+            }
+            if (!vs->conf.secondary_wwpn) {
+                error_setg(errp, "fc_host enabled but secondary_wwpn not set");
+                return;
+            }
+            if (!vs->conf.secondary_wwnn) {
+                error_setg(errp, "fc_host enabled but secondary_wwnn not set");
+                return;
+            }
+            s->vm_state_change =
+                qemu_add_vm_change_state_handler(virtio_scsi_vm_state_change, s);
+            s->config_change_pending = runstate_check(RUN_STATE_INMIGRATE);
+        } else {
+            error_setg(errp, "Invalid fc_host option. "
+                             "Must be 'off', 'primary' or 'secondary'");
+            return;
+        }
+    }
+
     virtio_scsi_common_realize(dev, &err, virtio_scsi_handle_ctrl,
                                virtio_scsi_handle_event,
                                virtio_scsi_handle_cmd);
@@ -932,6 +987,11 @@ static Property virtio_scsi_properties[] = {
                                            VIRTIO_SCSI_F_HOTPLUG, true),
     DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features,
                                                 VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_PROP_UINT64("primary_wwpn", VirtIOSCSI, parent_obj.conf.primary_wwpn, 0),
+    DEFINE_PROP_UINT64("primary_wwnn", VirtIOSCSI, parent_obj.conf.primary_wwnn, 0),
+    DEFINE_PROP_UINT64("secondary_wwpn", VirtIOSCSI, parent_obj.conf.secondary_wwpn, 0),
+    DEFINE_PROP_UINT64("secondary_wwnn", VirtIOSCSI, parent_obj.conf.secondary_wwnn, 0),
+    DEFINE_PROP_STRING("fc_host", VirtIOSCSI, parent_obj.conf.fc_host),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scsi.h
index 7375196..a0eb080 100644
--- a/include/hw/virtio/virtio-scsi.h
+++ b/include/hw/virtio/virtio-scsi.h
@@ -53,6 +53,13 @@ struct VirtIOSCSIConf {
     char *wwpn;
     uint32_t boot_tpgt;
     IOThread *iothread;
+
+    char *fc_host;
+    bool primary_active;
+    uint64_t primary_wwnn;
+    uint64_t primary_wwpn;
+    uint64_t secondary_wwnn;
+    uint64_t secondary_wwpn;
 };
 
 struct VirtIOSCSI;
@@ -83,6 +90,9 @@ typedef struct VirtIOSCSI {
     bool dataplane_stopping;
     bool dataplane_fenced;
     uint32_t host_features;
+
+    bool config_change_pending;
+    VMChangeStateEntry *vm_state_change;
 } VirtIOSCSI;
 
 typedef struct VirtIOSCSIReq {
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature
  2017-01-16 16:07 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature Fam Zheng
@ 2017-01-17 10:54   ` Stefan Hajnoczi
  2017-01-18  0:02     ` Fam Zheng
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2017-01-17 10:54 UTC (permalink / raw)
  To: Fam Zheng; +Cc: qemu-devel, Paolo Bonzini, stefanha, Michael S. Tsirkin

[-- Attachment #1: Type: text/plain, Size: 1801 bytes --]

On Tue, Jan 17, 2017 at 12:07:30AM +0800, Fam Zheng wrote:
>  static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
>  {
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      VirtIOSCSI *s = VIRTIO_SCSI(dev);
> +    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
>      Error *err = NULL;
>  
> +    if (vs->conf.fc_host) {
> +        if (!strcmp(vs->conf.fc_host, "off")) {
> +            vs->conf.primary_wwpn = 0;
> +            vs->conf.primary_wwnn = 0;
> +            vs->conf.secondary_wwpn = 0;
> +            vs->conf.secondary_wwnn = 0;
> +        } else if (!strcmp(vs->conf.fc_host, "primary") ||
> +                   !strcmp(vs->conf.fc_host, "secondary")) {
> +            virtio_add_feature(&vdev->host_features, VIRTIO_SCSI_F_FC_HOST);
> +            vs->conf.primary_active = !strcmp(vs->conf.fc_host, "primary");
> +            if (!vs->conf.primary_wwpn) {
> +                error_setg(errp, "fc_host enabled but primary_wwpn not set");
> +                return;
> +            }
> +            if (!vs->conf.primary_wwnn) {
> +                error_setg(errp, "fc_host enabled but primary_wwnn not set");
> +                return;
> +            }
> +            if (!vs->conf.secondary_wwpn) {
> +                error_setg(errp, "fc_host enabled but secondary_wwpn not set");
> +                return;
> +            }
> +            if (!vs->conf.secondary_wwnn) {
> +                error_setg(errp, "fc_host enabled but secondary_wwnn not set");
> +                return;
> +            }
> +            s->vm_state_change =
> +                qemu_add_vm_change_state_handler(virtio_scsi_vm_state_change, s);

Missing qemu_del_vm_change_state_handler() in .unrealize() and in error
code paths in this function.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature
  2017-01-17 10:54   ` Stefan Hajnoczi
@ 2017-01-18  0:02     ` Fam Zheng
  0 siblings, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2017-01-18  0:02 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, Paolo Bonzini, stefanha, Michael S. Tsirkin

On Tue, 01/17 10:54, Stefan Hajnoczi wrote:
> On Tue, Jan 17, 2017 at 12:07:30AM +0800, Fam Zheng wrote:
> >  static void virtio_scsi_device_realize(DeviceState *dev, Error **errp)
> >  {
> >      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> >      VirtIOSCSI *s = VIRTIO_SCSI(dev);
> > +    VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev);
> >      Error *err = NULL;
> >  
> > +    if (vs->conf.fc_host) {
> > +        if (!strcmp(vs->conf.fc_host, "off")) {
> > +            vs->conf.primary_wwpn = 0;
> > +            vs->conf.primary_wwnn = 0;
> > +            vs->conf.secondary_wwpn = 0;
> > +            vs->conf.secondary_wwnn = 0;
> > +        } else if (!strcmp(vs->conf.fc_host, "primary") ||
> > +                   !strcmp(vs->conf.fc_host, "secondary")) {
> > +            virtio_add_feature(&vdev->host_features, VIRTIO_SCSI_F_FC_HOST);
> > +            vs->conf.primary_active = !strcmp(vs->conf.fc_host, "primary");
> > +            if (!vs->conf.primary_wwpn) {
> > +                error_setg(errp, "fc_host enabled but primary_wwpn not set");
> > +                return;
> > +            }
> > +            if (!vs->conf.primary_wwnn) {
> > +                error_setg(errp, "fc_host enabled but primary_wwnn not set");
> > +                return;
> > +            }
> > +            if (!vs->conf.secondary_wwpn) {
> > +                error_setg(errp, "fc_host enabled but secondary_wwpn not set");
> > +                return;
> > +            }
> > +            if (!vs->conf.secondary_wwnn) {
> > +                error_setg(errp, "fc_host enabled but secondary_wwnn not set");
> > +                return;
> > +            }
> > +            s->vm_state_change =
> > +                qemu_add_vm_change_state_handler(virtio_scsi_vm_state_change, s);
> 
> Missing qemu_del_vm_change_state_handler() in .unrealize() and in error
> code paths in this function.

Will fix it. Thanks!

Fam

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-18  0:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-16 16:07 [Qemu-devel] [PATCH 0/2] virtio-scsi: Implement fc_host feature Fam Zheng
2017-01-16 16:07 ` [Qemu-devel] [PATCH 1/2] manual update linux header for virtio scsi fc_host Fam Zheng
2017-01-16 16:07 ` [Qemu-devel] [PATCH 2/2] virtio-scsi: Implement fc_host feature Fam Zheng
2017-01-17 10:54   ` Stefan Hajnoczi
2017-01-18  0:02     ` Fam Zheng

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