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

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