Blame SOURCES/0096-libmultipath-enable-linear-ordering-of-bus-proto-tup.patch

aab12e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
aab12e
From: Martin Wilck <mwilck@suse.com>
aab12e
Date: Thu, 17 Feb 2022 17:22:32 +0100
aab12e
Subject: [PATCH] libmultipath: enable linear ordering of bus/proto tuple
aab12e
aab12e
We categorized protocols by bus/proto_id, while we only differentiate
aab12e
protocol IDs for SCSI. Allow transforming this into a linear sequence
aab12e
of bus/protocol IDs by having non-SCSI first, and follwing up with
aab12e
the different SCSI protocols.
aab12e
aab12e
Signed-off-by: Martin Wilck <mwilck@suse.com>
aab12e
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
aab12e
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
aab12e
---
aab12e
 libmultipath/structs.c | 10 ++++++++++
aab12e
 libmultipath/structs.h | 14 ++++++++++++--
aab12e
 2 files changed, 22 insertions(+), 2 deletions(-)
aab12e
aab12e
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
aab12e
index dda9884c..aaf85297 100644
aab12e
--- a/libmultipath/structs.c
aab12e
+++ b/libmultipath/structs.c
aab12e
@@ -722,3 +722,13 @@ out:
aab12e
 
aab12e
 	return 0;
aab12e
 }
aab12e
+
aab12e
+unsigned int bus_protocol_id(const struct path *pp) {
aab12e
+	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
aab12e
+		return SYSFS_BUS_UNDEF;
aab12e
+	if (pp->bus != SYSFS_BUS_SCSI)
aab12e
+		return pp->bus;
aab12e
+	if ((int)pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
aab12e
+		return SYSFS_BUS_UNDEF;
aab12e
+	return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
aab12e
+}
aab12e
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
aab12e
index a5dbad5b..5e29ae38 100644
aab12e
--- a/libmultipath/structs.h
aab12e
+++ b/libmultipath/structs.h
aab12e
@@ -57,12 +57,13 @@ enum failback_mode {
aab12e
 	FAILBACK_FOLLOWOVER
aab12e
 };
aab12e
 
aab12e
+/* SYSFS_BUS_SCSI should be last, see bus_protocol_id() */
aab12e
 enum sysfs_buses {
aab12e
 	SYSFS_BUS_UNDEF,
aab12e
-	SYSFS_BUS_SCSI,
aab12e
 	SYSFS_BUS_CCW,
aab12e
 	SYSFS_BUS_CCISS,
aab12e
 	SYSFS_BUS_NVME,
aab12e
+	SYSFS_BUS_SCSI,
aab12e
 };
aab12e
 
aab12e
 enum pathstates {
aab12e
@@ -190,9 +191,18 @@ enum scsi_protocol {
aab12e
 	SCSI_PROTOCOL_SAS = 6,
aab12e
 	SCSI_PROTOCOL_ADT = 7,	/* Media Changers */
aab12e
 	SCSI_PROTOCOL_ATA = 8,
aab12e
-	SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
aab12e
+	SCSI_PROTOCOL_USB = 9,  /* USB Attached SCSI (UAS), and others */
aab12e
+	SCSI_PROTOCOL_UNSPEC = 0xa, /* No specific protocol */
aab12e
 };
aab12e
 
aab12e
+/*
aab12e
+ * Linear ordering of bus/protocol
aab12e
+ * This assumes that SYSFS_BUS_SCSI is last in enum sysfs_buses
aab12e
+ * SCSI is the only bus type for which we distinguish protocols.
aab12e
+ */
aab12e
+#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC)
aab12e
+unsigned int bus_protocol_id(const struct path *pp);
aab12e
+
aab12e
 enum no_undef_states {
aab12e
 	NU_NO = -1,
aab12e
 	NU_UNDEF = 0,