[PATCH] nvme-multipath: expose path_state via sysfs

Nilay Shroff nilay at linux.ibm.com
Sun Jun 21 22:10:27 PDT 2026


On 6/17/26 5:45 PM, Guixin Liu wrote:
> Add a read-only "path_state" sysfs attribute to each NVMe path namespace
> device (/sys/class/nvme/nvmeX/nvmeXcYnZ/path_state) that exposes whether
> the path is currently enabled or disabled.
> 
> The attribute reflects the result of nvme_path_is_disabled(), showing
> "disabled" when the controller is not live/deleting, the namespace has
> an ANA state change pending, or the namespace is not ready. Otherwise
> it shows "enabled".
> 
> This gives userspace visibility into the multipath path selection state
> without requiring users to piece together controller state and namespace
> flags manually.
> 
> Signed-off-by: Guixin Liu<kanie at linux.alibaba.com>
> ---
>   drivers/nvme/host/multipath.c | 10 ++++++++++
>   drivers/nvme/host/nvme.h      |  1 +
>   drivers/nvme/host/sysfs.c     |  4 +++-
>   3 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 81fff2f20d23..65bd3dd188ee 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -1210,6 +1210,16 @@ static ssize_t in_flight_bytes_show(struct device *dev,
>   }
>   DEVICE_ATTR_RO(in_flight_bytes);
>   
> +static ssize_t path_state_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct nvme_ns *ns = nvme_get_ns_from_dev(dev);
> +
> +	return sysfs_emit(buf, "%s\n",
> +			  nvme_path_is_disabled(ns) ? "disabled" : "enabled");
> +}
> +DEVICE_ATTR_RO(path_state);
> +

Instead of only exposing disabled/enabled state, can we also expose the
reason why the path was not usable?

For instance, path_state attribute shall expose "enabled" when it's
available for I/O (this is straightforward):
- enabled

But in case path is not usable/available then expose "disabled" along
with the reason:
- disabled (ctrl_down)
- disabled (ana_pending)
- disabled (ns_not_ready)

Or any other combination depending on the ns->flags and ctrl->state.

That way, the userspace would know the exact reason when path is
not available/usable for I/O.

Thanks,
--Nilay



More information about the Linux-nvme mailing list