device-mapper-multipath/SOURCES/0097-libmultipath-use-bus_protocol_id-in-snprint_path_pro.patch

83 lines
2.8 KiB
Diff
Raw Normal View History

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