[PATCH 02/19] nvme: introduce a namespace count in the ns head structure
John Garry
john.g.garry at oracle.com
Mon Mar 2 07:57:16 PST 2026
On 02/03/2026 12:46, Nilay Shroff wrote:
>>
>> 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?
As mentioned, if CONFIG_NVME_MULTIPATH is disabled, mpath_head->dev_list
is not maintained. So we need another method to set NS count in the core
code.
> 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?
I think that it should be ok. I was just trying to reduce pointer
declaration (as they need to be maintained).
Thanks!
More information about the Linux-nvme
mailing list