@@ -1855,6 +1855,67 @@ 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;
+ int flags = 0;
+ int total = 0;
+ int64_t offset;
+ char *buf;
+ int nr_iov;
+ int pattern = 0xcd;
+ QEMUIOVector qiov;
+
+ if (optind > argc - 2) {
+ return -EINVAL;
+ }
+ optind++;
+ 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);
+ 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;
+ }
+
+ out:
+ qemu_iovec_destroy(&qiov);
+ qemu_io_free(buf);
+ return ret;
+}
+
+static const cmdinfo_t zone_append_cmd = {
+ .name = "zone_append",
+ .altname = "zap",
+ .cfunc = zone_append_f,
+ .argmin = 3,
+ .argmax = 3,
+ .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",
@@ -2652,6 +2713,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);
@@ -50,4 +50,11 @@ 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
+After appending the first zone:
+start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2]
+After appending the second zone:
+start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2]
*** done
@@ -79,6 +79,15 @@ echo "(5) resetting the second zone"
sudo $QEMU_IO $IMG -c "zrs 268435456 268435456"
echo "After resetting a zone:"
sudo $QEMU_IO $IMG -c "zrp 268435456 1"
+echo
+echo
+echo "(6) append write" # physical block size of the device is 4096
+sudo $QEMU_IO $IMG -c "zap 0 0x1000 0x2000"
+echo "After appending the first zone:"
+sudo $QEMU_IO $IMG -c "zrp 0 1"
+sudo $QEMU_IO $IMG -c "zap 268435456 0x1000 0x2000"
+echo "After appending the second zone:"
+sudo $QEMU_IO $IMG -c "zrp 268435456 1"
# success, all done
echo "*** done"
This tests is mainly a helper to indicate append writes in block layer behaves as expected. Signed-off-by: Sam Li <faithilikerun@gmail.com> --- qemu-io-cmds.c | 62 ++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/zoned.out | 7 ++++ tests/qemu-iotests/tests/zoned.sh | 9 +++++ 3 files changed, 78 insertions(+)