[PATCH 06/19] nvme-multipath: add nvme_mpath_{add, remove}_cdev()
From: John Garry
Date: Wed Feb 25 2026 - 10:59:20 EST
These are for mpath_head_template.add_cdev+del_cdev callbacks.
Currently the same functionality is in nvme_add_ns_cdev() and
nvme_cdev_del().
Signed-off-by: John Garry <john.g.garry@xxxxxxxxxx>
---
drivers/nvme/host/multipath.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index e888791b8947a..c90ac76dbe317 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -628,6 +628,26 @@ const struct block_device_operations nvme_ns_head_ops = {
.pr_ops = &nvme_pr_ops,
};
+static int nvme_mpath_add_cdev(struct mpath_head *mpath_head)
+{
+ struct nvme_ns_head *head = mpath_head->drvdata;
+ int ret;
+
+ mpath_head->cdev_device.parent = &head->subsys->dev;
+ ret = dev_set_name(&mpath_head->cdev_device, "ng%dn%d",
+ head->subsys->instance, head->instance);
+ if (ret)
+ return ret;
+ ret = nvme_cdev_add(&mpath_head->cdev, &mpath_head->cdev_device,
+ &mpath_generic_chr_fops, THIS_MODULE);
+ return ret;
+}
+
+static void nvme_mpath_del_cdev(struct mpath_head *mpath_head)
+{
+ nvme_cdev_del(&mpath_head->cdev, &mpath_head->cdev_device);
+}
+
static inline struct nvme_ns_head *cdev_to_ns_head(struct cdev *cdev)
{
return container_of(cdev, struct nvme_ns_head, cdev);
@@ -1433,4 +1453,6 @@ void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
__maybe_unused
static const struct mpath_head_template mpdt = {
.available_path = nvme_mpath_available_path,
+ .add_cdev = nvme_mpath_add_cdev,
+ .del_cdev = nvme_mpath_del_cdev,
};
--
2.43.5