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

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