Whether a zone is conventional is encoded in the most significant bit of the write pointer that the block layer keeps for it, so a caller that wants to know has to reach into bs->wps->wp[] and apply BDRV_ZT_IS_CONV() to the raw value. virtio-blk does that, which means a device model both knows how a block driver stores its write pointers and knows what one of the bits of a write pointer means.
Add an accessor next to bdrv_zone_index() and use it there, so that the encoding stays with the code that chose it. Unlike bdrv_zone_is_full(), this does not need the write pointer lock. get_zones_wp() only ever sets the bit for a conventional zone and never clears it, and a zone does not change type, so the answer cannot become stale. The rest of the word does change, on every write, which is what the lock is there for. Signed-off-by: Niklas Cassel <[email protected]> --- block/io.c | 7 +++++++ hw/block/virtio-blk.c | 2 +- include/block/block-io.h | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index cef23ee5bc..da61e641ac 100644 --- a/block/io.c +++ b/block/io.c @@ -3373,6 +3373,13 @@ uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset) return offset >> bs->bl.zone_size_bits; } +bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_t index) +{ + IO_CODE(); + + return BDRV_ZT_IS_CONV(bs->wps->wp[index]); +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6e4a7a4076..dd69d81532 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -524,7 +524,7 @@ static bool check_zoned_request(VirtIOBlock *s, int64_t offset, int64_t len, } index = bdrv_zone_index(bs, offset); - if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) { + if (bdrv_zone_is_conv(bs, index)) { *status = VIRTIO_BLK_S_ZONE_INVALID_CMD; return false; } diff --git a/include/block/block-io.h b/include/block/block-io.h index 9d1c0eb7fb..e469df7061 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -128,6 +128,12 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_append(BlockDriverState *bs, BdrvRequestFlags flags); /* The index of the zone that @offset falls in. */ uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset); +/* + * True if the zone at @index is a conventional zone, which can be written + * anywhere in any order. The type of a zone does not change, so unlike + * bdrv_zone_is_full() this does not need the write pointer lock. + */ +bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_t index); bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); -- 2.55.0
