Skip to contentSkip to conversation

libmultipath: utter less dev_loss_tmo warnings

PATCH In review [email protected] 2 participants 7 messages Feb 17, 2022 – Feb 21, 2022 Device mapper

lore
Share & tools
lore
#0 lore raw

cover libmultipath: utter less dev_loss_tmo warnings

From: Martin Wilck <[email protected]>

Hi Christophe,

since 3ab1f3b ("libmultipath: print message if setting dev_loss_tmo is unsupported"), multipathd prints a warning at level 2 for every map for which dev_loss_tmo can't be set. This results in a large number of warnings if there are many maps with such unsupported protocols, like this:

multipathd[1398]: 36001405328d6683b6cb4739943adf643: setting dev_loss_tmo is unsupported for protocol scsi:unspec

This patch set makes changes the code to print this warning only once per unsupported protocol. It would have been simpler to never print the warning more than once, but I figured that might suppress important information in some cases.

Regards
Martin

Martin Wilck (4):
libmultipath: enable linear ordering of bus/proto tuple
libmultipath: use bus_protocol_id() in snprint_path_protocol()
libmultipath: enable defining a static bitfield
libmultipath: only warn once about unsupported dev_loss_tmo

 libmultipath/discovery.c |  4 ++-
 libmultipath/print.c     | 58 +++++++++++++++-------------------------
 libmultipath/structs.c   | 10 +++++++
 libmultipath/structs.h   | 13 +++++++--
 libmultipath/util.h      | 10 +++++++
 5 files changed, 55 insertions(+), 40 deletions(-)
Signature · 7 lines
2.35.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw

PATCH 1/4 libmultipath: enable linear ordering of bus/proto tuple

From: Martin Wilck <[email protected]>

We categorized protocols by bus/proto_id, while we only differentiate protocol IDs for SCSI. Allow transforming this into a linear sequence of bus/protocol IDs by having non-SCSI first, and follwing up with the different SCSI protocols.

---
 libmultipath/structs.c | 10 ++++++++++
 libmultipath/structs.h | 13 +++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)
libmultipath/structs.c +10 -0
index 17f4baf..5849bf1 100644
@@ -753,3 +753,13 @@ out:
 
 	return 0;
 }
+
+unsigned int bus_protocol_id(const struct path *pp) {
+	if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
+		return SYSFS_BUS_UNDEF;
+	if (pp->bus != SYSFS_BUS_SCSI)
+		return pp->bus;
+	if (pp->sg_id.proto_id < 0 || pp->sg_id.proto_id > SCSI_PROTOCOL_UNSPEC)
+		return SYSFS_BUS_UNDEF;
+	return SYSFS_BUS_SCSI + pp->sg_id.proto_id;
+}
libmultipath/structs.h +11 -2
index 205cf64..d94f93a 100644
@@ -57,12 +57,13 @@ enum failback_mode {
 	FAILBACK_FOLLOWOVER
 };
 
