Skip to content

Commit b7e9787

Browse files
MaisenbacherDChristoph Hellwig
authored andcommitted
nvmet: fix mar and mor off-by-one errors
Maximum Active Resources (MAR) and Maximum Open Resources (MOR) are 0's based vales where a value of 0xffffffff indicates that there is no limit. Decrement the values that are returned by bdev_max_open_zones and bdev_max_active_zones as the block layer helpers are not 0's based. A 0 returned by the block layer helpers indicates no limit, thus convert it to 0xffffffff (U32_MAX). Fixes: aaf2e04 ("nvmet: add ZBD over ZNS backend support") Suggested-by: Niklas Cassel <[email protected]> Signed-off-by: Dennis Maisenbacher <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 3770a42 commit b7e9787

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/nvme/target/zns.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req)
100100
struct nvme_id_ns_zns *id_zns;
101101
u64 zsze;
102102
u16 status;
103+
u32 mar, mor;
103104

104105
if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
105106
req->error_loc = offsetof(struct nvme_identify, nsid);
@@ -130,8 +131,20 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req)
130131
zsze = (bdev_zone_sectors(req->ns->bdev) << 9) >>
131132
req->ns->blksize_shift;
132133
id_zns->lbafe[0].zsze = cpu_to_le64(zsze);
133-
id_zns->mor = cpu_to_le32(bdev_max_open_zones(req->ns->bdev));
134-
id_zns->mar = cpu_to_le32(bdev_max_active_zones(req->ns->bdev));
134+
135+
mor = bdev_max_open_zones(req->ns->bdev);
136+
if (!mor)
137+
mor = U32_MAX;
138+
else
139+
mor--;
140+
id_zns->mor = cpu_to_le32(mor);
141+
142+
mar = bdev_max_active_zones(req->ns->bdev);
143+
if (!mar)
144+
mar = U32_MAX;
145+
else
146+
mar--;
147+
id_zns->mar = cpu_to_le32(mar);
135148

136149
done:
137150
status = nvmet_copy_to_sgl(req, 0, id_zns, sizeof(*id_zns));

0 commit comments

Comments
 (0)