Add support for zoned device
Subsystems (2)
v14 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"
v14:
- address Stefan's comments of probing block sizes
v13:
- add some tracing points for new zone APIs [Dmitry]
- change error handling in zone_mgmt [Damien, Stefan]
v12:
- address review comments
* drop BLK_ZO_RESET_ALL bit [Damien]
* fix error messages, style, and typos[Damien, Hannes]
v11:
- address review comments
* fix possible BLKZONED config compiling warnings [Stefan]
* fix capacity field compiling warnings on older kernel [Stefan,Damien]
v10:
- address review comments
* deal with the last small zone case in zone_mgmt operations [Damien]
* handle the capacity field outdated in old kernel(before 5.9) [Damien]
* use byte unit in block layer to be consistent with QEMU [Eric]
* fix coding style related problems [Stefan]
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 (8):
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
block: add some trace events for new block layer APIs docs/zoned-storage: add zoned device documentation
block.c | 19 + block/block-backend.c | 147 ++++++++ block/file-posix.c | 503 +++++++++++++++++++++++-- block/io.c | 41 ++ block/raw-format.c | 14 + block/trace-events | 2 + docs/devel/zoned-storage.rst | 43 +++ 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 | 18 + meson.build | 4 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 149 ++++++++ tests/qemu-iotests/tests/zoned.out | 53 +++ tests/qemu-iotests/tests/zoned.sh | 86 +++++ 18 files changed, 1139 insertions(+), 39 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.38.1
PATCH v14 1/8 include: add zoned device structs
--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
include/block/block-common.h +43 -0
@@ -64,6 +64,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 BlockZoneState { +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 , +}BlockZoneState ; + +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; +BlockZoneState state; +}BlockZoneDescriptor ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size;
Signature · 1 line
2.38.1
PATCH v14 2/8 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 | 124 ++++++++++++++++++++++--------- include/block/block_int-common.h | 3 + 2 files changed, 91 insertions(+), 36 deletions(-)
block/file-posix.c +88 -36
@@ -1201,66 +1201,112 @@ 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);
@@ -1298,6 +1344,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
@@ -840,6 +840,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.38.1
PATCH v14 3/8 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, reset_all).
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 | 147 ++++++++++++ block/file-posix.c | 364 ++++++++++++++++++++++++++++++ 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 | 18 ++ meson.build | 4 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 149 ++++++++++++ 10 files changed, 762 insertions(+), 3 deletions(-)
block/block-backend.c +147 -0
@@ -1451,6 +1451,15 @@ typedef struct BlkRwCo {void *iobuf;int ret;BdrvRequestFlags flags; +union { +struct { +unsigned int *nr_zones; +BlockZoneDescriptor *zones; + } zone_report; +struct { +unsigned long op; + } zone_mgmt; + }; } BlkRwCo;int blk_make_zero (BlockBackend *blk,BdrvRequestFlags flags)
@@ -1795,6 +1804,144 @@ int coroutine_fn blk_co_flush(BlockBackend *blk)return ret; } +static void coroutine_fn 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 coroutine_fn 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 device zone 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 ) { +blk_dec_in_flight (blk); +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 +364 -0
412 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
@@ -95,6 +95,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,int64_t bytes); +/* 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); +bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map,
include/block/block_int-common.h +21 -0
@@ -707,6 +707,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_load_vmstate)(BlockDriverState *bs,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);
@@ -843,6 +849,21 @@ typedef struct BlockLimits {/* device zone model */ BlockZoneModel zoned; + +/* zone size expressed in bytes */ +uint32_t zone_size; + +/* total number of zones */ +uint32_t 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 +18 -0
@@ -45,6 +45,13 @@ 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);
@@ -165,6 +172,17 @@ int co_wrapper_mixed 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 co_wrapper_mixed 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 co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op, +int64_t offset,int64_t len); + int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
meson.build +4 -0
@@ -1948,6 +1948,7 @@ config_host_data.set('CONFIG_REPLICATION', get_option('replication').allowed()) # 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'))
@@ -2042,6 +2043,9 @@ config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID', config_host_data.set('HAVE_STRUCT_STAT_ST_ATIM', cc.has_member('struct stat', 'st_atim', prefix: '#include <sys/stat.h>')) +config_host_data.set('HAVE_BLK_ZONE_REP_CAPACITY', + cc.has_member('struct blk_zone', 'capacity', + prefix: '#include <linux/blkzoned.h>')) # has_type config_host_data.set('CONFIG_IOVEC',
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 ##
@@ -2963,7 +2964,8 @@ { 'name': 'virtio-blk-vfio-pci', 'if': 'CONFIG_BLKIO' }, { 'name': 'virtio-blk-vhost-user', 'if': 'CONFIG_BLKIO' }, { 'name': 'virtio-blk-vhost-vdpa', 'if': 'CONFIG_BLKIO' }, - 'vmdk', 'vpc', 'vvfat' ] } + 'vmdk', 'vpc', 'vvfat', + { 'name': 'zoned_host_device', 'if': 'CONFIG_BLKZONED' } ] } ## # @BlockdevOptionsFile:
@@ -4416,7 +4418,9 @@ 'if': 'CONFIG_BLKIO' }, 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'vvfat': 'BlockdevOptionsVVFAT' + 'vvfat': 'BlockdevOptionsVVFAT', + 'zoned_host_device': { 'type': 'BlockdevOptionsFile', + 'if': 'CONFIG_BLKZONED' } } } ##
qemu-io-cmds.c +149 -0
161 lines not on this page · raw message
Signature · 1 line
2.38.1
Re: [PATCH v14 3/8] block: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 16 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,reset_all).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]>
Quoted 12 lines
--- block/block-backend.c | 147 ++++++++++++ block/file-posix.c | 364 ++++++++++++++++++++++++++++++ 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 | 18 ++ meson.build | 4 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 149 ++++++++++++ 10 files changed, 762 insertions(+), 3 deletions(-)
Quoted 18 lines · Sam Li
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).
Quoted 7 lines
It can be tested on a
null_blkdevice 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"v14:
- address Stefan's comments of probing block sizes
I have reviewed all patches now.
Kevin: Please review and merge.
Thanks,
Stefan
Quoted 117 lines
v13:
- add some tracing points for new zone APIs [Dmitry]
- change error handling inzone_mgmt[Damien, Stefan]v12:
- address review comments
* dropBLK_ZO_RESET_ALLbit [Damien]
* fix error messages, style, and typos[Damien, Hannes]v11:
- address review comments
* fix possible BLKZONED config compiling warnings [Stefan]
* fix capacity field compiling warnings on older kernel [Stefan,Damien]v10:
- address review comments
* deal with the last small zone case inzone_mgmtoperations [Damien]
* handle the capacity field outdated in old kernel(before 5.9) [Damien]
* use byte unit in block layer to be consistent with QEMU [Eric]
* fix coding style related problems [Stefan]v9:
- address review comments
* specify units of zone commands requests [Stefan]
* fix some error handling in file-posix [Stefan]
* introducezoned_host_devciein 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 configv7:
- address review comments
* modify sysfs attribute helper funcations
* move the input validation and error checking into raw_co_zone_* function
* fix checks in configv6:
- drop virtio-blk emulation changes
- address Stefan's review comments
* fixCONFIG_BLKZONEDconfigs in related functions
* replace reading fd byg_file_get_contents()inget_sysfs_str_val()
* rewrite documentation for zoned storagev5:
- 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 patchesv4:
- 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 inzone_report
* add checks to block layers
* fix qemu-iotests format
* fix sysfs helper functionsv3:
- 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 blockingioctl()callsv2:
- add qemu-io sub-commands
- address review comments
* modify interfaces of APIsv1:
- add block layer APIs resembling Linux ZoneBlockDevice ioctlsSam Li (8):
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
block: add some trace events for new block layer APIs docs/zoned-storage: add zoned device documentationblock.c | 19 + block/block-backend.c | 147 ++++++++ block/file-posix.c | 503 +++++++++++++++++++++++-- block/io.c | 41 ++ block/raw-format.c | 14 + block/trace-events | 2 + docs/devel/zoned-storage.rst | 43 +++ 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 | 18 + meson.build | 4 + qapi/block-core.json | 8 +- qemu-io-cmds.c | 149 ++++++++ tests/qemu-iotests/tests/zoned.out | 53 +++ tests/qemu-iotests/tests/zoned.sh | 86 +++++ 18 files changed, 1139 insertions(+), 39 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.shSignature · 1 line
2.38.1