[PATCH v3 2/4] nvme: initialize head before namespace

Christoph Hellwig hch at lst.de
Wed Dec 6 00:50:44 PST 2023


On Wed, Dec 06, 2023 at 09:12:42AM +0100, Daniel Wagner wrote:
> In preparation to use struct nvme_ns_head pointers instead of a struct
> nvme_ns pointers, initialize the head pointer before we create the disk.
> This allows us to attach the head as private data to the disk object.
> 
> Signed-off-by: Daniel Wagner <dwagner at suse.de>
> ---
>  drivers/nvme/host/core.c | 46 ++++++++++++++++++++++------------------
>  1 file changed, 25 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 900c045fcae0..1fabe1b81de0 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3474,10 +3474,11 @@ static int nvme_global_check_duplicate_ids(struct nvme_subsystem *this,
>  	return ret;
>  }
>  
> -static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
> +static int nvme_init_ns_head(struct nvme_ctrl *ctrl,
> +			     struct nvme_ns_info *info,
> +			     struct nvme_ns_head **head)

Can we just return the head or an ERR_PTR here instead of an additional 
argument?  That would also remove the need for the variable renaming
below.

I'd also rename the function to nvme_find_or_alloc_ns_head if you're at
it.

> +	mutex_lock(&ctrl->subsys->lock);
> +	list_add_tail_rcu(&ns->siblings, &ns->head->list);
> +	mutex_unlock(&ctrl->subsys->lock);

This can't race with someone else adding the ns as all scanning is
from the scan work item.  Maybe ad da comment on why this pattern is
safe?  Because I think it wasn't when the code was originally added..

Otherwise this looks good to me.



More information about the Linux-nvme mailing list