[PATCH] nvme: Add module reference counting for multipath nvme device
Keith Busch
kbusch at kernel.org
Tue Aug 11 12:12:35 PDT 2026
On Mon, Aug 10, 2026 at 07:50:34PM -0400, wenxiong at linux.ibm.com wrote:
> static int nvme_ns_head_open(struct gendisk *disk, blk_mode_t mode)
> {
> - if (!nvme_tryget_ns_head(disk->private_data))
> + struct nvme_ns_head *head = disk->private_data;
> + struct nvme_ns *ns;
> + int srcu_idx;
> +
> + if (!nvme_tryget_ns_head(head))
> return -ENXIO;
> +
> + /* Get module reference from any available path */
> + srcu_idx = srcu_read_lock(&head->srcu);
> + ns = nvme_find_path(head);
> + if (ns && !try_module_get(ns->ctrl->ops->module)) {
> + srcu_read_unlock(&head->srcu, srcu_idx);
> + nvme_put_ns_head(head);
> + return -ENXIO;
> + }
> + srcu_read_unlock(&head->srcu, srcu_idx);
> +
> return 0;
> }
>
> static void nvme_ns_head_release(struct gendisk *disk)
> {
> - nvme_put_ns_head(disk->private_data);
> + struct nvme_ns_head *head = disk->private_data;
> + struct nvme_ns *ns;
> + int srcu_idx;
> +
> + srcu_idx = srcu_read_lock(&head->srcu);
> + ns = nvme_find_path(head);
> + if (ns)
> + module_put(ns->ctrl->ops->module);
> + srcu_read_unlock(&head->srcu, srcu_idx);
> +
> + nvme_put_ns_head(head);
> }
The result of nvme_find_path() is just the current path at the moment,
so I don't think this is right.
I think you need the head to hold a module reference on every path the
head has, so the module_get/put should be in nvme_mpath_add_disk and
nvme_mpath_remove_disk.
More information about the Linux-nvme
mailing list