[PATCH 16/19] nvme-multipath: add nvme_mpath_{add,delete}_ns()

John Garry posted 19 patches 1 month, 1 week ago
[PATCH 16/19] nvme-multipath: add nvme_mpath_{add,delete}_ns()
Posted by John Garry 1 month, 1 week ago
Add functions to call into the mpath_add_device() and mpath_delete_device()
functions.

The per-NS gendisk pointer is used as the mpath_device disk pointer, which
is used in libmultipath for references the per-path block device.

Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/nvme/host/multipath.c | 26 ++++++++++++++++++++++++++
 drivers/nvme/host/nvme.h      |  8 ++++++++
 2 files changed, 34 insertions(+)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 7ee0ad7bdfa26..bd96211123fee 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -982,6 +982,32 @@ void nvme_mpath_synchronize(struct nvme_ns_head *head)
 	mpath_synchronize(mpath_disk->mpath_head);
 }
 
+void nvme_mpath_add_ns(struct nvme_ns *ns)
+{
+	struct nvme_ns_head *head = ns->head;
+	struct mpath_disk *mpath_disk = head->mpath_disk;
+	struct mpath_head *mpath_head;
+
+	if (!mpath_disk)
+		return;
+
+	mpath_head = mpath_disk->mpath_head;
+
+	ns->mpath_device.disk = ns->disk;
+	mpath_add_device(mpath_head, &ns->mpath_device);
+}
+
+void nvme_mpath_delete_ns(struct nvme_ns *ns)
+{
+	struct nvme_ns_head *head = ns->head;
+	struct mpath_disk *mpath_disk = head->mpath_disk;
+
+	if (!mpath_disk)
+		return;
+
+	mpath_delete_device(mpath_disk->mpath_head, &ns->mpath_device);
+}
+
 static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
 		struct nvme_ana_group_desc *desc, void *data)
 {
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index d642b0eddf010..3c08212e4a54f 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -1028,6 +1028,8 @@ static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
 }
 
 void nvme_mpath_synchronize(struct nvme_ns_head *head);
+void nvme_mpath_add_ns(struct nvme_ns *ns);
+void nvme_mpath_delete_ns(struct nvme_ns *ns);
 void nvme_mpath_unfreeze(struct nvme_subsystem *subsys);
 void nvme_mpath_wait_freeze(struct nvme_subsystem *subsys);
 void nvme_mpath_start_freeze(struct nvme_subsystem *subsys);
@@ -1099,6 +1101,12 @@ static inline bool nvme_ctrl_use_ana(struct nvme_ctrl *ctrl)
 static inline void nvme_mpath_synchronize(struct nvme_ns_head *head)
 {
 }
+static inline void nvme_mpath_add_ns(struct nvme_ns *ns)
+{
+}
+static inline void nvme_mpath_delete_ns(struct nvme_ns *ns)
+{
+}
 static inline void nvme_failover_req(struct request *req)
 {
 }
-- 
2.43.5
Re: [PATCH 16/19] nvme-multipath: add nvme_mpath_{add,delete}_ns()
Posted by Nilay Shroff 1 month ago
On 2/25/26 9:10 PM, John Garry wrote:
> Add functions to call into the mpath_add_device() and mpath_delete_device()
> functions.
> 
> The per-NS gendisk pointer is used as the mpath_device disk pointer, which
> is used in libmultipath for references the per-path block device.
> 
> Signed-off-by: John Garry<john.g.garry@oracle.com>
> ---
>   drivers/nvme/host/multipath.c | 26 ++++++++++++++++++++++++++
>   drivers/nvme/host/nvme.h      |  8 ++++++++
>   2 files changed, 34 insertions(+)
> 
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 7ee0ad7bdfa26..bd96211123fee 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -982,6 +982,32 @@ void nvme_mpath_synchronize(struct nvme_ns_head *head)
>   	mpath_synchronize(mpath_disk->mpath_head);
>   }
>   
> +void nvme_mpath_add_ns(struct nvme_ns *ns)
> +{
> +	struct nvme_ns_head *head = ns->head;
> +	struct mpath_disk *mpath_disk = head->mpath_disk;
> +	struct mpath_head *mpath_head;
> +
> +	if (!mpath_disk)
> +		return;
> +
> +	mpath_head = mpath_disk->mpath_head;
> +
> +	ns->mpath_device.disk = ns->disk;
> +	mpath_add_device(mpath_head, &ns->mpath_device);
> +}

As we have now reference to mpath_device from struct nvme_ns
then why do we still maintain reference to ns->disk? We may
want to directly access path device disk using ns->mpath_device.disk,
makes sense?

Thanks,
--Nilay
Re: [PATCH 16/19] nvme-multipath: add nvme_mpath_{add,delete}_ns()
Posted by John Garry 1 month ago
On 02/03/2026 12:48, Nilay Shroff wrote:
>> +void nvme_mpath_add_ns(struct nvme_ns *ns)
>> +{
>> +    struct nvme_ns_head *head = ns->head;
>> +    struct mpath_disk *mpath_disk = head->mpath_disk;
>> +    struct mpath_head *mpath_head;
>> +
>> +    if (!mpath_disk)
>> +        return;
>> +
>> +    mpath_head = mpath_disk->mpath_head;
>> +
>> +    ns->mpath_device.disk = ns->disk;
>> +    mpath_add_device(mpath_head, &ns->mpath_device);
>> +}
> 
> As we have now reference to mpath_device from struct nvme_ns
> then why do we still maintain reference to ns->disk? We may
> want to directly access path device disk using ns->mpath_device.disk,
> makes sense?

For !CONFIG_NVME_MULTIPATH or !multipath mod param set, mpath_device is 
not properly maintained, so I would rather not use it in the core code.

Thanks,
John