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

86e138
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
86e138
From: Benjamin Marzinski <bmarzins@redhat.com>
86e138
Date: Fri, 7 Oct 2022 12:35:40 -0500
86e138
Subject: [PATCH] libmultipath: fix queue_mode feature handling
86e138
86e138
device-mapper is not able to change the queue_mode on a table reload.
86e138
Make sure that when multipath sets up the map, both on regular reloads
86e138
and reconfigures, it keeps the queue_mode the same.
86e138
86e138
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
86e138
Reviewed-by: Martin Wilck <mwilck@suse.com>
86e138
---
86e138
 libmultipath/configure.c   |  4 +++
86e138
 libmultipath/dmparser.c    |  2 ++
86e138
 libmultipath/propsel.c     | 55 ++++++++++++++++++++++++++++++++++++++
86e138
 libmultipath/structs.h     |  7 +++++
86e138
 multipath/multipath.conf.5 |  7 +++--
86e138
 5 files changed, 73 insertions(+), 2 deletions(-)
86e138
86e138
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
86e138
index 70049f47..cc778a22 100644
86e138
--- a/libmultipath/configure.c
86e138
+++ b/libmultipath/configure.c
86e138
@@ -1118,6 +1118,7 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
86e138
 	struct config *conf = NULL;
86e138
 	int allow_queueing;
86e138
 	struct bitfield *size_mismatch_seen;
86e138
+	struct multipath * cmpp;
86e138
 
86e138
 	/* ignore refwwid if it's empty */
86e138
 	if (refwwid && !strlen(refwwid))
86e138
@@ -1227,6 +1228,9 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
86e138
 		}
86e138
 		verify_paths(mpp);
86e138
 
86e138
+		cmpp = find_mp_by_wwid(curmp, mpp->wwid);
86e138
+		if (cmpp)
86e138
+			mpp->queue_mode = cmpp->queue_mode;
86e138
 		if (setup_map(mpp, &params, vecs)) {
86e138
 			remove_map(mpp, vecs->pathvec, NULL);
86e138
 			continue;
86e138
diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c
86e138
index bc311421..16377c54 100644
86e138
--- a/libmultipath/dmparser.c
86e138
+++ b/libmultipath/dmparser.c
86e138
@@ -152,6 +152,8 @@ int disassemble_map(const struct _vector *pathvec,
86e138
 
86e138
 		FREE(word);
86e138
 	}
86e138
+	mpp->queue_mode = strstr(mpp->features, "queue_mode bio") ?
86e138
+			  QUEUE_MODE_BIO : QUEUE_MODE_RQ;
86e138
 
86e138
 	/*
86e138
 	 * hwhandler
86e138
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
86e138
index 2b47f5f8..9dea6f92 100644
86e138
--- a/libmultipath/propsel.c
86e138
+++ b/libmultipath/propsel.c
86e138
@@ -27,6 +27,7 @@
86e138
 #include "strbuf.h"
86e138
 #include <inttypes.h>
86e138
 #include <libudev.h>
86e138
+#include <ctype.h>
86e138
 
86e138
 pgpolicyfn *pgpolicies[] = {
86e138
 	NULL,
86e138
@@ -414,6 +415,59 @@ void reconcile_features_with_options(const char *id, char **features, int* no_pa
86e138
 	}
86e138
 }
86e138
 
86e138
+static void reconcile_features_with_queue_mode(struct multipath *mp)
86e138
+{
86e138
+	char *space = NULL, *val = NULL, *mode_str = NULL, *feat;
86e138
+	int features_mode = QUEUE_MODE_UNDEF;
86e138
+
86e138
+	if (!mp->features)
86e138
+		return;
86e138
+
86e138
+	pthread_cleanup_push(cleanup_free_ptr, &space);
86e138
+	pthread_cleanup_push(cleanup_free_ptr, &val;;
86e138
+	pthread_cleanup_push(cleanup_free_ptr, &mode_str);
86e138
+
86e138
+	if (!(feat = strstr(mp->features, "queue_mode")) ||
86e138
+	    feat == mp->features || !isspace(*(feat - 1)) ||
86e138
+	    sscanf(feat, "queue_mode%m[ \f\n\r\t\v]%ms", &space, &val) != 2)
86e138
+		goto sync_mode;
86e138
+	if (asprintf(&mode_str, "queue_mode%s%s", space, val) < 0) {
86e138
+		condlog(1, "failed to allocate space for queue_mode feature string");
86e138
+		mode_str = NULL; /* value undefined on failure */
86e138
+		goto exit;
86e138
+	}
86e138
+
86e138
+	if (!strcmp(val, "rq") || !strcmp(val, "mq"))
86e138
+		features_mode = QUEUE_MODE_RQ;
86e138
+	else if (!strcmp(val, "bio"))
86e138
+		features_mode = QUEUE_MODE_BIO;
86e138
+	if (features_mode == QUEUE_MODE_UNDEF) {
86e138
+		condlog(2, "%s: ignoring invalid feature '%s'",
86e138
+			mp->alias, mode_str);
86e138
+		goto sync_mode;
86e138
+	}
86e138
+
86e138
+	if (mp->queue_mode == QUEUE_MODE_UNDEF)
86e138
+		mp->queue_mode = features_mode;
86e138
+	if (mp->queue_mode == features_mode)
86e138
+		goto exit;
86e138
+
86e138
+	condlog(2,
86e138
+		"%s: ignoring feature '%s' because queue_mode is set to '%s'",
86e138
+		mp->alias, mode_str,
86e138
+		(mp->queue_mode == QUEUE_MODE_RQ)? "rq" : "bio");
86e138
+
86e138
+sync_mode:
86e138
+	if (mode_str)
86e138
+		remove_feature(&mp->features, mode_str);
86e138
+	if (mp->queue_mode == QUEUE_MODE_BIO)
86e138
+		add_feature(&mp->features, "queue_mode bio");
86e138
+exit:
86e138
+	pthread_cleanup_pop(1);
86e138
+	pthread_cleanup_pop(1);
86e138
+	pthread_cleanup_pop(1);
86e138
+}
86e138
+
86e138
 int select_features(struct config *conf, struct multipath *mp)
