[PATCH 02/19] nvme: introduce a namespace count in the ns head structure
Nilay Shroff
nilay at linux.ibm.com
Mon Mar 2 04:46:01 PST 2026
On 2/25/26 9:09 PM, John Garry wrote:
> For switching to use libmultipath, the per-namespace sibling list entry in
> nvme_ns.sibling will be replaced with multipath_device.sibling list
> pointer.
>
> For when CONFIG_LIBMULTIPATH is disabled, that list of namespaces would no
> longer be maintained.
>
> However the core code checks in many places whether there is any
> namespace in the head list, like in nvme_ns_remove().
>
> Introduce a separate count of the number of namespaces for the namespace
> head and use that count for the places where the per-namespace head list
> of namespaces is checked to be empty.
>
> Signed-off-by: John Garry<john.g.garry at oracle.com>
> ---
> drivers/nvme/host/core.c | 10 +++++++---
> drivers/nvme/host/multipath.c | 4 ++--
> drivers/nvme/host/nvme.h | 1 +
> 3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 37e30caff4149..76249871dd7c2 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -4024,7 +4024,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
> } else {
> ret = -EINVAL;
> if ((!info->is_shared || !head->shared) &&
> - !list_empty(&head->list)) {
> + head->ns_count) {
> dev_err(ctrl->device,
> "Duplicate unshared namespace %d\n",
> info->nsid);
> @@ -4047,6 +4047,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
> }
>
> list_add_tail_rcu(&ns->siblings, &head->list);
> + head->ns_count++;
> ns->head = head;
> mutex_unlock(&ctrl->subsys->lock);
>
I think we could still access head->mpath_disk->mpath_head->dev_list.
So in that case do we really need to have ->ns_count? Moreover, if
we could maintain a pointer to struct mpath_head from struct
nvme_ns_head then we may avoid one dereference. What do you think?
Thanks,
--Nilay
More information about the Linux-nvme
mailing list