Blame SOURCES/0075-libmultipath-enforce-queue_mode-bio-for-nmve-tcp-pat.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:44 -0500
86e138
Subject: [PATCH] libmultipath: enforce queue_mode bio for nmve:tcp paths
86e138
86e138
nvme:tcp devices set BLK_MQ_F_BLOCKING (they are the only block devices
86e138
which multipath supports that do so), meaning that block_mq expects that
86e138
they can block at certain points while servicing a request.  However,
86e138
due to the way device-mapper sets up its queue, it is not able to set
86e138
BLK_MQ_F_BLOCKING when it includes paths that set this flag.  Patches
86e138
were written to address this issue but they were rejected upstream
86e138
86e138
https://lore.kernel.org/linux-block/YcH%2FE4JNag0QYYAa@infradead.org/T/#t
86e138
86e138
The proposed solution was to have multipath use the bio queue_mode for
86e138
multipath devices that include nvme:tcp paths.
86e138
86e138
Multipath devices now automatically add the "queue_mode bio" feature if
86e138
they include nvme:tcp paths.  If a multipath devices was created with
86e138
"queue_mode rq", it will disallow the addition of nvme:tcp paths.
86e138
86e138
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
86e138
Reviewed-by: Martin Wilck <mwilck@suse.com>
86e138
---
86e138
 libmultipath/configure.c   | 17 ++++++++++++++++-
86e138
 libmultipath/structs_vec.c |  7 +++++++
86e138
 multipath/multipath.conf.5 |  4 +++-
86e138
 3 files changed, 26 insertions(+), 2 deletions(-)
86e138
86e138
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
86e138
index c6803b40..193bf27d 100644
86e138
--- a/libmultipath/configure.c
86e138
+++ b/libmultipath/configure.c
86e138
@@ -296,6 +296,7 @@ static int wait_for_pending_paths(struct multipath *mpp,
86e138
 int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
86e138
 {
86e138
 	struct pathgroup * pgp;
86e138
+	struct path *pp;
86e138
 	struct config *conf;
86e138
 	int i, n_paths, marginal_pathgroups;
86e138
 	char *save_attr;
86e138
@@ -311,6 +312,14 @@ int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
86e138
 	if (mpp->disable_queueing && VECTOR_SIZE(mpp->paths) != 0)
86e138
 		mpp->disable_queueing = 0;
86e138
 
86e138
+	/* Force QUEUE_MODE_BIO for maps with nvme:tcp paths */
86e138
+	vector_foreach_slot(mpp->paths, pp, i) {
86e138
+		if (pp->bus == SYSFS_BUS_NVME &&
86e138
+		    pp->sg_id.proto_id == NVME_PROTOCOL_TCP) {
86e138
+			mpp->queue_mode = QUEUE_MODE_BIO;
86e138
+			break;
86e138
+		}
86e138
+	}
86e138
 	/*
86e138
 	 * If this map was created with add_map_without_path(),
86e138
 	 * mpp->hwe might not be set yet.
86e138
@@ -1191,6 +1200,13 @@ int coalesce_paths (struct vectors *vecs, vector mpvec, char *refwwid,
86e138
 			continue;
86e138
 		}
86e138
 
86e138
+		cmpp = find_mp_by_wwid(curmp, pp1->wwid);
86e138
+		if (cmpp && cmpp->queue_mode == QUEUE_MODE_RQ &&
86e138
+		    pp1->bus == SYSFS_BUS_NVME && pp1->sg_id.proto_id ==
86e138
+		    NVME_PROTOCOL_TCP) {
86e138
+			orphan_path(pp1, "nvme:tcp path not allowed with request queue_mode multipath device");
86e138
+			continue;
86e138
+		}
86e138
 		/*
86e138
 		 * at this point, we know we really got a new mp
86e138
 		 */
86e138
@@ -1229,7 +1245,6 @@ 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
diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c
86e138
index 85d97ac1..4a32b405 100644
86e138
--- a/libmultipath/structs_vec.c
86e138
+++ b/libmultipath/structs_vec.c
86e138
@@ -262,6 +262,13 @@ int adopt_paths(vector pathvec, struct multipath *mpp)
86e138
 			}
86e138
 			if (pp->initialized == INIT_REMOVED)
86e138
 				continue;
86e138
+			if (mpp->queue_mode == QUEUE_MODE_RQ &&
86e138
+			    pp->bus == SYSFS_BUS_NVME &&
86e138
+			    pp->sg_id.proto_id == NVME_PROTOCOL_TCP) {
86e138
+				condlog(2, "%s: mulitpath device %s created with request queue_mode. Unable to add nvme:tcp paths",
86e138
+					pp->dev, mpp->alias);
86e138
+				continue;
86e138
+			}
86e138
 			if (!mpp->paths && !(mpp->paths = vector_alloc()))
86e138
 				goto err;
86e138
 
86e138
diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5
86e138
index 7af53588..01904feb 100644
86e138
--- a/multipath/multipath.conf.5
86e138
+++ b/multipath/multipath.conf.5
86e138
@@ -472,7 +472,9 @@ 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
+cannot be changed. \fInvme:tcp\fR paths are only supported in multipath
86e138
+devices with queue_mode set to \fIbio\fR. multipath will automatically
86e138
+set this when creating a device with \fInvme:tcp\fR paths.
86e138
 .TP
86e138
 The default is: \fB<unset>\fR
86e138
 .RE