All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: remove indenty ctrl before scan namespace
@ 2017-06-27 15:23 weiping zhang
  2017-06-27 18:50 ` Steve Blightman
  2017-06-27 19:47 ` Keith Busch
  0 siblings, 2 replies; 5+ messages in thread
From: weiping zhang @ 2017-06-27 15:23 UTC (permalink / 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] nvme: remove indenty ctrl before scan namespace
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Steve Blightman @ 2017-06-27 18:50 UTC (permalink / raw)


Doesn't this mean that when using namespace management to add a 
namespace, that it won't be found?

On 6/27/2017 8:23 AM, weiping zhang wrote:
> 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;
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] nvme: remove indenty ctrl before scan namespace
  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   ` 张伟平(基础平台部)
  1 sibling, 1 reply; 5+ messages in thread
From: Keith Busch @ 2017-06-27 19:47 UTC (permalink / raw)


On Tue, Jun 27, 2017@11:23:36PM +0800, weiping zhang wrote:
> 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.

The scan work can be schedule in more than just the reset path, though,
which is where ID ctrl is initialized. In those cases, attaching
namespaces may stop working.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] nvme: remove indenty ctrl before scan namespace
  2017-06-27 19:47 ` Keith Busch
@ 2017-06-28  0:48   ` 张伟平(基础平台部)
  0 siblings, 0 replies; 5+ messages in thread
From: 张伟平(基础平台部) @ 2017-06-28  0:48 UTC (permalink / raw)


You are right, thanks.

> ? 2017?6?28??03:39?Keith Busch <keith.busch at intel.com> ???
> 
>> On Tue, Jun 27, 2017@11:23:36PM +0800, weiping zhang wrote:
>> 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.
> 
> The scan work can be schedule in more than just the reset path, though,
> which is where ID ctrl is initialized. In those cases, attaching
> namespaces may stop working.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] nvme: remove indenty ctrl before scan namespace
@ 2017-06-27 14:46 张伟平(基础平台部)
  0 siblings, 0 replies; 5+ messages in thread
From: 张伟平(基础平台部) @ 2017-06-27 14:46 UTC (permalink / 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-28  0:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` 张伟平(基础平台部)
  -- strict thread matches above, loose matches on Subject: below --
2017-06-27 14:46 张伟平(基础平台部)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.