Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sbradshaw@micron.com (Sam Bradshaw)
Subject: [PATCH] NVMe: Defer namespace add_disk() until after char device creation
Date: Tue, 4 Nov 2014 16:18:06 -0800	[thread overview]
Message-ID: <54596CBE.5070501@micron.com> (raw)

In the current probe flow, each namespace gets an add_disk() then the 
char device for the controller is registered.  For misbehaving devices 
or namespace(s) that are not yet ready when add_disk() is called (eg. 
namespace accesses that return NVME_SC_NS_NOT_READY and are requeued), 
it can take time to disposition all the accesses.

This change moves add_disk() after the char device is created to give 
manageability stacks an interface to query as IO flushes out.

(I also considered deferring the nvme_ns_add() to an async context but
that requires some sort of mutex between probe and remove to handle the
surprise remove during add_disk condition and was messier than this 
patch)

Signed-off-by: Sam Bradshaw <sbradshaw at micron.com>
---
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 00fa5d2..1d14378 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -2336,6 +2336,16 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
 	return result;
 }
 
+static int nvme_ns_add(struct nvme_dev *dev)
+{
+	struct nvme_ns *ns;
+
+	list_for_each_entry(ns, &dev->namespaces, list)
+		add_disk(ns->disk);
+
+	return 0;
+}
+
 /*
  * Return: error value if an error occurred setting up the queues or calling
  * Identify Device.  0 if these succeeded, even if adding some of the
@@ -2398,8 +2408,6 @@ static int nvme_dev_add(struct nvme_dev *dev)
 		if (ns)
 			list_add_tail(&ns->list, &dev->namespaces);
 	}
-	list_for_each_entry(ns, &dev->namespaces, list)
-		add_disk(ns->disk);
 	res = 0;
 
  out:
@@ -2941,10 +2949,13 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (result)
 		goto remove;
 
+	nvme_ns_add(dev);
+
 	dev->initialized = 1;
 	return 0;
 
  remove:
+	INIT_LIST_HEAD(&dev->namespaces);
 	nvme_dev_remove(dev);
 	nvme_free_namespaces(dev);
  shutdown:

             reply	other threads:[~2014-11-05  0:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05  0:18 Sam Bradshaw [this message]
2014-11-15  4:44 ` [PATCH] NVMe: Defer namespace add_disk() until after char device creation Jens Axboe
2014-11-17 15:19   ` Keith Busch
2014-11-17 19:55     ` Jens Axboe

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=54596CBE.5070501@micron.com \
    --to=sbradshaw@micron.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