From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-nvme@lists.infradead.org, Sagi Grimberg <sagi@grimberg.me>,
Keith Busch <keith.busch@wdc.com>, Hannes Reinecke <hare@suse.de>
Subject: [PATCH] nvme: add 'fail_if_no_path' sysfs attribute
Date: Fri, 19 Feb 2021 15:46:25 +0100 [thread overview]
Message-ID: <20210219144625.56344-1-hare@suse.de> (raw)
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 | 36 ++++++++++++++++++++++++++++++++++-
drivers/nvme/host/nvme.h | 2 ++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9879153d8d28..eee42d0b3400 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3440,6 +3440,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,
};
@@ -3470,6 +3471,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 9ac762b28811..47fecb3f9434 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;
+ 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;
+
+ else 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 09d142a9628c..f3ba741d44d0 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -411,6 +411,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
};
@@ -684,6 +685,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.29.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next reply other threads:[~2021-02-19 14:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-19 14:46 Hannes Reinecke [this message]
2021-02-19 23:16 ` [PATCH] nvme: add 'fail_if_no_path' sysfs attribute Keith Busch
2021-02-20 14:58 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210219144625.56344-1-hare@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=keith.busch@wdc.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox