[PATCH V3 10/10] nvmet: use xarray for ctrl ns storing
Chaitanya Kulkarni
Chaitanya.Kulkarni at wdc.com
Thu Jul 16 21:52:52 EDT 2020
On 7/15/20 00:10, Christoph Hellwig wrote:
>> index 9cdc39c8b729..2908acc7b1e2 100644
>> --- a/drivers/nvme/target/core.c
>> +++ b/drivers/nvme/target/core.c
>> @@ -115,13 +115,14 @@ u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len)
>>
>> static unsigned int nvmet_max_nsid(struct nvmet_subsys *subsys)
>> {
>> - struct nvmet_ns *ns;
>> + unsigned long nsid = 0;
>> + struct nvmet_ns *cur;
>> + unsigned long idx;
>>
>> - if (list_empty(&subsys->namespaces))
>> - return 0;
>> + xa_for_each(&subsys->namespaces, idx, cur)
>> + nsid = cur->nsid;
>>
>> - ns = list_last_entry(&subsys->namespaces, struct nvmet_ns, dev_link);
>> - return ns->nsid;
>> + return nsid;
>> }
>
> If Matthew wants to add a helper to return the highest id for an xarray
> this would be the place to use it.
>
Matthew, any suggestions on how to add a helper for above use case ?
we want to get the highest possible available index for in the XArray.
>
>> + ret = xa_insert(&subsys->namespaces, ns->nsid, ns, GFP_KERNEL);
>> + if (ret)
>> + goto out_dev_put;
>
Christoph,
> I don't think out_dev_put is enough here as that fails to tear down
> ns->ref.
>
Yes the call to percpu_ref_exit() is missing here, also it needs to
restore the subsys->max_nsid when xa_insert() fails (correct me if I'm
wrong), will add it to V4.
More information about the Linux-nvme
mailing list