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