linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: keith.busch@intel.com (Keith Busch)
Subject: [PATCH 2/3] nvme: Kill detached namespaces prior to removal
Date: Thu, 23 Jun 2016 11:29:05 -0600	[thread overview]
Message-ID: <1466702946-13065-3-git-send-email-keith.busch@intel.com> (raw)
In-Reply-To: <1466702946-13065-1-git-send-email-keith.busch@intel.com>

If a previously namespace allocated is detatched or deleted from the
controller, the driver needs to make sure nothing can send new IO to
the namespace prior to removing. This prevents buffered writers from
potentially stalling device removal indefinitely.

The patch pulls the request queue stoppage into a function and provides
a function to kill and remove the namespace. Any invalid namespace being
removed should go through here.

Signed-off-by: Keith Busch <keith.busch at intel.com>
---
 drivers/nvme/host/core.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 67aba46..43d6947 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1534,6 +1534,26 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 	nvme_put_ns(ns);
 }
 
+static void nvme_ns_kill(struct nvme_ns *ns)
+{
+	/*
+	 * Revalidating a dead namespace sets capacity to 0. This will
+	 * end buffered writers dirtying pages that can't be synced.
+	 */
+	if (!test_and_set_bit(NVME_NS_DEAD, &ns->flags))
+		revalidate_disk(ns->disk);
+
+	blk_set_queue_dying(ns->queue);
+	blk_mq_abort_requeue_list(ns->queue);
+	blk_mq_start_stopped_hw_queues(ns->queue, true);
+}
+
+static void nvme_remove_dead_ns(struct nvme_ns *ns)
+{
+	nvme_ns_kill(ns);
+	nvme_ns_remove(ns);
+}
+
 static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 {
 	struct nvme_ns *ns;
@@ -1554,7 +1574,7 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
 
 	list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
 		if (ns->ns_id > nsid)
-			nvme_ns_remove(ns);
+			nvme_remove_dead_ns(ns);
 	}
 }
 
@@ -1584,7 +1604,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 			while (++prev < nsid) {
 				ns = nvme_get_ns(ctrl, prev);
 				if (ns) {
-					nvme_ns_remove(ns);
+					nvme_remove_dead_ns(ns);
 					nvme_put_ns(ns);
 				}
 			}
@@ -1837,19 +1857,9 @@ void nvme_kill_queues(struct nvme_ctrl *ctrl)
 	mutex_lock(&ctrl->namespaces_mutex);
 	list_for_each_entry(ns, &ctrl->namespaces, list) {
 		if (!kref_get_unless_zero(&ns->kref))
-			continue;
-
-		/*
-		 * Revalidating a dead namespace sets capacity to 0. This will
-		 * end buffered writers dirtying pages that can't be synced.
-		 */
-		if (!test_and_set_bit(NVME_NS_DEAD, &ns->flags))
-			revalidate_disk(ns->disk);
-
-		blk_set_queue_dying(ns->queue);
-		blk_mq_abort_requeue_list(ns->queue);
-		blk_mq_start_stopped_hw_queues(ns->queue, true);
+			return;
 
+		nvme_ns_kill(ns);
 		nvme_put_ns(ns);
 	}
 	mutex_unlock(&ctrl->namespaces_mutex);
-- 
2.7.2

  parent reply	other threads:[~2016-06-23 17:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 17:29 [PATCH 0/3] Namespace iteration fixes Keith Busch
2016-06-23 17:29 ` [PATCHv2 1/3] nvme: Remove RCU namespace protection Keith Busch
2016-06-28  8:31   ` Christoph Hellwig
2016-06-28 16:35     ` Keith Busch
2016-06-30  6:48       ` Christoph Hellwig
2016-06-30 14:57         ` Keith Busch
2016-06-30 22:59           ` Keith Busch
2016-06-23 17:29 ` Keith Busch [this message]
2016-06-28  8:32   ` [PATCH 2/3] nvme: Kill detached namespaces prior to removal Christoph Hellwig
2016-06-23 17:29 ` [PATCH 3/3] nvme: Put invalid namespaces on removal list Keith Busch
2016-06-28  8:32   ` Christoph Hellwig
2016-06-23 17:44 ` [PATCH 0/3] Namespace iteration fixes Keith Busch

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=1466702946-13065-3-git-send-email-keith.busch@intel.com \
    --to=keith.busch@intel.com \
    /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;
as well as URLs for NNTP newsgroup(s).