Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: zhangweiping@didichuxing.com (张伟平(基础平台部))
Subject: [PATCH] nvme: remove indenty ctrl before scan namespace
Date: Tue, 27 Jun 2017 14:46:24 +0000	[thread overview]
Message-ID: <20170627144624.GA36121@localhost.didichuxing.com> (raw)

All nvme host drivers have already identified ctrl beforce scan namespace,
so when first time identify ctrl we get the number of namespace and store it
into nvme_ctrl. When we scan namespace just use it instead of indentify again.

Signed-off-by: weiping zhang <zhangweiping at didichuxing.com>
---
 drivers/nvme/host/core.c | 25 ++++++++++---------------
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 903d581..34f85df 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1586,6 +1586,7 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		ctrl->quirks &= ~NVME_QUIRK_NO_DEEPEST_PS;
 	}
 
+	ctrl->nn = le32_to_cpu(id->nn);
 	ctrl->oacs = le16_to_cpu(id->oacs);
 	ctrl->vid = le16_to_cpu(id->vid);
 	ctrl->oncs = le16_to_cpup(&id->oncs);
@@ -2147,13 +2148,14 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
 	}
 }
 
-static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
+static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)
 {
 	struct nvme_ns *ns;
 	__le32 *ns_list;
-	unsigned i, j, nsid, prev = 0, num_lists = DIV_ROUND_UP(nn, 1024);
+	u32 i, j, nsid, prev = 0, num_lists, nn =  ctrl->nn;
 	int ret = 0;
 
+	num_lists = DIV_ROUND_UP(nn, 1024);
 	ns_list = kzalloc(0x1000, GFP_KERNEL);
 	if (!ns_list)
 		return -ENOMEM;
@@ -2187,41 +2189,34 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
 	return ret;
 }
 
-static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
+static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl)
 {
-	unsigned i;
+	u32 i;
 
-	for (i = 1; i <= nn; i++)
+	for (i = 1; i <= ctrl->nn; i++)
 		nvme_validate_ns(ctrl, i);
 
-	nvme_remove_invalid_namespaces(ctrl, nn);
+	nvme_remove_invalid_namespaces(ctrl, ctrl->nn);
 }
 
 static void nvme_scan_work(struct work_struct *work)
 {
 	struct nvme_ctrl *ctrl =
 		container_of(work, struct nvme_ctrl, scan_work);
-	struct nvme_id_ctrl *id;
-	unsigned nn;
 
 	if (ctrl->state != NVME_CTRL_LIVE)
 		return;
 
-	if (nvme_identify_ctrl(ctrl, &id))
-		return;
-
-	nn = le32_to_cpu(id->nn);
 	if (ctrl->vs >= NVME_VS(1, 1, 0) &&
 	    !(ctrl->quirks & NVME_QUIRK_IDENTIFY_CNS)) {
-		if (!nvme_scan_ns_list(ctrl, nn))
+		if (!nvme_scan_ns_list(ctrl))
 			goto done;
 	}
-	nvme_scan_ns_sequential(ctrl, nn);
+	nvme_scan_ns_sequential(ctrl);
  done:
 	mutex_lock(&ctrl->namespaces_mutex);
 	list_sort(NULL, &ctrl->namespaces, ns_cmp);
 	mutex_unlock(&ctrl->namespaces_mutex);
-	kfree(id);
 }
 
 void nvme_queue_scan(struct nvme_ctrl *ctrl)
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 9d6a070..67f373b 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -131,6 +131,7 @@ struct nvme_ctrl {
 	struct device *device;	/* char device */
 	struct list_head node;
 	struct ida ns_ida;
+	u32 nn; /* namespace num */
 
 	struct opal_dev *opal_dev;
 
-- 
2.9.4

             reply	other threads:[~2017-06-27 14:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 14:46 张伟平(基础平台部) [this message]
  -- strict thread matches above, loose matches on Subject: below --
2017-06-27 15:23 [PATCH] nvme: remove indenty ctrl before scan namespace weiping zhang
2017-06-27 18:50 ` Steve Blightman
2017-06-27 19:47 ` Keith Busch
2017-06-28  0:48   ` 张伟平(基础平台部)

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=20170627144624.GA36121@localhost.didichuxing.com \
    --to=zhangweiping@didichuxing.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