Blame SOURCES/0122-libmultipath-prepare-proto_id-for-use-by-non-scsi-de.patch

8b67ad
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8b67ad
From: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Date: Fri, 7 Oct 2022 12:35:42 -0500
8b67ad
Subject: [PATCH] libmultipath: prepare proto_id for use by non-scsi devivces
8b67ad
8b67ad
Make sure that when we are checking for a scsi protocol, we are first
8b67ad
checking that we are working with a scsi path.
8b67ad
8b67ad
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Reviewed-by: Martin Wilck <mwilck@suse.com>
8b67ad
---
8b67ad
 libmultipath/configure.c   |  9 +++++----
8b67ad
 libmultipath/discovery.c   | 13 ++++++++-----
8b67ad
 libmultipath/print.c       |  6 ++++--
8b67ad
 libmultipath/structs.c     |  2 +-
8b67ad
 libmultipath/structs.h     |  4 +++-
8b67ad
 multipathd/fpin_handlers.c |  2 +-
8b67ad
 6 files changed, 22 insertions(+), 14 deletions(-)
8b67ad
8b67ad
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
8b67ad
index 287289f7..8e1bc488 100644
8b67ad
--- a/libmultipath/configure.c
8b67ad
+++ b/libmultipath/configure.c
8b67ad
@@ -223,10 +223,11 @@ int rr_optimize_path_order(struct pathgroup *pgp)
8b67ad
 
8b67ad
 	total_paths = VECTOR_SIZE(pgp->paths);
