[PATCH 2/2] nvme: fix unmatched id's under delayed path deletion
Christoph Hellwig
hch at lst.de
Thu Feb 26 07:37:40 PST 2026
On Wed, Feb 25, 2026 at 12:21:09PM -0800, Keith Busch wrote:
> From: Keith Busch <kbusch at kernel.org>
>
> The NVMe controller is allowed to reuse an NSID for a new namespace after
> deleting the previous namespace that had been using it. The delayed removal may
> have the stale namespace head in the subsystem list pending the timer, which
Overlong lines.
> + bool retry = IS_ENABLED(CONFIG_NVME_MULTIPATH);
> struct nvme_ctrl *ctrl = ns->ctrl;
> struct nvme_ns_head *head = NULL;
> int ret;
> @@ -4008,6 +4009,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
> ctrl->quirks |= NVME_QUIRK_BOGUS_NID;
> }
>
> +again:
> mutex_lock(&ctrl->subsys->lock);
> head = nvme_find_ns_head(ctrl, info->nsid);
> if (!head) {
> @@ -4033,6 +4035,22 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
> goto out_put_ns_head;
> }
> if (!nvme_ns_ids_equal(&head->ids, &info->ids)) {
> + /*
> + * A newly created namespace can reuse an NSID that was
> + * previously deleted. If the head has no active paths,
> + * it is pending delayed removal and still occupying
> + * this NSID in the subsystem list. Flush the removal
> + * work to clear the stale head and retry.
> + */
> + if (retry && list_empty(&head->list)) {
I find the retry logic a bit odd and different from other places
do in similar areas. What I'd expected is either a "nr_retries" or
"did_retry" variable initialized to 0/false, then checked here to
be not set (plus the IS_ENABLED() for multipath) and incremented/set
below.
But independent of that, the actual logic looks fine.
More information about the Linux-nvme
mailing list