* [PATCHv2] nvme: add 'fail_if_no_path' sysfs attribute
@ 2021-02-22 6:41 Hannes Reinecke
2021-02-22 10:15 ` Minwoo Im
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Reinecke @ 2021-02-22 6:41 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-nvme, Sagi Grimberg, Keith Busch, Hannes Reinecke
In some setups like RAID we need to return an I/O error
once all paths are unavailable to allow the upper layers
to start their own error recovery (like redirecting I/O
to other mirrors).
This patch adds a sysfs attribute 'fail_if_no_path' to
allow the admin to enable that behaviour instead of the
current 'queue until a path becomes available' policy.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/host/core.c | 5 +++++
drivers/nvme/host/multipath.c | 38 +++++++++++++++++++++++++++++++++--
drivers/nvme/host/nvme.h | 2 ++
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 5c1ec3bfb9d3..ef20029a46b2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3466,6 +3466,7 @@ static struct attribute *nvme_ns_id_attrs[] = {
#ifdef CONFIG_NVME_MULTIPATH
&dev_attr_ana_grpid.attr,
&dev_attr_ana_state.attr,
+ &dev_attr_fail_if_no_path.attr,
#endif
NULL,
};
@@ -3496,6 +3497,10 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,
if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl))
return 0;
}
+ if (a == &dev_attr_fail_if_no_path.attr) {
+ if (dev_to_disk(dev)->fops == &nvme_bdev_ops)
+ return 0;
+ }
#endif
return a->mode;
}
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 0696319adaf6..35ed2f6d431b 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -283,10 +283,13 @@ static bool nvme_available_path(struct nvme_ns_head *head)
continue;
switch (ns->ctrl->state) {
case NVME_CTRL_LIVE:
+ return true;
case NVME_CTRL_RESETTING:
- case NVME_CTRL_CONNECTING:
/* fallthru */
- return true;
+ case NVME_CTRL_CONNECTING:
+ if (!test_bit(NVME_NSHEAD_FAIL_IF_NO_PATH,
+ &head->flags))
+ return true;
default:
break;
}
@@ -641,6 +644,37 @@ static ssize_t ana_state_show(struct device *dev, struct device_attribute *attr,
}
DEVICE_ATTR_RO(ana_state);
+static ssize_t fail_if_no_path_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ struct nvme_ns_head *head = disk->private_data;
+
+ return sprintf(buf, "%d\n",
+ test_bit(NVME_NSHEAD_FAIL_IF_NO_PATH, &head->flags) ?
+ 1 : 0);
+}
+
+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;
+ int fail_if_no_path, err;
+
+ err = kstrtoint(buf, 10, &fail_if_no_path);
+ if (err)
+ return -EINVAL;
+
+ if (fail_if_no_path <= 0)
+ clear_bit(NVME_NSHEAD_FAIL_IF_NO_PATH, &head->flags);
+ else
+ set_bit(NVME_NSHEAD_FAIL_IF_NO_PATH, &head->flags);
+ return count;
+}
+DEVICE_ATTR(fail_if_no_path, S_IRUGO | S_IWUSR,
+ fail_if_no_path_show, fail_if_no_path_store);
+
static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl,
struct nvme_ana_group_desc *desc, void *data)
{
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 02aa4ba665c0..e8de2b9dcdc7 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -419,6 +419,7 @@ struct nvme_ns_head {
struct mutex lock;
unsigned long flags;
#define NVME_NSHEAD_DISK_LIVE 0
+#define NVME_NSHEAD_FAIL_IF_NO_PATH 1
struct nvme_ns __rcu *current_path[];
#endif
};
@@ -695,6 +696,7 @@ static inline void nvme_trace_bio_complete(struct request *req)
extern struct device_attribute dev_attr_ana_grpid;
extern struct device_attribute dev_attr_ana_state;
+extern struct device_attribute dev_attr_fail_if_no_path;
extern struct device_attribute subsys_attr_iopolicy;
#else
--
2.26.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCHv2] nvme: add 'fail_if_no_path' sysfs attribute
2021-02-22 6:41 [PATCHv2] nvme: add 'fail_if_no_path' sysfs attribute Hannes Reinecke
@ 2021-02-22 10:15 ` Minwoo Im
2021-02-22 12:37 ` Hannes Reinecke
0 siblings, 1 reply; 3+ messages in thread
From: Minwoo Im @ 2021-02-22 10:15 UTC (permalink / raw)
To: Hannes Reinecke; +Cc: Keith Busch, Christoph Hellwig, linux-nvme, Sagi Grimberg
On 21-02-22 07:41:55, Hannes Reinecke wrote:
> In some setups like RAID we need to return an I/O error
> once all paths are unavailable to allow the upper layers
> to start their own error recovery (like redirecting I/O
> to other mirrors).
> This patch adds a sysfs attribute 'fail_if_no_path' to
> allow the admin to enable that behaviour instead of the
> current 'queue until a path becomes available' policy.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/nvme/host/core.c | 5 +++++
> drivers/nvme/host/multipath.c | 38 +++++++++++++++++++++++++++++++++--
> drivers/nvme/host/nvme.h | 2 ++
> 3 files changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 5c1ec3bfb9d3..ef20029a46b2 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3466,6 +3466,7 @@ static struct attribute *nvme_ns_id_attrs[] = {
> #ifdef CONFIG_NVME_MULTIPATH
> &dev_attr_ana_grpid.attr,
> &dev_attr_ana_state.attr,
> + &dev_attr_fail_if_no_path.attr,
> #endif
> NULL,
> };
> @@ -3496,6 +3497,10 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,
> if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl))
> return 0;
> }
> + if (a == &dev_attr_fail_if_no_path.attr) {
> + if (dev_to_disk(dev)->fops == &nvme_bdev_ops)
> + return 0;
> + }
> #endif
> return a->mode;
> }
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 0696319adaf6..35ed2f6d431b 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -283,10 +283,13 @@ static bool nvme_available_path(struct nvme_ns_head *head)
> continue;
> switch (ns->ctrl->state) {
> case NVME_CTRL_LIVE:
> + return true;
Hello Hannes,
May I ask there's any reason why LIVE state is not covered by the sysfs
attribute that this patch introduced ? Wouldn't it be possible to have
no available paths (inaccessible) in LIVE state ?
Thanks! :)
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCHv2] nvme: add 'fail_if_no_path' sysfs attribute
2021-02-22 10:15 ` Minwoo Im
@ 2021-02-22 12:37 ` Hannes Reinecke
0 siblings, 0 replies; 3+ messages in thread
From: Hannes Reinecke @ 2021-02-22 12:37 UTC (permalink / raw)
To: Minwoo Im; +Cc: Keith Busch, Christoph Hellwig, linux-nvme, Sagi Grimberg
On 2/22/21 11:15 AM, Minwoo Im wrote:
> On 21-02-22 07:41:55, Hannes Reinecke wrote:
>> In some setups like RAID we need to return an I/O error
>> once all paths are unavailable to allow the upper layers
>> to start their own error recovery (like redirecting I/O
>> to other mirrors).
>> This patch adds a sysfs attribute 'fail_if_no_path' to
>> allow the admin to enable that behaviour instead of the
>> current 'queue until a path becomes available' policy.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>> drivers/nvme/host/core.c | 5 +++++
>> drivers/nvme/host/multipath.c | 38 +++++++++++++++++++++++++++++++++--
>> drivers/nvme/host/nvme.h | 2 ++
>> 3 files changed, 43 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index 5c1ec3bfb9d3..ef20029a46b2 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -3466,6 +3466,7 @@ static struct attribute *nvme_ns_id_attrs[] = {
>> #ifdef CONFIG_NVME_MULTIPATH
>> &dev_attr_ana_grpid.attr,
>> &dev_attr_ana_state.attr,
>> + &dev_attr_fail_if_no_path.attr,
>> #endif
>> NULL,
>> };
>> @@ -3496,6 +3497,10 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,
>> if (!nvme_ctrl_use_ana(nvme_get_ns_from_dev(dev)->ctrl))
>> return 0;
>> }
>> + if (a == &dev_attr_fail_if_no_path.attr) {
>> + if (dev_to_disk(dev)->fops == &nvme_bdev_ops)
>> + return 0;
>> + }
>> #endif
>> return a->mode;
>> }
>> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
>> index 0696319adaf6..35ed2f6d431b 100644
>> --- a/drivers/nvme/host/multipath.c
>> +++ b/drivers/nvme/host/multipath.c
>> @@ -283,10 +283,13 @@ static bool nvme_available_path(struct nvme_ns_head *head)
>> continue;
>> switch (ns->ctrl->state) {
>> case NVME_CTRL_LIVE:
>> + return true;
>
> Hello Hannes,
>
> May I ask there's any reason why LIVE state is not covered by the sysfs
> attribute that this patch introduced ? Wouldn't it be possible to have
> no available paths (inaccessible) in LIVE state ?
>
> Thanks! :)
>
Ah, you mean ANA inaccessible?
Hmm. Technically, yes, this might be the case.
I'll be updating the patch.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-22 12:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-22 6:41 [PATCHv2] nvme: add 'fail_if_no_path' sysfs attribute Hannes Reinecke
2021-02-22 10:15 ` Minwoo Im
2021-02-22 12:37 ` Hannes Reinecke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox