Blame SOURCES/0097-libmultipath-use-bus_protocol_id-in-snprint_path_pro.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:24:25 +0100
c90e5b
Subject: [PATCH] libmultipath: use bus_protocol_id() in
c90e5b
 snprint_path_protocol()
c90e5b
c90e5b
Simplify bus_protocol_id() by using the linear ordering.
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/print.c | 56 +++++++++++++++++---------------------------
c90e5b
 1 file changed, 21 insertions(+), 35 deletions(-)
c90e5b
c90e5b
diff --git a/libmultipath/print.c b/libmultipath/print.c
c90e5b
index 298b3764..ff4d1854 100644
c90e5b
--- a/libmultipath/print.c
c90e5b
+++ b/libmultipath/print.c
c90e5b
@@ -662,41 +662,27 @@ snprint_path_failures(char * buff, size_t len, const struct path * pp)
c90e5b
 int
c90e5b
 snprint_path_protocol(char * buff, size_t len, const struct path * pp)
c90e5b
 {
c90e5b
-	switch (pp->bus) {
c90e5b
-	case SYSFS_BUS_SCSI:
c90e5b
-		switch (pp->sg_id.proto_id) {
c90e5b
-		case SCSI_PROTOCOL_FCP:
c90e5b
-			return snprintf(buff, len, "scsi:fcp");
c90e5b
-		case SCSI_PROTOCOL_SPI:
c90e5b
-			return snprintf(buff, len, "scsi:spi");
c90e5b
-		case SCSI_PROTOCOL_SSA:
c90e5b
-			return snprintf(buff, len, "scsi:ssa");
c90e5b
-		case SCSI_PROTOCOL_SBP:
c90e5b
-			return snprintf(buff, len, "scsi:sbp");
c90e5b
-		case SCSI_PROTOCOL_SRP:
c90e5b
-			return snprintf(buff, len, "scsi:srp");
c90e5b
-		case SCSI_PROTOCOL_ISCSI:
c90e5b
-			return snprintf(buff, len, "scsi:iscsi");
c90e5b
-		case SCSI_PROTOCOL_SAS:
c90e5b
-			return snprintf(buff, len, "scsi:sas");
c90e5b
-		case SCSI_PROTOCOL_ADT:
c90e5b
-			return snprintf(buff, len, "scsi:adt");
c90e5b
-		case SCSI_PROTOCOL_ATA:
c90e5b
-			return snprintf(buff, len, "scsi:ata");
c90e5b
-		case SCSI_PROTOCOL_UNSPEC:
c90e5b
-		default:
c90e5b
-			return snprintf(buff, len, "scsi:unspec");
c90e5b
-		}
c90e5b
-	case SYSFS_BUS_CCW:
c90e5b
-		return snprintf(buff, len, "ccw");
c90e5b
-	case SYSFS_BUS_CCISS:
c90e5b
-		return snprintf(buff, len, "cciss");
c90e5b
-	case SYSFS_BUS_NVME:
c90e5b
-		return snprintf(buff, len, "nvme");
c90e5b
-	case SYSFS_BUS_UNDEF:
c90e5b
-	default:
c90e5b
-		return snprintf(buff, len, "undef");
c90e5b
-	}
c90e5b
+	static const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
c90e5b
+		[SYSFS_BUS_UNDEF] = "undef",
c90e5b
+		[SYSFS_BUS_CCW] = "ccw",
c90e5b
+		[SYSFS_BUS_CCISS] = "cciss",
c90e5b
+		[SYSFS_BUS_NVME] = "nvme",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP] = "scsi:fcp",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SPI] = "scsi:spi",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SSA] = "scsi:ssa",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SBP] = "scsi:sbp",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SRP] = "scsi:srp",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ISCSI] = "scsi:iscsi",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SAS] = "scsi:sas",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ADT] = "scsi:adt",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ATA] = "scsi:ata",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_USB] = "scsi:usb",
c90e5b
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC] = "scsi:unspec",
c90e5b
+	};
c90e5b
+	const char *pn = protocol_name[bus_protocol_id(pp)];
c90e5b
+
c90e5b
+	assert(pn != NULL);
c90e5b
+	return snprintf(buff, len, "%s", pn);
c90e5b
 }
c90e5b
 
c90e5b
 int