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

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