From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>,
linux-nvme@lists.infradead.org, Sagi Grimberg <sagi@grimberg.me>,
Keith Busch <keith.busch@wdc.com>, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 2/2] nvme: delete disk when last path is gone
Date: Thu, 25 Feb 2021 12:05:34 +0100 [thread overview]
Message-ID: <20210225110534.75710-3-hare@suse.de> (raw)
In-Reply-To: <20210225110534.75710-1-hare@suse.de>
The multipath code currently deletes the disk only after all references
to it are dropped rather than when the last path to that disk is lost.
This differs from the behaviour in the non-multipathed case where the
disk is deleted once the controller is removed.
This has been reported to cause problems with some use cases like MD RAID.
This patch implements an alternative behaviour of deleting the disk when
the last path is gone, ie the same behaviour as non-multipathed nvme
devices. The alternative behaviour can be enabled with the new sysfs
attribute 'no_path_detach'.
Suggested-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/host/core.c | 9 ++++++++-
drivers/nvme/host/multipath.c | 31 ++++++++++++++++++++++++++++++-
drivers/nvme/host/nvme.h | 21 ++++++++++++++++++---
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ba639049e385..7af6ba18f461 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -541,7 +541,9 @@ static void nvme_free_ns_head(struct kref *ref)
struct nvme_ns_head *head =
container_of(ref, struct nvme_ns_head, ref);
- nvme_mpath_remove_disk(head);
+ if (!test_bit(NVME_NSHEAD_NO_PATH_DETACH, &head->flags))
+ nvme_mpath_remove_disk(head);
+ nvme_mpath_put_disk(head);
ida_simple_remove(&head->subsys->ns_ida, head->instance);
cleanup_srcu_struct(&head->srcu);
nvme_put_subsystem(head->subsys);
@@ -3464,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_no_path_detach.attr,
#endif
NULL,
};
@@ -3494,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_no_path_detach.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..7d38f9272490 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -641,6 +641,36 @@ static ssize_t ana_state_show(struct device *dev, struct device_attribute *attr,
}
DEVICE_ATTR_RO(ana_state);
+static ssize_t no_path_detach_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_NO_PATH_DETACH, &head->flags) ?
+ 1 : 0);
+}
+
+static ssize_t no_path_detach_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 err, no_path_detach;
+
+ err = kstrtoint(buf, 10, &no_path_detach);
+ if (err || no_path_detach < 0)
+ return -EINVAL;
+ if (no_path_detach)
+ set_bit(NVME_NSHEAD_NO_PATH_DETACH, &head->flags);
+ else
+ clear_bit(NVME_NSHEAD_NO_PATH_DETACH, &head->flags);
+ return count;
+}
+DEVICE_ATTR(no_path_detach, S_IRUGO | S_IWUSR,
+ no_path_detach_show, no_path_detach_store);
+
static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl,
struct nvme_ana_group_desc *desc, void *data)
{
@@ -702,7 +732,6 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
*/
head->disk->queue = NULL;
}
- put_disk(head->disk);
}
int nvme_mpath_init(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 07b34175c6ce..317f8a6cb7f4 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -417,7 +417,8 @@ struct nvme_ns_head {
struct work_struct requeue_work;
struct mutex lock;
unsigned long flags;
-#define NVME_NSHEAD_DISK_LIVE 0
+#define NVME_NSHEAD_DISK_LIVE 0
+#define NVME_NSHEAD_NO_PATH_DETACH 1
struct nvme_ns __rcu *current_path[];
#endif
};
@@ -680,8 +681,12 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns)
{
struct nvme_ns_head *head = ns->head;
- if (head->disk && list_empty(&head->list))
- kblockd_schedule_work(&head->requeue_work);
+ if (head->disk && list_empty(&head->list)) {
+ if (test_bit(NVME_NSHEAD_NO_PATH_DETACH, &head->flags))
+ nvme_mpath_remove_disk(head);
+ else
+ kblockd_schedule_work(&head->requeue_work);
+ }
}
static inline void nvme_trace_bio_complete(struct request *req)
@@ -692,8 +697,15 @@ static inline void nvme_trace_bio_complete(struct request *req)
trace_block_bio_complete(ns->head->disk->queue, req->bio);
}
+static inline void nvme_mpath_put_disk(struct nvme_ns_head *head)
+{
+ if (head->disk)
+ put_disk(head->disk);
+}
+
extern struct device_attribute dev_attr_ana_grpid;
extern struct device_attribute dev_attr_ana_state;
+extern struct device_attribute dev_attr_no_path_detach;
extern struct device_attribute subsys_attr_iopolicy;
#else
@@ -729,6 +741,9 @@ static inline void nvme_mpath_add_disk(struct nvme_ns *ns,
static inline void nvme_mpath_remove_disk(struct nvme_ns_head *head)
{
}
+static inline void nvme_mpath_put_disk(struct nvme_ns_head *head)
+{
+}
static inline bool nvme_mpath_clear_current_path(struct nvme_ns *ns)
{
return false;
--
2.29.2
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-02-25 11:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-25 11:05 [PATCHv2 0/2] nvme: fixup MD RAID usage Hannes Reinecke
2021-02-25 11:05 ` [PATCH 1/2] nvme: add 'fast_io_fail_tmo' controller sysfs attribute Hannes Reinecke
2021-03-05 21:10 ` Sagi Grimberg
2021-02-25 11:05 ` Hannes Reinecke [this message]
2021-02-25 16:59 ` [PATCH 2/2] nvme: delete disk when last path is gone Keith Busch
2021-02-25 17:37 ` Hannes Reinecke
2021-03-05 21:12 ` Sagi Grimberg
2021-03-03 1:01 ` [PATCHv2 0/2] nvme: fixup MD RAID usage Minwoo Im
-- strict thread matches above, loose matches on Subject: below --
2021-02-23 11:59 [PATCH 0/2] nvme: fix regression with MD RAID Hannes Reinecke
2021-02-23 11:59 ` [PATCH 2/2] nvme: delete disk when last path is gone Hannes Reinecke
2021-02-23 12:56 ` Minwoo Im
2021-02-23 14:07 ` Hannes Reinecke
2021-02-24 22:40 ` Sagi Grimberg
2021-02-25 8:37 ` 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=20210225110534.75710-3-hare@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--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