aboutsummaryrefslogtreecommitdiff
path: root/qemu-io-cmds.c
diff options
context:
space:
mode:
authorSam Li <faithilikerun@gmail.com>2023-05-08 13:15:09 +0800
committerStefan Hajnoczi <stefanha@redhat.com>2023-05-15 08:18:10 -0400
commitfe4fe70d27db31e4aa139387cdf66c23cace7fd3 (patch)
tree4e493183e080e7f24460ec63307807dca9b2be0d /qemu-io-cmds.c
parent4751d09adcc3dd76b4124f5c408055ee0940b3ee (diff)
qemu-iotests: test zone append operation
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. Signed-off-by: Sam Li <faithilikerun@gmail.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 20230508051510.177850-4-faithilikerun@gmail.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r--qemu-io-cmds.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index f35ea627d7..3f75d2f5a6 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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);