Block patches
Subsystems (3)
The following changes since commit 8844bb8d896595ee1d25d21c770e6e6f29803097:
Merge tag 'or1k-pull-request-20230513' of https://github.com/stffrdhrn/qemu into staging (2023-05-13 11:23:14 +0100)
are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to 01562fee5f3ad4506d57dbcf4b1903b565eceec7:
docs/zoned-storage:add zoned emulation use case (2023-05-15 08:19:04 -0400)
----------------------------------------------------------------
Pull request
This pull request contain's Sam Li's zoned storage support in the QEMU block layer and virtio-blk emulation.
v2:
- Sam fixed the CI failures. CI passes for me now. [Richard]
----------------------------------------------------------------
Sam Li (16):
block/block-common: add zoned device structs block/file-posix: introduce helper functions for sysfs attributes block/block-backend: add block layer APIs resembling Linux
ZonedBlockDevice ioctls
block/raw-format: add zone operations to pass through requests
block: add zoned BlockDriver check to block layer
iotests: test new zone operations
block: add some trace events for new block layer APIs docs/zoned-storage: add zoned device documentation
file-posix: add tracking of the zone write pointers
block: introduce zone append write for zoned devices
qemu-iotests: test zone append operation
block: add some trace events for zone append
virtio-blk: add zoned storage emulation for zoned devices
block: add accounting for zone append operation
virtio-blk: add some trace events for zoned emulation docs/zoned-storage:add zoned emulation use case
docs/devel/index-api.rst | 1 + docs/devel/zoned-storage.rst | 62 +++ qapi/block-core.json | 68 ++- qapi/block.json | 4 + meson.build | 5 + include/block/accounting.h | 1 + include/block/block-common.h | 57 ++ include/block/block-io.h | 13 + include/block/block_int-common.h | 37 ++ include/block/raw-aio.h | 8 +- include/sysemu/block-backend-io.h | 27 + block.c | 19 + block/block-backend.c | 198 +++++++ block/file-posix.c | 692 +++++++++++++++++++++++-- block/io.c | 68 +++ block/io_uring.c | 4 + block/linux-aio.c | 3 + block/qapi-sysemu.c | 11 + block/qapi.c | 18 + block/raw-format.c | 26 + hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 405 +++++++++++++++ hw/virtio/virtio-qmp.c | 2 + qemu-io-cmds.c | 224 ++++++++ block/trace-events | 4 + docs/system/qemu-block-drivers.rst.inc | 6 + hw/block/trace-events | 7 + tests/qemu-iotests/227.out | 18 + tests/qemu-iotests/tests/zoned | 105 ++++ tests/qemu-iotests/tests/zoned.out | 69 +++ 30 files changed, 2106 insertions(+), 58 deletions(-) create mode 100644 docs/devel/zoned-storage.rst create mode 100755 tests/qemu-iotests/tests/zoned create mode 100644 tests/qemu-iotests/tests/zoned.out
Signature · 1 line
2.40.1
[PULL v2 07/16] block: add some trace events for new block layer APIs
From: Sam Li <[email protected]>
Message-id: [email protected]
Message-id: [email protected]
--- block/file-posix.c | 3 +++ block/trace-events | 2 ++ 2 files changed, 5 insertions(+)
block/file-posix.c +3 -0
@@ -3267,6 +3267,7 @@ static int coroutine_fn raw_co_zone_report(BlockDriverState *bs, int64_t offset, }, }; +trace_zbd_zone_report (bs, *nr_zones, offset >>BDRV_SECTOR_BITS );return raw_thread_pool_submit (handle_aiocb_zone_report, &acb); }#endif
@@ -3333,6 +3334,8 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, }, }; +trace_zbd_zone_mgmt (bs, op_name, offset >>BDRV_SECTOR_BITS , + len >>BDRV_SECTOR_BITS ); ret =raw_thread_pool_submit (handle_aiocb_zone_mgmt, &acb);if (ret !=0 ) {error_report ("ioctl %s failed %d" , op_name, ret);
block/trace-events +2 -0
@@ -209,6 +209,8 @@ file_FindEjectableOpticalMedia(const char *media) "Matching using %s" file_setup_cdrom(const char *partition) "Using %s as optical disc" file_hdev_is_sg(int type, int version) "SG device found: type=%d, version=%d" file_flush_fdatasync_failed(int err) "errno %d" +zbd_zone_report(void *bs, unsigned int nr_zones, int64_t sector) "bs %p report %d zones starting at sector offset 0x%" PRIx64 "" +zbd_zone_mgmt(void *bs, const char *op_name, int64_t sector, int64_t len) "bs %p %s starts at sector offset 0x%" PRIx64 " over a range of 0x%" PRIx64 " sectors" # ssh.c sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp_err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)"
Signature · 1 line
2.40.1
[PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Use 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.
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]>.
--Stefan]
--- include/block/block_int-common.h | 3 + block/file-posix.c | 135 ++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 38 deletions(-)
include/block/block_int-common.h +3 -0
@@ -862,6 +862,9 @@ typedef struct BlockLimits {* an explicit monitor command to load the disk inside the guest). */ bool has_variable_length; + +/* device zone model */ +BlockZoneModel zoned; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
block/file-posix.c +97 -38
162 lines not on this page · raw message
Signature · 1 line
2.40.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes
Quoted 23 lines · Matthew Rosato <[email protected]> 于2023年6月1日周四 02:21写道:
Quoted 8 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
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.Hi Stefan, Sam,
I am having an issue on s390x using virtio-blk-{pci,ccw} backed by an NVMe partition, and I've bisected the root cause to this commit.
I noticed that tests which use the partition e.g.
/dev/nvme0n1p1as a backing device would fail, but those that use the namespace e.g./dev/nvme0n1would still succeed. The root issue appears to be that the block device associated with the partition does not have a "max_segments" attribute, and prior to this patchhdev_get_max_segment()would return-ENOENTin this case. After this patch, however, QEMU is instead crashing. It looks likeg_file_get_contentsis returning 0 with a len == 0 if the specified sysfs path does not exist. The following diff on top seems to resolve the issue for me:block/file-posix.c +0
-0
block/file-posix.c static int get_sysfs_str_val(struct stat *st, const char *attribute, · line 1249
Quoted 8 lines
block/file-posix.c +1
-1@@ -1243,7 +1243,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,major (st->st_rdev),minor (st->st_rdev), attribute); ret =g_file_get_contents (sysfspath, val, &len,NULL ); -if (ret ==-1 ) { +if (ret ==-1 || len ==0 ) {return -ENOENT ; }
Hi Matthew,
Thanks for the information. After some checking, I think the bug here is that g_file_get_contens returns g_boolean value and the error case will return 0 instead of -1 in my previous code. Can the following line fix your issue on the s390x device?
+ if (ret == FALSE) {
https://docs.gtk.org/glib/func.file_get_contents.html
Thanks,
Sam
Quoted 206 lines
Quoted 205 lines
Signed-off-by Sam Li <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Reviewed-by Damien Le Moal <[email protected]>Reviewed-by Dmitry Fomichev <[email protected]>Acked-by Kevin Wolf <[email protected]>Signed-off-by Stefan Hajnoczi <[email protected]>Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]>.
--Stefan]Signed-off-by Stefan Hajnoczi <[email protected]>--- include/block/block_int-common.h | 3 + block/file-posix.c | 135 ++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 38 deletions(-)include/block/block_int-common.h +3
-0@@ -862,6 +862,9 @@ typedef struct BlockLimits {* an explicit monitor command to load the disk inside the guest). */ bool has_variable_length; + +/* device zone model */ +BlockZoneModel zoned; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;block/file-posix.c +97
-38@@ -1202,15 +1202,89 @@ 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. +*/ +#ifdef CONFIG_LINUX +static int get_sysfs_str_val (struct stat *st,const char *attribute, +char **val) { + g_autofree char *sysfspath = NULL; +int ret; +size_t len; + +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 ; + } + +/* The file is ended with '\n' */ +char *p; + p = *val; +if (*(p + len -1 ) =='\n' ) { + *(p + len -1 ) ='\0' ; + } +return ret; +} +#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 ) { +return ret; + } + +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 ; +} + +/* +* Get a sysfs attribute value as a long integer. +*/ #ifdef CONFIG_LINUX -char buf[32 ]; +static long get_sysfs_long_val (struct stat *st,const char *attribute) +{ + g_autofree char *str = NULL;const char *end; -char *sysfspath =NULL ; +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; + } +return ret; +} +#endif + +static int hdev_get_max_segments (int fd,struct stat *st) +{ +#ifdef CONFIG_LINUX int ret; -int sysfd =-1 ; -long max_segments;if (S_ISCHR (st->st_mode)) {if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) {@@ -1218,44 +1292,27 @@ static int hdev_get_max_segments(int fd, struct stat *st) }return -ENOTSUP ; } - -if (!S_ISBLK (st->st_mode)) { -return -ENOTSUP ; - } - - 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; - } - ret =RETRY_ON_EINTR (read (sysfd, buf,sizeof (buf) -1 )); -if (ret <0 ) { - ret = -errno; - goto out; - }else if (ret ==0 ) { - ret = -EIO ; - goto out; - } - 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; - } - -out: -if (sysfd !=-1 ) { -close (sysfd); - } -g_free (sysfspath); -return ret; +return get_sysfs_long_val (st,"max_segments" );#else return -ENOTSUP ;#endif } +static void raw_refresh_zoned_limits (BlockDriverState *bs,struct stat *st, +Error **errp) +{ +BlockZoneModel zoned; +int ret; + + bs->bl.zoned =BLK_Z_NONE ; + + ret =get_sysfs_zoned_model (st, &zoned); +if (ret <0 || zoned ==BLK_Z_NONE ) { +return ; + } + bs->bl.zoned = zoned; +} +static void raw_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque;@@ -1297,6 +1354,8 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) bs->bl.max_hw_iov = ret; } } + +raw_refresh_zoned_limits (bs, &st, errp); }static int check_for_dasd (int fd)
Re: [PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes
Quoted 35 lines · Sam Li
Quoted 23 lines · Matthew Rosato <[email protected]> 于2023年6月1日周四 02:21写道:
Quoted 8 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
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.Hi Stefan, Sam,
I am having an issue on s390x using virtio-blk-{pci,ccw} backed by an NVMe partition, and I've bisected the root cause to this commit.
I noticed that tests which use the partition e.g.
/dev/nvme0n1p1as a backing device would fail, but those that use the namespace e.g./dev/nvme0n1would still succeed. The root issue appears to be that the block device associated with the partition does not have a "max_segments" attribute, and prior to this patchhdev_get_max_segment()would return-ENOENTin this case. After this patch, however, QEMU is instead crashing. It looks likeg_file_get_contentsis returning 0 with a len == 0 if the specified sysfs path does not exist. The following diff on top seems to resolve the issue for me:block/file-posix.c +0
-0block/file-posix.c static int get_sysfs_str_val(struct stat *st, const char *attribute, · line 1249
Quoted 8 lines
block/file-posix.c +1
-1@@ -1243,7 +1243,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,major (st->st_rdev),minor (st->st_rdev), attribute); ret =g_file_get_contents (sysfspath, val, &len,NULL ); -if (ret ==-1 ) { +if (ret ==-1 || len ==0 ) {return -ENOENT ; }Hi Matthew,
Quoted 8 lines
Thanks for the information. After some checking, I think the bug here is that
g_file_get_contensreturnsg_booleanvalue and the error case will return 0 instead of -1 in my previous code. Can the following line fix your issue on the s390x device?+ if (ret == FALSE) {
Hi Sam,
Ah, good point, I didn't notice file_get_contents was meant to be a bool return and wondered why I was getting a return of 0 in the failing case, hence the check for len == 0.
Anyway, yes, I verified that checking for ret == FALSE fixes the issue. FWIW, along the same line I also checked that this works:
if (!g_file_get_contents(sysfspath, val, &len, NULL)) {
return -ENOENT;
}which I personally think looks cleaner and matches the other uses of g_file_get_contents in QEMU. Could also get rid of ret and just return 0 at the bottom of the function.
Thanks,
Matt
Re: [PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes
Quoted 50 lines · Matthew Rosato <[email protected]> 于2023年6月3日周六 02:41写道:
Quoted 35 lines · Sam Li
Quoted 23 lines · Matthew Rosato <[email protected]> 于2023年6月1日周四 02:21写道:
Quoted 8 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
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.Hi Stefan, Sam,
I am having an issue on s390x using virtio-blk-{pci,ccw} backed by an NVMe partition, and I've bisected the root cause to this commit.
I noticed that tests which use the partition e.g.
/dev/nvme0n1p1as a backing device would fail, but those that use the namespace e.g./dev/nvme0n1would still succeed. The root issue appears to be that the block device associated with the partition does not have a "max_segments" attribute, and prior to this patchhdev_get_max_segment()would return-ENOENTin this case. After this patch, however, QEMU is instead crashing. It looks likeg_file_get_contentsis returning 0 with a len == 0 if the specified sysfs path does not exist. The following diff on top seems to resolve the issue for me:block/file-posix.c +0
-0block/file-posix.c static int get_sysfs_str_val(struct stat *st, const char *attribute, · line 1249
Quoted 8 lines
block/file-posix.c +1
-1@@ -1243,7 +1243,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,major (st->st_rdev),minor (st->st_rdev), attribute); ret =g_file_get_contents (sysfspath, val, &len,NULL ); -if (ret ==-1 ) { +if (ret ==-1 || len ==0 ) {return -ENOENT ; }Hi Matthew,
Quoted 8 lines
Thanks for the information. After some checking, I think the bug here is that
g_file_get_contensreturnsg_booleanvalue and the error case will return 0 instead of -1 in my previous code. Can the following line fix your issue on the s390x device?+ if (ret == FALSE) {
Hi Sam,
Ah, good point, I didn't notice
file_get_contentswas meant to be a bool return and wondered why I was getting a return of 0 in the failing case, hence the check for len == 0.
Quoted 7 lines
Anyway, yes, I verified that checking for ret == FALSE fixes the issue. FWIW, along the same line I also checked that this works:
if (!g_file_get_contents(sysfspath, val, &len, NULL)) { return -ENOENT; }which I personally think looks cleaner and matches the other uses of
g_file_get_contentsin QEMU. Could also get rid of ret and just return 0 at the bottom of the function.
Indeed. I will fix this. Thanks!
Sam
[PULL v2 13/16] virtio-blk: add zoned storage emulation for zoned devices
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
This patch extends virtio-blk emulation to handle zoned device commands by calling the new block layer APIs to perform zoned device I/O on behalf of the guest. It supports Report Zone, four zone oparations (open, close, finish, reset), and Append Zone.
The VIRTIO_BLK_F_ZONED feature bit will only be set if the host does support zoned block devices. Regular block devices(conventional zones) will not be set.
The guest os can use blktests, fio to test those commands on zoned devices. Furthermore, using zonefs to test zone append write is also supported.
Message-id: [email protected]
--- hw/block/virtio-blk-common.c | 2 + hw/block/virtio-blk.c | 389 +++++++++++++++++++++++++++++++++++ hw/virtio/virtio-qmp.c | 2 + 3 files changed, 393 insertions(+)
hw/block/virtio-blk-common.c +2 -0
@@ -29,6 +29,8 @@ static const VirtIOFeature feature_sizes[] = { .end = endof(struct virtio_blk_config, discard_sector_alignment)}, {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES, .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)}, + {.flags = 1ULL << VIRTIO_BLK_F_ZONED, + .end = endof(struct virtio_blk_config, zoned)}, {} };
hw/block/virtio-blk.c +389 -0
431 lines not on this page · raw message
hw/virtio/virtio-qmp.c +2 -0
@@ -176,6 +176,8 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = { "VIRTIO_BLK_F_DISCARD: Discard command supported"),FEATURE_ENTRY (VIRTIO_BLK_F_WRITE_ZEROES , \"VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported" ), +FEATURE_ENTRY (VIRTIO_BLK_F_ZONED , \ +"VIRTIO_BLK_F_ZONED: Zoned block devices" ), #ifndef VIRTIO_BLK_NO_LEGACYFEATURE_ENTRY (VIRTIO_BLK_F_BARRIER , \ "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
Signature · 1 line
2.40.1
[PULL v2 01/16] block/block-common: add zoned device structs
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]>.
--Stefan]
--- include/block/block-common.h | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
include/block/block-common.h +43 -0
@@ -75,6 +75,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.40.1
[PULL v2 10/16] block: introduce zone append write for zoned devices
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone.
Message-id: [email protected]
--- include/block/block-io.h | 4 ++ include/block/block_int-common.h | 3 ++ include/block/raw-aio.h | 4 +- include/sysemu/block-backend-io.h | 9 +++++ block/block-backend.c | 61 +++++++++++++++++++++++++++++++ block/file-posix.c | 58 +++++++++++++++++++++++++---- block/io.c | 27 ++++++++++++++ block/io_uring.c | 4 ++ block/linux-aio.c | 3 ++ block/raw-format.c | 8 ++++ 10 files changed, 173 insertions(+), 8 deletions(-)
include/block/block-io.h +4 -0
@@ -122,6 +122,10 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_mgmt(BlockDriverState *bs,BlockZoneOp op,int64_t offset,int64_t len); +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_append(BlockDriverState *bs, +int64_t *offset, +QEMUIOVector *qiov, +BdrvRequestFlags flags);bool bdrv_can_write_zeroes_with_unmap (BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset,
include/block/block_int-common.h +3 -0
@@ -723,6 +723,9 @@ struct BlockDriver { BlockZoneDescriptor *zones); int coroutine_fn (*bdrv_co_zone_mgmt)(BlockDriverState *bs, BlockZoneOp op,int64_t offset,int64_t len); + int coroutine_fn (*bdrv_co_zone_append)(BlockDriverState *bs, +int64_t *offset,QEMUIOVector *qiov, +BdrvRequestFlags flags);/* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)(
include/block/raw-aio.h +3 -1
@@ -30,6 +30,7 @@#define QEMU_AIO_TRUNCATE 0x0080#define QEMU_AIO_ZONE_REPORT 0x0100#define QEMU_AIO_ZONE_MGMT 0x0200 +#define QEMU_AIO_ZONE_APPEND 0x0400#define QEMU_AIO_TYPE_MASK \ (QEMU_AIO_READ | \ QEMU_AIO_WRITE | \
@@ -40,7 +41,8 @@ QEMU_AIO_COPY_RANGE | \ QEMU_AIO_TRUNCATE | \ QEMU_AIO_ZONE_REPORT | \ - QEMU_AIO_ZONE_MGMT) + QEMU_AIO_ZONE_MGMT | \ + QEMU_AIO_ZONE_APPEND)/* AIO flags */ #define QEMU_AIO_MISALIGNED 0x1000
include/sysemu/block-backend-io.h +9 -0
@@ -53,6 +53,9 @@ BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset,BlockAIOCB *blk_aio_zone_mgmt (BlockBackend *blk,BlockZoneOp op,int64_t offset,int64_t len,BlockCompletionFunc *cb,void *opaque); +BlockAIOCB *blk_aio_zone_append (BlockBackend *blk,int64_t *offset, +QEMUIOVector *qiov,BdrvRequestFlags flags, +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);
@@ -208,6 +211,12 @@ 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 coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset, +QEMUIOVector *qiov, +BdrvRequestFlags flags); +int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset, +QEMUIOVector *qiov, +BdrvRequestFlags flags); int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,int64_t bytes);
block/block-backend.c +61 -0
73 lines not on this page · raw message
block/file-posix.c +51 -7
119 lines not on this page · raw message
block/io.c +27 -0
@@ -3154,6 +3154,33 @@ out:return co.ret; } +int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset, +QEMUIOVector *qiov, +BdrvRequestFlags flags) +{ +int ret; +BlockDriver *drv = bs->drv; +CoroutineIOCompletion co = { + .coroutine =qemu_coroutine_self (), + }; +IO_CODE (); + + ret =bdrv_check_qiov_request (*offset, qiov->size, qiov,0 ,NULL ); +if (ret <0 ) { +return ret; + } + +bdrv_inc_in_flight (bs); +if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned ==BLK_Z_NONE ) { + co.ret = -ENOTSUP ; + goto out; + } + co.ret = drv->bdrv_co_zone_append (bs, offset, qiov, flags); +out: +bdrv_dec_in_flight (bs); +return co.ret; +} +void *qemu_blockalign (BlockDriverState *bs,size_t size) {IO_CODE ();
block/io_uring.c +4 -0
@@ -350,6 +350,10 @@ static int luring_do_submit(int fd, LuringAIOCB *luringcb, LuringState *s,io_uring_prep_writev (sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset);break ; +case QEMU_AIO_ZONE_APPEND : +io_uring_prep_writev (sqes, fd, luringcb->qiov->iov, + luringcb->qiov->niov, offset); +break ;case QEMU_AIO_READ :io_uring_prep_readv (sqes, fd, luringcb->qiov->iov, luringcb->qiov->niov, offset);
block/linux-aio.c +3 -0
@@ -394,6 +394,9 @@ static int laio_do_submit(int fd, struct qemu_laiocb *laiocb, off_t offset,case QEMU_AIO_WRITE :io_prep_pwritev (iocbs, fd, qiov->iov, qiov->niov, offset);break ; +case QEMU_AIO_ZONE_APPEND : +io_prep_pwritev (iocbs, fd, qiov->iov, qiov->niov, offset); +break ;case QEMU_AIO_READ :io_prep_preadv (iocbs, fd, qiov->iov, qiov->niov, offset);break ;
block/raw-format.c +8 -0
@@ -332,6 +332,13 @@ raw_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op,return bdrv_co_zone_mgmt (bs->file->bs, op, offset, len); } +static int coroutine_fn GRAPH_RDLOCK +raw_co_zone_append (BlockDriverState *bs,int64_t *offset,QEMUIOVector *qiov, +BdrvRequestFlags flags) +{ +return bdrv_co_zone_append (bs->file->bs, offset, qiov, flags); +} + static int64_t coroutine_fn GRAPH_RDLOCKraw_co_getlength (BlockDriverState *bs) {
@@ -637,6 +644,7 @@ BlockDriver bdrv_raw = { .bdrv_co_pdiscard = &raw_co_pdiscard, .bdrv_co_zone_report = &raw_co_zone_report, .bdrv_co_zone_mgmt = &raw_co_zone_mgmt, + .bdrv_co_zone_append = &raw_co_zone_append, .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.40.1
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 10 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone.
Quoted 5 lines
Signed-off-by Sam Li <[email protected]>Reviewed-by Dmitry Fomichev <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Message-id: [email protected]
Signed-off-by Stefan Hajnoczi <[email protected]>
Hi; Coverity flagged up a possible bug here (CID 1512459):
block/file-posix.c static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, · line 2457
Quoted 6 lines
block/file-posix.c +1
-1@@ -2453,8 +2454,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,if (fd_open (bs) <0 )return -EIO ;#if defined(CONFIG_BLKZONED ) -if (type &QEMU_AIO_WRITE && bs->wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && bs->wps) {
Here we check for bs->wps being NULL, which implies that it might be NULL...
Quoted 24 lines
block/file-posix.c +9
-1qemu_co_mutex_lock (&bs->wps->colock); +if (type &QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) { +int index = offset / bs->bl.zone_size; + offset = bs->wps->wp[index]; + } }#endif @@ -2502,9 +2507,13 @@ out: {BlockZoneWps *wps = bs->wps;if (ret ==0 ) { -if (type &QEMU_AIO_WRITE && wps && bs->bl.zone_size) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) + && wps && bs->bl.zone_size) {uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];if (!BDRV_ZT_IS_CONV (*wp)) { +if (type &QEMU_AIO_ZONE_APPEND ) { + *s->offset = *wp; + }/* Advance the wp if needed */ if (offset + bytes > *wp) { *wp = offset + bytes;
block/file-posix.c out: · line 2524
Quoted 5 lines
block/file-posix.c +1
-1@@ -2512,12 +2521,12 @@ out: } } }else { -if (type &QEMU_AIO_WRITE ) { +if (type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) {
...but here we do not, even though update_zones_wp() can dereference bs->wps in some code paths.
Should we be checking for NULL here before calling, or should update_zones_wp() handle a NULL bs->wps, or something else?
block/file-posix.c out: · line 2532
Quoted 9 lines
block/file-posix.c +1
-1update_zones_wp (bs, s->fd,0 ,1 ); } } -if (type &QEMU_AIO_WRITE && wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && wps) {qemu_co_mutex_unlock (&wps->colock); } }
thanks
-- PMM
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 62 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 00:52写道:
Quoted 10 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone.
Quoted 5 lines
Signed-off-by Sam Li <[email protected]>Reviewed-by Dmitry Fomichev <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Message-id: [email protected]
Signed-off-by Stefan Hajnoczi <[email protected]>Hi; Coverity flagged up a possible bug here (CID 1512459):
block/file-posix.c static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, · line 2457
Quoted 6 lines
block/file-posix.c +1
-1@@ -2453,8 +2454,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,if (fd_open (bs) <0 )return -EIO ;#if defined(CONFIG_BLKZONED ) -if (type &QEMU_AIO_WRITE && bs->wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && bs->wps) {Here we check for
bs->wpsbeing NULL, which implies that it might be NULL...Quoted 24 lines
block/file-posix.c +9
-1qemu_co_mutex_lock (&bs->wps->colock); +if (type &QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) { +int index = offset / bs->bl.zone_size; + offset = bs->wps->wp[index]; + } }#endif @@ -2502,9 +2507,13 @@ out: {BlockZoneWps *wps = bs->wps;if (ret ==0 ) { -if (type &QEMU_AIO_WRITE && wps && bs->bl.zone_size) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) + && wps && bs->bl.zone_size) {uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];if (!BDRV_ZT_IS_CONV (*wp)) { +if (type &QEMU_AIO_ZONE_APPEND ) { + *s->offset = *wp; + }/* Advance the wp if needed */ if (offset + bytes > *wp) { *wp = offset + bytes;block/file-posix.c out: · line 2524
Quoted 5 lines
block/file-posix.c +1
-1@@ -2512,12 +2521,12 @@ out: } } }else { -if (type &QEMU_AIO_WRITE ) { +if (type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) {...but here we do not, even though
update_zones_wp()can dereferencebs->wpsin some code paths.
Quoted 2 lines
Should we be checking for NULL here before calling, or should
update_zones_wp()handle a NULLbs->wps, or something else?
Hi Peter,
Thanks for spotting this. You are right that bs->wps is not checked in this code path. I think the get_zones_wp() should handle a NULL bs->wps which is the function calling wps directly.
Would you like to submit a patch for this? Or I can do it if you are not available.
Thanks,
Sam
Quoted 13 lines
block/file-posix.c out: · line 2532
Quoted 10 lines
block/file-posix.c +1
-1update_zones_wp (bs, s->fd,0 ,1 ); } } -if (type &QEMU_AIO_WRITE && wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && wps) {qemu_co_mutex_unlock (&wps->colock); } }thanks
-- PMM
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 67 lines · Sam Li
Quoted 62 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 00:52写道:
Quoted 10 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone.
Quoted 5 lines
Signed-off-by Sam Li <[email protected]>Reviewed-by Dmitry Fomichev <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Message-id: [email protected]
Signed-off-by Stefan Hajnoczi <[email protected]>Hi; Coverity flagged up a possible bug here (CID 1512459):
block/file-posix.c static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, · line 2457
Quoted 6 lines
block/file-posix.c +1
-1@@ -2453,8 +2454,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,if (fd_open (bs) <0 )return -EIO ;#if defined(CONFIG_BLKZONED ) -if (type &QEMU_AIO_WRITE && bs->wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && bs->wps) {Here we check for
bs->wpsbeing NULL, which implies that it might be NULL...Quoted 24 lines
block/file-posix.c +9
-1qemu_co_mutex_lock (&bs->wps->colock); +if (type &QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) { +int index = offset / bs->bl.zone_size; + offset = bs->wps->wp[index]; + } }#endif @@ -2502,9 +2507,13 @@ out: {BlockZoneWps *wps = bs->wps;if (ret ==0 ) { -if (type &QEMU_AIO_WRITE && wps && bs->bl.zone_size) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) + && wps && bs->bl.zone_size) {uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];if (!BDRV_ZT_IS_CONV (*wp)) { +if (type &QEMU_AIO_ZONE_APPEND ) { + *s->offset = *wp; + }/* Advance the wp if needed */ if (offset + bytes > *wp) { *wp = offset + bytes;block/file-posix.c out: · line 2524
Quoted 5 lines
block/file-posix.c +1
-1@@ -2512,12 +2521,12 @@ out: } } }else { -if (type &QEMU_AIO_WRITE ) { +if (type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) {...but here we do not, even though
update_zones_wp()can dereferencebs->wpsin some code paths.Quoted 2 lines
Should we be checking for NULL here before calling, or should
update_zones_wp()handle a NULLbs->wps, or something else?
Quoted 8 lines
Hi Peter,
Thanks for spotting this. You are right that
bs->wpsis not checked in this code path. I think theget_zones_wp()should handle a NULLbs->wpswhich is the function calling wps directly.Would you like to submit a patch for this? Or I can do it if you are not available.
I don't know anything about this code, so I'm not really in a position to write a patch. I'm just passing on the information from the Coverity scanner -- it scales a lot better that way than trying to write fixes for everything myself :-)
thanks
-- PMM
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 75 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 01:30写道:
Quoted 73 lines · Sam Li
Quoted 62 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 00:52写道:
Quoted 10 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
A zone append command is a write operation that specifies the first logical block of a zone as the write position. When writing to a zoned block device using zone append, the byte offset of the call may point at any position within the zone to which the data is being appended. Upon completion the device will respond with the position where the data has been written in the zone.
Quoted 5 lines
Signed-off-by Sam Li <[email protected]>Reviewed-by Dmitry Fomichev <[email protected]>Reviewed-by Stefan Hajnoczi <[email protected]>Message-id: [email protected]
Signed-off-by Stefan Hajnoczi <[email protected]>Hi; Coverity flagged up a possible bug here (CID 1512459):
block/file-posix.c static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset, · line 2457
Quoted 6 lines
block/file-posix.c +1
-1@@ -2453,8 +2454,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,if (fd_open (bs) <0 )return -EIO ;#if defined(CONFIG_BLKZONED ) -if (type &QEMU_AIO_WRITE && bs->wps) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) && bs->wps) {Here we check for
bs->wpsbeing NULL, which implies that it might be NULL...Quoted 24 lines
block/file-posix.c +9
-1qemu_co_mutex_lock (&bs->wps->colock); +if (type &QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) { +int index = offset / bs->bl.zone_size; + offset = bs->wps->wp[index]; + } }#endif @@ -2502,9 +2507,13 @@ out: {BlockZoneWps *wps = bs->wps;if (ret ==0 ) { -if (type &QEMU_AIO_WRITE && wps && bs->bl.zone_size) { +if ((type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) + && wps && bs->bl.zone_size) {uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];if (!BDRV_ZT_IS_CONV (*wp)) { +if (type &QEMU_AIO_ZONE_APPEND ) { + *s->offset = *wp; + }/* Advance the wp if needed */ if (offset + bytes > *wp) { *wp = offset + bytes;block/file-posix.c out: · line 2524
Quoted 5 lines
block/file-posix.c +1
-1@@ -2512,12 +2521,12 @@ out: } } }else { -if (type &QEMU_AIO_WRITE ) { +if (type & (QEMU_AIO_WRITE |QEMU_AIO_ZONE_APPEND )) {...but here we do not, even though
update_zones_wp()can dereferencebs->wpsin some code paths.Quoted 2 lines
Should we be checking for NULL here before calling, or should
update_zones_wp()handle a NULLbs->wps, or something else?Hi Peter,
Thanks for spotting this. You are right that
bs->wpsis not checked in this code path. I think theget_zones_wp()should handle a NULLbs->wpswhich is the function calling wps directly.
Quoted 7 lines
Quoted 2 lines
Would you like to submit a patch for this? Or I can do it if you are not available.
I don't know anything about this code, so I'm not really in a position to write a patch. I'm just passing on the information from the Coverity scanner -- it scales a lot better that way than trying to write fixes for everything myself :-)
I see. I'll fix it. Wish I had known more about this tool when I was testing this code.
Thanks,
Sam
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 11 lines · Sam Li
Quoted 9 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 01:30写道:
Quoted 6 lines · Sam Li
Thanks for spotting this. You are right that
bs->wpsis not checked in this code path. I think theget_zones_wp()should handle a NULLbs->wpswhich is the function calling wps directly.Would you like to submit a patch for this? Or I can do it if you are not available.
Quoted 7 lines
Quoted 4 lines
I don't know anything about this code, so I'm not really in a position to write a patch. I'm just passing on the information from the Coverity scanner -- it scales a lot better that way than trying to write fixes for everything myself :-)
I see. I'll fix it. Wish I had known more about this tool when I was testing this code.
Coverity is a bit awkward because the free online scanner only runs on code that's already been committed to QEMU, so it doesn't tell us about issues until we've already gone through the whole code-review-test cycle. Plus it often complains about things that aren't bugs, so you have to be a bit cautious about interpreting its reports. But it's still a nice tool to have.
The online UI is at https://scan.coverity.com/projects/qemu
and you can create an account and apply for permission to look at the recorded defects if you like.
thanks
-- PMM
Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Quoted 29 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 01:52写道:
Quoted 11 lines · Sam Li
Quoted 9 lines · Peter Maydell <[email protected]> 于2023年6月3日周六 01:30写道:
Quoted 6 lines · Sam Li
Thanks for spotting this. You are right that
bs->wpsis not checked in this code path. I think theget_zones_wp()should handle a NULLbs->wpswhich is the function calling wps directly.Would you like to submit a patch for this? Or I can do it if you are not available.
Quoted 7 lines
Quoted 4 lines
I don't know anything about this code, so I'm not really in a position to write a patch. I'm just passing on the information from the Coverity scanner -- it scales a lot better that way than trying to write fixes for everything myself :-)
I see. I'll fix it. Wish I had known more about this tool when I was testing this code.
Coverity is a bit awkward because the free online scanner only runs on code that's already been committed to QEMU, so it doesn't tell us about issues until we've already gone through the whole code-review-test cycle. Plus it often complains about things that aren't bugs, so you have to be a bit cautious about interpreting its reports. But it's still a nice tool to have.
Quoted 3 lines
The online UI is at https://scan.coverity.com/projects/qemu
and you can create an account and apply for permission to look at the recorded defects if you like.
Good to know. Thanks!
Sam
[PULL v2 03/16] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Add zoned device option to host_device BlockDriver. It will be presented only for zoned host block devices. By adding zone management operations to the host_block_device 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=host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]> and remove spurious ret = -errno in raw_co_zone_mgmt().
--Stefan]
--- meson.build | 5 + include/block/block-io.h | 9 + include/block/block_int-common.h | 21 ++ include/block/raw-aio.h | 6 +- include/sysemu/block-backend-io.h | 18 ++ block/block-backend.c | 137 +++++++++++++ block/file-posix.c | 313 +++++++++++++++++++++++++++++- block/io.c | 41 ++++ qemu-io-cmds.c | 149 ++++++++++++++ 9 files changed, 696 insertions(+), 3 deletions(-)
meson.build +5 -0
@@ -2025,6 +2025,8 @@ if rdma.found() endif # has_header_symbol +config_host_data.set('CONFIG_BLKZONED', + cc.has_header_symbol('linux/blkzoned.h', 'BLKOPENZONE')) config_host_data.set('CONFIG_EPOLL_CREATE1', cc.has_header_symbol('sys/epoll.h', 'epoll_create1')) config_host_data.set('CONFIG_FALLOCATE_PUNCH_HOLE',
@@ -2060,6 +2062,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',
include/block/block-io.h +9 -0
@@ -114,6 +114,15 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t offset,int64_t bytes); +/* Report zone information of zone block device. */ +int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, +int64_t offset, +unsigned int *nr_zones, +BlockZoneDescriptor *zones); +int coroutine_fn GRAPH_RDLOCK 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
@@ -713,6 +713,12 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_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 coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs);
@@ -865,6 +871,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 */ +uint32_t max_append_sectors; + +/* maximum number of open zones */ +uint32_t max_open_zones; + +/* maximum number of active zones */ +uint32_t max_active_zones; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
include/block/raw-aio.h +5 -1
@@ -28,6 +28,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 | \
@@ -36,7 +38,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
@@ -46,6 +46,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);
@@ -191,6 +198,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,
block/block-backend.c +137 -0
143 lines not on this page · raw message
block/file-posix.c +311 -2
375 lines not on this page · raw message
block/io.c +41 -0
47 lines not on this page · raw message
qemu-io-cmds.c +149 -0
161 lines not on this page · raw message
Signature · 1 line
2.40.1
Re: [PULL v2 03/16] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 9 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
Add zoned device option to
host_deviceBlockDriver. It will be presented only for zoned host block devices. By adding zone management operations to thehost_block_deviceBlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations
(open, close, finish, reset,reset_all).
Quoted 7 lines
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=host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"
Hi; Coverity points out an issue in this commit (CID 1544771):
qemu-io-cmds.c static const cmdinfo_t flush_cmd = { · line 1747
Quoted 10 lines
qemu-io-cmds.c +10
-0+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]);
cvtnum() can fail and return a negative value on error (e.g. if the number in the string is out of range), but we are not checking for that. Instead we stuff the value into an 'unsigned int' and then pass that to g_new(), which will result in our trying to allocate a large amount of memory.
Here, and also in the other functions below that use cvtnum(), I think we should follow the pattern for use of that function that is used in the pre-existing code in this function:
int64_t foo; /* NB: not an unsigned or some smaller type */
foo = cvtnum(arg)
if (foo < 0) {
print_cvtnum_err(foo, arg);
return foo; /* or otherwise handle returning an error upward */
}
It looks like all the uses of cvtnum in this patch should be adjusted to handle errors.
thanks
-- PMM
Re: [PULL v2 03/16] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls
Quoted 44 lines · Peter Maydell
Quoted 9 lines · Stefan Hajnoczi
From: Sam Li <[email protected]>
Add zoned device option to
host_deviceBlockDriver. It will be presented only for zoned host block devices. By adding zone management operations to thehost_block_deviceBlockDriver, users can use the new block layer APIs including Report Zone and four zone management operations
(open, close, finish, reset,reset_all).Quoted 7 lines
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=host_device, filename=/dev/nullb0 -c "zrp offset nr_zones"Hi; Coverity points out an issue in this commit (CID 1544771):
qemu-io-cmds.c static const cmdinfo_t flush_cmd = { · line 1747
Quoted 10 lines
qemu-io-cmds.c +10
-0+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]);
cvtnum()can fail and return a negative value on error (e.g. if the number in the string is out of range), but we are not checking for that. Instead we stuff the value into an 'unsigned int' and then pass that tog_new(), which will result in our trying to allocate a large amount of memory.Here, and also in the other functions below that use
cvtnum(), I think we should follow the pattern for use of that function that is used in the pre-existing code in this function:
int64_tfoo; /* NB: not an unsigned or some smaller type */
Quoted 8 lines
foo = cvtnum(arg)
if (foo < 0) {
print_cvtnum_err(foo, arg);
return foo; /* or otherwise handle returning an error upward */
}It looks like all the uses of cvtnum in this patch should be adjusted to handle errors.
Thanks for letting me know. I will send a patch.
Stefan
[PULL v2 05/16] block: add zoned BlockDriver check to block layer
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Putting zoned/non-zoned BlockDrivers on top of each other is not allowed.
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]> and clarify that the check is about zoned BlockDrivers.
--Stefan]
--- include/block/block_int-common.h | 5 +++++ block.c | 19 +++++++++++++++++++ block/file-posix.c | 12 ++++++++++++ block/raw-format.c | 1 + 4 files changed, 37 insertions(+)
include/block/block_int-common.h +5 -0
@@ -137,6 +137,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
block.c +19 -0
@@ -7982,6 +7982,25 @@ 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 ) { +/* +* The host-aware model allows zoned storage constraints and random +* write. Allow mixing host-aware and non-zoned drivers. Using +* host-aware device as a regular device. +*/ +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 +12 -0
@@ -776,6 +776,18 @@ static int raw_open_common(BlockDriverState *bs, QDict *options, goto fail; } } +#ifdef CONFIG_BLKZONED +/* +* The kernel page cache does not reliably work for writes to SWR zones +* of zoned block device because it can not guarantee the order of writes. +*/ +if ((bs->bl.zoned !=BLK_Z_NONE ) && + (!(s->open_flags &O_DIRECT ))) { +error_setg (errp,"The driver supports zoned devices, and it requires " +"cache.direct=on, which was not specified." ); +return -EINVAL ;/* No host kernel page cache */ + } +#endif if (S_ISBLK (st.st_mode)) {#ifdef __linux__
block/raw-format.c +1 -0
@@ -623,6 +623,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,
Signature · 1 line
2.40.1
[PULL v2 06/16] iotests: test new zone operations
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
The new block layer APIs of zoned block devices can be tested by:
$ tests/qemu-iotests/check zoned Run each zone operation on a newly created null_blk device and see whether it outputs the same zone information.
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]>.
--Stefan]
--- tests/qemu-iotests/tests/zoned | 89 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned.out | 53 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100755 tests/qemu-iotests/tests/zoned create mode 100644 tests/qemu-iotests/tests/zoned.out
tests/qemu-iotests/tests/zoned new file +89 -0
@@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# +# Test zone management operations. +# + +seq="$(basename $0)" +echo "QA output created by $seq" +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + sudo -n rmmod null_blk +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ../common.rc +. ../common.filter +. ../common.qemu + +# This test only runs on Linux hosts with raw image files. +_supported_fmt raw +_supported_proto file +_supported_os Linux + +sudo -n true || \ + _notrun 'Password-less sudo required' + +IMG="--image-opts -n driver=host_device,filename=/dev/nullb0" +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT + +echo "Testing a null_blk device:" +echo "case 1: if the operations work" +sudo -n modprobe null_blk nr_devices=1 zoned=1 +sudo -n chmod 0666 /dev/nullb0 + +echo "(1) report the first zone:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "report the first 10 zones" +$QEMU_IO $IMG -c "zrp 0 10" +echo +echo "report the last zone:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" # 0x3e70000000 / 512 = 0x1f380000 +echo +echo +echo "(2) opening the first zone" +$QEMU_IO $IMG -c "zo 0 268435456" # 268435456 / 512 = 524288 +echo "report after:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "opening the second zone" +$QEMU_IO $IMG -c "zo 268435456 268435456" # +echo "report after:" +$QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo "opening the last zone" +$QEMU_IO $IMG -c "zo 0x3e70000000 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(3) closing the first zone" +$QEMU_IO $IMG -c "zc 0 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0 1" +echo +echo "closing the last zone" +$QEMU_IO $IMG -c "zc 0x3e70000000 268435456" +echo "report after:" +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" +echo +echo +echo "(4) finishing the second zone" +$QEMU_IO $IMG -c "zf 268435456 268435456" +echo "After finishing a zone:" +$QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo +echo "(5) resetting the second zone" +$QEMU_IO $IMG -c "zrs 268435456 268435456" +echo "After resetting a zone:" +$QEMU_IO $IMG -c "zrp 268435456 1" + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/tests/zoned.out new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.40.1
[PULL v2 04/16] block/raw-format: add zone operations to pass through requests
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
raw-format driver usually sits on top of file-posix driver. It needs to pass through requests of zone commands.
Message-id: [email protected]
Message-id: [email protected] [Adjust commit message prefix as suggested by Philippe Mathieu-Daudé <[email protected]>.
--Stefan]
--- block/raw-format.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
block/raw-format.c +17 -0
@@ -317,6 +317,21 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes)return bdrv_co_pdiscard (bs->file, offset, bytes); } +static int coroutine_fn GRAPH_RDLOCK +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 GRAPH_RDLOCK +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 coroutine_fn GRAPH_RDLOCKraw_co_getlength (BlockDriverState *bs) {
@@ -619,6 +634,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.40.1
[PULL v2 08/16] docs/zoned-storage: add zoned device documentation
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Add the documentation about the zoned device support to virtio-blk emulation.
Message-id: [email protected]
Message-id: [email protected] [Add index-api.rst to fix "zoned-storage.rst:document isn't included in any toctree" error and fix pre-formatted code syntax. --Stefan]
--- docs/devel/index-api.rst | 1 + docs/devel/zoned-storage.rst | 43 ++++++++++++++++++++++++++ docs/system/qemu-block-drivers.rst.inc | 6 ++++ 3 files changed, 50 insertions(+) create mode 100644 docs/devel/zoned-storage.rst
docs/devel/index-api.rst +1 -0
@@ -12,3 +12,4 @@ generated from in-code annotations to function prototypes. memory modules ui + zoned-storage
docs/devel/zoned-storage.rst new file +43 -0
43 lines not on this page · raw message
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 host_device, + node-name=drive0,filename=/dev/nullb0,cache.direct=on`` to pass through + ``/dev/nullb0`` as ``drive0``. + Windows ^^^^^^^
Signature · 1 line
2.40.1
[PULL v2 11/16] qemu-iotests: test zone append operation
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
The patch tests zone append writes by reporting the zone wp after the completion of the call. "zap -p" option can print the sector offset value after completion, which should be the start sector where the append write begins.
Message-id: [email protected]
--- qemu-io-cmds.c | 75 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned | 16 +++++++ tests/qemu-iotests/tests/zoned.out | 16 +++++++ 3 files changed, 107 insertions(+)
qemu-io-cmds.c +75 -0
@@ -1874,6 +1874,80 @@ static const cmdinfo_t zone_reset_cmd = { .oneline = "reset a zone write pointer in zone block device", }; +static int do_aio_zone_append (BlockBackend *blk,QEMUIOVector *qiov, +int64_t *offset,int flags,int *total) +{ +int async_ret =NOT_DONE ; + +blk_aio_zone_append (blk, offset, qiov, flags, aio_rw_done, &async_ret); +while (async_ret ==NOT_DONE ) { +main_loop_wait (false); + } + + *total = qiov->size; +return async_ret <0 ? async_ret :1 ; +} + +static int zone_append_f (BlockBackend *blk,int argc,char **argv) +{ +int ret; +bool pflag = false; +int flags =0 ; +int total =0 ; +int64_t offset; +char *buf; +int c, nr_iov; +int pattern =0xcd ; +QEMUIOVector qiov; + +if (optind > argc -3 ) { +return -EINVAL ; + } + +if ((c =getopt (argc, argv,"p" )) !=-1 ) { + pflag = true; + } + + offset =cvtnum (argv[optind]); +if (offset <0 ) { +print_cvtnum_err (offset, argv[optind]); +return offset; + } + optind++; + nr_iov = argc - optind; + buf =create_iovec (blk, &qiov, &argv[optind], nr_iov, pattern, + flags &BDRV_REQ_REGISTERED_BUF ); +if (buf ==NULL ) { +return -EINVAL ; + } + ret =do_aio_zone_append (blk, &qiov, &offset, flags, &total); +if (ret <0 ) { +printf ("zone append failed: %s\n" ,strerror (-ret)); + goto out; + } + +if (pflag) { +printf ("After zap done, the append sector is 0x%" PRIx64"\n" , +tosector (offset)); + } + +out: +qemu_io_free (blk, buf, qiov.size, + flags &BDRV_REQ_REGISTERED_BUF ); +qemu_iovec_destroy (&qiov); +return ret; +} + +static const cmdinfo_t zone_append_cmd = { + .name ="zone_append" , + .altname ="zap" , + .cfunc = zone_append_f, + .argmin =3 , + .argmax =4 , + .args ="offset len [len..]" , + .oneline ="append write a number of bytes at a specified offset" , +}; +static int truncate_f (BlockBackend *blk,int argc,char **argv);static const cmdinfo_t truncate_cmd = { .name ="truncate" ,
@@ -2672,6 +2746,7 @@ static void __attribute((constructor)) init_qemuio_commands(void)qemuio_add_command (&zone_close_cmd);qemuio_add_command (&zone_finish_cmd);qemuio_add_command (&zone_reset_cmd); +qemuio_add_command (&zone_append_cmd);qemuio_add_command (&truncate_cmd);qemuio_add_command (&length_cmd);qemuio_add_command (&info_cmd);
tests/qemu-iotests/tests/zoned +16 -0
@@ -82,6 +82,22 @@ echo "(5) resetting the second zone" $QEMU_IO $IMG -c "zrs 268435456 268435456" echo "After resetting a zone:" $QEMU_IO $IMG -c "zrp 268435456 1" +echo +echo +echo "(6) append write" # the physical block size of the device is 4096 +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone firstly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000" +echo "After appending the first zone secondly:" +$QEMU_IO $IMG -c "zrp 0 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone firstly:" +$QEMU_IO $IMG -c "zrp 268435456 1" +$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000" +echo "After appending the second zone secondly:" +$QEMU_IO $IMG -c "zrp 268435456 1" # success, all done echo "*** done"
tests/qemu-iotests/tests/zoned.out +16 -0
@@ -50,4 +50,20 @@ 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] + + +(6) append write +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] +After zap done, the append sector is 0x0 +After appending the first zone firstly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2] +After zap done, the append sector is 0x18 +After appending the first zone secondly: +start: 0x0, len 0x80000, cap 0x80000, wptr 0x30, zcond:2, [type: 2] +After zap done, the append sector is 0x80000 +After appending the second zone firstly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2] +After zap done, the append sector is 0x80018 +After appending the second zone secondly: +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80030, zcond:2, [type: 2] *** done
Signature · 1 line
2.40.1
[PULL v2 16/16] docs/zoned-storage:add zoned emulation use case
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Add the documentation about the example of using virtio-blk driver to pass the zoned block devices through to the guest.
Message-id: [email protected] [Fix pre-formatted code syntax
--Stefan]
--- docs/devel/zoned-storage.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
docs/devel/zoned-storage.rst +19 -0
@@ -41,3 +41,22 @@ APIs for zoned storage emulation or testing. For example, to test zone_report on a null_blk device using qemu-io is:: $ path/to/qemu-io --image-opts -n driver=host_device,filename=/dev/nullb0 -c "zrp offset nr_zones" + +To expose the host's zoned block device through virtio-blk, the command line +can be (includes the -device parameter):: + + -blockdev node-name=drive0,driver=host_device,filename=/dev/nullb0,cache.direct=on \ + -device virtio-blk-pci,drive=drive0 + +Or only use the -drive parameter:: + + -driver driver=host_device,file=/dev/nullb0,if=virtio,cache.direct=on + +Additionally, QEMU has several ways of supporting zoned storage, including: +(1) Using virtio-scsi: --device scsi-block allows for the passing through of +SCSI ZBC devices, enabling the attachment of ZBC or ZAC HDDs to QEMU. +(2) PCI device pass-through: While NVMe ZNS emulation is available for testing +purposes, it cannot yet pass through a zoned device from the host. To pass on +the NVMe ZNS device to the guest, use VFIO PCI pass the entire NVMe PCI adapter +through to the guest. Likewise, an HDD HBA can be passed on to QEMU all HDDs +attached to the HBA.
Signature · 1 line
2.40.1
[PULL v2 09/16] file-posix: add tracking of the zone write pointers
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Since Linux doesn't have a user API to issue zone append operations to zoned devices from user space, the file-posix driver is modified to add zone append emulation using regular writes. To do this, the file-posix driver tracks the wp location of all zones of the device. It uses an array of uint64_t. The most significant bit of each wp location indicates if the zone type is conventional zones.
The zones wp can be changed due to the following operations issued:
- zone reset: change the wp to the start offset of that zone
- zone finish: change to the end location of that zone
- write to a zone
- zone append
Message-id: [email protected] [Fix errno propagation from handle_aiocb_zone_mgmt() --Stefan]
--- include/block/block-common.h | 14 +++ include/block/block_int-common.h | 5 + block/file-posix.c | 178 ++++++++++++++++++++++++++++++- 3 files changed, 193 insertions(+), 4 deletions(-)
include/block/block-common.h +14 -0
@@ -118,6 +118,14 @@ typedef struct BlockZoneDescriptor {BlockZoneState state; } BlockZoneDescriptor; +/* +* Track write pointers of a zone in bytes. +*/ +typedef struct BlockZoneWps { +CoMutex colock; +uint64_t wp[]; +}BlockZoneWps ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size;
@@ -240,6 +248,12 @@ typedef enum {#define BDRV_SECTOR_BITS 9#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS) +/* +* Get the first most significant bit of wp. If it is zero, then +* the zone type is SWR. +*/ +#define BDRV_ZT_IS_CONV (wp) (wp & (1ULL << 63)) +#define BDRV_REQUEST_MAX_SECTORS MIN_CONST(SIZE_MAX >> BDRV_SECTOR_BITS, \ INT_MAX >> BDRV_SECTOR_BITS)#define BDRV_REQUEST_MAX_BYTES (BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS)
include/block/block_int-common.h +5 -0
@@ -891,6 +891,8 @@ typedef struct BlockLimits {/* maximum number of active zones */ uint32_t max_active_zones; + +uint32_t write_granularity; } BlockLimits;typedef struct BdrvOpBlocker BdrvOpBlocker ;
@@ -1252,6 +1254,9 @@ struct BlockDriverState {CoMutex bsc_modify_lock;/* Always non-NULL, but must only be dereferenced under an RCU read guard */ BdrvBlockStatusCache *block_status_cache; + +/* array of write pointers' location of each zone in the zoned device. */ +BlockZoneWps *wps; };struct BlockBackendRootState {
block/file-posix.c +174 -4
249 lines not on this page · raw message
Signature · 1 line
2.40.1
[PULL v2 15/16] virtio-blk: add some trace events for zoned emulation
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Message-id: [email protected]
--- hw/block/virtio-blk.c | 12 ++++++++++++ hw/block/trace-events | 7 +++++++ 2 files changed, 19 insertions(+)
hw/block/virtio-blk.c +12 -0
@@ -676,6 +676,7 @@ static void virtio_blk_zone_report_complete(void *opaque, int ret)int64_t nz = data->zone_report_data.nr_zones;int8_t err_status =VIRTIO_BLK_S_OK ; +trace_virtio_blk_zone_report_complete (vdev, req, nz, ret);if (ret) { err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; goto out;
@@ -792,6 +793,8 @@ static void virtio_blk_handle_zone_report(VirtIOBlockReq *req, nr_zones = (req->in_len -sizeof (struct virtio_blk_inhdr ) -sizeof (struct virtio_blk_zone_report )) /sizeof (struct virtio_blk_zone_descriptor ); +trace_virtio_blk_handle_zone_report (vdev, req, + offset >>BDRV_SECTOR_BITS , nr_zones); zone_size =sizeof (BlockZoneDescriptor) * nr_zones; data =g_malloc (sizeof (ZoneCmdData));
@@ -814,7 +817,9 @@ static void virtio_blk_zone_mgmt_complete(void *opaque, int ret) {VirtIOBlockReq *req = opaque;VirtIOBlock *s = req->dev; +VirtIODevice *vdev =VIRTIO_DEVICE (s);int8_t err_status =VIRTIO_BLK_S_OK ; +trace_virtio_blk_zone_mgmt_complete (vdev, req,ret);if (ret) { err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ;
@@ -841,6 +846,8 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op)/* Entire drive capacity */ offset =0 ; len = capacity; +trace_virtio_blk_handle_zone_reset_all (vdev, req,0 , + bs->total_sectors); }else {if (bs->bl.zone_size > capacity - offset) {/* The zoned device allows the last smaller zone. */
@@ -848,6 +855,9 @@ static int virtio_blk_handle_zone_mgmt(VirtIOBlockReq *req, BlockZoneOp op) }else { len = bs->bl.zone_size; } +trace_virtio_blk_handle_zone_mgmt (vdev, req, op, + offset >>BDRV_SECTOR_BITS , + len >>BDRV_SECTOR_BITS ); }if (!check_zoned_request (s, offset, len, false, &err_status)) {
@@ -888,6 +898,7 @@ static void virtio_blk_zone_append_complete(void *opaque, int ret) err_status =VIRTIO_BLK_S_ZONE_INVALID_CMD ; goto out; } +trace_virtio_blk_zone_append_complete (vdev, req, append_sector, ret); out:aio_context_acquire (blk_get_aio_context (s->conf.conf.blk));
@@ -909,6 +920,7 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req,int64_t offset =virtio_ldq_p (vdev, &req->out.sector) <<BDRV_SECTOR_BITS ;int64_t len =iov_size (out_iov, out_num); +trace_virtio_blk_handle_zone_append (vdev, req, offset >>BDRV_SECTOR_BITS );if (!check_zoned_request (s, offset, len, true, &err_status)) { goto out; }
hw/block/trace-events +7 -0
@@ -44,9 +44,16 @@ pflash_write_unknown(const char *name, uint8_t cmd) "%s: unknown command 0x%02x" # virtio-blk.c virtio_blk_req_complete(void *vdev, void *req, int status) "vdev %p req %p status %d" virtio_blk_rw_complete(void *vdev, void *req, int ret) "vdev %p req %p ret %d" +virtio_blk_zone_report_complete(void *vdev, void *req, unsigned int nr_zones, int ret) "vdev %p req %p nr_zones %u ret %d" +virtio_blk_zone_mgmt_complete(void *vdev, void *req, int ret) "vdev %p req %p ret %d" +virtio_blk_zone_append_complete(void *vdev, void *req, int64_t sector, int ret) "vdev %p req %p, append sector 0x%" PRIx64 " ret %d" virtio_blk_handle_write(void *vdev, void *req, uint64_t sector, size_t nsectors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_handle_read(void *vdev, void *req, uint64_t sector, size_t nsectors) "vdev %p req %p sector %"PRIu64" nsectors %zu" virtio_blk_submit_multireq(void *vdev, void *mrb, int start, int num_reqs, uint64_t offset, size_t size, bool is_write) "vdev %p mrb %p start %d num_reqs %d offset %"PRIu64" size %zu is_write %d" +virtio_blk_handle_zone_report(void *vdev, void *req, int64_t sector, unsigned int nr_zones) "vdev %p req %p sector 0x%" PRIx64 " nr_zones %u" +virtio_blk_handle_zone_mgmt(void *vdev, void *req, uint8_t op, int64_t sector, int64_t len) "vdev %p req %p op 0x%x sector 0x%" PRIx64 " len 0x%" PRIx64 "" +virtio_blk_handle_zone_reset_all(void *vdev, void *req, int64_t sector, int64_t len) "vdev %p req %p sector 0x%" PRIx64 " cap 0x%" PRIx64 "" +virtio_blk_handle_zone_append(void *vdev, void *req, int64_t sector) "vdev %p req %p, append sector 0x%" PRIx64 "" # hd-geometry.c hd_geometry_lchs_guess(void *blk, int cyls, int heads, int secs) "blk %p LCHS %d %d %d"
Signature · 1 line
2.40.1
[PULL v2 12/16] block: add some trace events for zone append
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Message-id: [email protected]
--- block/file-posix.c | 3 +++ block/trace-events | 2 ++ 2 files changed, 5 insertions(+)
block/file-posix.c +3 -0
@@ -2513,6 +2513,8 @@ out:if (!BDRV_ZT_IS_CONV (*wp)) {if (type &QEMU_AIO_ZONE_APPEND ) { *s->offset = *wp; +trace_zbd_zone_append_complete (bs, *s->offset + >>BDRV_SECTOR_BITS ); }/* Advance the wp if needed */ if (offset + bytes > *wp) {
@@ -3554,6 +3556,7 @@ static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, len += iov_len; } +trace_zbd_zone_append (bs, *offset >>BDRV_SECTOR_BITS );return raw_co_prw (bs, *offset, len, qiov,QEMU_AIO_ZONE_APPEND ); }#endif
block/trace-events +2 -0
@@ -211,6 +211,8 @@ file_hdev_is_sg(int type, int version) "SG device found: type=%d, version=%d" file_flush_fdatasync_failed(int err) "errno %d" zbd_zone_report(void *bs, unsigned int nr_zones, int64_t sector) "bs %p report %d zones starting at sector offset 0x%" PRIx64 "" zbd_zone_mgmt(void *bs, const char *op_name, int64_t sector, int64_t len) "bs %p %s starts at sector offset 0x%" PRIx64 " over a range of 0x%" PRIx64 " sectors" +zbd_zone_append(void *bs, int64_t sector) "bs %p append at sector offset 0x%" PRIx64 "" +zbd_zone_append_complete(void *bs, int64_t sector) "bs %p returns append sector 0x%" PRIx64 "" # ssh.c sftp_error(const char *op, const char *ssh_err, int ssh_err_code, int sftp_err_code) "%s failed: %s (libssh error code: %d, sftp error code: %d)"
Signature · 1 line
2.40.1
[PULL v2 14/16] block: add accounting for zone append operation
In reply to Stefan HajnocziFrom: Sam Li <[email protected]>
Taking account of the new zone append write operation for zoned devices, BLOCK_ACCT_ZONE_APPEND enum is introduced as other I/O request type (read, write, flush).
Message-id: [email protected]
--- qapi/block-core.json | 68 ++++++++++++++++++++++++++++++++------ qapi/block.json | 4 +++ include/block/accounting.h | 1 + block/qapi-sysemu.c | 11 ++++++ block/qapi.c | 18 ++++++++++ hw/block/virtio-blk.c | 4 +++ tests/qemu-iotests/227.out | 18 ++++++++++ 7 files changed, 113 insertions(+), 11 deletions(-)
qapi/block-core.json +57 -11
@@ -854,6 +854,10 @@ # @min_wr_latency_ns: Minimum latency of write operations in the # defined interval, in nanoseconds. # +# @min_zone_append_latency_ns: Minimum latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @min_flush_latency_ns: Minimum latency of flush operations in the # defined interval, in nanoseconds. #
@@ -863,6 +867,10 @@ # @max_wr_latency_ns: Maximum latency of write operations in the # defined interval, in nanoseconds. # +# @max_zone_append_latency_ns: Maximum latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @max_flush_latency_ns: Maximum latency of flush operations in the # defined interval, in nanoseconds. #
@@ -872,6 +880,10 @@ # @avg_wr_latency_ns: Average latency of write operations in the # defined interval, in nanoseconds. # +# @avg_zone_append_latency_ns: Average latency of zone append operations +# in the defined interval, in nanoseconds +# (since 8.1) +# # @avg_flush_latency_ns: Average latency of flush operations in the # defined interval, in nanoseconds. #
@@ -881,15 +893,23 @@ # @avg_wr_queue_depth: Average number of pending write operations in # the defined interval. # +# @avg_zone_append_queue_depth: Average number of pending zone append +# operations in the defined interval +# (since 8.1). +# # Since: 2.5 ## { 'struct': 'BlockDeviceTimedStats', 'data': { 'interval_length': 'int', 'min_rd_latency_ns': 'int', 'max_rd_latency_ns': 'int', 'avg_rd_latency_ns': 'int', 'min_wr_latency_ns': 'int', 'max_wr_latency_ns': 'int', - 'avg_wr_latency_ns': 'int', 'min_flush_latency_ns': 'int', - 'max_flush_latency_ns': 'int', 'avg_flush_latency_ns': 'int', - 'avg_rd_queue_depth': 'number', 'avg_wr_queue_depth': 'number' } } + 'avg_wr_latency_ns': 'int', 'min_zone_append_latency_ns': 'int', + 'max_zone_append_latency_ns': 'int', + 'avg_zone_append_latency_ns': 'int', + 'min_flush_latency_ns': 'int', 'max_flush_latency_ns': 'int', + 'avg_flush_latency_ns': 'int', 'avg_rd_queue_depth': 'number', + 'avg_wr_queue_depth': 'number', + 'avg_zone_append_queue_depth': 'number' } } ## # @BlockDeviceStats:
@@ -900,6 +920,9 @@ # # @wr_bytes: The number of bytes written by the device. # +# @zone_append_bytes: The number of bytes appended by the zoned devices +# (since 8.1) +# # @unmap_bytes: The number of bytes unmapped by the device (Since 4.2) # # @rd_operations: The number of read operations performed by the
@@ -908,6 +931,9 @@ # @wr_operations: The number of write operations performed by the # device. # +# @zone_append_operations: The number of zone append operations performed +# by the zoned devices (since 8.1) +# # @flush_operations: The number of cache flush operations performed by # the device (since 0.15) #
@@ -920,6 +946,9 @@ # @wr_total_time_ns: Total time spent on writes in nanoseconds (since # 0.15). # +# @zone_append_total_time_ns: Total time spent on zone append writes +# in nanoseconds (since 8.1) +# # @flush_total_time_ns: Total time spent on cache flushes in # nanoseconds (since 0.15). #
@@ -937,6 +966,9 @@ # @wr_merged: Number of write requests that have been merged into # another request (Since 2.3). # +# @zone_append_merged: Number of zone append requests that have been merged +# into another request (since 8.1) +# # @unmap_merged: Number of unmap requests that have been merged into # another request (Since 4.2) #
@@ -950,6 +982,10 @@ # @failed_wr_operations: The number of failed write operations # performed by the device (Since 2.5) # +# @failed_zone_append_operations: The number of failed zone append write +# operations performed by the zoned devices +# (since 8.1) +# # @failed_flush_operations: The number of failed flush operations # performed by the device (Since 2.5) #
@@ -962,6 +998,9 @@ # @invalid_wr_operations: The number of invalid write operations # performed by the device (Since 2.5) # +# @invalid_zone_append_operations: The number of invalid zone append operations +# performed by the zoned device (since 8.1) +# # @invalid_flush_operations: The number of invalid flush operations # performed by the device (Since 2.5) #
@@ -981,27 +1020,34 @@ # # @wr_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) # +# @zone_append_latency_histogram: @BlockLatencyHistogramInfo. (since 8.1) +# # @flush_latency_histogram: @BlockLatencyHistogramInfo. (Since 4.0) # # Since: 0.14 ## { 'struct': 'BlockDeviceStats', - 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'unmap_bytes' : 'int', - 'rd_operations': 'int', 'wr_operations': 'int', + 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'zone_append_bytes': 'int', + 'unmap_bytes' : 'int', 'rd_operations': 'int', + 'wr_operations': 'int', 'zone_append_operations': 'int', 'flush_operations': 'int', 'unmap_operations': 'int', 'rd_total_time_ns': 'int', 'wr_total_time_ns': 'int', - 'flush_total_time_ns': 'int', 'unmap_total_time_ns': 'int', - 'wr_highest_offset': 'int', - 'rd_merged': 'int', 'wr_merged': 'int', 'unmap_merged': 'int', - '*idle_time_ns': 'int', + 'zone_append_total_time_ns': 'int', 'flush_total_time_ns': 'int', + 'unmap_total_time_ns': 'int', 'wr_highest_offset': 'int', + 'rd_merged': 'int', 'wr_merged': 'int', 'zone_append_merged': 'int', + 'unmap_merged': 'int', '*idle_time_ns': 'int', 'failed_rd_operations': 'int', 'failed_wr_operations': 'int', - 'failed_flush_operations': 'int', 'failed_unmap_operations': 'int', - 'invalid_rd_operations': 'int', 'invalid_wr_operations': 'int', + 'failed_zone_append_operations': 'int', + 'failed_flush_operations': 'int', + 'failed_unmap_operations': 'int', 'invalid_rd_operations': 'int', + 'invalid_wr_operations': 'int', + 'invalid_zone_append_operations': 'int', 'invalid_flush_operations': 'int', 'invalid_unmap_operations': 'int', 'account_invalid': 'bool', 'account_failed': 'bool', 'timed_stats': ['BlockDeviceTimedStats'], '*rd_latency_histogram': 'BlockLatencyHistogramInfo', '*wr_latency_histogram': 'BlockLatencyHistogramInfo', + '*zone_append_latency_histogram': 'BlockLatencyHistogramInfo', '*flush_latency_histogram': 'BlockLatencyHistogramInfo' } } ##
qapi/block.json +4 -0
@@ -534,6 +534,9 @@ # @boundaries-write: list of interval boundary values for write # latency histogram. # +# @boundaries-zap: list of interval boundary values for zone append write +# latency histogram. +# # @boundaries-flush: list of interval boundary values for flush # latency histogram. #
@@ -587,5 +590,6 @@ '*boundaries': ['uint64'], '*boundaries-read': ['uint64'], '*boundaries-write': ['uint64'], + '*boundaries-zap': ['uint64'], '*boundaries-flush': ['uint64'] }, 'allow-preconfig': true }
include/block/accounting.h +1 -0
@@ -37,6 +37,7 @@ enum BlockAcctType {BLOCK_ACCT_READ ,BLOCK_ACCT_WRITE ,BLOCK_ACCT_FLUSH , +BLOCK_ACCT_ZONE_APPEND ,BLOCK_ACCT_UNMAP , BLOCK_MAX_IOTYPE, };
block/qapi-sysemu.c +11 -0
@@ -517,6 +517,7 @@ void qmp_block_latency_histogram_set( bool has_boundaries, uint64List *boundaries, bool has_boundaries_read, uint64List *boundaries_read, bool has_boundaries_write, uint64List *boundaries_write, + bool has_boundaries_append, uint64List *boundaries_append, bool has_boundaries_flush, uint64List *boundaries_flush, Error **errp) {
@@ -557,6 +558,16 @@ void qmp_block_latency_histogram_set( } } +if (has_boundaries || has_boundaries_append) { + ret =block_latency_histogram_set ( + stats,BLOCK_ACCT_ZONE_APPEND , + has_boundaries_append ? boundaries_append : boundaries); +if (ret) { +error_setg (errp,"Device '%s' set append write boundaries fail" , id); +return ; + } + } +if (has_boundaries || has_boundaries_flush) { ret = block_latency_histogram_set( stats, BLOCK_ACCT_FLUSH,
block/qapi.c +18 -0
@@ -533,27 +533,36 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ ]; ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE ]; + ds->zone_append_bytes = stats->nr_bytes[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_bytes = stats->nr_bytes[BLOCK_ACCT_UNMAP ]; ds->rd_operations = stats->nr_ops[BLOCK_ACCT_READ ]; ds->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE ]; + ds->zone_append_operations = stats->nr_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_operations = stats->nr_ops[BLOCK_ACCT_UNMAP ]; ds->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ ]; ds->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE ]; + ds->failed_zone_append_operations = + stats->failed_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH ]; ds->failed_unmap_operations = stats->failed_ops[BLOCK_ACCT_UNMAP ]; ds->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ ]; ds->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE ]; + ds->invalid_zone_append_operations = + stats->invalid_ops[BLOCK_ACCT_ZONE_APPEND ]; ds->invalid_flush_operations = stats->invalid_ops[BLOCK_ACCT_FLUSH ]; ds->invalid_unmap_operations = stats->invalid_ops[BLOCK_ACCT_UNMAP ]; ds->rd_merged = stats->merged[BLOCK_ACCT_READ ]; ds->wr_merged = stats->merged[BLOCK_ACCT_WRITE ]; + ds->zone_append_merged = stats->merged[BLOCK_ACCT_ZONE_APPEND ]; ds->unmap_merged = stats->merged[BLOCK_ACCT_UNMAP ]; ds->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH ]; ds->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE ]; + ds->zone_append_total_time_ns = + stats->total_time_ns[BLOCK_ACCT_ZONE_APPEND ]; ds->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ ]; ds->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH ]; ds->unmap_total_time_ns = stats->total_time_ns[BLOCK_ACCT_UNMAP ];
@@ -571,6 +580,7 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)TimedAverage *rd = &ts->latency[BLOCK_ACCT_READ ];TimedAverage *wr = &ts->latency[BLOCK_ACCT_WRITE ]; +TimedAverage *zap = &ts->latency[BLOCK_ACCT_ZONE_APPEND ];TimedAverage *fl = &ts->latency[BLOCK_ACCT_FLUSH ]; dev_stats->interval_length = ts->interval_length;
@@ -583,6 +593,10 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) dev_stats->max_wr_latency_ns =timed_average_max (wr); dev_stats->avg_wr_latency_ns =timed_average_avg (wr); + dev_stats->min_zone_append_latency_ns =timed_average_min (zap); + dev_stats->max_zone_append_latency_ns =timed_average_max (zap); + dev_stats->avg_zone_append_latency_ns =timed_average_avg (zap); + dev_stats->min_flush_latency_ns =timed_average_min (fl); dev_stats->max_flush_latency_ns =timed_average_max (fl); dev_stats->avg_flush_latency_ns =timed_average_avg (fl);
@@ -591,6 +605,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)block_acct_queue_depth (ts,BLOCK_ACCT_READ ); dev_stats->avg_wr_queue_depth =block_acct_queue_depth (ts,BLOCK_ACCT_WRITE ); + dev_stats->avg_zone_append_queue_depth = +block_acct_queue_depth (ts,BLOCK_ACCT_ZONE_APPEND );QAPI_LIST_PREPEND (ds->timed_stats, dev_stats); }
@@ -600,6 +616,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) = bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_READ]); ds->wr_latency_histogram =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_WRITE ]); + ds->zone_append_latency_histogram + =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_ZONE_APPEND ]); ds->flush_latency_histogram =bdrv_latency_histogram_stats (&hgram[BLOCK_ACCT_FLUSH ]); }
hw/block/virtio-blk.c +4 -0
@@ -919,6 +919,10 @@ static int virtio_blk_handle_zone_append(VirtIOBlockReq *req, data->in_num = in_num; data->zone_append_data.offset = offset;qemu_iovec_init_external (&req->qiov, out_iov, out_num); + +block_acct_start (blk_get_stats (s->blk), &req->acct, len, +BLOCK_ACCT_ZONE_APPEND ); +blk_aio_zone_append (s->blk, &data->zone_append_data.offset, &req->qiov,0 , virtio_blk_zone_append_complete, data);return 0 ;
tests/qemu-iotests/227.out +18 -0
@@ -17,6 +17,7 @@ Testing: -drive driver=null-co,read-zeroes=on,if=virtio "stats": { "unmap_operations": 0, "unmap_merged": 0, + "failed_zone_append_operations": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0,
@@ -27,6 +28,7 @@ Testing: -drive driver=null-co,read-zeroes=on,if=virtio "timed_stats": [ ], "failed_unmap_operations": 0, + "zone_append_merged": 0, "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0,
@@ -39,7 +41,11 @@ Testing: -drive driver=null-co,read-zeroes=on,if=virtio "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": true, + "zone_append_total_time_ns": 0, + "zone_append_operations": 0, "rd_operations": 0, + "zone_append_bytes": 0, + "invalid_zone_append_operations": 0, "invalid_wr_operations": 0, "invalid_rd_operations": 0 },
@@ -82,6 +88,7 @@ Testing: -drive driver=null-co,if=none "stats": { "unmap_operations": 0, "unmap_merged": 0, + "failed_zone_append_operations": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0,
@@ -92,6 +99,7 @@ Testing: -drive driver=null-co,if=none "timed_stats": [ ], "failed_unmap_operations": 0, + "zone_append_merged": 0, "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0,
@@ -104,7 +112,11 @@ Testing: -drive driver=null-co,if=none "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": true, + "zone_append_total_time_ns": 0, + "zone_append_operations": 0, "rd_operations": 0, + "zone_append_bytes": 0, + "invalid_zone_append_operations": 0, "invalid_wr_operations": 0, "invalid_rd_operations": 0 },
@@ -177,6 +189,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-b "stats": { "unmap_operations": 0, "unmap_merged": 0, + "failed_zone_append_operations": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0,
@@ -187,6 +200,7 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-b "timed_stats": [ ], "failed_unmap_operations": 0, + "zone_append_merged": 0, "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0,
@@ -199,7 +213,11 @@ Testing: -blockdev driver=null-co,read-zeroes=on,node-name=null -device virtio-b "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": true, + "zone_append_total_time_ns": 0, + "zone_append_operations": 0, "rd_operations": 0, + "zone_append_bytes": 0, + "invalid_zone_append_operations": 0, "invalid_wr_operations": 0, "invalid_rd_operations": 0 },
Signature · 1 line
2.40.1
Richard Henderson
AppliedQuoted 12 lines · Stefan Hajnoczi
The following changes since commit
8844bb8d896595ee1d25d21c770e6e6f29803097:Merge tag 'or1k-pull-request-20230513' ofhttps://github.com/stffrdhrn/qemu into staging (2023-05-13 11:23:14 +0100)are available in the Git repository at:
https://gitlab.com/stefanha/qemu.git tags/block-pull-request
for you to fetch changes up to
01562fee5f3ad4506d57dbcf4b1903b565eceec7:docs/zoned-storage:add zoned emulation use case (2023-05-15 08:19:04 -0400)
Quoted 8 lines
----------------------------------------------------------------
Pull requestThis pull request contain's Sam Li's zoned storage support in the QEMU block layer and virtio-blk emulation.
v2:
- Sam fixed the CI failures. CI passes for me now. [Richard]
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~