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

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