On 9/5/26 01:17, Niklas Cassel wrote:
> Deriving the zone that an offset belongs to is open coded in five places,
> in two files, as a division of the offset by BlockLimits.zone_size. The
> zone size of a zoned device is always a power of two, which Linux requires
> of every device it accepts, so the division is a shift.
> 
> Add bdrv_zone_index() and use it. No functional change; the count of zones
> that a management operation spans stays a division, since it is a length
> rather than an offset.
> 
> Signed-off-by: Niklas Cassel <[email protected]>

Nice cleanup! One comment below.

Reviewed-by: Damien Le Moal <[email protected]>

> +uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset)
> +{
> +    IO_CODE();
> +
> +    return offset >> ctz64(bs->bl.zone_size);
> +}

Should we save ctz64(bs->bl.zone_size) as bs->bl.zone_size_shift to avoid these
repeated ctz64() calls? Given how frequently this helper is used, that may be
worthwhile.

-- 
Damien Le Moal
Western Digital Research

Reply via email to