Skip to contentSkip to conversation

virtio-scsi: Implement FC_HOST feature

PATCH In review Fam Zheng 5 participants 10 messages Jan 26, 2017 – Jan 27, 2017

Subsystems (3)
lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

v2 cover virtio-scsi: Implement FC_HOST feature

v2: Fix endianness of WWNN/WWPN. [Paolo]

This series implements the proposed fc_host feature of virtio-scsi.

The first patch updates the data structure changes according to the spec proposal; the second patch actually implements the operations.

Fam Zheng (2):
virtio_scsi: Add fc_host definitions
virtio_scsi: Implement fc_host

 drivers/scsi/virtio_scsi.c       | 60 +++++++++++++++++++++++++++++++++++++++-
 include/uapi/linux/virtio_scsi.h |  6 ++++
 2 files changed, 65 insertions(+), 1 deletion(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH v2 1/2 virtio_scsi: Add fc_host definitions

---
 include/uapi/linux/virtio_scsi.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/linux/virtio_scsi.h +6 -0
index cc18ef8..a26fb31 100644
@@ -113,6 +113,11 @@ struct virtio_scsi_config {
 	__u16 max_channel;
 	__u16 max_target;
 	__u32 max_lun;
+	__u8  primary_wwpn[8];
+	__u8  primary_wwnn[8];
+	__u8  secondary_wwpn[8];
+	__u8  secondary_wwnn[8];
+	__u8  primary_active;
 } __attribute__((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
Signature · 1 line
2.9.3
author
#3 lore raw

PATCH v2 1/2 virtio_scsi: Add fc_host definitions

In reply to Fam Zheng
---
 include/uapi/linux/virtio_scsi.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/linux/virtio_scsi.h +6 -0
index cc18ef8..a26fb31 100644
@@ -113,6 +113,11 @@ struct virtio_scsi_config {
 	__u16 max_channel;
 	__u16 max_target;
 	__u32 max_lun;
+	__u8  primary_wwpn[8];
+	__u8  primary_wwnn[8];
+	__u8  secondary_wwpn[8];
+	__u8  secondary_wwnn[8];
+	__u8  primary_active;
 } __attribute__((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
Signature · 1 line
2.9.3
author
#4 lore raw

PATCH v2 2/2 virtio_scsi: Implement fc_host

In reply to Fam Zheng

This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration.

---
 drivers/scsi/virtio_scsi.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
drivers/scsi/virtio_scsi.c +59 -1
index ec91bd0..1bb330c 100644
@@ -28,6 +28,7 @@
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_tcq.h>
+#include <scsi/scsi_transport_fc.h>
 #include <linux/seqlock.h>
 
 #define VIRTIO_SCSI_MEMPOOL_SZ 64
@@ -795,6 +796,15 @@ static struct scsi_host_template virtscsi_host_template_multi = {
 	.track_queue_depth = 1,
 };
 
+static struct fc_function_template virtscsi_fc_template = {
+	.show_host_node_name = 1,
+	.show_host_port_name = 1,
+	.show_host_port_type = 1,
+	.show_host_port_state = 1,
+};
+
+static struct scsi_transport_template *virtscsi_fc_transport_template;
+
 #define virtscsi_config_get(vdev, fld) \
 	({ \
 		typeof(((struct virtio_scsi_config *)0)->fld) __val; \
@@ -956,15 +966,42 @@ static int virtscsi_init(struct virtio_device *vdev,
 	return err;
 }
 
+static void virtscsi_update_fc_host_attrs(struct virtio_device *vdev)
+{
+	struct Scsi_Host *shost = vdev->priv;
+	u8 node_name[8], port_name[8];
+
+	if (virtscsi_config_get(vdev, primary_active)) {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, primary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, primary_wwpn),
+			&port_name, 8);
+	} else {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwpn),
+			&port_name, 8);
+	}
+	fc_host_node_name(shost) = wwn_to_u64(node_name);
+	fc_host_port_name(shost) = wwn_to_u64(port_name);
+	fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
+	fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
+}
+
 static int virtscsi_probe(struct virtio_device *vdev)
 {
-	struct Scsi_Host *shost;
+	struct Scsi_Host *shost = NULL;
 	struct virtio_scsi *vscsi;
 	int err;
 	u32 sg_elems, num_targets;
 	u32 cmd_per_lun;
 	u32 num_queues;
 	struct scsi_host_template *hostt;
+	bool fc_host_enabled;
 
 	if (!vdev->config->get) {
 		dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -987,6 +1024,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (!shost)
 		return -ENOMEM;
 
+	fc_host_enabled = virtio_has_feature(vdev, VIRTIO_SCSI_F_FC_HOST);
+	if (fc_host_enabled)
+		shost->transportt = virtscsi_fc_transport_template;
 	sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1;
 	shost->sg_tablesize = sg_elems;
 	vscsi = shost_priv(shost);
@@ -1032,6 +1072,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (err)
 		goto scsi_add_host_failed;
 
+	if (fc_host_enabled)
+		virtscsi_update_fc_host_attrs(vdev);
+
 	virtio_device_ready(vdev);
 
 	if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG))
@@ -1098,6 +1141,11 @@ static int virtscsi_restore(struct virtio_device *vdev)
 }
 #endif
 
+static void virtscsi_config_changed(struct virtio_device *vdev)
+{
+	virtscsi_update_fc_host_attrs(vdev);
+}
+
 static struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_SCSI, VIRTIO_DEV_ANY_ID },
 	{ 0 },
@@ -1109,6 +1157,7 @@ static unsigned int features[] = {
 #ifdef CONFIG_BLK_DEV_INTEGRITY
 	VIRTIO_SCSI_F_T10_PI,
 #endif
+	VIRTIO_SCSI_F_FC_HOST,
 };
 
 static struct virtio_driver virtio_scsi_driver = {
@@ -1123,12 +1172,20 @@ static struct virtio_driver virtio_scsi_driver = {
 	.restore = virtscsi_restore,
 #endif
 	.remove = virtscsi_remove,
+	.config_changed = virtscsi_config_changed,
 };
 
 static int __init init(void)
 {
 	int ret = -ENOMEM;
 
+	virtscsi_fc_transport_template =
+		fc_attach_transport(&virtscsi_fc_template);
+	if (!virtscsi_fc_transport_template) {
+		pr_err("fc_attach_transport() failed\n");
+		goto error;
+	}
+
 	virtscsi_cmd_cache = KMEM_CACHE(virtio_scsi_cmd, 0);
 	if (!virtscsi_cmd_cache) {
 		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
@@ -1176,6 +1233,7 @@ static int __init init(void)
 
 static void __exit fini(void)
 {
+	fc_release_transport(virtscsi_fc_transport_template);
 	unregister_virtio_driver(&virtio_scsi_driver);
 	cpuhp_remove_multi_state(virtioscsi_online);
 	cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD);
Signature · 1 line
2.9.3
#5 lore raw

Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

Quoted 4 lines · Fam Zheng

This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration.

This needs a way, way better description on why the heck we would even bother with something odd like this.

Also please coordinate with Cathy's "lightweight" FC attrs for storsvcs as the code seems to be clearly following the "lead" set by Hyper-V.

#6 lore raw

Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

In reply to Fam Zheng
Quoted 4 lines · Fam Zheng

This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration.

This needs a way, way better description on why the heck we would even bother with something odd like this.

Also please coordinate with Cathy's "lightweight" FC attrs for storsvcs as the code seems to be clearly following the "lead" set by Hyper-V.

#7 lore raw

Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

In reply to Fam Zheng
url: https://github.com/0day-ci/linux/commits/Fam-Zheng/virtio-scsi-Implement-FC_HOST-feature/20170126-114655 config: i386-randconfig-h0-01261251 (attached as .config) compiler: gcc-6 (Debian…

Hi Fam,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.10-rc5 next-20170125]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Fam-Zheng/virtio-scsi-Implement-FC_HOST-feature/20170126-114655
config: i386-randconfig-h0-01261251 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "fc_release_transport" [drivers/scsi/virtio_scsi.ko] undefined!
>> ERROR: "fc_attach_transport" [drivers/scsi/virtio_scsi.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#2 lore raw

Re: [PATCH v2 1/2] virtio_scsi: Add fc_host definitions

In reply to Fam Zheng
Quoted 2 lines · Fam Zheng

---

I pefer combining this with implementation,
hard to reason about interface alone.

Quoted 8 lines
 include/uapi/linux/virtio_scsi.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/uapi/linux/virtio_scsi.h +0 -0
index cc18ef8..a26fb31 100644

include/uapi/linux/virtio_scsi.h struct virtio_scsi_config { · line 120

Quoted 8 lines
include/uapi/linux/virtio_scsi.h +5 -0
@@ -113,6 +113,11 @@ struct virtio_scsi_config {
 	__u16 max_channel;
 	__u16 max_target;
 	__u32 max_lun;
+	__u8  primary_wwpn[8];
+	__u8  primary_wwnn[8];
+	__u8  secondary_wwpn[8];
+	__u8  secondary_wwnn[8];
+	__u8  primary_active;

Is this in fact a binary value?
Also pls add padding to align on 8 byte boundary.

Quoted 13 lines
include/uapi/linux/virtio_scsi.h +1 -0
 } __attribute__((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
Signature · 1 line
2.9.3
#8 lore raw

Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

In reply to Fam Zheng
Quoted 4 lines · Fam Zheng

This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration.

Looks like there's active discussion on virtio tc mailing list. It's ok to post patches meanwhile but best as RFC, and repost after controversy is resolved.

Quoted 48 lines
---
 drivers/scsi/virtio_scsi.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
drivers/scsi/virtio_scsi.c +20 -0
index ec91bd0..1bb330c 100644
@@ -28,6 +28,7 @@
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_tcq.h>
+#include <scsi/scsi_transport_fc.h>
 #include <linux/seqlock.h>
 
 #define VIRTIO_SCSI_MEMPOOL_SZ 64
@@ -795,6 +796,15 @@ static struct scsi_host_template virtscsi_host_template_multi = {
 	.track_queue_depth = 1,
 };
 
+static struct fc_function_template virtscsi_fc_template = {
+	.show_host_node_name = 1,
+	.show_host_port_name = 1,
+	.show_host_port_type = 1,
+	.show_host_port_state = 1,
+};
+
+static struct scsi_transport_template *virtscsi_fc_transport_template;
+
 #define virtscsi_config_get(vdev, fld) \
 	({ \
 		typeof(((struct virtio_scsi_config *)0)->fld) __val; \
@@ -956,15 +966,42 @@ static int virtscsi_init(struct virtio_device *vdev,
 	return err;
 }
 
+static void virtscsi_update_fc_host_attrs(struct virtio_device *vdev)
+{
+	struct Scsi_Host *shost = vdev->priv;
+	u8 node_name[8], port_name[8];
+
+	if (virtscsi_config_get(vdev, primary_active)) {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, primary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,

drivers/scsi/virtio_scsi.c static int virtscsi_init(struct virtio_device *vdev, · line 988

Quoted 10 lines
drivers/scsi/virtio_scsi.c +10 -0
+			offsetof(struct virtio_scsi_config, primary_wwpn),
+			&port_name, 8);
+	} else {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwpn),
+			&port_name, 8);
+	}

This is racy, isn't it? You need to wrap this in a generation check otherwise read can race with primary_active changing. And you might want a wrapper to virtio_cread_bytes that does not include generation check.

Quoted 41 lines
drivers/scsi/virtio_scsi.c +14 -1
+	fc_host_node_name(shost) = wwn_to_u64(node_name);
+	fc_host_port_name(shost) = wwn_to_u64(port_name);
+	fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
+	fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
+}
+
 static int virtscsi_probe(struct virtio_device *vdev)
 {
-	struct Scsi_Host *shost;
+	struct Scsi_Host *shost = NULL;
 	struct virtio_scsi *vscsi;
 	int err;
 	u32 sg_elems, num_targets;
 	u32 cmd_per_lun;
 	u32 num_queues;
 	struct scsi_host_template *hostt;
+	bool fc_host_enabled;
 
 	if (!vdev->config->get) {
 		dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -987,6 +1024,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (!shost)
 		return -ENOMEM;
 
+	fc_host_enabled = virtio_has_feature(vdev, VIRTIO_SCSI_F_FC_HOST);
+	if (fc_host_enabled)
+		shost->transportt = virtscsi_fc_transport_template;
 	sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1;
 	shost->sg_tablesize = sg_elems;
 	vscsi = shost_priv(shost);
@@ -1032,6 +1072,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (err)
 		goto scsi_add_host_failed;
 
+	if (fc_host_enabled)
+		virtscsi_update_fc_host_attrs(vdev);
+
 	virtio_device_ready(vdev);
 
 	if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG))

drivers/scsi/virtio_scsi.c static int virtscsi_restore(struct virtio_device *vdev) · line 1145

Quoted 5 lines
drivers/scsi/virtio_scsi.c +2 -0
@@ -1098,6 +1141,11 @@ static int virtscsi_restore(struct virtio_device *vdev)
 }
 #endif
 
+static void virtscsi_config_changed(struct virtio_device *vdev)
+{

This is called unconditionally here, will access invalid config fields if feature is off.
In fact this is wasting an MSIX vector when feature is not negotiated. No easy way not to, but best document this in a code comment.

Quoted 45 lines
drivers/scsi/virtio_scsi.c +13 -0
+	virtscsi_update_fc_host_attrs(vdev);
+}
+
 static struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_SCSI, VIRTIO_DEV_ANY_ID },
 	{ 0 },
@@ -1109,6 +1157,7 @@ static unsigned int features[] = {
 #ifdef CONFIG_BLK_DEV_INTEGRITY
 	VIRTIO_SCSI_F_T10_PI,
 #endif
+	VIRTIO_SCSI_F_FC_HOST,
 };
 
 static struct virtio_driver virtio_scsi_driver = {
@@ -1123,12 +1172,20 @@ static struct virtio_driver virtio_scsi_driver = {
 	.restore = virtscsi_restore,
 #endif
 	.remove = virtscsi_remove,
+	.config_changed = virtscsi_config_changed,
 };
 
 static int __init init(void)
 {
 	int ret = -ENOMEM;
 
+	virtscsi_fc_transport_template =
+		fc_attach_transport(&virtscsi_fc_template);
+	if (!virtscsi_fc_transport_template) {
+		pr_err("fc_attach_transport() failed\n");
+		goto error;
+	}
+
 	virtscsi_cmd_cache = KMEM_CACHE(virtio_scsi_cmd, 0);
 	if (!virtscsi_cmd_cache) {
 		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
@@ -1176,6 +1233,7 @@ static int __init init(void)
 
 static void __exit fini(void)
 {
+	fc_release_transport(virtscsi_fc_transport_template);
 	unregister_virtio_driver(&virtio_scsi_driver);
 	cpuhp_remove_multi_state(virtioscsi_online);
 	cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD);
Signature · 1 line
2.9.3
reviewer
#9 lore raw

Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

----- Original Message -----

Quoted 9 lines

From: "Michael S. Tsirkin" <[email protected]>
To: "Fam Zheng" <[email protected]>
Cc: [email protected], "Paolo Bonzini" <[email protected]>, [email protected], "James E.J. Bottomley" <[email protected]>, "Jason Wang" <[email protected]>, "Martin K. Petersen" <[email protected]>, [email protected], [email protected]
Sent: Thursday, January 26, 2017 11:06:27 PM
Subject: Re: [PATCH v2 2/2] virtio_scsi: Implement fc_host

On Thu, Jan 26, 2017 at 11:41:09AM +0800, Fam Zheng wrote:

Quoted 8 lines
Quoted 4 lines

This implements the VIRTIO_SCSI_F_FC_HOST feature by reading the config fields and presenting them as sysfs fc_host attributes. The config change handler is added here because primary_active will toggle during migration.

Looks like there's active discussion on virtio tc mailing list. It's ok to post patches meanwhile but best as RFC, and repost after controversy is resolved.

Discussion on the TC mailing list was not about the merit of the feature, only about the timing of the vote.

Paolo

Quoted 167 lines
Quoted 51 lines
---
 drivers/scsi/virtio_scsi.c | 60
 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
drivers/scsi/virtio_scsi.c +10 -0
index ec91bd0..1bb330c 100644
@@ -28,6 +28,7 @@
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_tcq.h>
+#include <scsi/scsi_transport_fc.h>
 #include <linux/seqlock.h>
 
 #define VIRTIO_SCSI_MEMPOOL_SZ 64
@@ -795,6 +796,15 @@ static struct scsi_host_template
 virtscsi_host_template_multi = {
 	.track_queue_depth = 1,
 };
 
+static struct fc_function_template virtscsi_fc_template = {
+	.show_host_node_name = 1,
+	.show_host_port_name = 1,
+	.show_host_port_type = 1,
+	.show_host_port_state = 1,
+};
+
+static struct scsi_transport_template *virtscsi_fc_transport_template;
+
 #define virtscsi_config_get(vdev, fld) \
 	({ \
drivers/scsi/virtio_scsi.c +10 -0
 		typeof(((struct virtio_scsi_config *)0)->fld) __val; \
@@ -956,15 +966,42 @@ static int virtscsi_init(struct virtio_device *vdev,
 	return err;
 }
 
+static void virtscsi_update_fc_host_attrs(struct virtio_device *vdev)
+{
+	struct Scsi_Host *shost = vdev->priv;
+	u8 node_name[8], port_name[8];
+
+	if (virtscsi_config_get(vdev, primary_active)) {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, primary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,

drivers/scsi/virtio_scsi.c static int virtscsi_init(struct virtio_device *vdev, · line 988

Quoted 10 lines
drivers/scsi/virtio_scsi.c +10 -0
+			offsetof(struct virtio_scsi_config, primary_wwpn),
+			&port_name, 8);
+	} else {
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwnn),
+			&node_name, 8);
+		virtio_cread_bytes(vdev,
+			offsetof(struct virtio_scsi_config, secondary_wwpn),
+			&port_name, 8);
+	}

This is racy, isn't it? You need to wrap this in a generation check otherwise read can race with primary_active changing. And you might want a wrapper to virtio_cread_bytes that does not include generation check.

Quoted 41 lines
drivers/scsi/virtio_scsi.c +14 -1
+	fc_host_node_name(shost) = wwn_to_u64(node_name);
+	fc_host_port_name(shost) = wwn_to_u64(port_name);
+	fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
+	fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
+}
+
 static int virtscsi_probe(struct virtio_device *vdev)
 {
-	struct Scsi_Host *shost;
+	struct Scsi_Host *shost = NULL;
 	struct virtio_scsi *vscsi;
 	int err;
 	u32 sg_elems, num_targets;
 	u32 cmd_per_lun;
 	u32 num_queues;
 	struct scsi_host_template *hostt;
+	bool fc_host_enabled;
 
 	if (!vdev->config->get) {
 		dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -987,6 +1024,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (!shost)
 		return -ENOMEM;
 
+	fc_host_enabled = virtio_has_feature(vdev, VIRTIO_SCSI_F_FC_HOST);
+	if (fc_host_enabled)
+		shost->transportt = virtscsi_fc_transport_template;
 	sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1;
 	shost->sg_tablesize = sg_elems;
 	vscsi = shost_priv(shost);
@@ -1032,6 +1072,9 @@ static int virtscsi_probe(struct virtio_device *vdev)
 	if (err)
 		goto scsi_add_host_failed;
 
+	if (fc_host_enabled)
+		virtscsi_update_fc_host_attrs(vdev);
+
 	virtio_device_ready(vdev);
 
 	if (virtio_has_feature(vdev, VIRTIO_SCSI_F_HOTPLUG))

drivers/scsi/virtio_scsi.c static int virtscsi_restore(struct virtio_device · line 1146

Quoted 6 lines
drivers/scsi/virtio_scsi.c +2 -0
@@ -1098,6 +1141,11 @@ static int virtscsi_restore(struct virtio_device
 *vdev)
 }
 #endif
 
+static void virtscsi_config_changed(struct virtio_device *vdev)
+{

This is called unconditionally here, will access invalid config fields if feature is off.
In fact this is wasting an MSIX vector when feature is not negotiated. No easy way not to, but best document this in a code comment.

Quoted 45 lines
drivers/scsi/virtio_scsi.c +3 -0
+	virtscsi_update_fc_host_attrs(vdev);
+}
+
 static struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_SCSI, VIRTIO_DEV_ANY_ID },
drivers/scsi/virtio_scsi.c +10 -1
 	{ 0 },
@@ -1109,6 +1157,7 @@ static unsigned int features[] = {
 #ifdef CONFIG_BLK_DEV_INTEGRITY
 	VIRTIO_SCSI_F_T10_PI,
 #endif
+	VIRTIO_SCSI_F_FC_HOST,
 };
 
 static struct virtio_driver virtio_scsi_driver = {
@@ -1123,12 +1172,20 @@ static struct virtio_driver virtio_scsi_driver = {
 	.restore = virtscsi_restore,
 #endif
 	.remove = virtscsi_remove,
+	.config_changed = virtscsi_config_changed,
 };
 
 static int __init init(void)
 {
 	int ret = -ENOMEM;
 
+	virtscsi_fc_transport_template =
+		fc_attach_transport(&virtscsi_fc_template);
+	if (!virtscsi_fc_transport_template) {
+		pr_err("fc_attach_transport() failed\n");
+		goto error;
+	}
+
 	virtscsi_cmd_cache = KMEM_CACHE(virtio_scsi_cmd, 0);
 	if (!virtscsi_cmd_cache) {
 		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
@@ -1176,6 +1233,7 @@ static int __init init(void)
 
 static void __exit fini(void)
 {
+	fc_release_transport(virtscsi_fc_transport_template);
 	unregister_virtio_driver(&virtio_scsi_driver);
 	cpuhp_remove_multi_state(virtioscsi_online);
 	cpuhp_remove_multi_state(CPUHP_VIRT_SCSI_DEAD);
--

2.9.3