86e138
 {
86e138
 	const char *origin;
86e138
@@ -429,6 +483,7 @@ out:
86e138
 	reconcile_features_with_options(mp->alias, &mp->features,
86e138
 					&mp->no_path_retry,
86e138
 					&mp->retain_hwhandler);
86e138
+	reconcile_features_with_queue_mode(mp);
86e138
 	condlog(3, "%s: features = \"%s\" %s", mp->alias, mp->features, origin);
86e138
 	return 0;
86e138
 }
86e138
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
86e138
index 8a07d470..b4f75de0 100644
86e138
--- a/libmultipath/structs.h
86e138
+++ b/libmultipath/structs.h
86e138
@@ -170,6 +170,12 @@ enum max_sectors_kb_states {
86e138
 	MAX_SECTORS_KB_MIN = 4,  /* can't be smaller than page size */
86e138
 };
86e138
 
86e138
+enum queue_mode_states {
86e138
+	QUEUE_MODE_UNDEF = 0,
86e138
+	QUEUE_MODE_BIO,
86e138
+	QUEUE_MODE_RQ,
86e138
+};
86e138
+
86e138
 enum scsi_protocol {
86e138
 	SCSI_PROTOCOL_FCP = 0,	/* Fibre Channel */
86e138
 	SCSI_PROTOCOL_SPI = 1,	/* parallel SCSI */
86e138
@@ -387,6 +393,7 @@ struct multipath {
86e138
 	int needs_paths_uevent;
86e138
 	int ghost_delay;
86e138
 	int ghost_delay_tick;
86e138
+	int queue_mode;
86e138
 	uid_t uid;
86e138
 	gid_t gid;
86e138
 	mode_t mode;
86e138
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
86e138
index f7de5140..e1a787d4 100644
86e138
--- a/multipath/multipath.conf.5
86e138
+++ b/multipath/multipath.conf.5
86e138
@@ -468,8 +468,11 @@ precedence. See KNOWN ISSUES.
86e138
 <mode> can be \fIbio\fR, \fIrq\fR or \fImq\fR, which corresponds to
86e138
 bio-based, request-based, and block-multiqueue (blk-mq) request-based,
86e138
 respectively.
86e138
-The default depends on the kernel parameter \fBdm_mod.use_blk_mq\fR. It is
86e138
-\fImq\fR if the latter is set, and \fIrq\fR otherwise.
86e138
+Before kernel 4.20 The default depends on the kernel parameter
86e138
+\fBdm_mod.use_blk_mq\fR. It is \fImq\fR if the latter is set, and \fIrq\fR
86e138
+otherwise. Since kernel 4.20, \fIrq\fR and \fImq\fR both correspond to
86e138
+block-multiqueue. Once a multipath device has been created, its queue_mode
86e138
+cannot be changed.
86e138
 .TP
86e138
 The default is: \fB<unset>\fR
86e138
 .RE