nvme: fix error handling in nvme_ns_report_zones
Christoph Hellwig
maintainerPATCH 1/1 nvme: fix error handling in nvme_ns_report_zones
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.
--- drivers/nvme/host/zns.c | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-)
drivers/nvme/host/zns.c +13 -25
@@ -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 ;
Signature · 7 lines
2.28.0 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 5 lines · Christoph Hellwig
nvme_submit_sync_cmdcan return positive NVMe error codes in addition to the negative Linux error code, which are currently ignored. Fix this by removing__nvme_ns_report_zonesand handling the errors fromnvme_submit_sync_cmdin the caller instead of multiplexing the return value and the zone size into a single return value.
Indeed, looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerQuoted 2 lines
Reviewed-by Sagi Grimberg <[email protected]>
Removed from nvme-5.9-rc due to test robot complaints. Will let you resend.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 8 lines · Christoph Hellwig
nvme_submit_sync_cmdcan return positive NVMe error codes in addition to the negative Linux error code, which are currently ignored. Fix this by removing__nvme_ns_report_zonesand handling the errors fromnvme_submit_sync_cmdin 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<[email protected]>
Looks good.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme