Blame SOURCES/0120-libmultipath-fix-queue_mode-feature-handling.patch

8b67ad
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8b67ad
From: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Date: Fri, 7 Oct 2022 12:35:40 -0500
8b67ad
Subject: [PATCH] libmultipath: fix queue_mode feature handling
8b67ad
8b67ad
device-mapper is not able to change the queue_mode on a table reload.
8b67ad
Make sure that when multipath sets up the map, both on regular reloads
8b67ad
and reconfigures, it keeps the queue_mode the same.
8b67ad
8b67ad
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
8b67ad
Reviewed-by: Martin Wilck <mwilck@suse.com>
8b67ad
---
8b67ad
 libmultipath/configure.c   |  4 +++
8b67ad
 libmultipath/dmparser.c    |  2 ++
8b67ad
 libmultipath/propsel.c     | 55 ++++++++++++++++++++++++++++++++++++++
8b67ad
 libmultipath/structs.h     |  7 +++++
8b67ad
 libmultipath/util.c        | 10 +++++++
8b67ad
 libmultipath/util.h        |  1 +
8b67ad
 multipath/multipath.conf.5 |  7 +++--
8b67ad
 7 files changed, 84 insertions(+), 2 deletions(-)
8b67ad
8b67ad
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
8b67ad
index 6cad0468..287289f7 100644
8b67ad
--- a/libmultipath/configure.c
8b67ad
+++ b/libmultipath/configure.c
8b67ad
@@ -1102,6 +1102,7 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid,
8b67ad
 	uint64_t *size_mismatch_seen;
8b67ad
 	bool map_processed = false;
8b67ad
 	bool no_daemon = false;
8b67ad
+	struct multipath * cmpp;
8b67ad
 
8b67ad
 	/* ignore refwwid if it's empty */
8b67ad
 	if (refwwid && !strlen(refwwid))
8b67ad
@@ -1197,6 +1198,9 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid,
8b67ad
 		}
8b67ad
 		verify_paths(mpp, vecs);
8b67ad
 
8b67ad
+		cmpp = find_mp_by_wwid(curmp, mpp->wwid);
8b67ad
+		if (cmpp)
8b67ad
+			mpp->queue_mode = cmpp->queue_mode;
8b67ad
 		params[0] = '\0';
8b67ad
 		if (setup_map(mpp, params, PARAMS_SIZE, vecs)) {
8b67ad
 			remove_map(mpp, vecs, 0);
8b67ad
diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c
8b67ad
index b856a07f..b9c4dabc 100644
8b67ad
--- a/libmultipath/dmparser.c
8b67ad
+++ b/libmultipath/dmparser.c
8b67ad
@@ -164,6 +164,8 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp,
8b67ad
 
8b67ad
 		FREE(word);
8b67ad
 	}
8b67ad
+	mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ?
8b67ad
+			  QUEUE_MODE_BIO : QUEUE_MODE_RQ;
8b67ad
 
8b67ad
 	/*
8b67ad
 	 * hwhandler
8b67ad
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
8b67ad
index be79902f..3f119dd9 100644
8b67ad
--- a/libmultipath/propsel.c
8b67ad
+++ b/libmultipath/propsel.c
8b67ad
@@ -26,6 +26,7 @@
8b67ad
 #include "propsel.h"
8b67ad
 #include <inttypes.h>
8b67ad
 #include <libudev.h>
8b67ad
+#include <ctype.h>
8b67ad
 
8b67ad
 pgpolicyfn *pgpolicies[] = {
8b67ad
 	NULL,
8b67ad
@@ -413,6 +414,59 @@ void reconcile_features_with_options(const char *id, char **features, int* no_pa
8b67ad
 	}
8b67ad
 }
8b67ad
 
8b67ad
+static void reconcile_features_with_queue_mode(struct multipath *mp)
8b67ad
+{
8b67ad
+	char *space = NULL, *val = NULL, *mode_str = NULL, *feat;
8b67ad
+	int features_mode = QUEUE_MODE_UNDEF;
8b67ad
+
8b67ad
+	if (!mp->features)
8b67ad
+		return;
8b67ad
+
8b67ad
+	pthread_cleanup_push(cleanup_free_ptr, &space);
8b67ad
+	pthread_cleanup_push(cleanup_free_ptr, &val;;
8b67ad
+	pthread_cleanup_push(cleanup_free_ptr, &mode_str);
8b67ad
+
8b67ad
+	if (!(feat = strstr(mp->features, "queue_mode")) ||
8b67ad
+	    feat == mp->features || !isspace(*(feat - 1)) ||
8b67ad
+	    sscanf(feat, "queue_mode%m[ \f\n\r\t\v]%ms", &space, &val) != 2)
8b67ad
+		goto sync_mode;
8b67ad
+	if (asprintf(&mode_str, "queue_mode%s%s", space, val) < 0) {
8b67ad
+		condlog(1, "failed to allocate space for queue_mode feature string");
8b67ad
+		mode_str = NULL; /* value undefined on failure */
8b67ad
+		goto exit;
8b67ad
+	}
8b67ad
+
8b67ad
+	if (!strcmp(val, "rq") || !strcmp(val, "mq"))
8b67ad
+		features_mode = QUEUE_MODE_RQ;
8b67ad
+	else if (!strcmp(val, "bio"))
8b67ad
+		features_mode = QUEUE_MODE_BIO;
8b67ad
+	if (features_mode == QUEUE_MODE_UNDEF) {
8b67ad
+		condlog(2, "%s: ignoring invalid feature '%s'",
8b67ad
+			mp->alias, mode_str);
8b67ad
+		goto sync_mode;
8b67ad
+	}
8b67ad
+
8b67ad
+	if (mp->queue_mode == QUEUE_MODE_UNDEF)
8b67ad
+		mp->queue_mode = features_mode;
8b67ad
+	if (mp->queue_mode == features_mode)
8b67ad
+		goto exit;
8b67ad
+
8b67ad
+	condlog(2,
8b67ad
+		"%s: ignoring feature '%s' because queue_mode is set to '%s'",
8b67ad
+		mp->alias, mode_str,
8b67ad
+		(mp->queue_mode == QUEUE_MODE_RQ)? "rq" : "bio");
8b67ad
+
8b67ad
+sync_mode:
8b67ad
+	if (mode_str)
8b67ad
+		remove_feature(&mp->features, mode_str);
8b67ad
+	if (mp->queue_mode == QUEUE_MODE_BIO)
8b67ad
+		add_feature(&mp->features, "queue_mode bio");
8b67ad
+exit:
8b67ad
+	pthread_cleanup_pop(1);
8b67ad
+	pthread_cleanup_pop(1);
8b67ad
+	pthread_cleanup_pop(1);
8b67ad
+}
8b67ad
+
8b67ad
 int select_features(struct config *conf, struct multipath *mp)
