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