[PATCH v4] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock
Nilay Shroff
nilay at linux.ibm.com
Wed Dec 2 07:24:41 PST 2026
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.
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.
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