* [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
@ 2016-05-27 10:29 Sunad Bhandary S
2016-05-27 13:28 ` Keith Busch
0 siblings, 1 reply; 5+ messages in thread
From: Sunad Bhandary S @ 2016-05-27 10:29 UTC (permalink / raw)
From: Sunad Bhandary <sunad.s@samsung.com>
In case of the active namespace list scanning method, a namespace that
is detached is not removed from the host if it was the last entry in
the list. Fix this by adding a scan to validate namespaces greater than
the value of prev.
This also handles the case of removing namespaces whose value exceed
the device's reported number of namespaces.
Signed-off-by: Sunad Bhandary S <sunad.s at samsung.com>
Reviewed-by: Christoph Hellwig <hch at lst.de>
---
v1 -> v2:
Removed unnecessary braces around if condition
drivers/nvme/host/core.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2de248b..3da998f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1483,6 +1483,17 @@ static void nvme_validate_ns(struct nvme_ctrl *ctrl, unsigned nsid)
nvme_alloc_ns(ctrl, nsid);
}
+static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,
+ unsigned nsid)
+{
+ struct nvme_ns *ns, *next;
+
+ list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
+ if (ns->ns_id > nsid)
+ nvme_ns_remove(ns);
+ }
+}
+
static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
{
struct nvme_ns *ns;
@@ -1497,7 +1508,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
for (i = 0; i < num_lists; i++) {
ret = nvme_identify_ns_list(ctrl, prev, ns_list);
if (ret)
- goto out;
+ goto free;
for (j = 0; j < min(nn, 1024U); j++) {
nsid = le32_to_cpu(ns_list[j]);
@@ -1515,13 +1526,14 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
nn -= j;
}
out:
+ nvme_remove_invalid_namespaces(ctrl, prev);
+ free:
kfree(ns_list);
return ret;
}
static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
{
- struct nvme_ns *ns, *next;
unsigned i;
lockdep_assert_held(&ctrl->namespaces_mutex);
@@ -1529,10 +1541,7 @@ static void nvme_scan_ns_sequential(struct nvme_ctrl *ctrl, unsigned nn)
for (i = 1; i <= nn; i++)
nvme_validate_ns(ctrl, i);
- list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
- if (ns->ns_id > nn)
- nvme_ns_remove(ns);
- }
+ nvme_remove_invalid_namespaces(ctrl, nn);
}
static void nvme_scan_work(struct work_struct *work)
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
2016-05-27 10:29 [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method Sunad Bhandary S
@ 2016-05-27 13:28 ` Keith Busch
2016-05-30 10:45 ` Sunad Bhandary
0 siblings, 1 reply; 5+ messages in thread
From: Keith Busch @ 2016-05-27 13:28 UTC (permalink / raw)
On Fri, May 27, 2016@03:59:43PM +0530, Sunad Bhandary S wrote:
> static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
> {
> struct nvme_ns *ns;
> @@ -1497,7 +1508,7 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
> for (i = 0; i < num_lists; i++) {
> ret = nvme_identify_ns_list(ctrl, prev, ns_list);
> if (ret)
> - goto out;
> + goto free;
>
> for (j = 0; j < min(nn, 1024U); j++) {
> nsid = le32_to_cpu(ns_list[j]);
> @@ -1515,13 +1526,14 @@ static int nvme_scan_ns_list(struct nvme_ctrl *ctrl, unsigned nn)
> nn -= j;
> }
> out:
> + nvme_remove_invalid_namespaces(ctrl, prev);
> + free:
We don't want to remove the namespaces on error here. That could remove
valid, in use namespaces: if nvme_identify_ns_list fails (maybe controller
just doesn't support that identify mode), we do the sequential scanning.
Just leave the 'goto free' alone, and call nvme_remove_invalid_namespaces
only on success.
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
2016-05-27 13:28 ` Keith Busch
@ 2016-05-30 10:45 ` Sunad Bhandary
2016-05-31 14:35 ` Keith Busch
0 siblings, 1 reply; 5+ messages in thread
From: Sunad Bhandary @ 2016-05-30 10:45 UTC (permalink / raw)
>We don't want to remove the namespaces on error here. That could
>remove valid, in use namespaces: if nvme_identify_ns_list fails (maybe
>controller just doesn't support that identify mode), we do the
>sequential scanning.
>Just leave the 'goto free' alone, and call
>nvme_remove_invalid_namespaces only on success.
In the patch, the namespaces are not removed on failure of identify
list. If nvme_identify_ns_list fails, the value is returned and
sequential scanning is done. The call to nvme_remove_invalid_namespaces
is done when the value of nsid in the list is 0.
Snapshot of patch:
....
ret = nvme_identify_ns_list(ctrl, prev, ns_list);
if (ret)
goto free;
....
nsid = le32_to_cpu(ns_list[j]);
if (!nsid)
goto out;
....
out:
nvme_remove_invalid_namespaces(ctrl, prev);
free:
kfree(ns_list);
return ret;
This should be able to handle error scenarios or am I missing something?
Thanks and Regards,
Sunad
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
2016-05-30 10:45 ` Sunad Bhandary
@ 2016-05-31 14:35 ` Keith Busch
2016-06-08 5:13 ` Sunad Bhandary
0 siblings, 1 reply; 5+ messages in thread
From: Keith Busch @ 2016-05-31 14:35 UTC (permalink / raw)
On Mon, May 30, 2016@04:15:41PM +0530, Sunad Bhandary wrote:
> In the patch, the namespaces are not removed on failure of identify
> list. If nvme_identify_ns_list fails, the value is returned and
> sequential scanning is done. The call to nvme_remove_invalid_namespaces is
> done when the value of nsid in the list is 0.
Sorry, my mistake. You're right, it is good as-is.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
2016-05-31 14:35 ` Keith Busch
@ 2016-06-08 5:13 ` Sunad Bhandary
0 siblings, 0 replies; 5+ messages in thread
From: Sunad Bhandary @ 2016-06-08 5:13 UTC (permalink / raw)
Hi Jens,
Can this be picked up?
Thanks and Regards,
Sunad
> -----Original Message-----
> From: Linux-nvme [mailto:linux-nvme-bounces at lists.infradead.org] On Behalf Of Keith Busch
> Sent: Tuesday, May 31, 2016 8:05 PM
> To: Sunad Bhandary
> Cc: hch at infradead.org; linux-nvme at lists.infradead.org
> Subject: Re: Re: [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method
>
> On Mon, May 30, 2016@04:15:41PM +0530, Sunad Bhandary wrote:
>> In the patch, the namespaces are not removed on failure of identify
>> list. If nvme_identify_ns_list fails, the value is returned and
>> sequential scanning is done. The call to
>> nvme_remove_invalid_namespaces is done when the value of nsid in the list is 0.
>
> Sorry, my mistake. You're right, it is good as-is.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-06-08 5:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 10:29 [PATCHv2] NVMe: Fix removal in case of active namespace list scanning method Sunad Bhandary S
2016-05-27 13:28 ` Keith Busch
2016-05-30 10:45 ` Sunad Bhandary
2016-05-31 14:35 ` Keith Busch
2016-06-08 5:13 ` Sunad Bhandary
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.