[PATCH v6 2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal
From: Qiliang Yuan
Date: Thu Nov 19 2026 - 20:25:38 EST
With delayed_removal_secs set, removing the last path of a namespace
head doesn't delete the head right away. nvme_mpath_remove_disk()
queues remove_work with the configured delay, and bios submitted in the
meantime wait on head->requeue_list in case a path comes back.
A write to delayed_removal_secs only takes effect for removals that
start later. A removal that is already pending keeps the old delay, so
clearing the attribute leaves the queued bios waiting until that delay
expires instead of failing them, and lowering or raising it doesn't
move the pending removal either. When paths remain but none of them is
usable, for example because they are ANA inaccessible, nothing
resubmits the queued bios after the attribute is cleared at all.
Requeue a pending remove_work with the new delay when the attribute is
written, cancelling it first so that the module reference taken for it
carries over. Have nvme_init_ns_head() cancel the pending removal
before it drops subsys->lock rather than after, so that a write to the
attribute cannot requeue the removal once a path is back. When the
attribute is cleared, kick requeue_work, so that the queued bios fail
right away if there is still no usable path.
With delayed_removal_secs set and no path left, the attribute is
changed two seconds later and the head is removed after (mean of two
runs, min-max in parentheses):
delay (s) before (ms) after (ms) change
30 -> 0 26311 (26103-26518) 8.5 (8-9) -99.97%
30 -> 5 28281 (28037-28525) 5293 (5198-5388) -81%
10 -> 30 8110 (8097-8122) 30094 (30057-30130) +271%
A direct read queued before the 30 -> 0 write fails this long after
the write, with no path left and with the only path ANA inaccessible
("> 15000" means it was still queued 15 s later):
paths before (ms) after (ms) change
none 26261 (26071-26451) 4.5 (4-5) -99.98%
inaccessible > 15000 4.5 (4-5) < -99.97%
Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
Suggested-by: Nilay Shroff <nilay@xxxxxxxxxxxxx>
Signed-off-by: Qiliang Yuan <qiliang.yuan@xxxxxxxxx>
Reviewed-by: Nilay Shroff <nilay@xxxxxxxxxxxxx>
---
drivers/nvme/host/core.c | 7 +++++--
drivers/nvme/host/multipath.c | 11 +++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f4aa02869b790..48d432c5d7aeb 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4231,12 +4231,15 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)
list_add_tail_rcu(&ns->siblings, &head->list);
ns->head = head;
- mutex_unlock(&ctrl->subsys->lock);
-
#ifdef CONFIG_NVME_MULTIPATH
+ /*
+ * Cancel a pending head removal under subsys->lock, so that
+ * delayed_removal_secs_store() never requeues it once a path is back.
+ */
if (cancel_delayed_work(&head->remove_work))
module_put(THIS_MODULE);
#endif
+ mutex_unlock(&ctrl->subsys->lock);
return 0;
out_put_ns_head:
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 9958d08cd3829..df96933f49459 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -1251,6 +1251,13 @@ static ssize_t delayed_removal_secs_store(struct device *dev,
mutex_lock(&head->subsys->lock);
head->delayed_removal_secs = sec;
assign_bit(NVME_NSHEAD_QUEUE_IF_NO_PATH, &head->flags, sec);
+ /*
+ * Apply the new delay to a removal that is still pending. The module
+ * reference taken for it carries over to the requeued work.
+ */
+ if (cancel_delayed_work(&head->remove_work))
+ queue_delayed_work(nvme_wq, &head->remove_work,
+ nvme_delayed_removal_jiffies(sec));
mutex_unlock(&head->subsys->lock);
/*
* Ensure that update to NVME_NSHEAD_QUEUE_IF_NO_PATH is seen
@@ -1258,6 +1265,10 @@ static ssize_t delayed_removal_secs_store(struct device *dev,
*/
synchronize_srcu(&head->srcu);
+ /* Resubmit queued bios, so that they fail without a usable path */
+ if (!sec)
+ kblockd_schedule_work(&head->requeue_work);
+
return count;
}
--
2.43.0