Add the block-backend accessors blk_get_zone_model(),
blk_get_zone_capacity() and blk_get_max_open_zones(), which report the
zoned model, the zone capacity and the maximum number of open zones of
the backing device, mirroring the existing blk_get_zone_size(). This
lets device models query the zoned geometry without dereferencing
BlockDriverState internals.

Signed-off-by: Niklas Cassel <[email protected]>
---
 block/block-backend.c             | 33 +++++++++++++++++++++++++++++++
 include/system/block-backend-io.h |  3 +++
 2 files changed, 36 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index 656c0aed67..397ec9ed5a 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2338,6 +2338,39 @@ uint64_t blk_get_zone_size(BlockBackend *blk)
     return bs ? bs->bl.zone_size : 0;
 }
 
+/*
+ * Returns the zoned model of @blk (BLK_Z_HM, BLK_Z_HA), or BLK_Z_NONE if
+ * @blk does not present zoned geometry.
+ */
+BlockZoneModel blk_get_zone_model(BlockBackend *blk)
+{
+    BlockDriverState *bs = blk_bs(blk);
+    IO_CODE();
+    return bs ? bs->bl.zoned : BLK_Z_NONE;
+}
+
+/*
+ * Returns the maximum number of simultaneously open zones for a zoned
+ * backend, or 0 if there is no limit or @blk is not zoned.
+ */
+uint32_t blk_get_max_open_zones(BlockBackend *blk)
+{
+    BlockDriverState *bs = blk_bs(blk);
+    IO_CODE();
+    return bs ? bs->bl.max_open_zones : 0;
+}
+
+/*
+ * Returns how many bytes of each zone of @blk can be written (the zone
+ * capacity), or 0 if that is not known.
+ */
+uint64_t blk_get_zone_capacity(BlockBackend *blk)
+{
+    BlockDriverState *bs = blk_bs(blk);
+    IO_CODE();
+    return bs ? bs->bl.zone_capacity : 0;
+}
+
 /* Returns the optimal write zeroes alignment, in bytes; guaranteed nonzero */
 uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk)
 {
diff --git a/include/system/block-backend-io.h 
b/include/system/block-backend-io.h
index 78d410b8df..7c958843b4 100644
--- a/include/system/block-backend-io.h
+++ b/include/system/block-backend-io.h
@@ -122,6 +122,9 @@ uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk);
 uint32_t blk_get_max_transfer(BlockBackend *blk);
 uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
 uint64_t blk_get_zone_size(BlockBackend *blk);
+BlockZoneModel blk_get_zone_model(BlockBackend *blk);
+uint32_t blk_get_max_open_zones(BlockBackend *blk);
+uint64_t blk_get_zone_capacity(BlockBackend *blk);
 
 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
                                    BlockBackend *blk_out, int64_t off_out,
-- 
2.56.0


Reply via email to