Add support for zoned device
Subsystems (2)
v9 cover Add support for zoned device
Zoned Block Devices (ZBDs) devide the LBA space to block regions called zones that are larger than the LBA size. It can only allow sequential writes, which reduces write amplification in SSD, leading to higher throughput and increased capacity. More details about ZBDs can be found at:
https://zonedstorage.io/docs/introduction/zoned-storage
The zoned device support aims to let guests (virtual machines) access zoned storage devices on the host (hypervisor) through a virtio-blk device. This involves extending QEMU's block layer and virtio-blk emulation code. In its current status, the virtio-blk device is not aware of ZBDs but the guest sees host-managed drives as regular drive that will runs correctly under the most common write workloads.
This patch series extend the block layer APIs with the minimum set of zoned commands that are necessary to support zoned devices. The commands are - Report Zones, four zone operations and Zone Append (developing).
It can be tested on a null_blk device using qemu-io or qemu-iotests. For example, to test zone report using qemu-io:
$ path/to/qemu-io --image-opts -n driver=zoned_host_device,filename=/dev/nullb0 -c "zrp offset nr_zones"
v9:
- address review comments
* specify units of zone commands requests [Stefan]
* fix some error handling in file-posix [Stefan]
* introduce zoned_host_devcie in the commit message [Markus]
v8:
- address review comments
* solve patch conflicts and merge sysfs helper funcations into one patch
* add cache.direct=on check in config
v7:
- address review comments
* modify sysfs attribute helper funcations
* move the input validation and error checking into raw_co_zone_* function
* fix checks in config
v6:
- drop virtio-blk emulation changes
- address Stefan's review comments
* fix CONFIG_BLKZONED configs in related functions
* replace reading fd by g_file_get_contents() in get_sysfs_str_val()
* rewrite documentation for zoned storage
v5:
- add zoned storage emulation to virtio-blk device
- add documentation for zoned storage
- address review comments
* fix qemu-iotests
* fix check to block layer
* modify interfaces of sysfs helper functions
* rename zoned device structs according to QEMU styles
* reorder patches
v4:
- add virtio-blk headers for zoned device
- add configurations for zoned host device
- add zone operations for raw-format
- address review comments
* fix memory leak bug in zone_report
* add checks to block layers
* fix qemu-iotests format
* fix sysfs helper functions
v3:
- add helper functions to get sysfs attributes
- address review comments
* fix zone report bugs
* fix the qemu-io code path
* use thread pool to avoid blocking ioctl() calls
v2:
- add qemu-io sub-commands
- address review comments
* modify interfaces of APIs
v1:
- add block layer APIs resembling Linux ZoneBlockDevice ioctls
Sam Li (7):
include: add zoned device structs
file-posix: introduce helper functions for sysfs attributes
block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
raw-format: add zone operations to pass through requests
config: add check to block layer
qemu-iotests: test new zone operations docs/zoned-storage: add zoned device documentation
block.c | 14 + block/block-backend.c | 145 ++++++++ block/file-posix.c | 458 +++++++++++++++++++++++-- block/io.c | 41 +++ block/raw-format.c | 14 + docs/devel/zoned-storage.rst | 41 +++ docs/system/qemu-block-drivers.rst.inc | 6 + include/block/block-common.h | 43 +++ include/block/block-io.h | 7 + include/block/block_int-common.h | 29 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 + meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 ++++++++ tests/qemu-iotests/tests/zoned.out | 53 +++ tests/qemu-iotests/tests/zoned.sh | 85 +++++ 17 files changed, 1071 insertions(+), 40 deletions(-) create mode 100644 docs/devel/zoned-storage.rst create mode 100644 tests/qemu-iotests/tests/zoned.out create mode 100755 tests/qemu-iotests/tests/zoned.sh
Signature · 1 line
2.37.3
PATCH v9 1/7 include: add zoned device structs
--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
include/block/block-common.h +43 -0
@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/* +* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes. +*/ +typedef struct BlockZoneDescriptor { +uint64_t start; +uint64_t length; +uint64_t cap; +uint64_t wp; +BlockZoneType type; +BlockZoneCondition cond; +}BlockZoneDescriptor ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size;
Signature · 1 line
2.37.3
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 38 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)include/block/block-common.h +23
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ;
include/block/block-common.h typedef struct BlockDriver BlockDriver; · line 84
Quoted 10 lines
include/block/block-common.h +10
-0+ +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/* +* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes.
I'm glad that you chose bytes here for use in qemu. But since the kernel struct blk_zone uses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?
Quoted 16 lines
include/block/block-common.h +10
-0+*/ +typedef struct BlockZoneDescriptor { +uint64_t start; +uint64_t length; +uint64_t cap; +uint64_t wp; +BlockZoneType type; +BlockZoneCondition cond; +}BlockZoneDescriptor ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size;Signature · 1 line
2.37.3
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 48 lines · Eric Blake <[email protected]> 于2022年9月15日周四 16:05写道:
Quoted 46 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)include/block/block-common.h +31
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/*
Quoted 8 lines
include/block/block-common.h typedef struct BlockDriver BlockDriver; · line 84
Quoted 2 lines
include/block/block-common.h +2
-0+* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes. I'm glad that you chose bytes here for use in qemu. But since the kernel struct
blk_zoneuses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?
Sorry about the unit mistake. The zone information is in sectors which is the same as kernel struct blk_zone. I think adding a sentence to inform the sector unit makes it clear what the zone descriptor is.
Quoted 23 lines
Quoted 15 lines
include/block/block-common.h +10
-1+*/ +typedef struct BlockZoneDescriptor { +uint64_t start; +uint64_t length; +uint64_t cap; +uint64_t wp; +BlockZoneType type; +BlockZoneCondition cond; +}BlockZoneDescriptor ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size; --Quoted 2 lines
2.37.3
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 58 lines · Sam Li
Quoted 48 lines · Eric Blake <[email protected]> 于2022年9月15日周四 16:05写道:
Quoted 46 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)include/block/block-common.h +31
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/* Quoted 8 lines
include/block/block-common.h typedef struct BlockDriver BlockDriver; · line 84
Quoted 2 lines
include/block/block-common.h +2
-0+* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes. I'm glad that you chose bytes here for use in qemu. But since the kernel struct
blk_zoneuses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?
Quoted 3 lines
Sorry about the unit mistake. The zone information is in sectors which is the same as kernel struct
blk_zone. I think adding a sentence to inform the sector unit makes it clear what the zone descriptor is.
I'd make the units bytes for consistency with the rest of the QEMU block layer. For example, the MapEntry structure that "qemu-img map" reports has names with similar fields and they are in bytes:
struct MapEntry {
int64_t start;
int64_t length;Stefan
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 64 lines · Stefan Hajnoczi <[email protected]> 于2022年9月18日周日 04:17写道:
Quoted 58 lines · Sam Li
Quoted 48 lines · Eric Blake <[email protected]> 于2022年9月15日周四 16:05写道:
Quoted 46 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)include/block/block-common.h +31
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/* Quoted 8 lines
include/block/block-common.h typedef struct BlockDriver BlockDriver; · line 84
Quoted 2 lines
include/block/block-common.h +2
-0+* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes. I'm glad that you chose bytes here for use in qemu. But since the kernel struct
blk_zoneuses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?Quoted 3 lines
Sorry about the unit mistake. The zone information is in sectors which is the same as kernel struct
blk_zone. I think adding a sentence to inform the sector unit makes it clear what the zone descriptor is.
Quoted 8 lines
I'd make the units bytes for consistency with the rest of the QEMU block layer. For example, the MapEntry structure that "qemu-img map" reports has names with similar fields and they are in bytes:
struct MapEntry { int64_t start; int64_t length;
I think the zone descriptor uses sector units because ioctl() will report zones in sector units. Making blk_zone.offset = zone_descriptor.offset is more convenient than using byte units where it needs make conversions twice(sector -> byte -> sector in zone descriptors and offset argument in bdrv_co_zone_report). The MapEntry uses byte units because lseek() in bdrv_co_block_status suggests the file offset is set to bytes and I think it may be why the rest of the block layer uses bytes(not sure).
I do not object to using bytes here but it would require some compromises. If I was wrong about anything, please let me know.
Sam
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 83 lines · Sam Li
Quoted 64 lines · Stefan Hajnoczi <[email protected]> 于2022年9月18日周日 04:17写道:
Quoted 58 lines · Sam Li
Quoted 48 lines · Eric Blake <[email protected]> 于2022年9月15日周四 16:05写道:
Quoted 46 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)include/block/block-common.h +31
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType { +BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +}BlockZoneType ; + +/* Quoted 8 lines
include/block/block-common.h typedef struct BlockDriver BlockDriver; · line 84
Quoted 2 lines
include/block/block-common.h +2
-0+* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes. I'm glad that you chose bytes here for use in qemu. But since the kernel struct
blk_zoneuses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?Quoted 3 lines
Sorry about the unit mistake. The zone information is in sectors which is the same as kernel struct
blk_zone. I think adding a sentence to inform the sector unit makes it clear what the zone descriptor is.Quoted 8 lines
I'd make the units bytes for consistency with the rest of the QEMU block layer. For example, the MapEntry structure that "qemu-img map" reports has names with similar fields and they are in bytes:
struct MapEntry { int64_t start; int64_t length;I think the zone descriptor uses sector units because
ioctl()will report zones in sector units. Making blk_zone.offset = zone_descriptor.offset is more convenient than using byte units where it needs make conversionstwice(sector -> byte -> sector in zone descriptors and offset argument in bdrv_co_zone_report). The MapEntry uses byte units becauselseek()inbdrv_co_block_statussuggests the file offset is set to bytes and I think it may be why the rest of the block layer uses bytes(not sure).
Quoted 2 lines
I do not object to using bytes here but it would require some compromises. If I was wrong about anything, please let me know.
The conversion can be done using 9-bits left and right shifts, which are cheap to do. I think it is important to be consistent with qemu block API, so using for the API bytes is preferred. That will avoid confusions.
Quoted 3 lines
Sam
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 1/7] include: add zoned device structs
Quoted 87 lines · Damien Le Moal <[email protected]>于2022年9月19日 周一16:04写道:
Quoted 11 lines · Sam Li
Quoted 10 lines · Stefan Hajnoczi <[email protected]> 于2022年9月18日周日 04:17写道:
Quoted 8 lines · Sam Li
Quoted 7 lines · Eric Blake <[email protected]> 于2022年9月15日周四 16:05写道:
Quoted 5 lines · Sam Li
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>--- include/block/block-common.h | 43++++++++++++++++++++++++++++++++++++
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Review
Quoted 3 lines
1 file changed, 43 insertions(+)(quoted diff) +0
-0
b/include/block/block-common.hQuoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
index
fdb7306e78..36bd0e480e100644include/block/block-common.h +25
-0@@ -49,6 +49,49 @@ typedef struct BlockDriver BlockDriver;typedef struct BdrvChild BdrvChild ;typedef struct BdrvChildClass BdrvChildClass ; +typedef enum BlockZoneOp { +BLK_ZO_OPEN , +BLK_ZO_CLOSE , +BLK_ZO_FINISH , +BLK_ZO_RESET , +}BlockZoneOp ; + +typedef enum BlockZoneModel { +BLK_Z_NONE =0x0 ,/* Regular block device */ +BLK_Z_HM =0x1 ,/* Host-managed zoned block device */ +BLK_Z_HA =0x2 ,/* Host-aware zoned block device */ +}BlockZoneModel ; + +typedef enum BlockZoneCondition { +BLK_ZS_NOT_WP =0x0 , +BLK_ZS_EMPTY =0x1 , +BLK_ZS_IOPEN =0x2 , +BLK_ZS_EOPEN =0x3 , +BLK_ZS_CLOSED =0x4 , +BLK_ZS_RDONLY =0xD , +BLK_ZS_FULL =0xE , +BLK_ZS_OFFLINE =0xF , +}BlockZoneCondition ; + +typedef enum BlockZoneType {Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/block/block-common.h typedef struct BlockDriver BlockDriver;
Quoted 8 lines
include/block/block-common.h +8
-0+BLK_ZT_CONV =0x1 ,/* Conventional random writes supported */ +BLK_ZT_SWR =0x2 ,/* Sequential writes required */ +BLK_ZT_SWP =0x3 ,/* Sequential writes preferred */ +} BlockZoneType; + +/* +* Zone descriptor data structure. +* Provides information on a zone with all position and size values in bytes.
Quoted 29 lines
Quoted 11 lines
Quoted 10 lines
Quoted 6 lines
I'm glad that you chose bytes here for use in qemu. But since the kernel struct
blk_zoneuses sectors instead of bytes, is it worth adding a sentence that we intentionally use bytes here, different from Linux, to make it easier for reviewers to realize that scaling when translating between qemu and kernel is necessary?Sorry about the unit mistake. The zone information is in sectors which is the same as kernel struct
blk_zone. I think adding a sentence to inform the sector unit makes it clear what the zone descriptor is.Quoted 8 lines
I'd make the units bytes for consistency with the rest of the QEMU block layer. For example, the MapEntry structure that "qemu-img map" reports has names with similar fields and they are in bytes:
struct MapEntry { int64_t start; int64_t length;I think the zone descriptor uses sector units because
ioctl()will report zones in sector units. Making blk_zone.offset = zone_descriptor.offset is more convenient than using byte units where it needs make conversionstwice(sector -> byte -> sector in zone descriptors and offset argument in bdrv_co_zone_report). The MapEntry uses byte units becauselseek()inbdrv_co_block_statussuggests the file offset is set to bytes and I think it may be why the rest of the block layer uses bytes(not sure).
Quoted 6 lines
Quoted 2 lines
I do not object to using bytes here but it would require some compromises. If I was wrong about anything, please let me know.
The conversion can be done using 9-bits left and right shifts, which are cheap to do. I think it is important to be consistent with qemu block API, so using for the API bytes is preferred. That will avoid confusions.
Ok, will change it. Thanks!
Quoted 10 lines
Quoted 4 lines
Sam
--
Damien Le Moal
Western Digital Research
PATCH v9 2/7 file-posix: introduce helper functions for sysfs attributes
In reply to Sam LiUse get_sysfs_str_val() to get the string value of device zoned model. Then get_sysfs_zoned_model() can convert it to BlockZoneModel type of QEMU.
Use get_sysfs_long_val() to get the long value of zoned device information.
--- block/file-posix.c | 121 ++++++++++++++++++++++--------- include/block/block_int-common.h | 3 + 2 files changed, 88 insertions(+), 36 deletions(-)
block/file-posix.c +85 -36
@@ -1210,66 +1210,109 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)#endif } -static int hdev_get_max_segments (int fd,struct stat *st) -{ +/* +* Get a sysfs attribute value as character string. +*/ +static int get_sysfs_str_val (struct stat *st,const char *attribute, +char **val) {#ifdef CONFIG_LINUX -char buf[32 ]; -const char *end; -char *sysfspath =NULL ; + g_autofree char *sysfspath = NULL;int ret; -int sysfd =-1 ; -long max_segments; +size_t len; -if (S_ISCHR (st->st_mode)) { -if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) { -return ret; - } +if (!S_ISBLK (st->st_mode)) {return -ENOTSUP ; } -if (!S_ISBLK (st->st_mode)) { -return -ENOTSUP ; + sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/%s" , +major (st->st_rdev),minor (st->st_rdev), + attribute); + ret =g_file_get_contents (sysfspath, val, &len,NULL ); +if (ret ==-1 ) { +return -ENOENT ; } - sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/max_segments" , -major (st->st_rdev),minor (st->st_rdev)); - sysfd =open (sysfspath,O_RDONLY ); -if (sysfd ==-1 ) { - ret = -errno; - goto out; +/* The file is ended with '\n' */ +char *p; + p = *val; +if (*(p + len -1 ) =='\n' ) { + *(p + len -1 ) ='\0' ; } -do { - ret =read (sysfd, buf,sizeof (buf) -1 ); - }while (ret ==-1 && errno ==EINTR ); +return ret; +#else +return -ENOTSUP ; +#endif +} + +static int get_sysfs_zoned_model (struct stat *st,BlockZoneModel *zoned) { + g_autofree char *val = NULL; +int ret; + + ret =get_sysfs_str_val (st,"zoned" , &val);if (ret <0 ) { - ret = -errno; - goto out; - }else if (ret ==0 ) { - ret = -EIO ; - goto out; +return ret; } - buf[ret] =0 ; -/* The file is ended with '\n', pass 'end' to accept that. */ - ret =qemu_strtol (buf, &end,10 , &max_segments); -if (ret ==0 && end && *end =='\n' ) { - ret = max_segments; + +if (strcmp (val,"host-managed" ) ==0 ) { + *zoned =BLK_Z_HM ; + }else if (strcmp (val,"host-aware" ) ==0 ) { + *zoned =BLK_Z_HA ; + }else if (strcmp (val,"none" ) ==0 ) { + *zoned =BLK_Z_NONE ; + }else { +return -ENOTSUP ; } +return 0 ; +} -out: -if (sysfd !=-1 ) { -close (sysfd); +/* +* Get a sysfs attribute value as a long integer. +*/ +static long get_sysfs_long_val (struct stat *st,const char *attribute) { +#ifdef CONFIG_LINUX + g_autofree char *str = NULL; +const char *end; +long val; +int ret; + + ret =get_sysfs_str_val (st, attribute, &str); +if (ret <0 ) { +return ret; + } + +/* The file is ended with '\n', pass 'end' to accept that. */ + ret =qemu_strtol (str, &end,10 , &val); +if (ret ==0 && end && *end =='\0' ) { + ret = val; } -g_free (sysfspath);return ret;#else return -ENOTSUP ;#endif } +static int hdev_get_max_segments (int fd,struct stat *st) { +#ifdef CONFIG_LINUX +int ret; + +if (S_ISCHR (st->st_mode)) { +if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) { +return ret; + } +return -ENOTSUP ; + } +return get_sysfs_long_val (st,"max_segments" ); +#else +return -ENOTSUP ; +#endif +} +static void raw_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque;struct stat st; +int ret; +BlockZoneModel zoned; s->needs_alignment =raw_needs_alignment (bs);raw_probe_alignment (bs, s->fd, errp);
@@ -1307,6 +1350,12 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.max_hw_iov = ret; } } + + ret =get_sysfs_zoned_model (&st, &zoned); +if (ret <0 ) { + zoned =BLK_Z_NONE ; + } + bs->bl.zoned = zoned; }static int check_for_dasd (int fd)
include/block/block_int-common.h +3 -0
@@ -825,6 +825,9 @@ typedef struct BlockLimits {/* maximum number of iovec elements */ int max_iov; + +/* device zone model */ +BlockZoneModel zoned; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
Signature · 1 line
2.37.3
Re: [PATCH v9 2/7] file-posix: introduce helper functions for sysfs attributes
Quoted 10 lines · Sam Li
Use
get_sysfs_str_val()to get the string value of device zoned model. Thenget_sysfs_zoned_model()can convert it to BlockZoneModel type of QEMU.Use
get_sysfs_long_val()to get the long value of zoned device information.Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>
Looks good to me.
Quoted 182 lines
--- block/file-posix.c | 121 ++++++++++++++++++++++--------- include/block/block_int-common.h | 3 + 2 files changed, 88 insertions(+), 36 deletions(-)block/file-posix.c +85
-36@@ -1210,66 +1210,109 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)#endif } -static int hdev_get_max_segments (int fd,struct stat *st) -{ +/* +* Get a sysfs attribute value as character string. +*/ +static int get_sysfs_str_val (struct stat *st,const char *attribute, +char **val) {#ifdef CONFIG_LINUX -char buf[32 ]; -const char *end; -char *sysfspath =NULL ; + g_autofree char *sysfspath = NULL;int ret; -int sysfd =-1 ; -long max_segments; +size_t len; -if (S_ISCHR (st->st_mode)) { -if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) { -return ret; - } +if (!S_ISBLK (st->st_mode)) {return -ENOTSUP ; } -if (!S_ISBLK (st->st_mode)) { -return -ENOTSUP ; + sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/%s" , +major (st->st_rdev),minor (st->st_rdev), + attribute); + ret =g_file_get_contents (sysfspath, val, &len,NULL ); +if (ret ==-1 ) { +return -ENOENT ; } - sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/max_segments" , -major (st->st_rdev),minor (st->st_rdev)); - sysfd =open (sysfspath,O_RDONLY ); -if (sysfd ==-1 ) { - ret = -errno; - goto out; +/* The file is ended with '\n' */ +char *p; + p = *val; +if (*(p + len -1 ) =='\n' ) { + *(p + len -1 ) ='\0' ; } -do { - ret =read (sysfd, buf,sizeof (buf) -1 ); - }while (ret ==-1 && errno ==EINTR ); +return ret; +#else +return -ENOTSUP ; +#endif +} + +static int get_sysfs_zoned_model (struct stat *st,BlockZoneModel *zoned) { + g_autofree char *val = NULL; +int ret; + + ret =get_sysfs_str_val (st,"zoned" , &val);if (ret <0 ) { - ret = -errno; - goto out; - }else if (ret ==0 ) { - ret = -EIO ; - goto out; +return ret; } - buf[ret] =0 ; -/* The file is ended with '\n', pass 'end' to accept that. */ - ret =qemu_strtol (buf, &end,10 , &max_segments); -if (ret ==0 && end && *end =='\n' ) { - ret = max_segments; + +if (strcmp (val,"host-managed" ) ==0 ) { + *zoned =BLK_Z_HM ; + }else if (strcmp (val,"host-aware" ) ==0 ) { + *zoned =BLK_Z_HA ; + }else if (strcmp (val,"none" ) ==0 ) { + *zoned =BLK_Z_NONE ; + }else { +return -ENOTSUP ; } +return 0 ; +} -out: -if (sysfd !=-1 ) { -close (sysfd); +/* +* Get a sysfs attribute value as a long integer. +*/ +static long get_sysfs_long_val (struct stat *st,const char *attribute) { +#ifdef CONFIG_LINUX + g_autofree char *str = NULL; +const char *end; +long val; +int ret; + + ret =get_sysfs_str_val (st, attribute, &str); +if (ret <0 ) { +return ret; + } + +/* The file is ended with '\n', pass 'end' to accept that. */ + ret =qemu_strtol (str, &end,10 , &val); +if (ret ==0 && end && *end =='\0' ) { + ret = val; } -g_free (sysfspath);return ret;#else return -ENOTSUP ;#endif } +static int hdev_get_max_segments (int fd,struct stat *st) { +#ifdef CONFIG_LINUX +int ret; + +if (S_ISCHR (st->st_mode)) { +if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) { +return ret; + } +return -ENOTSUP ; + } +return get_sysfs_long_val (st,"max_segments" ); +#else +return -ENOTSUP ; +#endif +} +static void raw_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque;struct stat st; +int ret; +BlockZoneModel zoned; s->needs_alignment =raw_needs_alignment (bs);raw_probe_alignment (bs, s->fd, errp);@@ -1307,6 +1350,12 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.max_hw_iov = ret; } } + + ret =get_sysfs_zoned_model (&st, &zoned); +if (ret <0 ) { + zoned =BLK_Z_NONE ; + } + bs->bl.zoned = zoned; }static int check_for_dasd (int fd)include/block/block_int-common.h +3
-0@@ -825,6 +825,9 @@ typedef struct BlockLimits {/* maximum number of iovec elements */ int max_iov; + +/* device zone model */ +BlockZoneModel zoned; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH v9 3/7 block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Sam LiAdd a new zoned_host_device BlockDriver. The zoned_host_device option accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).
Qemu-io uses the new APIs to perform zoned storage commands of the device:zone_report(zrp), zone_open(zo), zone_close(zc), zone_reset(zrs), zone_finish(zf).
For example, to test zone_report, use following command:
$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"
--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)
block/block-backend.c +145 -0
@@ -1431,6 +1431,15 @@ typedef struct BlkRwCo {void *iobuf;int ret;BdrvRequestFlags flags; +union { +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +BlockZoneOp op; + } zone_mgmt; + }; } BlkRwCo;int blk_make_zero (BlockBackend *blk,BdrvRequestFlags flags)
@@ -1775,6 +1784,142 @@ int coroutine_fn blk_co_flush(BlockBackend *blk)return ret; } +static void blk_aio_zone_report_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_report (rwco->blk, rwco->offset, + rwco->zone_report.nr_zones, + rwco->zone_report.zones); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque) +{ +BlkAioEmAIOCB *acb; +Coroutine *co; +IO_CODE (); + +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_report = { + .zones = zones, + .nr_zones = nr_zones, + }, + }; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_report_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +static void blk_aio_zone_mgmt_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_mgmt (rwco->blk, rwco->zone_mgmt.op, + rwco->offset, acb->bytes); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque) { +BlkAioEmAIOCB *acb; +Coroutine *co; +IO_CODE (); + +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_mgmt = { + .op = op, + }, + }; + acb->bytes = len; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_mgmt_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +/* +* Send a zone_report command. +* offset is a byte offset from the start of the device. No alignment +* required for offset. +* nr_zones represents IN maximum and OUT actual. +*/ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +int ret; +IO_CODE (); + +blk_inc_in_flight (blk);/* increase before waiting */ +blk_wait_while_drained (blk); +if (!blk_is_available (blk)) { +blk_dec_in_flight (blk); +return -ENOMEDIUM ; + } + ret =bdrv_co_zone_report (blk_bs (blk), offset, nr_zones, zones); +blk_dec_in_flight (blk); +return ret; +} + +/* +* Send a zone_management command. +* op is the zone operation; +* offset is the byte offset from the start of the zoned device; +* len is the maximum number of bytes the command should operate on. It +* should be aligned with the zone sector size. +*/ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len) +{ +int ret; +IO_CODE (); + + +blk_inc_in_flight (blk); +blk_wait_while_drained (blk); + + ret =blk_check_byte_request (blk, offset, len); +if (ret <0 ) { +return ret; + } + + ret =bdrv_co_zone_mgmt (blk_bs (blk), op, offset, len); +blk_dec_in_flight (blk); +return ret; +} +void blk_drain (BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);
block/file-posix.c +322 -1
371 lines not on this page · raw message
block/io.c +41 -0
47 lines not on this page · raw message
include/block/block-io.h +7 -0
@@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,
include/block/block_int-common.h +21 -0
@@ -691,6 +691,12 @@ struct BlockDriver {QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, +int64_t offset,unsigned int *nr_zones, +BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);
@@ -828,6 +834,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in 512-byte sectors */ +uint32_t zone_sectors; + +/* total number of zones */ +unsigned int nr_zones; + +/* maximum sectors of a zone append write operation */ +int64_t max_append_sectors; + +/* maximum number of open zones */ +int64_t max_open_zones; + +/* maximum number of active zones */ +int64_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
include/block/raw-aio.h +5 -1
@@ -29,6 +29,8 @@#define QEMU_AIO_WRITE_ZEROES 0x0020#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \
@@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000
include/sysemu/block-backend-io.h +17 -0
@@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *blk_aio_flush (BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones,BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque);BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk,int64_t offset,int64_t bytes,BlockCompletionFunc *cb,void *opaque);void blk_aio_cancel_async (BlockAIOCB *acb);
@@ -156,6 +162,17 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
meson.build +1 -0
@@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))
qapi/block-core.json +6 -2
@@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ##
@@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:
@@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##
qemu-io-cmds.c +143 -0
155 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
On 2022/09/10 14:27, Sam Li wrote:
[...]
Quoted 20 lines
block/block-backend.c +20
-0+/* +* Send a zone_report command. +* offset is a byte offset from the start of the device. No alignment +* required for offset. +* nr_zones represents IN maximum and OUT actual. +*/ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +int ret; +IO_CODE (); + +blk_inc_in_flight (blk);/* increase before waiting */ +blk_wait_while_drained (blk); +if (!blk_is_available (blk)) { +blk_dec_in_flight (blk); +return -ENOMEDIUM ; + } + ret =bdrv_co_zone_report (blk_bs (blk), offset, nr_zones, zones);
block/block-backend.c int coroutine_fn blk_co_flush(BlockBackend *blk) · line 1901
Quoted 10 lines
block/block-backend.c +10
-0+blk_dec_in_flight (blk); +return ret; +} + +/* +* Send a zone_management command. +* op is the zone operation; +* offset is the byte offset from the start of the zoned device; +* len is the maximum number of bytes the command should operate on. It +* should be aligned with the zone sector size.
This should read:
* offset is the byte offset of the start of the first zone to operate on;
* len is the maximum number of bytes the command should operate on. It
* should be aligned with the device zone size.
No ?
Quoted 64 lines
+ */
block/block-backend.c +20
-0+int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len) +{ +int ret; +IO_CODE (); + + +blk_inc_in_flight (blk); +blk_wait_while_drained (blk); + + ret =blk_check_byte_request (blk, offset, len); +if (ret <0 ) { +return ret; + } + + ret =bdrv_co_zone_mgmt (blk_bs (blk), op, offset, len); +blk_dec_in_flight (blk); +return ret; +} +void blk_drain (BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);block/file-posix.c +13
-1@@ -67,6 +67,9 @@#include <sys/param.h> #include <sys/syscall.h> #include <sys/vfs.h> +#if defined(CONFIG_BLKZONED ) +#include <linux/blkzoned.h> +#endif #include <linux/cdrom.h> #include <linux/fd.h> #include <linux/fs.h> @@ -216,6 +219,15 @@ typedef struct RawPosixAIOData {PreallocMode prealloc;Error **errp; } truncate; +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +unsigned long zone_op; +const char *zone_op_name; +bool all; + } zone_mgmt; }; } RawPosixAIOData;@@ -1339,7 +1351,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)#endif if (bs->sg ||S_ISBLK (st.st_mode)) { -int ret =hdev_get_max_hw_transfer (s->fd, &st); + ret =hdev_get_max_hw_transfer (s->fd, &st);if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { bs->bl.max_hw_transfer = ret;
block/file-posix.c static void raw_refresh_limits(BlockDriverState *bs, Error **errp) · line 1375
Quoted 8 lines
block/file-posix.c +5
-0@@ -1356,6 +1368,27 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) zoned =BLK_Z_NONE ; } bs->bl.zoned = zoned; +if (zoned !=BLK_Z_NONE ) { + ret =get_sysfs_long_val (&st,"chunk_sectors" ); +if (ret >0 ) { + bs->bl.zone_sectors = ret; + }
It may be good to check that we are getting a valid zone size here. So may be change the check to something like this ?
if (ret <= 0) {
*** print some error message mentioning the invalid zone size ***
bs->bl.zoned = BLK_Z_NONE;
return;
}
bs->bl.zone_sectors = ret;Quoted 47 lines
block/file-posix.c +40
-0+ + ret =get_sysfs_long_val (&st,"zone_append_max_bytes" ); +if (ret >0 ) { + bs->bl.max_append_sectors = ret /512 ; + } + + ret =get_sysfs_long_val (&st,"max_open_zones" ); +if (ret >=0 ) { + bs->bl.max_open_zones = ret; + } + + ret =get_sysfs_long_val (&st,"max_active_zones" ); +if (ret >=0 ) { + bs->bl.max_active_zones = ret; + } + } }static int check_for_dasd (int fd)@@ -1850,6 +1883,145 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, }#endif +/* +* parse_zone - Fill a zone descriptor +*/ +#if defined(CONFIG_BLKZONED ) +static inline void parse_zone (struct BlockZoneDescriptor *zone, +const struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity; + zone->wp = blkz->wp; + +switch (blkz->type) { +case BLK_ZONE_TYPE_SEQWRITE_REQ : + zone->type =BLK_ZT_SWR ; +break ; +case BLK_ZONE_TYPE_SEQWRITE_PREF : + zone->type =BLK_ZT_SWP ; +break ; +case BLK_ZONE_TYPE_CONVENTIONAL : + zone->type =BLK_ZT_CONV ; +break ; +default : +g_assert_not_reached (); + }
block/file-posix.c static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, · line 1919
Quoted 10 lines
block/file-posix.c +10
-0+ +switch (blkz->cond) { +case BLK_ZONE_COND_NOT_WP : + zone->cond =BLK_ZS_NOT_WP ; +break ; +case BLK_ZONE_COND_EMPTY : + zone->cond =BLK_ZS_EMPTY ; +break ; +case BLK_ZONE_COND_IMP_OPEN : + zone->cond =BLK_ZS_IOPEN ;
Missing a space after the "=".
Quoted 60 lines
block/file-posix.c +60
-0+break ; +case BLK_ZONE_COND_EXP_OPEN : + zone->cond =BLK_ZS_EOPEN ; +break ; +case BLK_ZONE_COND_CLOSED : + zone->cond =BLK_ZS_CLOSED ; +break ; +case BLK_ZONE_COND_READONLY : + zone->cond =BLK_ZS_RDONLY ; +break ; +case BLK_ZONE_COND_FULL : + zone->cond =BLK_ZS_FULL ; +break ; +case BLK_ZONE_COND_OFFLINE : + zone->cond =BLK_ZS_OFFLINE ; +break ; +default : + g_assert_not_reached(); + } +} +#endif + +#if defined(CONFIG_BLKZONED ) +static int do_zone_report (int64_t sector,int fd, +struct BlockZoneDescriptor *zones, +unsigned int nrz) { +struct blk_zone *blkz; +int ret, n =0 , i =0 ; + +int64_t rep_size =sizeof (struct blk_zone_report ) + nrz *sizeof (struct blk_zone ); + g_autofree struct blk_zone_report *rep = NULL; + rep =g_malloc (rep_size); + + blkz = (struct blk_zone *)(rep +1 ); +while (n < nrz) { +memset (rep,0 , rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + +do { + ret =ioctl (fd,BLKREPORTZONE , rep); + }while (ret !=0 && errno ==EINTR ); +if (ret !=0 ) { +error_report ("%d: ioctl BLKREPORTZONE at %" PRId64" failed %d" , + fd, sector, errno); +return -errno; + } + +if (!rep->nr_zones) { +break ; + } + +for (i =0 ; i < rep->nr_zones; i++, n++) { +parse_zone (&zones[n], &blkz[i]); +/* The next report should start after the last zone reported */ + sector = blkz[i].start + blkz[i].len; + } + } +return n; +}
block/file-posix.c static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, · line 1989
Quoted 10 lines
block/file-posix.c +10
-0+#endif + +static int handle_aiocb_zone_report (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +unsigned int *nr_zones = aiocb->zone_report.nr_zones; +BlockZoneDescriptor *zones = aiocb->zone_report.zones; +/* zoned block devices use 512-byte sectors */ +int64_t sector = aiocb->aio_offset /512 ;
This variable is not really necessary I think.
Quoted 85 lines
block/file-posix.c +78
-0+ + *nr_zones =do_zone_report (sector, fd, zones, *nr_zones); +return 0 ; +#else +return -ENOTSUP ; +#endif +} + +static int handle_aiocb_zone_mgmt (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +int64_t sector = aiocb->aio_offset /512 ; +int64_t nr_sectors = aiocb->aio_nbytes /512 ; +struct blk_zone_range range; +int ret; + +/* Execute the operation */ + range.sector = sector; + range.nr_sectors = nr_sectors; +do { + ret =ioctl (fd, aiocb->zone_mgmt.zone_op, &range); + }while (ret !=0 && errno ==EINTR ); + +if (ret !=0 ) { +error_report ("ioctl %s failed %d" , aiocb->zone_mgmt.zone_op_name, + errno); +return -errno; + } +return ret; +#else +return -ENOTSUP ; +#endif +} +static int handle_aiocb_copy_range (void *opaque) {RawPosixAIOData *aiocb = opaque;@@ -3022,6 +3194,104 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* +* zone report - Get a zone block device's information in the form +* of an array of zone descriptors. +* zones is an array of zone descriptors to hold zone information on reply; +* offset can be any byte within the entire size of the device; +* nr_zones is the maxium number of sectors the command should operate on. +*/ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_REPORT , + .aio_offset = offset, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_report, &acb); +#else +return -ENOTSUP ; +#endif +} + +/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false;
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3249
Quoted 10 lines
block/file-posix.c +10
-0+ + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {
Linux allows SMR drives to have a smaller last zone. So this needs to be accounted for here. Otherwise, a zone operation that includes the last smaller zone would always fail. Something like this would work:
if (((offset + len) < capacity &&
len & zone_sector_mask) ||
offset + len > capacity) {Quoted 487 lines
block/file-posix.c +96
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +} + static coroutine_fn intraw_do_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes,bool blkdev)@@ -3752,6 +4022,54 @@ static BlockDriver bdrv_host_device = {#endif }; +#if defined(CONFIG_BLKZONED ) +static BlockDriver bdrv_zoned_host_device = { + .format_name ="zoned_host_device" , + .protocol_name ="zoned_host_device" , + .instance_size =sizeof (BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + +/* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; +#endif +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)static void cdrom_parse_filename (const char *filename,QDict *options,Error **errp)@@ -4012,6 +4330,9 @@ static void bdrv_file_init(void)bdrv_register (&bdrv_file);#if defined(HAVE_HOST_BLOCK_DEVICE )bdrv_register (&bdrv_host_device); +#if defined(CONFIG_BLKZONED ) +bdrv_register (&bdrv_zoned_host_device); +#endif #ifdef __linux__bdrv_register (&bdrv_host_cdrom);#endif block/io.c +41
-0@@ -3198,6 +3198,47 @@ out:return co.ret; } +int bdrv_co_zone_report (BlockDriverState *bs,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_report) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_report (bs, offset, nr_zones, zones); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} + +int bdrv_co_zone_mgmt (BlockDriverState *bs,BlockZoneOp op, +int64_t offset,int64_t len) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_mgmt (bs, op, offset, len); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} +void *qemu_blockalign (BlockDriverState *bs,size_t size) {IO_CODE ();include/block/block-io.h +7
-0@@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,include/block/block_int-common.h +21
-0@@ -691,6 +691,12 @@ struct BlockDriver {QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, +int64_t offset,unsigned int *nr_zones, +BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);@@ -828,6 +834,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in 512-byte sectors */ +uint32_t zone_sectors; + +/* total number of zones */ +unsigned int nr_zones; + +/* maximum sectors of a zone append write operation */ +int64_t max_append_sectors; + +/* maximum number of open zones */ +int64_t max_open_zones; + +/* maximum number of active zones */ +int64_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;include/block/raw-aio.h +5
-1@@ -29,6 +29,8 @@#define QEMU_AIO_WRITE_ZEROES 0x0020#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \@@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000include/sysemu/block-backend-io.h +17
-0@@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *blk_aio_flush (BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones,BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque);BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk,int64_t offset,int64_t bytes,BlockCompletionFunc *cb,void *opaque);void blk_aio_cancel_async (BlockAIOCB *acb);@@ -156,6 +162,17 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,meson.build +1
-0@@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))qapi/block-core.json +6
-2@@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ##@@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:@@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##qemu-io-cmds.c +143
-0@@ -1712,6 +1712,144 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset; +unsigned int nr_zones; + + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + nr_zones =cvtnum (argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones =g_new (BlockZoneDescriptor, nr_zones); + ret =blk_zone_report (blk, offset, &nr_zones, zones); +if (ret <0 ) { +printf ("zone report failed: %s\n" ,strerror (-ret)); + }else { +for (int i =0 ; i < nr_zones; ++i) { +printf ("start: 0x%" PRIx64", len 0x%" PRIx64", " +"cap"" 0x%" PRIx64", wptr 0x%" PRIx64", " +"zcond:%u, [type: %u]\n" , + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } +return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name ="zone_report" , + .altname ="zrp" , + .cfunc = zone_report_f, + .argmin =2 , + .argmax =2 , + .args ="offset number" , + .oneline ="report zone information" , +}; + +static int zone_open_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_OPEN , offset, len); +if (ret <0 ) { +printf ("zone open failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name ="zone_open" , + .altname ="zo" , + .cfunc = zone_open_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="explicit open a range of zones in zone block device" , +}; + +static int zone_close_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_CLOSE , offset, len); +if (ret <0 ) { +printf ("zone close failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name ="zone_close" , + .altname ="zc" , + .cfunc = zone_close_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="close a range of zones in zone block device" , +}; + +static int zone_finish_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_FINISH , offset, len); +if (ret <0 ) { +printf ("zone finish failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name ="zone_finish" , + .altname ="zf" , + .cfunc = zone_finish_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="finish a range of zones in zone block device" , +}; + +static int zone_reset_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_RESET , offset, len); +if (ret <0 ) { +printf ("zone reset failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name ="zone_reset" , + .altname ="zrs" , + .cfunc = zone_reset_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="reset a zone write pointer in zone block device" , +}; +static int truncate_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t truncate_cmd = { .name ="truncate" ,@@ -2504,6 +2642,11 @@ static void __attribute((constructor)) init_qemuio_commands(void)qemuio_add_command (&aio_write_cmd);qemuio_add_command (&aio_flush_cmd);qemuio_add_command (&flush_cmd); +qemuio_add_command (&zone_report_cmd); +qemuio_add_command (&zone_open_cmd); +qemuio_add_command (&zone_close_cmd); +qemuio_add_command (&zone_finish_cmd); +qemuio_add_command (&zone_reset_cmd);qemuio_add_command (&truncate_cmd);qemuio_add_command (&length_cmd);qemuio_add_command (&info_cmd);
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 36 lines · Damien Le Moal <[email protected]> 于2022年9月11日周日 13:31写道:
On 2022/09/10 14:27, Sam Li wrote:
[...]Quoted 20 lines
block/block-backend.c +20
-0+/* +* Send a zone_report command. +* offset is a byte offset from the start of the device. No alignment +* required for offset. +* nr_zones represents IN maximum and OUT actual. +*/ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +int ret; +IO_CODE (); + +blk_inc_in_flight (blk);/* increase before waiting */ +blk_wait_while_drained (blk); +if (!blk_is_available (blk)) { +blk_dec_in_flight (blk); +return -ENOMEDIUM ; + } + ret =bdrv_co_zone_report (blk_bs (blk), offset, nr_zones, zones);block/block-backend.c int coroutine_fn blk_co_flush(BlockBackend *blk) · line 1901
Quoted 10 lines
block/block-backend.c +10
-0+blk_dec_in_flight (blk); +return ret; +} + +/* +* Send a zone_management command. +* op is the zone operation; +* offset is the byte offset from the start of the zoned device; +* len is the maximum number of bytes the command should operate on. It +* should be aligned with the zone sector size. This should read:
Quoted 5 lines
* offset is the byte offset of the start of the first zone to operate on;
* len is the maximum number of bytes the command should operate on. It
* should be aligned with the device zone size.No ?
Right. The zone sector size here is meant for the zone size whose unit is a 512-byte sector.
Quoted 77 lines
Quoted 65 lines
+ */
block/block-backend.c +20
-0+int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len) +{ +int ret; +IO_CODE (); + + +blk_inc_in_flight (blk); +blk_wait_while_drained (blk); + + ret =blk_check_byte_request (blk, offset, len); +if (ret <0 ) { +return ret; + } + + ret =bdrv_co_zone_mgmt (blk_bs (blk), op, offset, len); +blk_dec_in_flight (blk); +return ret; +} +void blk_drain (BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);block/file-posix.c +13
-1@@ -67,6 +67,9 @@#include <sys/param.h> #include <sys/syscall.h> #include <sys/vfs.h> +#if defined(CONFIG_BLKZONED ) +#include <linux/blkzoned.h> +#endif #include <linux/cdrom.h> #include <linux/fd.h> #include <linux/fs.h> @@ -216,6 +219,15 @@ typedef struct RawPosixAIOData {PreallocMode prealloc;Error **errp; } truncate; +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +unsigned long zone_op; +const char *zone_op_name; +bool all; + } zone_mgmt; }; } RawPosixAIOData;@@ -1339,7 +1351,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)#endif if (bs->sg ||S_ISBLK (st.st_mode)) { -int ret =hdev_get_max_hw_transfer (s->fd, &st); + ret =hdev_get_max_hw_transfer (s->fd, &st);if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { bs->bl.max_hw_transfer = ret;block/file-posix.c static void raw_refresh_limits(BlockDriverState *bs, Error **errp) · line 1375
Quoted 8 lines
block/file-posix.c +5
-0@@ -1356,6 +1368,27 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) zoned =BLK_Z_NONE ; } bs->bl.zoned = zoned; +if (zoned !=BLK_Z_NONE ) { + ret =get_sysfs_long_val (&st,"chunk_sectors" ); +if (ret >0 ) { + bs->bl.zone_sectors = ret; + }It may be good to check that we are getting a valid zone size here. So may be change the check to something like this ?
Quoted 7 lines
if (ret <= 0) {
*** print some error message mentioning the invalid zone size ***
bs->bl.zoned = BLK_Z_NONE;
return;
}
bs->bl.zone_sectors = ret;Ok, thanks!
Quoted 233 lines
Quoted 47 lines
block/file-posix.c +40
-0+ + ret =get_sysfs_long_val (&st,"zone_append_max_bytes" ); +if (ret >0 ) { + bs->bl.max_append_sectors = ret /512 ; + } + + ret =get_sysfs_long_val (&st,"max_open_zones" ); +if (ret >=0 ) { + bs->bl.max_open_zones = ret; + } + + ret =get_sysfs_long_val (&st,"max_active_zones" ); +if (ret >=0 ) { + bs->bl.max_active_zones = ret; + } + } }static int check_for_dasd (int fd)@@ -1850,6 +1883,145 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, }#endif +/* +* parse_zone - Fill a zone descriptor +*/ +#if defined(CONFIG_BLKZONED ) +static inline void parse_zone (struct BlockZoneDescriptor *zone, +const struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity; + zone->wp = blkz->wp; + +switch (blkz->type) { +case BLK_ZONE_TYPE_SEQWRITE_REQ : + zone->type =BLK_ZT_SWR ; +break ; +case BLK_ZONE_TYPE_SEQWRITE_PREF : + zone->type =BLK_ZT_SWP ; +break ; +case BLK_ZONE_TYPE_CONVENTIONAL : + zone->type =BLK_ZT_CONV ; +break ; +default : +g_assert_not_reached (); + }block/file-posix.c static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, · line 1919
Quoted 10 lines
block/file-posix.c +10
-0+ +switch (blkz->cond) { +case BLK_ZONE_COND_NOT_WP : + zone->cond =BLK_ZS_NOT_WP ; +break ; +case BLK_ZONE_COND_EMPTY : + zone->cond =BLK_ZS_EMPTY ; +break ; +case BLK_ZONE_COND_IMP_OPEN : + zone->cond =BLK_ZS_IOPEN ;Missing a space after the "=".
Quoted 60 lines
block/file-posix.c +60
-0+break ; +case BLK_ZONE_COND_EXP_OPEN : + zone->cond =BLK_ZS_EOPEN ; +break ; +case BLK_ZONE_COND_CLOSED : + zone->cond =BLK_ZS_CLOSED ; +break ; +case BLK_ZONE_COND_READONLY : + zone->cond =BLK_ZS_RDONLY ; +break ; +case BLK_ZONE_COND_FULL : + zone->cond =BLK_ZS_FULL ; +break ; +case BLK_ZONE_COND_OFFLINE : + zone->cond =BLK_ZS_OFFLINE ; +break ; +default : + g_assert_not_reached(); + } +} +#endif + +#if defined(CONFIG_BLKZONED ) +static int do_zone_report (int64_t sector,int fd, +struct BlockZoneDescriptor *zones, +unsigned int nrz) { +struct blk_zone *blkz; +int ret, n =0 , i =0 ; + +int64_t rep_size =sizeof (struct blk_zone_report ) + nrz *sizeof (struct blk_zone ); + g_autofree struct blk_zone_report *rep = NULL; + rep =g_malloc (rep_size); + + blkz = (struct blk_zone *)(rep +1 ); +while (n < nrz) { +memset (rep,0 , rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + +do { + ret =ioctl (fd,BLKREPORTZONE , rep); + }while (ret !=0 && errno ==EINTR ); +if (ret !=0 ) { +error_report ("%d: ioctl BLKREPORTZONE at %" PRId64" failed %d" , + fd, sector, errno); +return -errno; + } + +if (!rep->nr_zones) { +break ; + } + +for (i =0 ; i < rep->nr_zones; i++, n++) { +parse_zone (&zones[n], &blkz[i]); +/* The next report should start after the last zone reported */ + sector = blkz[i].start + blkz[i].len; + } + } +return n; +}block/file-posix.c static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, · line 1989
Quoted 10 lines
block/file-posix.c +10
-0+#endif + +static int handle_aiocb_zone_report (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +unsigned int *nr_zones = aiocb->zone_report.nr_zones; +BlockZoneDescriptor *zones = aiocb->zone_report.zones; +/* zoned block devices use 512-byte sectors */ +int64_t sector = aiocb->aio_offset /512 ;This variable is not really necessary I think.
Quoted 85 lines
block/file-posix.c +78
-0+ + *nr_zones =do_zone_report (sector, fd, zones, *nr_zones); +return 0 ; +#else +return -ENOTSUP ; +#endif +} + +static int handle_aiocb_zone_mgmt (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +int64_t sector = aiocb->aio_offset /512 ; +int64_t nr_sectors = aiocb->aio_nbytes /512 ; +struct blk_zone_range range; +int ret; + +/* Execute the operation */ + range.sector = sector; + range.nr_sectors = nr_sectors; +do { + ret =ioctl (fd, aiocb->zone_mgmt.zone_op, &range); + }while (ret !=0 && errno ==EINTR ); + +if (ret !=0 ) { +error_report ("ioctl %s failed %d" , aiocb->zone_mgmt.zone_op_name, + errno); +return -errno; + } +return ret; +#else +return -ENOTSUP ; +#endif +} +static int handle_aiocb_copy_range (void *opaque) {RawPosixAIOData *aiocb = opaque;@@ -3022,6 +3194,104 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* +* zone report - Get a zone block device's information in the form +* of an array of zone descriptors. +* zones is an array of zone descriptors to hold zone information on reply; +* offset can be any byte within the entire size of the device; +* nr_zones is the maxium number of sectors the command should operate on. +*/ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_REPORT , + .aio_offset = offset, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_report, &acb); +#else +return -ENOTSUP ; +#endif +} + +/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false;block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3249
Quoted 10 lines
block/file-posix.c +10
-0+ + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {Linux allows SMR drives to have a smaller last zone. So this needs to be accounted for here. Otherwise, a zone operation that includes the last smaller zone would always fail. Something like this would work:
Quoted 4 lines
if (((offset + len) < capacity &&
len & zone_sector_mask) ||
offset + len > capacity) {I see. I think the offset can be removed, like:
if (((len < capacity && len & zone_sector_mask) || len > capacity) { Then if we use the previous zone's len for the last smaller zone, it will be greater than its capacity.
I will also include "opening the last zone" as a test case later.
Quoted 492 lines
Quoted 477 lines
block/file-posix.c +96
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +} + static coroutine_fn intraw_do_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes,bool blkdev)@@ -3752,6 +4022,54 @@ static BlockDriver bdrv_host_device = {#endif }; +#if defined(CONFIG_BLKZONED ) +static BlockDriver bdrv_zoned_host_device = { + .format_name ="zoned_host_device" , + .protocol_name ="zoned_host_device" , + .instance_size =sizeof (BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + +/* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; +#endif +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)static void cdrom_parse_filename (const char *filename,QDict *options,Error **errp)@@ -4012,6 +4330,9 @@ static void bdrv_file_init(void)bdrv_register (&bdrv_file);#if defined(HAVE_HOST_BLOCK_DEVICE )bdrv_register (&bdrv_host_device); +#if defined(CONFIG_BLKZONED ) +bdrv_register (&bdrv_zoned_host_device); +#endif #ifdef __linux__bdrv_register (&bdrv_host_cdrom);#endif block/io.c +41
-0@@ -3198,6 +3198,47 @@ out:return co.ret; } +int bdrv_co_zone_report (BlockDriverState *bs,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_report) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_report (bs, offset, nr_zones, zones); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} + +int bdrv_co_zone_mgmt (BlockDriverState *bs,BlockZoneOp op, +int64_t offset,int64_t len) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_mgmt (bs, op, offset, len); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} +void *qemu_blockalign (BlockDriverState *bs,size_t size) {IO_CODE ();include/block/block-io.h +7
-0@@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,include/block/block_int-common.h +21
-0@@ -691,6 +691,12 @@ struct BlockDriver {QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, +int64_t offset,unsigned int *nr_zones, +BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);@@ -828,6 +834,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in 512-byte sectors */ +uint32_t zone_sectors; + +/* total number of zones */ +unsigned int nr_zones; + +/* maximum sectors of a zone append write operation */ +int64_t max_append_sectors; + +/* maximum number of open zones */ +int64_t max_open_zones; + +/* maximum number of active zones */ +int64_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;include/block/raw-aio.h +5
-1@@ -29,6 +29,8 @@#define QEMU_AIO_WRITE_ZEROES 0x0020#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \@@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000include/sysemu/block-backend-io.h +17
-0@@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *blk_aio_flush (BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones,BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque);BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk,int64_t offset,int64_t bytes,BlockCompletionFunc *cb,void *opaque);void blk_aio_cancel_async (BlockAIOCB *acb);@@ -156,6 +162,17 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,meson.build +1
-0@@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))qapi/block-core.json +6
-2@@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ##@@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:@@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##qemu-io-cmds.c +138
-0@@ -1712,6 +1712,144 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset; +unsigned int nr_zones; + + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + nr_zones =cvtnum (argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones =g_new (BlockZoneDescriptor, nr_zones); + ret =blk_zone_report (blk, offset, &nr_zones, zones); +if (ret <0 ) { +printf ("zone report failed: %s\n" ,strerror (-ret)); + }else { +for (int i =0 ; i < nr_zones; ++i) { +printf ("start: 0x%" PRIx64", len 0x%" PRIx64", " +"cap"" 0x%" PRIx64", wptr 0x%" PRIx64", " +"zcond:%u, [type: %u]\n" , + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } +return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name ="zone_report" , + .altname ="zrp" , + .cfunc = zone_report_f, + .argmin =2 , + .argmax =2 , + .args ="offset number" , + .oneline ="report zone information" , +}; + +static int zone_open_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_OPEN , offset, len); +if (ret <0 ) { +printf ("zone open failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name ="zone_open" , + .altname ="zo" , + .cfunc = zone_open_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="explicit open a range of zones in zone block device" , +}; + +static int zone_close_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_CLOSE , offset, len); +if (ret <0 ) { +printf ("zone close failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name ="zone_close" , + .altname ="zc" , + .cfunc = zone_close_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="close a range of zones in zone block device" , +}; + +static int zone_finish_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_FINISH , offset, len); +if (ret <0 ) { +printf ("zone finish failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name ="zone_finish" , + .altname ="zf" , + .cfunc = zone_finish_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="finish a range of zones in zone block device" , +}; + +static int zone_reset_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_RESET , offset, len); +if (ret <0 ) { +printf ("zone reset failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name ="zone_reset" , + .altname ="zrs" , + .cfunc = zone_reset_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="reset a zone write pointer in zone block device" , +}; +static int truncate_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t truncate_cmd = { .name ="truncate" ,@@ -2504,6 +2642,11 @@ static void __attribute((constructor)) init_qemuio_commands(void)qemuio_add_command (&aio_write_cmd);qemu-io-cmds.c static void __attribute((constructor)) init_qemuio_commands(void) · line 2652
Quoted 10 lines
qemu-io-cmds.c +5
-0qemuio_add_command (&aio_flush_cmd);qemuio_add_command (&flush_cmd); +qemuio_add_command (&zone_report_cmd); +qemuio_add_command (&zone_open_cmd); +qemuio_add_command (&zone_close_cmd); +qemuio_add_command (&zone_finish_cmd); +qemuio_add_command (&zone_reset_cmd);qemuio_add_command (&truncate_cmd);qemuio_add_command (&length_cmd);qemuio_add_command (&info_cmd);--
Damien Le Moal
Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 1 line · Sam Li
Damien Le Moal <[email protected]> 于2022年9月11日周日 13:31写道:
[...]
Quoted 32 lines
Quoted 27 lines
Quoted 12 lines
block/file-posix.c +12
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false;block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3249
Quoted 10 lines
block/file-posix.c +10
-0+ + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {Linux allows SMR drives to have a smaller last zone. So this needs to be accounted for here. Otherwise, a zone operation that includes the last smaller zone would always fail. Something like this would work:
Quoted 4 lines
if (((offset + len) < capacity && len & zone_sector_mask) || offset + len > capacity) {
Quoted 4 lines
I see. I think the offset can be removed, like:
if (((len < capacity && len &zone_sector_mask) || len > capacity) { Then if we use the previous zone's len for the last smaller zone, it will be greater than its capacity.
Nope, you cannot remove the offset since the zone operation may be for that last zone only, that is, offset == last zone start and len == last zone smaller size. In that case, len is alwats smaller than capacity.
Quoted 2 lines
I will also include "opening the last zone" as a test case later.
Note that you can create such smaller last zone on the host with null_blk by specifying a device capacity that is *not* a multiple of the zone size.
Quoted 45 lines
Quoted 45 lines
Quoted 45 lines
block/file-posix.c +44
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +}
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 36 lines · Damien Le Moal <[email protected]> 于2022年9月11日周日 14:48写道:
Quoted 1 line · Sam Li
Damien Le Moal <[email protected]> 于2022年9月11日周日 13:31写道:
[...]
Quoted 32 lines
Quoted 31 lines
Quoted 12 lines
block/file-posix.c +12
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false;block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3249
Quoted 10 lines
block/file-posix.c +10
-0+ + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {Linux allows SMR drives to have a smaller last zone. So this needs to be accounted for here. Otherwise, a zone operation that includes the last smaller zone would always fail. Something like this would work:
if (((offset + len) < capacity && len & zone_sector_mask) || offset + len > capacity) {
Quoted 8 lines
Quoted 4 lines
I see. I think the offset can be removed, like:
if (((len < capacity && len &zone_sector_mask) || len > capacity) { Then if we use the previous zone's len for the last smaller zone, it will be greater than its capacity.Nope, you cannot remove the offset since the zone operation may be for that last zone only, that is, offset == last zone start and len == last zone smaller size. In that case, len is alwats smaller than capacity.
Ok, I was mixing opening one zone with opening several zones.
Quoted 57 lines
Quoted 3 lines
I will also include "opening the last zone" as a test case later.
Note that you can create such smaller last zone on the host with
null_blkby specifying a device capacity that is *not* a multiple of the zone size.Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
block/file-posix.c +36
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all,Quoted 8 lines
Quoted 8 lines
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3293
Quoted 8 lines
block/file-posix.c +8
-0+ }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +}--
Damien Le Moal
Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Sam LiQuoted 262 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/block-backend.c +145
-0@@ -1431,6 +1431,15 @@ typedef struct BlkRwCo {void *iobuf;int ret;BdrvRequestFlags flags; +union { +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +BlockZoneOp op; + } zone_mgmt; + }; } BlkRwCo;int blk_make_zero (BlockBackend *blk,BdrvRequestFlags flags)@@ -1775,6 +1784,142 @@ int coroutine_fn blk_co_flush(BlockBackend *blk)return ret; } +static void blk_aio_zone_report_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_report (rwco->blk, rwco->offset, + rwco->zone_report.nr_zones, + rwco->zone_report.zones); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque) +{ +BlkAioEmAIOCB *acb; +Coroutine *co; +IO_CODE (); + +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_report = { + .zones = zones, + .nr_zones = nr_zones, + }, + }; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_report_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +static void blk_aio_zone_mgmt_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_mgmt (rwco->blk, rwco->zone_mgmt.op, + rwco->offset, acb->bytes); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque) { +BlkAioEmAIOCB *acb; +Coroutine *co; +IO_CODE (); + +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_mgmt = { + .op = op, + }, + }; + acb->bytes = len; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_mgmt_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +/* +* Send a zone_report command. +* offset is a byte offset from the start of the device. No alignment +* required for offset. +* nr_zones represents IN maximum and OUT actual. +*/ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +int ret; +IO_CODE (); + +blk_inc_in_flight (blk);/* increase before waiting */ +blk_wait_while_drained (blk); +if (!blk_is_available (blk)) { +blk_dec_in_flight (blk); +return -ENOMEDIUM ; + } + ret =bdrv_co_zone_report (blk_bs (blk), offset, nr_zones, zones); +blk_dec_in_flight (blk); +return ret; +} + +/* +* Send a zone_management command. +* op is the zone operation; +* offset is the byte offset from the start of the zoned device; +* len is the maximum number of bytes the command should operate on. It +* should be aligned with the zone sector size. +*/ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len) +{ +int ret; +IO_CODE (); + + +blk_inc_in_flight (blk); +blk_wait_while_drained (blk); + + ret =blk_check_byte_request (blk, offset, len); +if (ret <0 ) { +return ret; + } + + ret =bdrv_co_zone_mgmt (blk_bs (blk), op, offset, len); +blk_dec_in_flight (blk); +return ret; +} +void blk_drain (BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);block/file-posix.c +34
-1@@ -67,6 +67,9 @@#include <sys/param.h> #include <sys/syscall.h> #include <sys/vfs.h> +#if defined(CONFIG_BLKZONED ) +#include <linux/blkzoned.h> +#endif #include <linux/cdrom.h> #include <linux/fd.h> #include <linux/fs.h> @@ -216,6 +219,15 @@ typedef struct RawPosixAIOData {PreallocMode prealloc;Error **errp; } truncate; +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +unsigned long zone_op; +const char *zone_op_name; +bool all; + } zone_mgmt; }; } RawPosixAIOData;@@ -1339,7 +1351,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)#endif if (bs->sg ||S_ISBLK (st.st_mode)) { -int ret =hdev_get_max_hw_transfer (s->fd, &st); + ret =hdev_get_max_hw_transfer (s->fd, &st);if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { bs->bl.max_hw_transfer = ret;@@ -1356,6 +1368,27 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) zoned =BLK_Z_NONE ; } bs->bl.zoned = zoned; +if (zoned !=BLK_Z_NONE ) { + ret =get_sysfs_long_val (&st,"chunk_sectors" ); +if (ret >0 ) { + bs->bl.zone_sectors = ret; + } + + ret =get_sysfs_long_val (&st,"zone_append_max_bytes" ); +if (ret >0 ) { + bs->bl.max_append_sectors = ret /512 ; + } + + ret =get_sysfs_long_val (&st,"max_open_zones" ); +if (ret >=0 ) { + bs->bl.max_open_zones = ret; + } + + ret =get_sysfs_long_val (&st,"max_active_zones" ); +if (ret >=0 ) { + bs->bl.max_active_zones = ret; + } + } }static int check_for_dasd (int fd)@@ -1850,6 +1883,145 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, }#endif
block/file-posix.c static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, · line 1894
Quoted 10 lines
block/file-posix.c +9
-0+/* +* parse_zone - Fill a zone descriptor +*/ +#if defined(CONFIG_BLKZONED ) +static inline void parse_zone (struct BlockZoneDescriptor *zone, +const struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity;
One thing I forgot to mention here: the capacity field was added to Linux with kernel 5.9. Previous kernels do not have this, so this will not compile with kernels older than 5.9. Some trickiness is needed here.
You need to conditionally compile this depending on if the BLK_ZONE_REP_CAPACITY flag is defined or not in /usr/include/linux/blkzoned.h.
See libzbd code as an example of how to do this:
https://github.com/westerndigitalcorporation/libzbd/blob/master/lib/zbd.h#L27
and
https://github.com/westerndigitalcorporation/libzbd/blob/master/lib/zbd.c#L495
The HAVE_BLK_ZONE_REP_V2 macro comes from a config time test that you need to add to meson build, similarly to CONFIG_BLKZONED.
Quoted 677 lines
block/file-posix.c +279
-0+ zone->wp = blkz->wp; + +switch (blkz->type) { +case BLK_ZONE_TYPE_SEQWRITE_REQ : + zone->type =BLK_ZT_SWR ; +break ; +case BLK_ZONE_TYPE_SEQWRITE_PREF : + zone->type =BLK_ZT_SWP ; +break ; +case BLK_ZONE_TYPE_CONVENTIONAL : + zone->type =BLK_ZT_CONV ; +break ; +default : +g_assert_not_reached (); + } + +switch (blkz->cond) { +case BLK_ZONE_COND_NOT_WP : + zone->cond =BLK_ZS_NOT_WP ; +break ; +case BLK_ZONE_COND_EMPTY : + zone->cond =BLK_ZS_EMPTY ; +break ; +case BLK_ZONE_COND_IMP_OPEN : + zone->cond =BLK_ZS_IOPEN ; +break ; +case BLK_ZONE_COND_EXP_OPEN : + zone->cond =BLK_ZS_EOPEN ; +break ; +case BLK_ZONE_COND_CLOSED : + zone->cond =BLK_ZS_CLOSED ; +break ; +case BLK_ZONE_COND_READONLY : + zone->cond =BLK_ZS_RDONLY ; +break ; +case BLK_ZONE_COND_FULL : + zone->cond =BLK_ZS_FULL ; +break ; +case BLK_ZONE_COND_OFFLINE : + zone->cond =BLK_ZS_OFFLINE ; +break ; +default : +g_assert_not_reached (); + } +} +#endif + +#if defined(CONFIG_BLKZONED ) +static int do_zone_report (int64_t sector,int fd, +struct BlockZoneDescriptor *zones, +unsigned int nrz) { +struct blk_zone *blkz; +int ret, n =0 , i =0 ; + +int64_t rep_size =sizeof (struct blk_zone_report ) + nrz *sizeof (struct blk_zone ); + g_autofree struct blk_zone_report *rep = NULL; + rep =g_malloc (rep_size); + + blkz = (struct blk_zone *)(rep +1 ); +while (n < nrz) { +memset (rep,0 , rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + +do { + ret =ioctl (fd,BLKREPORTZONE , rep); + }while (ret !=0 && errno ==EINTR ); +if (ret !=0 ) { +error_report ("%d: ioctl BLKREPORTZONE at %" PRId64" failed %d" , + fd, sector, errno); +return -errno; + } + +if (!rep->nr_zones) { +break ; + } + +for (i =0 ; i < rep->nr_zones; i++, n++) { +parse_zone (&zones[n], &blkz[i]); +/* The next report should start after the last zone reported */ + sector = blkz[i].start + blkz[i].len; + } + } +return n; +} +#endif + +static int handle_aiocb_zone_report (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +unsigned int *nr_zones = aiocb->zone_report.nr_zones; +BlockZoneDescriptor *zones = aiocb->zone_report.zones; +/* zoned block devices use 512-byte sectors */ +int64_t sector = aiocb->aio_offset /512 ; + + *nr_zones =do_zone_report (sector, fd, zones, *nr_zones); +return 0 ; +#else +return -ENOTSUP ; +#endif +} + +static int handle_aiocb_zone_mgmt (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +int64_t sector = aiocb->aio_offset /512 ; +int64_t nr_sectors = aiocb->aio_nbytes /512 ; +struct blk_zone_range range; +int ret; + +/* Execute the operation */ + range.sector = sector; + range.nr_sectors = nr_sectors; +do { + ret =ioctl (fd, aiocb->zone_mgmt.zone_op, &range); + }while (ret !=0 && errno ==EINTR ); + +if (ret !=0 ) { +error_report ("ioctl %s failed %d" , aiocb->zone_mgmt.zone_op_name, + errno); +return -errno; + } +return ret; +#else +return -ENOTSUP ; +#endif +} +static int handle_aiocb_copy_range (void *opaque) {RawPosixAIOData *aiocb = opaque;@@ -3022,6 +3194,104 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* +* zone report - Get a zone block device's information in the form +* of an array of zone descriptors. +* zones is an array of zone descriptors to hold zone information on reply; +* offset can be any byte within the entire size of the device; +* nr_zones is the maxium number of sectors the command should operate on. +*/ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_REPORT , + .aio_offset = offset, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_report, &acb); +#else +return -ENOTSUP ; +#endif +} + +/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) { +error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all, + }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +} + static coroutine_fn intraw_do_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes,bool blkdev)@@ -3752,6 +4022,54 @@ static BlockDriver bdrv_host_device = {#endif }; +#if defined(CONFIG_BLKZONED ) +static BlockDriver bdrv_zoned_host_device = { + .format_name ="zoned_host_device" , + .protocol_name ="zoned_host_device" , + .instance_size =sizeof (BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + +/* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; +#endif +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)static void cdrom_parse_filename (const char *filename,QDict *options,Error **errp)@@ -4012,6 +4330,9 @@ static void bdrv_file_init(void)bdrv_register (&bdrv_file);#if defined(HAVE_HOST_BLOCK_DEVICE )bdrv_register (&bdrv_host_device); +#if defined(CONFIG_BLKZONED ) +bdrv_register (&bdrv_zoned_host_device); +#endif #ifdef __linux__bdrv_register (&bdrv_host_cdrom);#endif block/io.c +41
-0@@ -3198,6 +3198,47 @@ out:return co.ret; } +int bdrv_co_zone_report (BlockDriverState *bs,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_report) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_report (bs, offset, nr_zones, zones); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} + +int bdrv_co_zone_mgmt (BlockDriverState *bs,BlockZoneOp op, +int64_t offset,int64_t len) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_mgmt (bs, op, offset, len); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} +void *qemu_blockalign (BlockDriverState *bs,size_t size) {IO_CODE ();include/block/block-io.h +7
-0@@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,include/block/block_int-common.h +21
-0@@ -691,6 +691,12 @@ struct BlockDriver {QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, +int64_t offset,unsigned int *nr_zones, +BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);@@ -828,6 +834,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in 512-byte sectors */ +uint32_t zone_sectors; + +/* total number of zones */ +unsigned int nr_zones; + +/* maximum sectors of a zone append write operation */ +int64_t max_append_sectors; + +/* maximum number of open zones */ +int64_t max_open_zones; + +/* maximum number of active zones */ +int64_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;include/block/raw-aio.h +5
-1@@ -29,6 +29,8 @@#define QEMU_AIO_WRITE_ZEROES 0x0020#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \@@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000include/sysemu/block-backend-io.h +17
-0@@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *blk_aio_flush (BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones,BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque);BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk,int64_t offset,int64_t bytes,BlockCompletionFunc *cb,void *opaque);void blk_aio_cancel_async (BlockAIOCB *acb);@@ -156,6 +162,17 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,meson.build +1
-0@@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))qapi/block-core.json +6
-2@@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ##@@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:@@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##qemu-io-cmds.c +143
-0@@ -1712,6 +1712,144 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset; +unsigned int nr_zones; + + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + nr_zones =cvtnum (argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones =g_new (BlockZoneDescriptor, nr_zones); + ret =blk_zone_report (blk, offset, &nr_zones, zones); +if (ret <0 ) { +printf ("zone report failed: %s\n" ,strerror (-ret)); + }else { +for (int i =0 ; i < nr_zones; ++i) { +printf ("start: 0x%" PRIx64", len 0x%" PRIx64", " +"cap"" 0x%" PRIx64", wptr 0x%" PRIx64", " +"zcond:%u, [type: %u]\n" , + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } +return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name ="zone_report" , + .altname ="zrp" , + .cfunc = zone_report_f, + .argmin =2 , + .argmax =2 , + .args ="offset number" , + .oneline ="report zone information" , +}; + +static int zone_open_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_OPEN , offset, len); +if (ret <0 ) { +printf ("zone open failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name ="zone_open" , + .altname ="zo" , + .cfunc = zone_open_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="explicit open a range of zones in zone block device" , +}; + +static int zone_close_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_CLOSE , offset, len); +if (ret <0 ) { +printf ("zone close failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name ="zone_close" , + .altname ="zc" , + .cfunc = zone_close_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="close a range of zones in zone block device" , +}; + +static int zone_finish_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_FINISH , offset, len); +if (ret <0 ) { +printf ("zone finish failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name ="zone_finish" , + .altname ="zf" , + .cfunc = zone_finish_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="finish a range of zones in zone block device" , +}; + +static int zone_reset_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_RESET , offset, len); +if (ret <0 ) { +printf ("zone reset failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name ="zone_reset" , + .altname ="zrs" , + .cfunc = zone_reset_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="reset a zone write pointer in zone block device" , +}; +static int truncate_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t truncate_cmd = { .name ="truncate" ,@@ -2504,6 +2642,11 @@ static void __attribute((constructor)) init_qemuio_commands(void)qemuio_add_command (&aio_write_cmd);qemuio_add_command (&aio_flush_cmd);qemuio_add_command (&flush_cmd); +qemuio_add_command (&zone_report_cmd); +qemuio_add_command (&zone_open_cmd); +qemuio_add_command (&zone_close_cmd); +qemuio_add_command (&zone_finish_cmd); +qemuio_add_command (&zone_reset_cmd);qemuio_add_command (&truncate_cmd);qemuio_add_command (&length_cmd);qemuio_add_command (&info_cmd);
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Sam LiQuoted 71 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/block-backend.c +27
-0@@ -1431,6 +1431,15 @@ typedef struct BlkRwCo {void *iobuf;int ret;BdrvRequestFlags flags; +union { +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +BlockZoneOp op; + } zone_mgmt; + }; } BlkRwCo;int blk_make_zero (BlockBackend *blk,BdrvRequestFlags flags)@@ -1775,6 +1784,142 @@ int coroutine_fn blk_co_flush(BlockBackend *blk)return ret; } +static void blk_aio_zone_report_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_report (rwco->blk, rwco->offset, + rwco->zone_report.nr_zones, + rwco->zone_report.zones); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque) +{ +BlkAioEmAIOCB *acb; +Coroutine *co; +IO_CODE ();
block/block-backend.c int coroutine_fn blk_co_flush(BlockBackend *blk) · line 1814
Quoted 10 lines
block/block-backend.c +10
-0+ +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_report = { + .zones = zones, + .nr_zones = nr_zones,
Indentation is off here. QEMU uses 4-space indentation.
Quoted 30 lines
block/block-backend.c +30
-0+ }, + }; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_report_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +static void blk_aio_zone_mgmt_entry (void *opaque) { +BlkAioEmAIOCB *acb = opaque; +BlkRwCo *rwco = &acb->rwco; + + rwco->ret =blk_co_zone_mgmt (rwco->blk, rwco->zone_mgmt.op, + rwco->offset, acb->bytes); +blk_aio_complete (acb); +} + +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque) { +BlkAioEmAIOCB *acb; +Coroutine *co;
block/block-backend.c int coroutine_fn blk_co_flush(BlockBackend *blk) · line 1854
Quoted 10 lines
block/block-backend.c +10
-0+IO_CODE (); + +blk_inc_in_flight (blk); + acb =blk_aio_get (&blk_aio_em_aiocb_info, blk, cb, opaque); + acb->rwco = (BlkRwCo ) { + .blk = blk, + .offset = offset, + .ret =NOT_DONE , + .zone_mgmt = { + .op = op,
Indentation is off here. QEMU uses 4-space indentation.
Quoted 50 lines
block/block-backend.c +50
-0+ }, + }; + acb->bytes = len; + acb->has_returned = false; + + co =qemu_coroutine_create (blk_aio_zone_mgmt_entry, acb); +bdrv_coroutine_enter (blk_bs (blk), co); + + acb->has_returned = true; +if (acb->rwco.ret !=NOT_DONE ) { +replay_bh_schedule_oneshot_event (blk_get_aio_context (blk), + blk_aio_complete_bh, acb); + } + +return &acb->common; +} + +/* +* Send a zone_report command. +* offset is a byte offset from the start of the device. No alignment +* required for offset. +* nr_zones represents IN maximum and OUT actual. +*/ +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) +{ +int ret; +IO_CODE (); + +blk_inc_in_flight (blk);/* increase before waiting */ +blk_wait_while_drained (blk); +if (!blk_is_available (blk)) { +blk_dec_in_flight (blk); +return -ENOMEDIUM ; + } + ret =bdrv_co_zone_report (blk_bs (blk), offset, nr_zones, zones); +blk_dec_in_flight (blk); +return ret; +} + +/* +* Send a zone_management command. +* op is the zone operation; +* offset is the byte offset from the start of the zoned device; +* len is the maximum number of bytes the command should operate on. It +* should be aligned with the zone sector size. +*/ +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len)
block/block-backend.c int coroutine_fn blk_co_flush(BlockBackend *blk) · line 1914
Quoted 10 lines
block/block-backend.c +10
-0+{ +int ret; +IO_CODE (); + + +blk_inc_in_flight (blk); +blk_wait_while_drained (blk); + + ret =blk_check_byte_request (blk, offset, len); +if (ret <0 ) {
Missing blk_dec_in_flight(blk).
Quoted 240 lines
block/block-backend.c +8
-0+return ret; + } + + ret =bdrv_co_zone_mgmt (blk_bs (blk), op, offset, len); +blk_dec_in_flight (blk); +return ret; +} +void blk_drain (BlockBackend *blk) {BlockDriverState *bs =blk_bs (blk);block/file-posix.c +185
-1@@ -67,6 +67,9 @@#include <sys/param.h> #include <sys/syscall.h> #include <sys/vfs.h> +#if defined(CONFIG_BLKZONED ) +#include <linux/blkzoned.h> +#endif #include <linux/cdrom.h> #include <linux/fd.h> #include <linux/fs.h> @@ -216,6 +219,15 @@ typedef struct RawPosixAIOData {PreallocMode prealloc;Error **errp; } truncate; +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +unsigned long zone_op; +const char *zone_op_name; +bool all; + } zone_mgmt; }; } RawPosixAIOData;@@ -1339,7 +1351,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)#endif if (bs->sg ||S_ISBLK (st.st_mode)) { -int ret =hdev_get_max_hw_transfer (s->fd, &st); + ret =hdev_get_max_hw_transfer (s->fd, &st);if (ret >0 && ret <=BDRV_REQUEST_MAX_BYTES ) { bs->bl.max_hw_transfer = ret;@@ -1356,6 +1368,27 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) zoned =BLK_Z_NONE ; } bs->bl.zoned = zoned; +if (zoned !=BLK_Z_NONE ) { + ret =get_sysfs_long_val (&st,"chunk_sectors" ); +if (ret >0 ) { + bs->bl.zone_sectors = ret; + } + + ret =get_sysfs_long_val (&st,"zone_append_max_bytes" ); +if (ret >0 ) { + bs->bl.max_append_sectors = ret /512 ; + } + + ret =get_sysfs_long_val (&st,"max_open_zones" ); +if (ret >=0 ) { + bs->bl.max_open_zones = ret; + } + + ret =get_sysfs_long_val (&st,"max_active_zones" ); +if (ret >=0 ) { + bs->bl.max_active_zones = ret; + } + } }static int check_for_dasd (int fd)@@ -1850,6 +1883,145 @@ static off_t copy_file_range(int in_fd, off_t *in_off, int out_fd, }#endif +/* +* parse_zone - Fill a zone descriptor +*/ +#if defined(CONFIG_BLKZONED ) +static inline void parse_zone (struct BlockZoneDescriptor *zone, +const struct blk_zone *blkz) { + zone->start = blkz->start; + zone->length = blkz->len; + zone->cap = blkz->capacity; + zone->wp = blkz->wp; + +switch (blkz->type) { +case BLK_ZONE_TYPE_SEQWRITE_REQ : + zone->type =BLK_ZT_SWR ; +break ; +case BLK_ZONE_TYPE_SEQWRITE_PREF : + zone->type =BLK_ZT_SWP ; +break ; +case BLK_ZONE_TYPE_CONVENTIONAL : + zone->type =BLK_ZT_CONV ; +break ; +default : +g_assert_not_reached (); + } + +switch (blkz->cond) { +case BLK_ZONE_COND_NOT_WP : + zone->cond =BLK_ZS_NOT_WP ; +break ; +case BLK_ZONE_COND_EMPTY : + zone->cond =BLK_ZS_EMPTY ; +break ; +case BLK_ZONE_COND_IMP_OPEN : + zone->cond =BLK_ZS_IOPEN ; +break ; +case BLK_ZONE_COND_EXP_OPEN : + zone->cond =BLK_ZS_EOPEN ; +break ; +case BLK_ZONE_COND_CLOSED : + zone->cond =BLK_ZS_CLOSED ; +break ; +case BLK_ZONE_COND_READONLY : + zone->cond =BLK_ZS_RDONLY ; +break ; +case BLK_ZONE_COND_FULL : + zone->cond =BLK_ZS_FULL ; +break ; +case BLK_ZONE_COND_OFFLINE : + zone->cond =BLK_ZS_OFFLINE ; +break ; +default : +g_assert_not_reached (); + } +} +#endif + +#if defined(CONFIG_BLKZONED ) +static int do_zone_report (int64_t sector,int fd, +struct BlockZoneDescriptor *zones, +unsigned int nrz) { +struct blk_zone *blkz; +int ret, n =0 , i =0 ; + +int64_t rep_size =sizeof (struct blk_zone_report ) + nrz *sizeof (struct blk_zone ); + g_autofree struct blk_zone_report *rep = NULL; + rep =g_malloc (rep_size); + + blkz = (struct blk_zone *)(rep +1 ); +while (n < nrz) { +memset (rep,0 , rep_size); + rep->sector = sector; + rep->nr_zones = nrz - n; + +do { + ret =ioctl (fd,BLKREPORTZONE , rep); + }while (ret !=0 && errno ==EINTR ); +if (ret !=0 ) { +error_report ("%d: ioctl BLKREPORTZONE at %" PRId64" failed %d" , + fd, sector, errno); +return -errno; + } + +if (!rep->nr_zones) { +break ; + } + +for (i =0 ; i < rep->nr_zones; i++, n++) { +parse_zone (&zones[n], &blkz[i]); +/* The next report should start after the last zone reported */ + sector = blkz[i].start + blkz[i].len; + } + } +return n; +} +#endif + +static int handle_aiocb_zone_report (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +unsigned int *nr_zones = aiocb->zone_report.nr_zones; +BlockZoneDescriptor *zones = aiocb->zone_report.zones; +/* zoned block devices use 512-byte sectors */ +int64_t sector = aiocb->aio_offset /512 ; + + *nr_zones =do_zone_report (sector, fd, zones, *nr_zones); +return 0 ; +#else +return -ENOTSUP ; +#endif +} + +static int handle_aiocb_zone_mgmt (void *opaque) { +#if defined(CONFIG_BLKZONED ) +RawPosixAIOData *aiocb = opaque; +int fd = aiocb->aio_fildes; +int64_t sector = aiocb->aio_offset /512 ; +int64_t nr_sectors = aiocb->aio_nbytes /512 ; +struct blk_zone_range range; +int ret; + +/* Execute the operation */ + range.sector = sector; + range.nr_sectors = nr_sectors; +do { + ret =ioctl (fd, aiocb->zone_mgmt.zone_op, &range); + }while (ret !=0 && errno ==EINTR ); + +if (ret !=0 ) { +error_report ("ioctl %s failed %d" , aiocb->zone_mgmt.zone_op_name, + errno); +return -errno; + } +return ret; +#else +return -ENOTSUP ; +#endif +} +static int handle_aiocb_copy_range (void *opaque) {RawPosixAIOData *aiocb = opaque;@@ -3022,6 +3194,104 @@ static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) } } +/* +* zone report - Get a zone block device's information in the form +* of an array of zone descriptors. +* zones is an array of zone descriptors to hold zone information on reply; +* offset can be any byte within the entire size of the device; +* nr_zones is the maxium number of sectors the command should operate on. +*/ +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque;
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3218
Quoted 10 lines
block/file-posix.c +10
-0+RawPosixAIOData acb; + + acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_REPORT , + .aio_offset = offset, + .zone_report = { + .nr_zones = nr_zones, + .zones = zones,
Indentation is off here. QEMU uses 4-space indentation.
Quoted 57 lines
block/file-posix.c +57
-0+ }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_report, &acb); +#else +return -ENOTSUP ; +#endif +} + +/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) { +error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + } + +switch (op) { +case BLK_ZO_OPEN : + zone_op_name ="BLKOPENZONE" ; + zone_op =BLKOPENZONE ; +break ; +case BLK_ZO_CLOSE : + zone_op_name ="BLKCLOSEZONE" ; + zone_op =BLKCLOSEZONE ; +break ; +case BLK_ZO_FINISH : + zone_op_name ="BLKFINISHZONE" ; + zone_op =BLKFINISHZONE ; +break ; +case BLK_ZO_RESET : + zone_op_name ="BLKRESETZONE" ; + zone_op =BLKRESETZONE ; +break ; +default : +g_assert_not_reached (); + } +
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3285
Quoted 10 lines
block/file-posix.c +10
-0+ acb = (RawPosixAIOData ) { + .bs = bs, + .aio_fildes = s->fd, + .aio_type =QEMU_AIO_ZONE_MGMT , + .aio_offset = offset, + .aio_nbytes = len, + .zone_mgmt = { + .zone_op = zone_op, + .zone_op_name = zone_op_name, + .all = is_all,
This is unused. Please remove the field for now.
Quoted 82 lines
block/file-posix.c +60
-0+ }, + }; + +return raw_thread_pool_submit (bs, handle_aiocb_zone_mgmt, &acb); +#else +return -ENOTSUP ; +#endif +} + static coroutine_fn intraw_do_pdiscard (BlockDriverState *bs,int64_t offset,int64_t bytes,bool blkdev)@@ -3752,6 +4022,54 @@ static BlockDriver bdrv_host_device = {#endif }; +#if defined(CONFIG_BLKZONED ) +static BlockDriver bdrv_zoned_host_device = { + .format_name ="zoned_host_device" , + .protocol_name ="zoned_host_device" , + .instance_size =sizeof (BDRVRawState), + .bdrv_needs_filename = true, + .bdrv_probe_device = hdev_probe_device, + .bdrv_file_open = hdev_open, + .bdrv_close = raw_close, + .bdrv_reopen_prepare = raw_reopen_prepare, + .bdrv_reopen_commit = raw_reopen_commit, + .bdrv_reopen_abort = raw_reopen_abort, + .bdrv_co_create_opts = bdrv_co_create_opts_simple, + .create_opts = &bdrv_create_opts_simple, + .mutable_opts = mutable_opts, + .bdrv_co_invalidate_cache = raw_co_invalidate_cache, + .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes, + + .bdrv_co_preadv = raw_co_preadv, + .bdrv_co_pwritev = raw_co_pwritev, + .bdrv_co_flush_to_disk = raw_co_flush_to_disk, + .bdrv_co_pdiscard = hdev_co_pdiscard, + .bdrv_co_copy_range_from = raw_co_copy_range_from, + .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_refresh_limits = raw_refresh_limits, + .bdrv_io_plug = raw_aio_plug, + .bdrv_io_unplug = raw_aio_unplug, + .bdrv_attach_aio_context = raw_aio_attach_aio_context, + + .bdrv_co_truncate = raw_co_truncate, + .bdrv_getlength = raw_getlength, + .bdrv_get_info = raw_get_info, + .bdrv_get_allocated_file_size + = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_stats, + .bdrv_check_perm = raw_check_perm, + .bdrv_set_perm = raw_set_perm, + .bdrv_abort_perm_update = raw_abort_perm_update, + .bdrv_probe_blocksizes = hdev_probe_blocksizes, + .bdrv_probe_geometry = hdev_probe_geometry, + .bdrv_co_ioctl = hdev_co_ioctl, + +/* zone management operations */ + .bdrv_co_zone_report = raw_co_zone_report, + .bdrv_co_zone_mgmt = raw_co_zone_mgmt, +}; +#endif +#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)static void cdrom_parse_filename (const char *filename,QDict *options,Error **errp)@@ -4012,6 +4330,9 @@ static void bdrv_file_init(void)bdrv_register (&bdrv_file);#if defined(HAVE_HOST_BLOCK_DEVICE )bdrv_register (&bdrv_host_device); +#if defined(CONFIG_BLKZONED ) +bdrv_register (&bdrv_zoned_host_device); +#endif #ifdef __linux__bdrv_register (&bdrv_host_cdrom);#endif block/io.c +0
-0
block/io.c out: · line 3201
Quoted 4 lines
block/io.c +1
-0@@ -3198,6 +3198,47 @@ out:return co.ret; } +int bdrv_co_zone_report(BlockDriverState *bs, int64_t offset,
Missing coroutine_fn:
int coroutine_fn bdrv_co_foo(...)
All coroutine functions must be labelled like this.
Quoted 11 lines
block/io.c +11
-0+unsigned int *nr_zones, + BlockZoneDescriptor *zones) +{ + BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_report) {
block/io.c out: · line 3222
Quoted 10 lines
block/io.c +10
-0+ co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_report (bs, offset, nr_zones, zones); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} + +int bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op,
coroutine_fn is missing.
Quoted 347 lines
block/io.c +19
-0+ int64_t offset, int64_t len) +{ +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_mgmt) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_mgmt (bs, op, offset, len); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} +void *qemu_blockalign (BlockDriverState *bs,size_t size) {IO_CODE ();include/block/block-io.h +7
-0@@ -88,6 +88,13 @@ int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);/* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +/* Report zone information of zone block device. */ +int coroutine_fn bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +int bdrv_co_pdiscard (BdrvChild *child,int64_t offset,int64_t bytes);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,include/block/block_int-common.h +21
-0@@ -691,6 +691,12 @@ struct BlockDriver {QEMUIOVector *qiov, int64_t pos); + int coroutine_fn (*bdrv_co_zone_report)(BlockDriverState *bs, +int64_t offset,unsigned int *nr_zones, +BlockZoneDescriptor *zones); + int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len); +/* removable device specific */ bool (*bdrv_is_inserted)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,bool eject_flag);@@ -828,6 +834,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in 512-byte sectors */ +uint32_t zone_sectors; + +/* total number of zones */ +unsigned int nr_zones; + +/* maximum sectors of a zone append write operation */ +int64_t max_append_sectors; + +/* maximum number of open zones */ +int64_t max_open_zones; + +/* maximum number of active zones */ +int64_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;include/block/raw-aio.h +5
-1@@ -29,6 +29,8 @@#define QEMU_AIO_WRITE_ZEROES 0x0020#define QEMU_AIO_COPY_RANGE 0x0040#define QEMU_AIO_TRUNCATE 0x0080 +#define QEMU_AIO_ZONE_REPORT 0x0100 +#define QEMU_AIO_ZONE_MGMT 0x0200#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \@@ -37,7 +39,9 @@ QEMU_AIO_DISCARD | \ QEMU_AIO_WRITE_ZEROES | \ QEMU_AIO_COPY_RANGE | \ - QEMU_AIO_TRUNCATE) + QEMU_AIO_TRUNCATE | \ + QEMU_AIO_ZONE_REPORT | \ + QEMU_AIO_ZONE_MGMT)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000include/sysemu/block-backend-io.h +17
-0@@ -45,6 +45,12 @@ BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset, BlockCompletionFunc *cb, void *opaque);BlockAIOCB *blk_aio_flush (BlockBackend *blk,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_report (BlockBackend *blk,int64_t offset, +unsigned int *nr_zones,BlockZoneDescriptor *zones, +BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op, +int64_t offset,int64_t len, +BlockCompletionFunc *cb,void *opaque);BlockAIOCB *blk_aio_pdiscard (BlockBackend *blk,int64_t offset,int64_t bytes,BlockCompletionFunc *cb,void *opaque);void blk_aio_cancel_async (BlockAIOCB *acb);@@ -156,6 +162,17 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,int64_t bytes,BdrvRequestFlags flags); +int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int generated_co_wrapper blk_zone_report(BlockBackend *blk, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); +int generated_co_wrapper blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,meson.build +1
-0@@ -1883,6 +1883,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('live_block_migration').al # has_header config_host_data.set('CONFIG_EPOLL', cc.has_header('sys/epoll.h')) config_host_data.set('CONFIG_LINUX_MAGIC_H', cc.has_header('linux/magic.h')) +config_host_data.set('CONFIG_BLKZONED', cc.has_header('linux/blkzoned.h')) config_host_data.set('CONFIG_VALGRIND_H', cc.has_header('valgrind/valgrind.h')) config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h')) config_host_data.set('HAVE_DRM_H', cc.has_header('libdrm/drm.h'))qapi/block-core.json +6
-2@@ -2942,6 +2942,7 @@ # @compress: Since 5.0 # @copy-before-write: Since 6.2 # @snapshot-access: Since 7.0 +# @zoned_host_device: Since 7.2 # # Since: 2.9 ##@@ -2955,7 +2956,8 @@ 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd', { 'name': 'replication', 'if': 'CONFIG_REPLICATION' }, - 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat' ] } + 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:@@ -4329,7 +4331,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##qemu-io-cmds.c +143
-0@@ -1712,6 +1712,144 @@ static const cmdinfo_t flush_cmd = { .oneline = "flush all in-core file state to disk", }; +static int zone_report_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset; +unsigned int nr_zones; + + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + nr_zones =cvtnum (argv[optind]); + + g_autofree BlockZoneDescriptor *zones = NULL; + zones =g_new (BlockZoneDescriptor, nr_zones); + ret =blk_zone_report (blk, offset, &nr_zones, zones); +if (ret <0 ) { +printf ("zone report failed: %s\n" ,strerror (-ret)); + }else { +for (int i =0 ; i < nr_zones; ++i) { +printf ("start: 0x%" PRIx64", len 0x%" PRIx64", " +"cap"" 0x%" PRIx64", wptr 0x%" PRIx64", " +"zcond:%u, [type: %u]\n" , + zones[i].start, zones[i].length, zones[i].cap, zones[i].wp, + zones[i].cond, zones[i].type); + } + } +return ret; +} + +static const cmdinfo_t zone_report_cmd = { + .name ="zone_report" , + .altname ="zrp" , + .cfunc = zone_report_f, + .argmin =2 , + .argmax =2 , + .args ="offset number" , + .oneline ="report zone information" , +}; + +static int zone_open_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_OPEN , offset, len); +if (ret <0 ) { +printf ("zone open failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_open_cmd = { + .name ="zone_open" , + .altname ="zo" , + .cfunc = zone_open_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="explicit open a range of zones in zone block device" , +}; + +static int zone_close_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_CLOSE , offset, len); +if (ret <0 ) { +printf ("zone close failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_close_cmd = { + .name ="zone_close" , + .altname ="zc" , + .cfunc = zone_close_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="close a range of zones in zone block device" , +}; + +static int zone_finish_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_FINISH , offset, len); +if (ret <0 ) { +printf ("zone finish failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_finish_cmd = { + .name ="zone_finish" , + .altname ="zf" , + .cfunc = zone_finish_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="finish a range of zones in zone block device" , +}; + +static int zone_reset_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +int64_t offset, len; + ++optind; + offset =cvtnum (argv[optind]); + ++optind; + len =cvtnum (argv[optind]); + ret =blk_zone_mgmt (blk,BLK_ZO_RESET , offset, len); +if (ret <0 ) { +printf ("zone reset failed: %s\n" ,strerror (-ret)); + } +return ret; +} + +static const cmdinfo_t zone_reset_cmd = { + .name ="zone_reset" , + .altname ="zrs" , + .cfunc = zone_reset_f, + .argmin =2 , + .argmax =2 , + .args ="offset len" , + .oneline ="reset a zone write pointer in zone block device" , +}; +static int truncate_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t truncate_cmd = { .name ="truncate" ,@@ -2504,6 +2642,11 @@ static void __attribute((constructor)) init_qemuio_commands(void)qemuio_add_command (&aio_write_cmd);qemuio_add_command (&aio_flush_cmd);qemuio_add_command (&flush_cmd); +qemuio_add_command (&zone_report_cmd); +qemuio_add_command (&zone_open_cmd); +qemuio_add_command (&zone_close_cmd); +qemuio_add_command (&zone_finish_cmd); +qemuio_add_command (&zone_reset_cmd);qemuio_add_command (&truncate_cmd);qemuio_add_command (&length_cmd);qemuio_add_command (&info_cmd);Signature · 1 line
2.37.3
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Sam LiQuoted 45 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/file-posix.c +16
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) {
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3253
Quoted 10 lines
block/file-posix.c +10
-0+error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) { +error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + }
These checks impose a power-of-two constraint on the zone size. Can they be changed to divisions to lift that constraint? I don't see anything in this patch set that relies on power of two zone sizes.
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 53 lines · Klaus Jensen <[email protected]> 于2022年9月20日周二 16:51写道:
Quoted 51 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/file-posix.c +22
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {
Quoted 8 lines
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3253
Quoted 4 lines
block/file-posix.c +4
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + }These checks impose a power-of-two constraint on the zone size. Can they be changed to divisions to lift that constraint? I don't see anything in this patch set that relies on power of two zone sizes.
Yes, it can be changed when the kernel block layer has non-power-of-2 zone sizes support. For now, Dmitry's work on zoned device support on the kernel side put the constraint on zone sectors to be po2. The checks here follow this constraint.
Dmitry's patches can be found here:
https://lore.kernel.org/linux-block/[email protected]/T/#m9b0b3c8220de1307e53235d1a73dab1e3a10f62b
Sam
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Klaus JensenQuoted 52 lines · Klaus Jensen
Quoted 51 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/file-posix.c +22
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {
Quoted 8 lines
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3253
Quoted 4 lines
block/file-posix.c +4
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + }These checks impose a power-of-two constraint on the zone size. Can they be changed to divisions to lift that constraint? I don't see anything in this patch set that relies on power of two zone sizes.
Given that Linux will only expose zoned devices that have a zone size that is a power of 2 number of LBAs, this will work as is and avoid divisions in the IO path. But given that zone management operations are not performance critical, generalizing the code should be fine.
However, once we start adding the code for full zone emulation on top of a regular file or qcow image, sector-to-zone conversions requiring divisions will hurt. So I really would prefer the code be left as-is for now.
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 3/7] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 62 lines · Damien Le Moal
Quoted 52 lines · Klaus Jensen
Quoted 51 lines · Sam Li
Add a new
zoned_host_deviceBlockDriver. Thezoned_host_deviceoption accepts only zoned host block devices. By adding zone management operations in this new BlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations (open, close, finish, reset).Qemu-io uses the new APIs to perform zoned storage commands of the device:
zone_report(zrp),zone_open(zo),zone_close(zc),zone_reset(zrs),zone_finish(zf).For example, to test
zone_report, use following command:$ ./build/qemu-io --image-opts -n driver=zoned_host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>--- block/block-backend.c | 145 ++++++++++++++ block/file-posix.c | 323 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ include/block/block-io.h | 7 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 17 ++ meson.build | 1 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 143 +++++++++++++ 10 files changed, 708 insertions(+), 4 deletions(-)block/file-posix.c +22
-0+/* +* zone management operations - Execute an operation on a zone +*/ +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +#if defined(CONFIG_BLKZONED ) +BDRVRawState *s = bs->opaque; +RawPosixAIOData acb; +int64_t zone_sector, zone_sector_mask; +const char *zone_op_name; +unsigned long zone_op; +bool is_all = false; + + zone_sector = bs->bl.zone_sectors; + zone_sector_mask = zone_sector -1 ; +if (offset & zone_sector_mask) { +error_report ("sector offset %" PRId64" is not aligned to zone size " +"%" PRId64"" , offset, zone_sector); +return -EINVAL ; + } + +if (len & zone_sector_mask) {Quoted 8 lines
block/file-posix.c static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) · line 3253
Quoted 4 lines
block/file-posix.c +4
-0+error_report ("number of sectors %" PRId64" is not aligned to zone size" +" %" PRId64"" , len, zone_sector); +return -EINVAL ; + }These checks impose a power-of-two constraint on the zone size. Can they be changed to divisions to lift that constraint? I don't see anything in this patch set that relies on power of two zone sizes.
Quoted 5 lines
Given that Linux will only expose zoned devices that have a zone size that is a power of 2 number of LBAs, this will work as is and avoid divisions in the IO path. But given that zone management operations are not performance critical, generalizing the code should be fine.
Aight. That's fine, we can relax the constraint later. But I don't see why.
Quoted 4 lines
However, once we start adding the code for full zone emulation on top of a regular file or qcow image, sector-to-zone conversions requiring divisions will hurt. So I really would prefer the code be left as-is for now.
Block driver based zone emulation would not hit the above code path anyway (there would be no iotcl to call), so I don't think that is an argument for keeping it as-is.
On the sector-to-zone convertions. Yes, they may potentially hurt, but it would be emulation after all. Why would we care about optimizing those conversions at the expense of not being able to emulate all valid geometries? The performance option (which this series enables) is to use an underlying zoned device through virtio (or, potentially, hw/nvme). What would be the usecase for deploying a performance sensitive emulated zoned device?
PATCH v9 4/7 raw-format: add zone operations to pass through requests
In reply to Sam Liraw-format driver usually sits on top of file-posix driver. It needs to pass through requests of zone commands.
--- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
block/raw-format.c +13 -0
@@ -314,6 +314,17 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,return bdrv_co_pdiscard (bs->file, offset, bytes); } +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +return bdrv_co_zone_report (bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +return bdrv_co_zone_mgmt (bs->file->bs, op, offset, len); +} +static int64_t raw_getlength (BlockDriverState *bs) {int64_t len;
@@ -614,6 +625,8 @@ BlockDriver bdrv_raw = { .bdrv_co_pwritev = &raw_co_pwritev, .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes, .bdrv_co_pdiscard = &raw_co_pdiscard, + .bdrv_co_zone_report = &raw_co_zone_report, + .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, .bdrv_co_block_status = &raw_co_block_status, .bdrv_co_copy_range_from = &raw_co_copy_range_from, .bdrv_co_copy_range_to = &raw_co_copy_range_to,
Signature · 1 line
2.37.3
Re: [PATCH v9 4/7] raw-format: add zone operations to pass through requests
Quoted 5 lines · Sam Li
raw-format driver usually sits on top of file-posix driver. It needs to pass through requests of zone commands.
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>
Quoted 35 lines
--- block/raw-format.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)block/raw-format.c +13
-0@@ -314,6 +314,17 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs,return bdrv_co_pdiscard (bs->file, offset, bytes); } +static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones) { +return bdrv_co_zone_report (bs->file->bs, offset, nr_zones, zones); +} + +static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, +int64_t offset,int64_t len) { +return bdrv_co_zone_mgmt (bs->file->bs, op, offset, len); +} +static int64_t raw_getlength (BlockDriverState *bs) {int64_t len;@@ -614,6 +625,8 @@ BlockDriver bdrv_raw = { .bdrv_co_pwritev = &raw_co_pwritev, .bdrv_co_pwrite_zeroes = &raw_co_pwrite_zeroes, .bdrv_co_pdiscard = &raw_co_pdiscard, + .bdrv_co_zone_report = &raw_co_zone_report, + .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, .bdrv_co_block_status = &raw_co_block_status, .bdrv_co_copy_range_from = &raw_co_copy_range_from, .bdrv_co_copy_range_to = &raw_co_copy_range_to,
Signature · 2 lines
Damien Le Moal Western Digital Research
PATCH v9 5/7 config: add check to block layer
In reply to Sam LiPutting zoned/non-zoned BlockDrivers on top of each other is not allowed.
--- block.c | 14 ++++++++++++++ block/file-posix.c | 14 ++++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 34 insertions(+)
block.c +14 -0
@@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; } +/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && + child_bs->bl.zoned ==BLK_Z_HM ) { +error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->bl.zoned ==BLK_Z_HM ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);
block/file-posix.c +14 -0
@@ -779,6 +779,20 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } } +#ifdef CONFIG_BLKZONED +/* +* The kernel page chache does not reliably work for writes to SWR zones +* of zoned block device because it can not guarantee the order of writes. +*/ +if (strcmp (bs->drv->format_name,"zoned_host_device" ) ==0 ) { +if (!(s->open_flags &O_DIRECT )) { +error_setg (errp,"driver=zoned_host_device was specified, but it " +"requires cache.direct=on, which was not specified." ); + ret = -EINVAL ; +return ret;/* No host kernel page cache */ + } + } +#endif if (S_ISBLK (st.st_mode)) {#ifdef BLKDISCARDZEROES
block/raw-format.c +1 -0
@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,
include/block/block_int-common.h +5 -0
@@ -127,6 +127,11 @@ struct BlockDriver {*/ bool is_format; +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their
Signature · 1 line
2.37.3
Re: [PATCH v9 5/7] config: add check to block layer
Quoted 17 lines · Sam Li
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>--- block.c | 14 ++++++++++++++ block/file-posix.c | 14 ++++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 34 insertions(+)block.c +0
-0
block.c void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, · line 7956
Quoted 10 lines
block.c +7
-0@@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; } +/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && + child_bs->bl.zoned ==BLK_Z_HM ) {
Shouldn't this be "child_bs->bl.zoned != BLK_Z_NONE" ?
Quoted 18 lines
block.c +7
-0+error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->bl.zoned ==BLK_Z_HM ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);block/file-posix.c +0
-0@@ -779,6 +779,20 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } }
block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 791
Quoted 10 lines
block/file-posix.c +10
-0+#ifdef CONFIG_BLKZONED +/* +* The kernel page chache does not reliably work for writes to SWR zones +* of zoned block device because it can not guarantee the order of writes. +*/ +if (strcmp (bs->drv->format_name,"zoned_host_device" ) ==0 ) { +if (!(s->open_flags &O_DIRECT )) { +error_setg (errp,"driver=zoned_host_device was specified, but it " +"requires cache.direct=on, which was not specified." ); + ret = -EINVAL ;
This line is not needed. Simply "return -EINVAL;".
Quoted 35 lines
block/file-posix.c +4
-0+ return ret; /* No host kernel page cache */ + } + } +#endif if (S_ISBLK (st.st_mode)) {#ifdef BLKDISCARDZEROES block/raw-format.c +1
-0@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,include/block/block_int-common.h +5
-0@@ -127,6 +127,11 @@ struct BlockDriver {*/ bool is_format; +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 5/7] config: add check to block layer
Quoted 22 lines · Damien Le Moal <[email protected]> 于2022年9月11日周日 13:34写道:
Quoted 20 lines · Sam Li
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>--- block.c | 14 ++++++++++++++ block/file-posix.c | 14 ++++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 34 insertions(+)block.c +0
-0@@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; }
Quoted 9 lines
block.c void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, · line 7956
Quoted 7 lines
block.c +7
-0+/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && + child_bs->bl.zoned ==BLK_Z_HM ) {Shouldn't this be "
child_bs->bl.zoned!=BLK_Z_NONE" ?
The host-aware model allows zoned storage constraints(sequentially write) and random write. Is mixing HA and non-zoned drivers allowed? What's the difference?
Quoted 72 lines
Quoted 19 lines
block.c +7
-0+error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->bl.zoned ==BLK_Z_HM ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);block/file-posix.c +0
-0@@ -779,6 +779,20 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } }block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 791
Quoted 10 lines
block/file-posix.c +10
-0+#ifdef CONFIG_BLKZONED +/* +* The kernel page chache does not reliably work for writes to SWR zones +* of zoned block device because it can not guarantee the order of writes. +*/ +if (strcmp (bs->drv->format_name,"zoned_host_device" ) ==0 ) { +if (!(s->open_flags &O_DIRECT )) { +error_setg (errp,"driver=zoned_host_device was specified, but it " +"requires cache.direct=on, which was not specified." ); + ret = -EINVAL ;This line is not needed. Simply "return
-EINVAL;".Quoted 25 lines
block/file-posix.c +4
-0+ return ret; /* No host kernel page cache */ + } + } +#endif if (S_ISBLK (st.st_mode)) {#ifdef BLKDISCARDZEROES block/raw-format.c +1
-0@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,include/block/block_int-common.h +0
-0@@ -127,6 +127,11 @@ struct BlockDriver {*/ include/block/block_int-common.h struct BlockDriver { · line 137
Quoted 10 lines
include/block/block_int-common.h +5
-0bool is_format; +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their --
Damien Le Moal
Western Digital Research
Re: [PATCH v9 5/7] config: add check to block layer
Quoted 33 lines · Sam Li
Quoted 22 lines · Damien Le Moal <[email protected]> 于2022年9月11日周日 13:34写道:
Quoted 20 lines · Sam Li
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>--- block.c | 14 ++++++++++++++ block/file-posix.c | 14 ++++++++++++++ block/raw-format.c | 1 + include/block/block_int-common.h | 5 +++++ 4 files changed, 34 insertions(+)block.c +0
-0@@ -7947,6 +7947,20 @@ void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs,return ; }Quoted 9 lines
block.c void bdrv_add_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, · line 7956
Quoted 7 lines
block.c +7
-0+/* +* Non-zoned block drivers do not follow zoned storage constraints +* (i.e. sequential writes to zones). Refuse mixing zoned and non-zoned +* drivers in a graph. +*/ +if (!parent_bs->drv->supports_zoned_children && + child_bs->bl.zoned ==BLK_Z_HM ) {Shouldn't this be "
child_bs->bl.zoned!=BLK_Z_NONE" ?
Quoted 3 lines
The host-aware model allows zoned storage constraints(sequentially write) and random write. Is mixing HA and non-zoned drivers allowed? What's the difference?
Yes, HA devices can be used as regular devices too. If you are allowing this here, then add a comment explaining it. It may also be good to add a message like "Using host-aware device as a regular device" here for the HA case.
Quoted 73 lines
Quoted 73 lines
Quoted 20 lines
block.c +7
-0+error_setg (errp,"Cannot add a %s child to a %s parent" , + child_bs->bl.zoned ==BLK_Z_HM ?"zoned" :"non-zoned" , + parent_bs->drv->supports_zoned_children ? +"support zoned children" :"not support zoned children" ); +return ; + } +if (!QLIST_EMPTY (&child_bs->parents)) {error_setg (errp,"The node %s already has a parent" , child_bs->node_name);block/file-posix.c +0
-0@@ -779,6 +779,20 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } }block/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 791
Quoted 10 lines
block/file-posix.c +10
-0+#ifdef CONFIG_BLKZONED +/* +* The kernel page chache does not reliably work for writes to SWR zones +* of zoned block device because it can not guarantee the order of writes. +*/ +if (strcmp (bs->drv->format_name,"zoned_host_device" ) ==0 ) { +if (!(s->open_flags &O_DIRECT )) { +error_setg (errp,"driver=zoned_host_device was specified, but it " +"requires cache.direct=on, which was not specified." ); + ret = -EINVAL ;This line is not needed. Simply "return
-EINVAL;".Quoted 25 lines
block/file-posix.c +4
-0+ return ret; /* No host kernel page cache */ + } + } +#endif if (S_ISBLK (st.st_mode)) {#ifdef BLKDISCARDZEROES block/raw-format.c +1
-0@@ -614,6 +614,7 @@ static void raw_child_perm(BlockDriverState *bs, BdrvChild *c,BlockDriver bdrv_raw = { .format_name ="raw" , .instance_size =sizeof (BDRVRawState), + .supports_zoned_children = true, .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_reopen_commit = &raw_reopen_commit,include/block/block_int-common.h +0
-0@@ -127,6 +127,11 @@ struct BlockDriver {*/ include/block/block_int-common.h struct BlockDriver { · line 137
Quoted 10 lines
include/block/block_int-common.h +5
-0bool is_format; +/* +* Set to true if the BlockDriver supports zoned children. +*/ +bool supports_zoned_children; +/* * Drivers not implementing bdrv_parse_filename nor bdrv_open should have * this field set to true, except ones that are defined only by their --
Damien Le Moal
Western Digital Research
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v9 5/7] config: add check to block layer
In reply to Sam Liblock/file-posix.c static int raw_open_common(BlockDriverState *bs, QDict *options, · line 784
Quoted 11 lines · Sam Li
block/file-posix.c +3
-0@@ -779,6 +779,20 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } } +#ifdef CONFIG_BLKZONED +/* +* The kernel page chache does not reliably work for writes to SWR zones
s/chache/cache/
PATCH v9 6/7 qemu-iotests: test new zone operations
In reply to Sam LiWe have added new block layer APIs of zoned block devices. Test it with:
Create a null_blk device, run each zone operation on it and see whether reporting right zone information.
--- tests/qemu-iotests/tests/zoned.out | 53 +++++++++++++++++++ tests/qemu-iotests/tests/zoned.sh | 85 ++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 tests/qemu-iotests/tests/zoned.out create mode 100755 tests/qemu-iotests/tests/zoned.sh
tests/qemu-iotests/tests/zoned.out new file +53 -0
@@ -0,0 +1,53 @@ +QA output created by zoned.sh +Testing a null_blk device: +Simple cases: if the operations work +(1) report the first zone: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] + +report the first 10 zones +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2] +start: 0x100000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:1, [type: 2] +start: 0x180000, len 0x80000, cap 0x80000, wptr 0x180000, zcond:1, [type: 2] +start: 0x200000, len 0x80000, cap 0x80000, wptr 0x200000, zcond:1, [type: 2] +start: 0x280000, len 0x80000, cap 0x80000, wptr 0x280000, zcond:1, [type: 2] +start: 0x300000, len 0x80000, cap 0x80000, wptr 0x300000, zcond:1, [type: 2] +start: 0x380000, len 0x80000, cap 0x80000, wptr 0x380000, zcond:1, [type: 2] +start: 0x400000, len 0x80000, cap 0x80000, wptr 0x400000, zcond:1, [type: 2] +start: 0x480000, len 0x80000, cap 0x80000, wptr 0x480000, zcond:1, [type: 2] + +report the last zone: +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:1, [type: 2] + + +(2) opening the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:3, [type: 2] + +opening the second zone +report after: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:3, [type: 2] + +opening the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:3, [type: 2] + + +(3) closing the first zone +report after: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] + +closing the last zone +report after: +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:1, [type: 2] + + +(4) finishing the second zone +After finishing a zone: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:14, [type: 2] + + +(5) resetting the second zone +After resetting a zone: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2] +*** done
tests/qemu-iotests/tests/zoned.sh new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
2.37.3
PATCH v9 7/7 docs/zoned-storage: add zoned device documentation
In reply to Sam LiAdd the documentation about the zoned device support to virtio-blk emulation.
--- docs/devel/zoned-storage.rst | 41 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 2 files changed, 47 insertions(+) create mode 100644 docs/devel/zoned-storage.rst
docs/devel/zoned-storage.rst new file +41 -0
@@ -0,0 +1,41 @@ +============= +zoned-storage +============= + +Zoned Block Devices (ZBDs) devide the LBA space into block regions called zones +that are larger than the LBA size. It can only allow sequential writes, which +reduces write amplification in SSDs, leading to higher throughput and increased +capacity. More details about ZBDs can be found at: + +https://zonedstorage.io/docs/introduction/zoned-storage + +1. Block layer APIs for zoned storage +------------------------------------- +QEMU block layer has three zoned storage model: +- BLK_Z_HM: This model only allows sequential writes access. It supports a set +of ZBD-specific I/O request that used by the host to manage device zones. +- BLK_Z_HA: It deals with both sequential writes and random writes access. +- BLK_Z_NONE: Regular block devices and drive-managed ZBDs are treated as +non-zoned devices. + +The block device information resides inside BlockDriverState. QEMU uses +BlockLimits struct(BlockDriverState::bl) that is continuously accessed by the +block layer while processing I/O requests. A BlockBackend has a root pointer to +a BlockDriverState graph(for example, raw format on top of file-posix). The +zoned storage information can be propagated from the leaf BlockDriverState all +the way up to the BlockBackend. If the zoned storage model in file-posix is +set to BLK_Z_HM, then block drivers will declare support for zoned host device. + +The block layer APIs support commands needed for zoned storage devices, +including report zones, four zone operations, and zone append. + +2. Emulating zoned storage controllers +-------------------------------------- +When the BlockBackend's BlockLimits model reports a zoned storage device, users +like the virtio-blk emulation or the qemu-io-cmds.c utility can use block layer +APIs for zoned storage emulation or testing. + +For example, the command line for zone report testing a null_blk device of +qemu-io-cmds.c is: +$ path/to/qemu-io --image-opts driver=zoned_host_device,filename=/dev/nullb0 -c +"zrp offset nr_zones"
docs/system/qemu-block-drivers.rst.inc +6 -0
@@ -430,6 +430,12 @@ Hard disks you may corrupt your host data (use the ``-snapshot`` command line option or modify the device permissions accordingly). +Zoned block devices + Zoned block devices can be passed through to the guest if the emulated storage + controller supports zoned storage. Use ``--blockdev zoned_host_device, + node-name=drive0,filename=/dev/nullb0`` to pass through ``/dev/nullb0`` + as ``drive0``. + Windows ^^^^^^^
Signature · 1 line
2.37.3
Re: [PATCH v9 7/7] docs/zoned-storage: add zoned device documentation
Quoted 17 lines · Sam Li
Add the documentation about the zoned device support to virtio-blk emulation.
Signed-off-by Sam Li <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>--- docs/devel/zoned-storage.rst | 41 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 2 files changed, 47 insertions(+) create mode 100644 docs/devel/zoned-storage.rstdocs/devel/zoned-storage.rst new file +0
-0
docs/devel/zoned-storage.rst line 6
Quoted 6 lines
docs/devel/zoned-storage.rst new file +6
-0@@ -0,0 +1,41 @@ +============= +zoned-storage +============= + +Zoned Block Devices (ZBDs) devide the LBA space into block regions called zones +that are larger than the LBA size. It can only allow sequential writes, which
s/It/They
docs/devel/zoned-storage.rst line 8
Quoted 2 lines
docs/devel/zoned-storage.rst new file +2
-0+reduces write amplification in SSDs, leading to higher throughput and increased +capacity. More details about ZBDs can be found at:
I would rephrase this like this, to be less assertive about the potential benefits (as they depend on the vendor implementation):
..., which can reduce write amplification in SSDs, and potentially lead to higher throughput and increased device capacity.
Quoted 50 lines
docs/devel/zoned-storage.rst new file +33
-0+ +https://zonedstorage.io/docs/introduction/zoned-storage + +1. Block layer APIs for zoned storage +------------------------------------- +QEMU block layer has three zoned storage model: +- BLK_Z_HM: This model only allows sequential writes access. It supports a set +of ZBD-specific I/O request that used by the host to manage device zones. +- BLK_Z_HA: It deals with both sequential writes and random writes access. +- BLK_Z_NONE: Regular block devices and drive-managed ZBDs are treated as +non-zoned devices. + +The block device information resides inside BlockDriverState. QEMU uses +BlockLimits struct(BlockDriverState::bl) that is continuously accessed by the +block layer while processing I/O requests. A BlockBackend has a root pointer to +a BlockDriverState graph(for example, raw format on top of file-posix). The +zoned storage information can be propagated from the leaf BlockDriverState all +the way up to the BlockBackend. If the zoned storage model in file-posix is +set to BLK_Z_HM, then block drivers will declare support for zoned host device. + +The block layer APIs support commands needed for zoned storage devices, +including report zones, four zone operations, and zone append. + +2. Emulating zoned storage controllers +-------------------------------------- +When the BlockBackend's BlockLimits model reports a zoned storage device, users +like the virtio-blk emulation or the qemu-io-cmds.c utility can use block layer +APIs for zoned storage emulation or testing. + +For example, the command line for zone report testing a null_blk device of +qemu-io-cmds.c is: +$ path/to/qemu-io --image-opts driver=zoned_host_device,filename=/dev/nullb0 -c +"zrp offset nr_zones"docs/system/qemu-block-drivers.rst.inc +6
-0@@ -430,6 +430,12 @@ Hard disks you may corrupt your host data (use the ``-snapshot`` command line option or modify the device permissions accordingly). +Zoned block devices + Zoned block devices can be passed through to the guest if the emulated storage + controller supports zoned storage. Use ``--blockdev zoned_host_device, + node-name=drive0,filename=/dev/nullb0`` to pass through ``/dev/nullb0`` + as ``drive0``. + Windows ^^^^^^^
Signature · 2 lines
Damien Le Moal Western Digital Research