* [PATCH] nvme: fix error handling in nvme_ns_report_zones
@ 2020-08-25 9:58 Christoph Hellwig
2020-08-25 17:15 ` Keith Busch
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-08-25 9:58 UTC (permalink / raw)
To: kbusch, sagi; +Cc: linux-nvme
nvme_submit_sync_cmd can return positive NVMe error codes in addition to
the negative Linux error code, which are currently ignored. Fix this
by removing __nvme_ns_report_zones and handling the errors from
nvme_submit_sync_cmd in the caller instead of multiplexing the return
value and the zone size into a single return value.
Fixes: 240e6ee272c0 ("nvme: support for zoned namespaces")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/zns.c | 38 +++++++++++++-------------------------
1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 57cfd78731fbbe..e7798804d5afab 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -133,28 +133,6 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,
return NULL;
}
-static int __nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
- struct nvme_zone_report *report,
- size_t buflen)
-{
- struct nvme_command c = { };
- int ret;
-
- c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
- c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
- c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
- c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
- c.zmr.zra = NVME_ZRA_ZONE_REPORT;
- c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
- c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
-
- ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
- if (ret)
- return ret;
-
- return le64_to_cpu(report->nr_zones);
-}
-
static int nvme_zone_parse_entry(struct nvme_ns *ns,
struct nvme_zone_descriptor *entry,
unsigned int idx, report_zones_cb cb,
@@ -182,10 +160,18 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data)
{
struct nvme_zone_report *report;
+ struct nvme_command c = { };
int ret, zone_idx = 0;
unsigned int nz, i;
size_t buflen;
+ c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
+ c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
+ c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
+ c.zmr.zra = NVME_ZRA_ZONE_REPORT;
+ c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
+ c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
+
report = nvme_zns_alloc_report_buffer(ns, nr_zones, &buflen);
if (!report)
return -ENOMEM;
@@ -193,11 +179,13 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
sector &= ~(ns->zsze - 1);
while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) {
memset(report, 0, buflen);
- ret = __nvme_ns_report_zones(ns, sector, report, buflen);
- if (ret < 0)
+
+ c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
+ ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
+ if (ret)
goto out_free;
- nz = min_t(unsigned int, ret, nr_zones);
+ nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
if (!nz)
break;
--
2.28.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme: fix error handling in nvme_ns_report_zones
2020-08-25 9:58 [PATCH] nvme: fix error handling in nvme_ns_report_zones Christoph Hellwig
@ 2020-08-25 17:15 ` Keith Busch
2020-08-25 17:36 ` Sagi Grimberg
2020-08-25 22:18 ` Chaitanya Kulkarni
2 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2020-08-25 17:15 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: sagi, linux-nvme
On Tue, Aug 25, 2020 at 11:58:24AM +0200, Christoph Hellwig wrote:
> nvme_submit_sync_cmd can return positive NVMe error codes in addition to
> the negative Linux error code, which are currently ignored. Fix this
> by removing __nvme_ns_report_zones and handling the errors from
> nvme_submit_sync_cmd in the caller instead of multiplexing the return
> value and the zone size into a single return value.
Indeed, looks good.
Reviewed-by: Keith Busch <kbusch@kernel.org>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme: fix error handling in nvme_ns_report_zones
2020-08-25 9:58 [PATCH] nvme: fix error handling in nvme_ns_report_zones Christoph Hellwig
2020-08-25 17:15 ` Keith Busch
@ 2020-08-25 17:36 ` Sagi Grimberg
2020-08-28 15:44 ` Sagi Grimberg
2020-08-25 22:18 ` Chaitanya Kulkarni
2 siblings, 1 reply; 7+ messages in thread
From: Sagi Grimberg @ 2020-08-25 17:36 UTC (permalink / raw)
To: Christoph Hellwig, kbusch; +Cc: linux-nvme
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme: fix error handling in nvme_ns_report_zones
2020-08-25 9:58 [PATCH] nvme: fix error handling in nvme_ns_report_zones Christoph Hellwig
2020-08-25 17:15 ` Keith Busch
2020-08-25 17:36 ` Sagi Grimberg
@ 2020-08-25 22:18 ` Chaitanya Kulkarni
2 siblings, 0 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2020-08-25 22:18 UTC (permalink / raw)
To: Christoph Hellwig, kbusch, sagi; +Cc: linux-nvme
On 8/25/20 03:08, Christoph Hellwig wrote:
> nvme_submit_sync_cmd can return positive NVMe error codes in addition to
> the negative Linux error code, which are currently ignored. Fix this
> by removing __nvme_ns_report_zones and handling the errors from
> nvme_submit_sync_cmd in the caller instead of multiplexing the return
> value and the zone size into a single return value.
>
> Fixes: 240e6ee272c0 ("nvme: support for zoned namespaces")
> Signed-off-by: Christoph Hellwig<hch@lst.de>
Looks good.
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme: fix error handling in nvme_ns_report_zones
2020-08-25 17:36 ` Sagi Grimberg
@ 2020-08-28 15:44 ` Sagi Grimberg
0 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2020-08-28 15:44 UTC (permalink / raw)
To: Christoph Hellwig, kbusch; +Cc: linux-nvme
> Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Removed from nvme-5.9-rc due to test robot complaints.
Will let you resend.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme: fix error handling in nvme_ns_report_zones
2020-09-24 10:35 Christoph Hellwig
@ 2020-09-24 10:47 ` Damien Le Moal
0 siblings, 0 replies; 7+ messages in thread
From: Damien Le Moal @ 2020-09-24 10:47 UTC (permalink / raw)
To: Christoph Hellwig, kbusch, sagi; +Cc: linux-nvme
On 2020/09/24 19:35, Christoph Hellwig wrote:
> nvme_submit_sync_cmd can return positive NVMe error codes in addition to
> the negative Linux error code, which are currently ignored. Fix this
> by removing __nvme_ns_report_zones and handling the errors from
> nvme_submit_sync_cmd in the caller instead of multiplexing the return
> value and the number of zones reported into a single return value.
>
> Fixes: 240e6ee272c0 ("nvme: support for zoned namespaces")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/host/zns.c | 41 ++++++++++++++++-------------------------
> 1 file changed, 16 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
> index 57cfd78731fbbe..53efecb6789838 100644
> --- a/drivers/nvme/host/zns.c
> +++ b/drivers/nvme/host/zns.c
> @@ -133,28 +133,6 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,
> return NULL;
> }
>
> -static int __nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
> - struct nvme_zone_report *report,
> - size_t buflen)
> -{
> - struct nvme_command c = { };
> - int ret;
> -
> - c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
> - c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
> - c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
> - c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
> - c.zmr.zra = NVME_ZRA_ZONE_REPORT;
> - c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
> - c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
> -
> - ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
> - if (ret)
> - return ret;
> -
> - return le64_to_cpu(report->nr_zones);
> -}
> -
> static int nvme_zone_parse_entry(struct nvme_ns *ns,
> struct nvme_zone_descriptor *entry,
> unsigned int idx, report_zones_cb cb,
> @@ -182,6 +160,7 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
> unsigned int nr_zones, report_zones_cb cb, void *data)
> {
> struct nvme_zone_report *report;
> + struct nvme_command c = { };
> int ret, zone_idx = 0;
> unsigned int nz, i;
> size_t buflen;
> @@ -190,14 +169,26 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
> if (!report)
> return -ENOMEM;
>
> + c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
> + c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
> + c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
> + c.zmr.zra = NVME_ZRA_ZONE_REPORT;
> + c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
> + c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
> +
> sector &= ~(ns->zsze - 1);
> while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) {
> memset(report, 0, buflen);
> - ret = __nvme_ns_report_zones(ns, sector, report, buflen);
> - if (ret < 0)
> +
> + c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
> + ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
> + if (ret) {
> + if (ret > 0)
> + ret = -EIO;
> goto out_free;
> + }
>
> - nz = min_t(unsigned int, ret, nr_zones);
> + nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
> if (!nz)
> break;
>
>
Looks good.
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
--
Damien Le Moal
Western Digital Research
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] nvme: fix error handling in nvme_ns_report_zones
@ 2020-09-24 10:35 Christoph Hellwig
2020-09-24 10:47 ` Damien Le Moal
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2020-09-24 10:35 UTC (permalink / raw)
To: kbusch, sagi; +Cc: Damien.LeMoal, linux-nvme
nvme_submit_sync_cmd can return positive NVMe error codes in addition to
the negative Linux error code, which are currently ignored. Fix this
by removing __nvme_ns_report_zones and handling the errors from
nvme_submit_sync_cmd in the caller instead of multiplexing the return
value and the number of zones reported into a single return value.
Fixes: 240e6ee272c0 ("nvme: support for zoned namespaces")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/zns.c | 41 ++++++++++++++++-------------------------
1 file changed, 16 insertions(+), 25 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 57cfd78731fbbe..53efecb6789838 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -133,28 +133,6 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns,
return NULL;
}
-static int __nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
- struct nvme_zone_report *report,
- size_t buflen)
-{
- struct nvme_command c = { };
- int ret;
-
- c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
- c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
- c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
- c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
- c.zmr.zra = NVME_ZRA_ZONE_REPORT;
- c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
- c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
-
- ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
- if (ret)
- return ret;
-
- return le64_to_cpu(report->nr_zones);
-}
-
static int nvme_zone_parse_entry(struct nvme_ns *ns,
struct nvme_zone_descriptor *entry,
unsigned int idx, report_zones_cb cb,
@@ -182,6 +160,7 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
unsigned int nr_zones, report_zones_cb cb, void *data)
{
struct nvme_zone_report *report;
+ struct nvme_command c = { };
int ret, zone_idx = 0;
unsigned int nz, i;
size_t buflen;
@@ -190,14 +169,26 @@ static int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
if (!report)
return -ENOMEM;
+ c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
+ c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
+ c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
+ c.zmr.zra = NVME_ZRA_ZONE_REPORT;
+ c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL;
+ c.zmr.pr = NVME_REPORT_ZONE_PARTIAL;
+
sector &= ~(ns->zsze - 1);
while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) {
memset(report, 0, buflen);
- ret = __nvme_ns_report_zones(ns, sector, report, buflen);
- if (ret < 0)
+
+ c.zmr.slba = cpu_to_le64(nvme_sect_to_lba(ns, sector));
+ ret = nvme_submit_sync_cmd(ns->queue, &c, report, buflen);
+ if (ret) {
+ if (ret > 0)
+ ret = -EIO;
goto out_free;
+ }
- nz = min_t(unsigned int, ret, nr_zones);
+ nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
if (!nz)
break;
--
2.28.0
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-09-24 10:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 9:58 [PATCH] nvme: fix error handling in nvme_ns_report_zones Christoph Hellwig
2020-08-25 17:15 ` Keith Busch
2020-08-25 17:36 ` Sagi Grimberg
2020-08-28 15:44 ` Sagi Grimberg
2020-08-25 22:18 ` Chaitanya Kulkarni
2020-09-24 10:35 Christoph Hellwig
2020-09-24 10:47 ` Damien Le Moal
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.