[PATCH v2] nvme-multipath: add fail_if_no_path sysfs attribute
Nilay Shroff
nilay at linux.ibm.com
Fri Sep 18 01:58:48 PDT 2026
On 9/18/26 4:46 AM, Krishna Iyer wrote:
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 3d46c4f28a47..23aeb1737ab5 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -499,6 +499,8 @@ inline struct nvme_ns *nvme_find_path(struct nvme_ns_head *head)
> static bool nvme_available_path(struct nvme_ns_head *head)
> __must_hold_shared(&head->srcu)
> {
> + bool fail_if_no_path = test_bit(NVME_NSHEAD_FAIL_IF_NO_PATH,
> + &head->flags);
> struct nvme_ns *ns;
>
> if (!test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags))
> @@ -510,14 +512,25 @@ static bool nvme_available_path(struct nvme_ns_head *head)
> continue;
> switch (nvme_ctrl_state(ns->ctrl)) {
> case NVME_CTRL_LIVE:
> + if (fail_if_no_path &&
> + (ns->ana_state == NVME_ANA_INACCESSIBLE ||
> + ns->ana_state == NVME_ANA_PERSISTENT_LOSS))
> + continue;
I think we have helper nvme_state_is_live() which could be used here.
[...]
> +static ssize_t fail_if_no_path_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct gendisk *disk = dev_to_disk(dev);
> + struct nvme_ns_head *head = disk->private_data;
> + bool enable;
> + int ret;
> +
> + ret = kstrtobool(buf, &enable);
> + if (ret < 0)
> + return ret;
> +
> + if (enable)
> + set_bit(NVME_NSHEAD_FAIL_IF_NO_PATH, &head->flags);
> + else
> + clear_bit(NVME_NSHEAD_FAIL_IF_NO_PATH, &head->flags);
> +
> + /*
> + * Ensure that update to NVME_NSHEAD_FAIL_IF_NO_PATH is seen
> + * by its reader.
> + */
> + synchronize_srcu(&head->srcu);
> +
> + /* Make already-queued I/O re-evaluate path availability. */
> + if (enable)
> + kblockd_schedule_work(&head->requeue_work);
> +
If the user stores the same value as the current setting, we could
return immediately instead of waiting for synchronize_srcu() and
scheduling the requeue work.
Otherwise changes look good.
Thanks,
--Nilay
More information about the Linux-nvme
mailing list