Blame SOURCES/0123-libmultipath-get-nvme-path-transport-protocol.patch

1595c1
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
1595c1
From: Benjamin Marzinski <bmarzins@redhat.com>
1595c1
Date: Fri, 7 Oct 2022 12:35:43 -0500
1595c1
Subject: [PATCH] libmultipath: get nvme path transport protocol
1595c1
1595c1
Read the transport protocol from /sys/block/nvmeXnY/device/transport.
1595c1
Update protocol_name[] and bus_protocol_id() to store the nvme protocol
1595c1
names after the scsi protocol names.
1595c1
1595c1
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
1595c1
Reviewed-by: Martin Wilck <mwilck@suse.com>
1595c1
---
1595c1
 libmultipath/discovery.c   | 18 ++++++++++++++++--
1595c1
 libmultipath/structs.c     | 22 +++++++++++++++++-----
1595c1
 libmultipath/structs.h     | 33 +++++++++++++++++++++------------
1595c1
 multipath/multipath.conf.5 | 10 +++++++---
1595c1
 4 files changed, 61 insertions(+), 22 deletions(-)
1595c1
1595c1
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
1595c1
index 5f4e0794..eb7a634b 100644
1595c1
--- a/libmultipath/discovery.c
1595c1
+++ b/libmultipath/discovery.c
1595c1
@@ -1455,6 +1455,7 @@ nvme_sysfs_pathinfo (struct path * pp, vector hwtable)
1595c1
 	struct udev_device *parent;
1595c1
 	const char *attr_path = NULL;
1595c1
 	const char *attr;
1595c1
+	int i;
1595c1
 
1595c1
 	attr_path = udev_device_get_sysname(pp->udev);
1595c1
 	if (!attr_path)
1595c1
@@ -1476,6 +1477,18 @@ nvme_sysfs_pathinfo (struct path * pp, vector hwtable)
1595c1
 	attr = udev_device_get_sysattr_value(parent, "cntlid");
1595c1
 	pp->sg_id.channel = attr ? atoi(attr) : 0;
1595c1
 
1595c1
+	attr = udev_device_get_sysattr_value(parent, "transport");
1595c1
+	if (attr) {
1595c1
+		for (i = 0; i < NVME_PROTOCOL_UNSPEC; i++){
1595c1
+			if (protocol_name[SYSFS_BUS_NVME + i] &&
1595c1
+			    !strcmp(attr,
1595c1
+				    protocol_name[SYSFS_BUS_NVME + i] + 5)) {
1595c1
+				pp->sg_id.proto_id = i;
1595c1
+				break;
1595c1
+			}
1595c1
+		}
1595c1
+	}
1595c1
+
1595c1
 	snprintf(pp->vendor_id, SCSI_VENDOR_SIZE, "NVME");
1595c1
 	snprintf(pp->product_id, PATH_PRODUCT_SIZE, "%s",
1595c1
 		 udev_device_get_sysattr_value(parent, "model"));
1595c1
@@ -1727,9 +1740,10 @@ sysfs_pathinfo(struct path * pp, vector hwtable)
1595c1
 		pp->bus = SYSFS_BUS_SCSI;
1595c1
 		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
1595c1
 	}
1595c1
-	if (!strncmp(pp->dev,"nvme", 4))
1595c1
+	if (!strncmp(pp->dev,"nvme", 4)) {
1595c1
 		pp->bus = SYSFS_BUS_NVME;
1595c1
-
1595c1
+		pp->sg_id.proto_id = NVME_PROTOCOL_UNSPEC;
1595c1
+	}
1595c1
 	switch (pp->bus) {
1595c1
 	case SYSFS_BUS_SCSI:
1595c1
 		return scsi_sysfs_pathinfo(pp, hwtable);
1595c1
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
1595c1
index 1122cfae..7bdf9152 100644
1595c1
--- a/libmultipath/structs.c
1595c1
+++ b/libmultipath/structs.c
1595c1
@@ -25,7 +25,6 @@ const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
1595c1
 	[SYSFS_BUS_UNDEF] = "undef",
1595c1
 	[SYSFS_BUS_CCW] = "ccw",
1595c1
 	[SYSFS_BUS_CCISS] = "cciss",
1595c1
-	[SYSFS_BUS_NVME] = "nvme",
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP] = "scsi:fcp",
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SPI] = "scsi:spi",
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SSA] = "scsi:ssa",
1595c1
@@ -37,6 +36,13 @@ const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ATA] = "scsi:ata",
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_USB] = "scsi:usb",
1595c1
 	[SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC] = "scsi:unspec",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_PCIE] = "nvme:pcie",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_RDMA] = "nvme:rdma",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_FC] = "nvme:fc",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_TCP] = "nvme:tcp",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_LOOP] = "nvme:loop",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_APPLE_NVME] = "nvme:apple-nvme",
1595c1
+	[SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC] = "nvme:unspec",
1595c1
 };
1595c1
 
1595c1
 struct adapter_group *
1595c1
@@ -716,11 +722,17 @@ out:
1595c1
 }
1595c1
 
1595c1
 unsigned int bus_protocol_id(const struct path *pp) {
1595c1
-	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
1595c1
+	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_NVME)
1595c1
 		return SYSFS_BUS_UNDEF;
1595c1
-	if (pp->bus != SYSFS_BUS_SCSI)
1595c1
+	if (pp->bus != SYSFS_BUS_SCSI && pp->bus != SYSFS_BUS_NVME)
1595c1
 		return pp->bus;
