Skip to content

Commit fe4fe70

Browse files
sgzerolcstefanhaRH
authored andcommitted
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 <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Message-id: [email protected] Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent 4751d09 commit fe4fe70

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

qemu-io-cmds.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,80 @@ static const cmdinfo_t zone_reset_cmd = {
18741874
.oneline = "reset a zone write pointer in zone block device",
18751875
};
18761876

1877+
static int do_aio_zone_append(BlockBackend *blk, QEMUIOVector *qiov,
1878+
int64_t *offset, int flags, int *total)
1879+
{
1880+
int async_ret = NOT_DONE;
1881+
1882+
blk_aio_zone_append(blk, offset, qiov, flags, aio_rw_done, &async_ret);
1883+
while (async_ret == NOT_DONE) {
1884+
main_loop_wait(false);
1885+
}
1886+
1887+
*total = qiov->size;
1888+
return async_ret < 0 ? async_ret : 1;
1889+
}
1890+
1891+
static int zone_append_f(BlockBackend *blk, int argc, char **argv)
1892+
{
1893+
int ret;
1894+
bool pflag = false;
1895+
int flags = 0;
1896+
int total = 0;
1897+
int64_t offset;
1898+
char *buf;
1899+
int c, nr_iov;
1900+
int pattern = 0xcd;
1901+
QEMUIOVector qiov;
1902+
1903+
if (optind > argc - 3) {
1904+
return -EINVAL;
1905+
}
1906+
1907+
if ((c = getopt(argc, argv, "p")) != -1) {
1908+
pflag = true;
1909+
}
1910+
1911+
offset = cvtnum(argv[optind]);
1912+
if (offset < 0) {
1913+
print_cvtnum_err(offset, argv[optind]);
1914+
return offset;
1915+
}
1916+
optind++;
1917+
nr_iov = argc - optind;
1918+
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern,
1919+
flags & BDRV_REQ_REGISTERED_BUF);
1920+
if (buf == NULL) {
1921+
return -EINVAL;
1922+
}
1923+
ret = do_aio_zone_append(blk, &qiov, &offset, flags, &total);
1924+
if (ret < 0) {
1925+
printf("zone append failed: %s\n", strerror(-ret));
1926+
goto out;
1927+
}
1928+
1929+
if (pflag) {
1930+
printf("After zap done, the append sector is 0x%" PRIx64 "\n",
1931+
tosector(offset));
1932+
}
1933+
1934+
out:
1935+
qemu_io_free(blk, buf, qiov.size,
1936+
flags & BDRV_REQ_REGISTERED_BUF);
1937+
qemu_iovec_destroy(&qiov);
1938+
return ret;
1939+
}
1940+
1941+
static const cmdinfo_t zone_append_cmd = {
1942+
.name = "zone_append",
1943+
.altname = "zap",
1944+
.cfunc = zone_append_f,
1945+
.argmin = 3,
1946+
.argmax = 4,
1947+
.args = "offset len [len..]",
1948+
.oneline = "append write a number of bytes at a specified offset",
1949+
};
1950+
18771951
static int truncate_f(BlockBackend *blk, int argc, char **argv);
18781952
static const cmdinfo_t truncate_cmd = {
18791953
.name = "truncate",
@@ -2672,6 +2746,7 @@ static void __attribute((constructor)) init_qemuio_commands(void)
26722746
qemuio_add_command(&zone_close_cmd);
26732747
qemuio_add_command(&zone_finish_cmd);
26742748
qemuio_add_command(&zone_reset_cmd);
2749+
qemuio_add_command(&zone_append_cmd);
26752750
qemuio_add_command(&truncate_cmd);
26762751
qemuio_add_command(&length_cmd);
26772752
qemuio_add_command(&info_cmd);

tests/qemu-iotests/tests/zoned

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ echo "(5) resetting the second zone"
8282
$QEMU_IO $IMG -c "zrs 268435456 268435456"
8383
echo "After resetting a zone:"
8484
$QEMU_IO $IMG -c "zrp 268435456 1"
85+
echo
86+
echo
87+
echo "(6) append write" # the physical block size of the device is 4096
88+
$QEMU_IO $IMG -c "zrp 0 1"
89+
$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000"
90+
echo "After appending the first zone firstly:"
91+
$QEMU_IO $IMG -c "zrp 0 1"
92+
$QEMU_IO $IMG -c "zap -p 0 0x1000 0x2000"
93+
echo "After appending the first zone secondly:"
94+
$QEMU_IO $IMG -c "zrp 0 1"
95+
$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000"
96+
echo "After appending the second zone firstly:"
97+
$QEMU_IO $IMG -c "zrp 268435456 1"
98+
$QEMU_IO $IMG -c "zap -p 268435456 0x1000 0x2000"
99+
echo "After appending the second zone secondly:"
100+
$QEMU_IO $IMG -c "zrp 268435456 1"
85101

86102
# success, all done
87103
echo "*** done"

tests/qemu-iotests/tests/zoned.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,20 @@ start: 0x80000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:14, [type: 2]
5050
(5) resetting the second zone
5151
After resetting a zone:
5252
start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2]
53+
54+
55+
(6) append write
56+
start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2]
57+
After zap done, the append sector is 0x0
58+
After appending the first zone firstly:
59+
start: 0x0, len 0x80000, cap 0x80000, wptr 0x18, zcond:2, [type: 2]
60+
After zap done, the append sector is 0x18
61+
After appending the first zone secondly:
62+
start: 0x0, len 0x80000, cap 0x80000, wptr 0x30, zcond:2, [type: 2]
63+
After zap done, the append sector is 0x80000
64+
After appending the second zone firstly:
65+
start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80018, zcond:2, [type: 2]
66+
After zap done, the append sector is 0x80018
67+
After appending the second zone secondly:
68+
start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80030, zcond:2, [type: 2]
5369
*** done

0 commit comments

Comments
 (0)