Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: hare@suse.de (Hannes Reinecke)
Subject: [PATCH 2/2] nvme: do not remove namespaces during reset
Date: Thu,  1 Aug 2019 09:16:44 +0200	[thread overview]
Message-ID: <20190801071644.66690-3-hare@suse.de> (raw)
In-Reply-To: <20190801071644.66690-1-hare@suse.de>

Whenever the controller is resetting or connecting we cannot make
any decisions about the attached namespaces, and consequently we
shouldn't remove them. So skip namespace removal during reset;
a scan will be triggered anyway after reconnecting which will
clean up any stale namespaces.

Signed-off-by: Hannes Reinecke <hare at suse.com>
---
 drivers/nvme/host/core.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 177fa4185775..b24cf21f34d0 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3410,7 +3410,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	return ret;
 }
 
-static void nvme_ns_remove(struct nvme_ns *ns)
+static void __nvme_ns_remove(struct nvme_ns *ns)
 {
 	if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
 		return;
@@ -3439,6 +3439,21 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 	nvme_put_ns(ns);
 }
 
+static void nvme_ns_remove(struct nvme_ns *ns)
+{
+	/*
+	 * We cannot make any assumptions about namespaces during
+	 * reset; in particular we shouldn't attempt to remove them
+	 * as I/O might still be queued to them.
+	 * So ignore this call during reset and rely on the
+	 * rescan after reset to clean up things again.
+	 */
+	if (ns->ctrl->state == NVME_CTRL_RESETTING ||
+	    ns->ctrl->state == NVME_CTRL_CONNECTING)
+		return;
+	__nvme_ns_remove(ns);
+}
+
 static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 {
 	struct nvme_ns *ns;
@@ -3458,6 +3473,10 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
 	struct nvme_ns *ns, *next;
 	LIST_HEAD(rm_list);
 
+	if (ctrl->state == NVME_CTRL_RESETTING ||
+	    ctrl->state == NVME_CTRL_CONNECTING)
+		return;
+
 	down_write(&ctrl->namespaces_rwsem);
 	list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
 		if (test_bit(NVME_NS_REMOVING, &ns->flags))
@@ -3468,7 +3487,7 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
 	up_write(&ctrl->namespaces_rwsem);
 
 	list_for_each_entry_safe(ns, next, &rm_list, list)
-		nvme_ns_remove(ns);
+		__nvme_ns_remove(ns);
 
 }
 
@@ -3618,7 +3637,7 @@ void nvme_remove_namespaces(struct nvme_ctrl *ctrl)
 	up_write(&ctrl->namespaces_rwsem);
 
 	list_for_each_entry_safe(ns, next, &ns_list, list)
-		nvme_ns_remove(ns);
+		__nvme_ns_remove(ns);
 }
 EXPORT_SYMBOL_GPL(nvme_remove_namespaces);
 
-- 
2.16.4

  parent reply	other threads:[~2019-08-01  7:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-01  7:16 [PATCH 0/2] skip removed namespaces Hannes Reinecke
2019-08-01  7:16 ` [PATCH 1/2] nvme: skip namespaces which are about to be removed Hannes Reinecke
2019-08-01 18:13   ` Nadolski, Edmund
2019-08-01 18:34   ` Sagi Grimberg
2019-08-01 21:36   ` Keith Busch
2019-08-01 21:52     ` Sagi Grimberg
2019-08-01 22:10       ` Keith Busch
2019-08-02 20:45         ` Sagi Grimberg
2019-08-01  7:16 ` Hannes Reinecke [this message]
2019-08-01 18:15   ` [PATCH 2/2] nvme: do not remove namespaces during reset Nadolski, Edmund
2019-08-01 18:42   ` Sagi Grimberg

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=20190801071644.66690-3-hare@suse.de \
    --to=hare@suse.de \
    /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