8b67ad
 	vector_foreach_slot(pgp->paths, pp, i) {
8b67ad
-		if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP &&
8b67ad
-			pp->sg_id.proto_id != SCSI_PROTOCOL_SAS &&
8b67ad
-			pp->sg_id.proto_id != SCSI_PROTOCOL_ISCSI &&
8b67ad
-			pp->sg_id.proto_id != SCSI_PROTOCOL_SRP) {
8b67ad
+		if (pp->bus != SYSFS_BUS_SCSI ||
8b67ad
+		    (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP &&
8b67ad
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_SAS &&
8b67ad
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_ISCSI &&
8b67ad
+		     pp->sg_id.proto_id != SCSI_PROTOCOL_SRP)) {
8b67ad
 			/* return success as default path order
8b67ad
 			 * is maintained in path group
8b67ad
 			 */
8b67ad
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
8b67ad
index 36cc389e..5f4e0794 100644
8b67ad
--- a/libmultipath/discovery.c
8b67ad
+++ b/libmultipath/discovery.c
8b67ad
@@ -468,10 +468,11 @@ int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
8b67ad
 
8b67ad
 	proto_id = pp->sg_id.proto_id;
8b67ad
 
8b67ad
-	if (proto_id != SCSI_PROTOCOL_FCP &&
8b67ad
-	    proto_id != SCSI_PROTOCOL_SAS &&
8b67ad
-	    proto_id != SCSI_PROTOCOL_ISCSI &&
8b67ad
-	    proto_id != SCSI_PROTOCOL_SRP) {
8b67ad
+	if (pp->bus != SYSFS_BUS_SCSI ||
8b67ad
+	    (proto_id != SCSI_PROTOCOL_FCP &&
8b67ad
+	     proto_id != SCSI_PROTOCOL_SAS &&
8b67ad
+	     proto_id != SCSI_PROTOCOL_ISCSI &&
8b67ad
+	     proto_id != SCSI_PROTOCOL_SRP)) {
8b67ad
 		return 1;
8b67ad
 	}
8b67ad
 	/* iscsi doesn't have adapter info in sysfs
8b67ad
@@ -1722,8 +1723,10 @@ sysfs_pathinfo(struct path * pp, vector hwtable)
8b67ad
 		pp->bus = SYSFS_BUS_CCISS;
8b67ad
 	if (!strncmp(pp->dev,"dasd", 4))
8b67ad
 		pp->bus = SYSFS_BUS_CCW;
8b67ad
-	if (!strncmp(pp->dev,"sd", 2))
8b67ad
+	if (!strncmp(pp->dev,"sd", 2)) {
8b67ad
 		pp->bus = SYSFS_BUS_SCSI;
8b67ad
+		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
8b67ad
+	}
8b67ad
 	if (!strncmp(pp->dev,"nvme", 4))
8b67ad
 		pp->bus = SYSFS_BUS_NVME;
8b67ad
 
8b67ad
diff --git a/libmultipath/print.c b/libmultipath/print.c
8b67ad
index 8a6fbe83..8a85df66 100644
8b67ad
--- a/libmultipath/print.c
8b67ad
+++ b/libmultipath/print.c
8b67ad
@@ -558,7 +558,8 @@ snprint_host_attr (char * buff, size_t len, const struct path * pp, char *attr)
8b67ad
 	const char *value = NULL;
8b67ad
 	int ret;
8b67ad
 
8b67ad
-	if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
8b67ad
+	if (pp->bus != SYSFS_BUS_SCSI ||
8b67ad
+	    pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
8b67ad
 		return snprintf(buff, len, "[undef]");
8b67ad
 	sprintf(host_id, "host%d", pp->sg_id.host_no);
8b67ad
 	host_dev = udev_device_new_from_subsystem_sysname(udev, "fc_host",
8b67ad
@@ -597,7 +598,8 @@ snprint_tgt_wwpn (char * buff, size_t len, const struct path * pp)
8b67ad
 	const char *value = NULL;
8b67ad
 	int ret;
8b67ad
 
8b67ad
-	if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
8b67ad
+	if (pp->bus != SYSFS_BUS_SCSI ||
8b67ad
+	    pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
8b67ad
 		return snprintf(buff, len, "[undef]");
8b67ad
 	sprintf(rport_id, "rport-%d:%d-%d",
8b67ad
 		pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
8b67ad
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
8b67ad
index 84f9c959..1122cfae 100644
8b67ad
--- a/libmultipath/structs.c
8b67ad
+++ b/libmultipath/structs.c
8b67ad
@@ -115,7 +115,7 @@ alloc_path (void)
8b67ad
 		pp->sg_id.channel = -1;
8b67ad
 		pp->sg_id.scsi_id = -1;
8b67ad
 		pp->sg_id.lun = -1;
8b67ad
-		pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
8b67ad
+		pp->sg_id.proto_id = PROTOCOL_UNSET;
8b67ad
 		pp->fd = -1;
8b67ad
 		pp->tpgs = TPGS_UNDEF;
8b67ad
 		pp->priority = PRIO_UNDEF;
8b67ad
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
8b67ad
index 9a404da7..960ea024 100644
8b67ad
--- a/libmultipath/structs.h
8b67ad
+++ b/libmultipath/structs.h
8b67ad
@@ -193,6 +193,8 @@ enum queue_mode_states {
8b67ad
 	QUEUE_MODE_RQ,
8b67ad
 };
8b67ad
 
8b67ad
+#define PROTOCOL_UNSET -1
8b67ad
+
8b67ad
 enum scsi_protocol {
8b67ad
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
8b67ad
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
8b67ad
@@ -294,7 +296,7 @@ struct sg_id {
8b67ad
 	int lun;
8b67ad
 	short h_cmd_per_lun;
8b67ad
 	short d_queue_depth;
8b67ad
-	enum scsi_protocol proto_id;
8b67ad
+	int proto_id;
8b67ad
 	int transport_id;
8b67ad
 };
8b67ad
 
8b67ad
diff --git a/multipathd/fpin_handlers.c b/multipathd/fpin_handlers.c
8b67ad
index b14366d7..599f2893 100644
8b67ad
--- a/multipathd/fpin_handlers.c
8b67ad
+++ b/multipathd/fpin_handlers.c
8b67ad
@@ -220,7 +220,7 @@ static int  fpin_chk_wwn_setpath_marginal(uint16_t host_num,  struct vectors *ve
8b67ad
 
8b67ad
 	vector_foreach_slot(vecs->pathvec, pp, k) {
8b67ad
 		/* Checks the host number and also for the SCSI FCP */
8b67ad
-		if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP || host_num !=  pp->sg_id.host_no)
8b67ad
+		if (pp->bus != SYSFS_BUS_SCSI || pp->sg_id.proto_id != SCSI_PROTOCOL_FCP || host_num !=  pp->sg_id.host_no)
8b67ad
 			continue;
8b67ad
 		sprintf(rport_id, "rport-%d:%d-%d",
8b67ad
 				pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);