Blame SOURCES/0049-libmultipath-use-bus_protocol_id-in-snprint_path_pro.patch

aebebb
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
aebebb
From: Martin Wilck <mwilck@suse.com>
aebebb
Date: Thu, 17 Feb 2022 17:24:25 +0100
aebebb
Subject: [PATCH] libmultipath: use bus_protocol_id() in
aebebb
 snprint_path_protocol()
aebebb
aebebb
Simplify bus_protocol_id() by using the linear ordering.
aebebb
aebebb
Signed-off-by: Martin Wilck <mwilck@suse.com>
aebebb
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
aebebb
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
aebebb
---
aebebb
 libmultipath/print.c | 58 ++++++++++++++++----------------------------
aebebb
 1 file changed, 21 insertions(+), 37 deletions(-)
aebebb
aebebb
diff --git a/libmultipath/print.c b/libmultipath/print.c
aebebb
index 2fb9f4ef..8f1b18db 100644
aebebb
--- a/libmultipath/print.c
aebebb
+++ b/libmultipath/print.c
aebebb
@@ -696,43 +696,27 @@ snprint_path_failures(struct strbuf *buff, const struct path * pp)
aebebb
 int
aebebb
 snprint_path_protocol(struct strbuf *buff, const struct path * pp)
aebebb
 {
aebebb
-	switch (pp->bus) {
aebebb
-	case SYSFS_BUS_SCSI:
aebebb
-		switch (pp->sg_id.proto_id) {
aebebb
-		case SCSI_PROTOCOL_FCP:
aebebb
-			return append_strbuf_str(buff, "scsi:fcp");
aebebb
-		case SCSI_PROTOCOL_SPI:
aebebb
-			return append_strbuf_str(buff, "scsi:spi");
aebebb
-		case SCSI_PROTOCOL_SSA:
aebebb
-			return append_strbuf_str(buff, "scsi:ssa");
aebebb
-		case SCSI_PROTOCOL_SBP:
aebebb
-			return append_strbuf_str(buff, "scsi:sbp");
aebebb
-		case SCSI_PROTOCOL_SRP:
aebebb
-			return append_strbuf_str(buff, "scsi:srp");
aebebb
-		case SCSI_PROTOCOL_ISCSI:
aebebb
-			return append_strbuf_str(buff, "scsi:iscsi");
aebebb
-		case SCSI_PROTOCOL_SAS:
aebebb
-			return append_strbuf_str(buff, "scsi:sas");
aebebb
-		case SCSI_PROTOCOL_ADT:
aebebb
-			return append_strbuf_str(buff, "scsi:adt");
aebebb
-		case SCSI_PROTOCOL_ATA:
aebebb
-			return append_strbuf_str(buff, "scsi:ata");
aebebb
-		case SCSI_PROTOCOL_USB:
aebebb
-			return append_strbuf_str(buff, "scsi:usb");
aebebb
-		case SCSI_PROTOCOL_UNSPEC:
aebebb
-		default:
aebebb
-			return append_strbuf_str(buff, "scsi:unspec");
aebebb
-		}
aebebb
-	case SYSFS_BUS_CCW:
aebebb
-		return append_strbuf_str(buff, "ccw");
aebebb
-	case SYSFS_BUS_CCISS:
aebebb
-		return append_strbuf_str(buff, "cciss");
aebebb
-	case SYSFS_BUS_NVME:
aebebb
-		return append_strbuf_str(buff, "nvme");
aebebb
-	case SYSFS_BUS_UNDEF:
aebebb
-	default:
aebebb
-		return append_strbuf_str(buff, "undef");
aebebb
-	}
aebebb
+	static const char * const protocol_name[LAST_BUS_PROTOCOL_ID + 1] = {
aebebb
+		[SYSFS_BUS_UNDEF] = "undef",
aebebb
+		[SYSFS_BUS_CCW] = "ccw",
aebebb
+		[SYSFS_BUS_CCISS] = "cciss",
aebebb
+		[SYSFS_BUS_NVME] = "nvme",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_FCP] = "scsi:fcp",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SPI] = "scsi:spi",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SSA] = "scsi:ssa",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SBP] = "scsi:sbp",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SRP] = "scsi:srp",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ISCSI] = "scsi:iscsi",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_SAS] = "scsi:sas",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ADT] = "scsi:adt",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_ATA] = "scsi:ata",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_USB] = "scsi:usb",
aebebb
+		[SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC] = "scsi:unspec",
aebebb
+	};
aebebb
+	const char *pn = protocol_name[bus_protocol_id(pp)];
aebebb
+
aebebb
+	assert(pn != NULL);
aebebb
+	return append_strbuf_str(buff, pn);
aebebb
 }
aebebb
 
aebebb
 int