Re: [PATCH] nvme: Add module reference counting for multipath nvme device
Keith Busch <[email protected]>
| Newsgroups | org.infradead.lists.linux-nvme |
|---|---|
| Message-ID | <ant0I66BcAugTyGX@kbusch-mbp> |
On Mon, Aug 10, 2026 at 07:50:34PM -0400, [email protected] 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.