Re: [PATCH 2/2] block: fix the length of a smaller last zone in blkdev_get_zone_info()

From: Damien Le Moal

Date: Sun Oct 11 2026 - 12:06:32 EST


On 2026/10/11 7:19, Shashank Mohan Jain wrote:
> blkdev_get_zone_info() sets the length of every zone to the zone size
> of the device. The last zone of a zoned block device may be smaller
> than the others: blk_revalidate_zone_cb() accepts that and remembers
> the capacity of that zone in disk->last_zone_capacity. For such a zone
> the length reported from the cached information is too large, and
> start + len is beyond the end of the device. A conventional last zone
> is also given the capacity of a full zone.
>
> Example with a zoned null_blk device of 10 MiB (20480 sectors) with
> 4 MiB zones, last zone:
>
> BLKREPORTZONE: start 16384 len 4096 capacity 4096
> BLKREPORTZONEV2 with
> BLK_ZONE_REP_CACHED: start 16384 len 8192 capacity 4096
>
> Limit the length to what is left of the device. disk_zone_is_last()
> still recognises the last zone, as start + len is then equal to the
> capacity of the device. The capacity of a conventional zone is equal
> to its length, which blk_revalidate_conv_zone() checks, so use the
> length there.
>
> Tested with zoned null_blk devices in qemu (all zones sequential, and
> two conventional zones followed by sequential ones, both with a smaller
> last zone): the start, length and capacity of all zones in the cached
> report are the same as in the report from the device with this change.
> null_blk cannot create a device with a conventional last zone, so that
> case is not tested.
>
> Fixes: f2284eec5053 ("block: introduce blkdev_get_zone_info()")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: Shashank Mohan Jain <jain.sm@xxxxxxxxx>

Doh! Good catch.

Reviewed-by: Damien Le Moal <dlemoal@xxxxxxxxxx>

--
Damien Le Moal
Western Digital Research