1595c1
-	if ((int)pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
1595c1
+	if (pp->sg_id.proto_id < 0)
1595c1
 		return SYSFS_BUS_UNDEF;
1595c1
-	return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
1595c1
+	if (pp->bus == SYSFS_BUS_SCSI &&
1595c1
+	    pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
1595c1
+		return SYSFS_BUS_UNDEF;
1595c1
+	if (pp->bus == SYSFS_BUS_NVME &&
1595c1
+	    pp->sg_id.proto_id > NVME_PROTOCOL_UNSPEC)
1595c1
+		return SYSFS_BUS_UNDEF;
1595c1
+	return pp->bus + pp->sg_id.proto_id;
1595c1
 }
1595c1
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
1595c1
index 960ea024..9130efb5 100644
1595c1
--- a/libmultipath/structs.h
1595c1
+++ b/libmultipath/structs.h
1595c1
@@ -57,15 +57,6 @@ enum failback_mode {
1595c1
 	FAILBACK_FOLLOWOVER
1595c1
 };
1595c1
 
1595c1
-/* SYSFS_BUS_SCSI should be last, see bus_protocol_id() */
1595c1
-enum sysfs_buses {
1595c1
-	SYSFS_BUS_UNDEF,
1595c1
-	SYSFS_BUS_CCW,
1595c1
-	SYSFS_BUS_CCISS,
1595c1
-	SYSFS_BUS_NVME,
1595c1
-	SYSFS_BUS_SCSI,
1595c1
-};
1595c1
-
1595c1
 enum pathstates {
1595c1
 	PSTATE_UNDEF,
1595c1
 	PSTATE_FAILED,
1595c1
@@ -207,14 +198,32 @@ enum scsi_protocol {
1595c1
 	SCSI_PROTOCOL_ATA = 8,
1595c1
 	SCSI_PROTOCOL_USB = 9,  /* USB Attached SCSI (UAS), and others */
1595c1
 	SCSI_PROTOCOL_UNSPEC = 0xa, /* No specific protocol */
1595c1
+	SCSI_PROTOCOL_END = 0xb, /* offset of the next sysfs_buses entry */
1595c1
+};
1595c1
+
1595c1
+/* values from /sys/class/nvme/nvmeX */
1595c1
+enum nvme_protocol {
1595c1
+	NVME_PROTOCOL_PCIE = 0,
1595c1
+	NVME_PROTOCOL_RDMA = 1,
1595c1
+	NVME_PROTOCOL_FC = 2,
1595c1
+	NVME_PROTOCOL_TCP = 3,
1595c1
+	NVME_PROTOCOL_LOOP = 4,
1595c1
+	NVME_PROTOCOL_APPLE_NVME = 5,
1595c1
+	NVME_PROTOCOL_UNSPEC = 6, /* unknown protocol */
1595c1
+};
1595c1
+
1595c1
+enum sysfs_buses {
1595c1
+	SYSFS_BUS_UNDEF,
1595c1
+	SYSFS_BUS_CCW,
1595c1
+	SYSFS_BUS_CCISS,
1595c1
+	SYSFS_BUS_SCSI,
1595c1
+	SYSFS_BUS_NVME = SYSFS_BUS_SCSI + SCSI_PROTOCOL_END,
1595c1
 };
1595c1
 
1595c1
 /*
1595c1
  * Linear ordering of bus/protocol
1595c1
- * This assumes that SYSFS_BUS_SCSI is last in enum sysfs_buses
1595c1
- * SCSI is the only bus type for which we distinguish protocols.
1595c1
  */
1595c1
-#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC)
1595c1
+#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_NVME + NVME_PROTOCOL_UNSPEC)
1595c1
 unsigned int bus_protocol_id(const struct path *pp);
1595c1
 extern const char * const protocol_name[];
1595c1
 
1595c1
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
1595c1
index 61d2712b..1f5a40b6 100644
1595c1
--- a/multipath/multipath.conf.5
1595c1
+++ b/multipath/multipath.conf.5
1595c1
@@ -1369,7 +1369,9 @@ Regular expression for the protocol of a device to be excluded/included.
1595c1
 The protocol strings that multipath recognizes are \fIscsi:fcp\fR,
1595c1
 \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR,
1595c1
 \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR,
1595c1
-\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR.
1595c1
+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR,
1595c1
+\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
1595c1
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR.
1595c1
 The protocol that a path is using can be viewed by running
1595c1
 \fBmultipathd show paths format "%d %P"\fR
1595c1
 .RE
1595c1
@@ -1757,8 +1759,10 @@ The protocol subsection recognizes the following mandatory attribute:
1595c1
 The protocol string of the path device. The possible values are \fIscsi:fcp\fR,
1595c1
 \fIscsi:spi\fR, \fIscsi:ssa\fR, \fIscsi:sbp\fR, \fIscsi:srp\fR,
1595c1
 \fIscsi:iscsi\fR, \fIscsi:sas\fR, \fIscsi:adt\fR, \fIscsi:ata\fR,
1595c1
-\fIscsi:unspec\fR, \fIccw\fR, \fIcciss\fR, \fInvme\fR, and \fIundef\fR. This is
1595c1
-\fBnot\fR a regular expression. the path device protcol string must match
1595c1
+\fIscsi:unspec\fR, \fInvme:pcie\fR, \fInvme:rdma\fR, \fInvme:fc\fR,
1595c1
+\fInvme:tcp\fR, \fInvme:loop\fR, \fInvme:apple-nvme\fR, \fInvme:unspec\fR,
1595c1
+\fIccw\fR, \fIcciss\fR, and \fIundef\fR. This is
1595c1
+\fBnot\fR a regular expression. the path device protocol string must match
1595c1
 exactly. The protocol that a path is using can be viewed by running
1595c1
 \fBmultipathd show paths format "%d %P"\fR
1595c1
 .LP