8b67ad
 {
8b67ad
 	const char *origin;
8b67ad
@@ -428,6 +482,7 @@ out:
8b67ad
 	reconcile_features_with_options(mp->alias, &mp->features,
8b67ad
 					&mp->no_path_retry,
8b67ad
 					&mp->retain_hwhandler);
8b67ad
+	reconcile_features_with_queue_mode(mp);
8b67ad
 	condlog(3, "%s: features = \"%s\" %s", mp->alias, mp->features, origin);
8b67ad
 	return 0;
8b67ad
 }
8b67ad
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
8b67ad
index 3ed5cfc1..9a404da7 100644
8b67ad
--- a/libmultipath/structs.h
8b67ad
+++ b/libmultipath/structs.h
8b67ad
@@ -187,6 +187,12 @@ enum max_sectors_kb_states {
8b67ad
 	MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
8b67ad
 };
8b67ad
 
8b67ad
+enum queue_mode_states {
8b67ad
+	QUEUE_MODE_UNDEF = 0,
8b67ad
+	QUEUE_MODE_BIO,
8b67ad
+	QUEUE_MODE_RQ,
8b67ad
+};
8b67ad
+
8b67ad
 enum scsi_protocol {
8b67ad
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
8b67ad
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
8b67ad
@@ -397,6 +403,7 @@ struct multipath {
8b67ad
 	int needs_paths_uevent;
8b67ad
 	int ghost_delay;
8b67ad
 	int ghost_delay_tick;
8b67ad
+	int queue_mode;
8b67ad
 	uid_t uid;
8b67ad
 	gid_t gid;
8b67ad
 	mode_t mode;
8b67ad
diff --git a/libmultipath/util.c b/libmultipath/util.c
8b67ad
index dd30a46e..e04d20ab 100644
8b67ad
--- a/libmultipath/util.c
8b67ad
+++ b/libmultipath/util.c
8b67ad
@@ -465,6 +465,16 @@ void free_scandir_result(struct scandir_result *res)
8b67ad
 	FREE(res->di);
8b67ad
 }
8b67ad
 
8b67ad
+void cleanup_free_ptr(void *arg)
8b67ad
+{
8b67ad
+	void **p = arg;
8b67ad
+
8b67ad
+	if (p && *p) {
8b67ad
+		free(*p);
8b67ad
+		*p = NULL;
8b67ad
+	}
8b67ad
+}
8b67ad
+
8b67ad
 void close_fd(void *arg)
8b67ad
 {
8b67ad
 	close((long)arg);
8b67ad
diff --git a/libmultipath/util.h b/libmultipath/util.h
8b67ad
index ce277680..f898c829 100644
8b67ad
--- a/libmultipath/util.h
8b67ad
+++ b/libmultipath/util.h
8b67ad
@@ -44,6 +44,7 @@ void set_max_fds(rlim_t max_fds);
8b67ad
 	pthread_cleanup_push(((void (*)(void *))&f), (arg))
8b67ad
 
8b67ad
 void close_fd(void *arg);
8b67ad
+void cleanup_free_ptr(void *arg);
8b67ad
 void cleanup_mutex(void *arg);
8b67ad
 
8b67ad
 struct scandir_result {
8b67ad
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
8b67ad
index 8e418372..61d2712b 100644
8b67ad
--- a/multipath/multipath.conf.5
8b67ad
+++ b/multipath/multipath.conf.5
8b67ad
@@ -458,8 +458,11 @@ precedence. See KNOWN ISSUES.
8b67ad
 <mode> can be \fIbio\fR, \fIrq\fR or \fImq\fR, which corresponds to
8b67ad
 bio-based, request-based, and block-multiqueue (blk-mq) request-based,
8b67ad
 respectively.
8b67ad
-The default depends on the kernel parameter \fBdm_mod.use_blk_mq\fR. It is
8b67ad
-\fImq\fR if the latter is set, and \fIrq\fR otherwise.
8b67ad
+Before kernel 4.20 The default depends on the kernel parameter
8b67ad
+\fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR
8b67ad
+otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
8b67ad
+block-multiqueue. Once a multipath device has been created, its queue_mode
8b67ad
+cannot be changed.
8b67ad
 .TP
8b67ad
 The default is: \fB<unset>\fR
8b67ad
 .RE