Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b164316

Browse files
damien-lemoalaxboe
authored andcommitted
null_blk: Do not allow runt zone with zone capacity smaller then zone size
A zoned device with a smaller last zone together with a zone capacity smaller than the zone size does make any sense as that does not correspond to any possible setup for a real device: 1) For ZNS and zoned UFS devices, all zones are always the same size. 2) For SMR HDDs, all zones always have the same capacity. In other words, if we have a smaller last runt zone, then this zone capacity should always be equal to the zone size. Add a check in null_init_zoned_dev() to prevent a configuration to have both a smaller zone size and a zone capacity smaller than the zone size. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20240530054035.491497-2-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1521dc2 commit b164316

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/block/null_blk/zoned.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ int null_init_zoned_dev(struct nullb_device *dev,
7474
return -EINVAL;
7575
}
7676

77+
/*
78+
* If a smaller zone capacity was requested, do not allow a smaller last
79+
* zone at the same time as such zone configuration does not correspond
80+
* to any real zoned device.
81+
*/
82+
if (dev->zone_capacity != dev->zone_size &&
83+
dev->size & (dev->zone_size - 1)) {
84+
pr_err("A smaller last zone is not allowed with zone capacity smaller than zone size.\n");
85+
return -EINVAL;
86+
}
87+
7788
zone_capacity_sects = mb_to_sects(dev->zone_capacity);
7889
dev_capacity_sects = mb_to_sects(dev->size);
7990
dev->zone_size_sects = mb_to_sects(dev->zone_size);

0 commit comments

Comments
 (0)