[PATCH v4] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock

Guixin Liu kanie at linux.alibaba.com
Thu Dec 3 03:50:24 PST 2026



在 2026/12/2 23:24, Nilay Shroff 写道:
> On 12/2/26 2:21 PM, Guixin Liu wrote:
>>   void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
>>   {
>> -    if (nvme_ctrl_use_ana(ns->ctrl)) {
>> -        struct nvme_ana_group_desc desc = {
>> -            .grpid = anagrpid,
>> -            .state = 0,
>> -        };
>> +    struct nvme_ana_group_desc desc = {
>> +        .grpid = anagrpid,
>> +        .state = 0,
>> +    };
>> +    bool use_ana;
>>   -        mutex_lock(&ns->ctrl->ana_lock);
>> +    mutex_lock(&ns->ctrl->ana_lock);
>> +    use_ana = nvme_ctrl_use_ana(ns->ctrl);
>
> I think the existing lockless nvme_ctrl_use_ana() check is intentional.
> It is essentially a feature-selection test: for a controller that does
> not support ANA, ana_log_buf is never initialized, whereas for an
> ANA-capable controller, it is initialized before namespace scanning
> begins.
>
> In any case, even if nvme_mpath_uninit() runs concurrently with
> nvme_mpath_add_disk() and the latter proceeds to nvme_parse_ana_log(),
> the nvme_mpath_add_disk() rechecks ctrl->ana_log_buf, so we should be
> safe.
You are right, I will drop this in v5.
>
> Ideally, nvme_parse_ana_log() should return an error code that
> distinguishes between ctrl->ana_log_buf being NULL and other errors.
> This would then allow nvme_mpath_add_disk() to make the appropriate
> decision based on the actual failure.
That makes sense, changed in v5, thanks.

Best Regards,
Guixin Liu
>
> So IMO, moving nvme_ctrl_use_ana() under ctrl->ana_lock may
> not br optimal.
>
> Thanks,
> --Nilay




More information about the Linux-nvme mailing list