[PATCH 04/19] nvme-multipath: add initial support for using libmultipath

John Garry
2026-02-25T15:40:44Z

Add initial support, as follows:
- Add mpath_head_template
- Add mpath_device in nvme_ns
- Add mpath_disk pointer to head structure

Initially all the functionality which mpath_head_template points to will be
unused, until the driver fully switches to libmultipath. Otherwise it's
hard to do so in a step-wise fashion without breaking functionality.

Many of the libmultipath-based function added will reference the
ns mpath_device, so add that now. Also add the NS head disk pointer for the
same reason.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
drivers/nvme/host/Kconfig | 1 +
drivers/nvme/host/multipath.c | 6 ++++++
drivers/nvme/host/nvme.h | 6 ++++++
3 files changed, 13 insertions(+)

diff --git a/drivers/nvme/host/Kconfig b/drivers/nvme/host/Kconfig
index 31974c7dd20c9..fc6e75fe8cbfe 100644
--- a/drivers/nvme/host/Kconfig
+++ b/drivers/nvme/host/Kconfig
@@ -17,6 +17,7 @@ config BLK_DEV_NVME
config NVME_MULTIPATH
bool "NVMe multipath support"
depends on NVME_CORE
+ select LIBMULTIPATH
help
This option controls support for multipath access to NVMe
subsystems. If this option is enabled support for NVMe multipath
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 0d540749b16ee..390a1d1133921 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -12,6 +12,8 @@
bool multipath = true;
static bool multipath_always_on;

+static const struct mpath_head_template mpdt;
+
static int multipath_param_set(const char *val, const struct kernel_param *kp)
{
int ret;
@@ -1407,3 +1409,7 @@ void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
ctrl->ana_log_buf = NULL;
ctrl->ana_log_size = 0;
}
+
+__maybe_unused
+static const struct mpath_head_template mpdt = {
+};
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 6b5977610d886..c48efbfb46efc 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -13,6 +13,7 @@
#include <linux/blk-mq.h>
#include <linux/sed-opal.h>
#include <linux/fault-inject.h>
+#include <linux/multipath.h>
#include <linux/rcupdate.h>
#include <linux/wait.h>
#include <linux/t10-pi.h>
@@ -555,6 +556,8 @@ struct nvme_ns_head {

u16 nr_plids;
u16 *plids;
+
+ struct mpath_disk *mpath_disk;
#ifdef CONFIG_NVME_MULTIPATH
struct bio_list requeue_list;
spinlock_t requeue_lock;
@@ -582,6 +585,7 @@ enum nvme_ns_features {
};

struct nvme_ns {
+ struct mpath_device mpath_device;
struct list_head list;

struct nvme_ctrl *ctrl;
@@ -608,6 +612,8 @@ struct nvme_ns {
struct nvme_fault_inject fault_inject;
};

+#define nvme_mpath_to_ns(d) container_of(d, struct nvme_ns, mpath_device)
+
/* NVMe ns supports metadata actions by the controller (generate/strip) */
static inline bool nvme_ns_has_pi(struct nvme_ns_head *head)
{
--
2.43.5