nvme: remove indenty ctrl before scan namespace
PATCH 1/1 nvme: remove indenty ctrl before scan namespace
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.
--- drivers/nvme/host/core.c | 25 ++++++++++--------------- drivers/nvme/host/nvme.h | 1 + 2 files changed, 11 insertions(+), 15 deletions(-)
drivers/nvme/host/core.c +10 -15
@@ -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)
drivers/nvme/host/nvme.h +1 -0
@@ -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;
Signature · 1 line
2.9.4
PATCH 1/1 nvme: remove indenty ctrl before scan namespace
Doesn't this mean that when using namespace management to add a namespace, that it won't be found?
Quoted 99 lines · weiping zhang
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(-)drivers/nvme/host/core.c +10
-15@@ -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)drivers/nvme/host/nvme.h +1
-0@@ -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;
PATCH 1/1 nvme: remove indenty ctrl before scan namespace
In reply to weiping zhangQuoted 3 lines · weiping zhang
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.
PATCH 1/1 nvme: remove indenty ctrl before scan namespace
You are right, thanks.
Quoted 10 lines
? 2017?6?28??03:39?Keith Busch <keith.busch at intel.com> ???
Quoted 4 lines · weiping zhang
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.