+/* SYSFS_BUS_SCSI should be last, see bus_protocol_id() */
 enum sysfs_buses {
 	SYSFS_BUS_UNDEF,
-	SYSFS_BUS_SCSI,
 	SYSFS_BUS_CCW,
 	SYSFS_BUS_CCISS,
 	SYSFS_BUS_NVME,
+	SYSFS_BUS_SCSI,
 };
 
 enum pathstates {
@@ -181,9 +182,17 @@ enum scsi_protocol {
 	SCSI_PROTOCOL_ADT = 7,	/* Media Changers */
 	SCSI_PROTOCOL_ATA = 8,
 	SCSI_PROTOCOL_USB = 9,  /* USB Attached SCSI (UAS), and others */
-	SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
+	SCSI_PROTOCOL_UNSPEC = 0xa, /* No specific protocol */
 };
 
+/*
+ * Linear ordering of bus/protocol
+ * This assumes that SYSFS_BUS_SCSI is last in enum sysfs_buses
+ * SCSI is the only bus type for which we distinguish protocols.
+ */
+#define LAST_BUS_PROTOCOL_ID (SYSFS_BUS_SCSI + SCSI_PROTOCOL_UNSPEC)
+unsigned int bus_protocol_id(const struct path *pp);
+
 #define SCSI_INVALID_LUN ~0ULL
 
 enum no_undef_states {
Signature · 7 lines
2.35.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#2 lore raw

Re: [dm-devel] [PATCH 1/4] libmultipath: enable linear ordering of bus/proto tuple

Quoted 21 lines · On Thu, 2022-02-17 at 20:55 +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

We categorized protocols by bus/proto_id, while we only differentiate protocol IDs for SCSI. Allow transforming this into a linear sequence of bus/protocol IDs by having non-SCSI first, and follwing up with the different SCSI protocols.

---
 libmultipath/structs.c | 10 ++++++++++
 libmultipath/structs.h | 13 +++++++++++--

 2 files changed, 21 insertions(+), 2 deletions(-)
libmultipath/structs.c +0 -0
index 17f4baf..5849bf1 100644
@@ -753,3 +753,13 @@ out:


        return 0;
 }

libmultipath/structs.c out:

Quoted 7 lines
libmultipath/structs.c +7 -0
+
+unsigned int bus_protocol_id(const struct path *pp) {
+       if (!pp || pp->bus < 0 || pp->bus > SYSFS_BUS_SCSI)
+               return SYSFS_BUS_UNDEF;
+       if (pp->bus != SYSFS_BUS_SCSI)
+               return pp->bus;
+       if (pp->sg_id.proto_id < 0 || pp->sg_id.proto_id

It turns out that ^^^^^^^^^^^^^^^^^^ this comparison causes an error with clang 3.5, and possibly other compilers, because they use an unsigned int type for sg_id.proto_id.

Because some compilers will use "int", instead of dropping the test, I'll just add a cast to (int).

Regards
Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#3 lore raw

PATCH 2/4 libmultipath: use bus_protocol_id() in snprint_path_protocol()

In reply to [email protected]

From: Martin Wilck <[email protected]>

Simplify bus_protocol_id() by using the linear ordering.

---
 libmultipath/print.c | 58 ++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 37 deletions(-)
libmultipath/print.c +21 -37
index 8ea8557..bf88f30 100644
@@ -754,43 +754,27 @@ snprint_path_failures(struct strbuf *buff, const struct path * pp)
 int
 snprint_path_protocol(struct strbuf *buff, const struct path * pp)
 {
-	switch (pp->bus) {
-	case SYSFS_BUS_SCSI:
-		switch (pp->sg_id.proto_id) {
-		case SCSI_PROTOCOL_FCP:
-			return append_strbuf_str(buff, "scsi:fcp");
-		case SCSI_PROTOCOL_SPI:
-			return append_strbuf_str(buff, "scsi:spi");
-		case SCSI_PROTOCOL_SSA:
-			return append_strbuf_str(buff, "scsi:ssa");
-		case SCSI_PROTOCOL_SBP:
-			return append_strbuf_str(buff, "scsi:sbp");
-		case SCSI_PROTOCOL_SRP:
-			return append_strbuf_str(buff, "scsi:srp");
-		case SCSI_PROTOCOL_ISCSI:
-			return append_strbuf_str(buff, "scsi:iscsi");
-		case SCSI_PROTOCOL_SAS:
-			return append_strbuf_str(buff, "scsi:sas");
-		case SCSI_PROTOCOL_ADT:
-			return append_strbuf_str(buff, "scsi:adt");
-		case SCSI_PROTOCOL_ATA:
-			return append_strbuf_str(buff, "scsi:ata");
-		case SCSI_PROTOCOL_USB:
-			return append_strbuf_str(buff, "scsi:usb");
-		case SCSI_PROTOCOL_UNSPEC:
-		default:
-			return append_strbuf_str(buff, "scsi:unspec");
-		}
-	case SYSFS_BUS_CCW:
-		return append_strbuf_str(buff, "ccw");
-	case SYSFS_BUS_CCISS:
-		return append_strbuf_str(buff, "cciss");
-	case SYSFS_BUS_NVME:
-		return append_strbuf_str(buff, "nvme");
-	case SYSFS_BUS_UNDEF:
-	default:
-		return append_strbuf_str(buff, "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 append_strbuf_str(buff, pn);
 }
 
 static int
Signature · 7 lines
2.35.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#4 lore raw

PATCH 3/4 libmultipath: enable defining a static bitfield

In reply to [email protected]

From: Martin Wilck <[email protected]>

The STATIC_BITFIELD macro allows defining a static variable holding a bitfield of constant length.

---
 libmultipath/util.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
libmultipath/util.h +10 -0
index 79d9f32..5a44018 100644
@@ -82,6 +82,16 @@ struct bitfield {
 	bitfield_t bits[];
 };
 
+#define STATIC_BITFIELD(name, length)					\
+	static struct {							\
+		unsigned int len;					\
+		bitfield_t bits[((length) - 1) / bits_per_slot + 1];	\
+	} __static__ ## name = {					\
+		.len = (length),					\
+		.bits = { 0, },						\
+	}; \
+	struct bitfield *name = (struct bitfield *)& __static__ ## name
+
 struct bitfield *alloc_bitfield(unsigned int maxbit);
 
 void _log_bitfield_overflow(const char *f, unsigned int bit, unsigned int len);
Signature · 7 lines
2.35.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#5 lore raw

PATCH 4/4 libmultipath: only warn once about unsupported dev_loss_tmo

In reply to [email protected]

From: Martin Wilck <[email protected]>

On systems with many devices, the warning that setting dev_loss_tmo is unsupported for certain protocols is printed many times, cluttering the logs. Only print this message once per unsupported protocol.

---
 libmultipath/discovery.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
libmultipath/discovery.c +3 -1
index c165d9b..b969fba 100644
@@ -843,6 +843,7 @@ sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint)
 	int i;
 	unsigned int dev_loss_tmo = mpp->dev_loss;
 	struct path *err_path = NULL;
+	STATIC_BITFIELD(bf, LAST_BUS_PROTOCOL_ID + 1);
 
 	if (mpp->no_path_retry > 0) {
 		uint64_t no_path_retry_tmo =
@@ -897,12 +898,13 @@ sysfs_set_scsi_tmo (struct multipath *mpp, unsigned int checkint)
 		sysfs_set_eh_deadline(mpp, pp);
 	}
 
-	if (err_path) {
+	if (err_path && !is_bit_set_in_bitfield(bus_protocol_id(pp), bf)) {
 		STRBUF_ON_STACK(proto_buf);
 
 		snprint_path_protocol(&proto_buf, err_path);
 		condlog(2, "%s: setting dev_loss_tmo is unsupported for protocol %s",
 			mpp->alias, get_strbuf_str(&proto_buf));
+		set_bit_in_bitfield(bus_protocol_id(pp), bf);
 	}
 	return 0;
 }
Signature · 7 lines
2.35.1


--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on the v1 series
#6 lore raw
In reply to [email protected]
Quoted 9 lines · On Thu, Feb 17, 2022 at 08:55:29PM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

Hi Christophe,

since 3ab1f3b ("libmultipath: print message if setting dev_loss_tmo is unsupported"), multipathd prints a warning at level 2 for every map for which dev_loss_tmo can't be set. This results in a large number of warnings if there are many maps with such unsupported protocols, like this:

Quoted 8 lines

multipathd[1398]: 36001405328d6683b6cb4739943adf643: setting dev_loss_tmo is unsupported for protocol scsi:unspec

This patch set makes changes the code to print this warning only once per unsupported protocol. It would have been simpler to never print the warning more than once, but I figured that might suppress important information in some cases.

Regards
Martin

Quoted 7 lines

Martin Wilck (4):
libmultipath: enable linear ordering of bus/proto tuple
libmultipath: use bus_protocol_id() in snprint_path_protocol()
libmultipath: enable defining a static bitfield
libmultipath: only warn once about unsupported dev_loss_tmo

Quoted 9 lines
 libmultipath/discovery.c |  4 ++-
 libmultipath/print.c     | 58 +++++++++++++++-------------------------
 libmultipath/structs.c   | 10 +++++++
 libmultipath/structs.h   | 13 +++++++--
 libmultipath/util.h      | 10 +++++++
 5 files changed, 55 insertions(+), 40 deletions(-)
Signature · 1 line
2.35.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel