mirror of https://github.com/xemu-project/xemu.git
qemu-io: Support 'aio_write -z'
This allows testing blk_aio_write_zeroes(). Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
538a467329
commit
5ceb77652e
|
@ -1416,6 +1416,7 @@ struct aio_ctx {
|
||||||
int vflag;
|
int vflag;
|
||||||
int Cflag;
|
int Cflag;
|
||||||
int Pflag;
|
int Pflag;
|
||||||
|
int zflag;
|
||||||
BlockAcctCookie acct;
|
BlockAcctCookie acct;
|
||||||
int pattern;
|
int pattern;
|
||||||
struct timeval t1;
|
struct timeval t1;
|
||||||
|
@ -1446,8 +1447,10 @@ static void aio_write_done(void *opaque, int ret)
|
||||||
print_report("wrote", &t2, ctx->offset, ctx->qiov.size,
|
print_report("wrote", &t2, ctx->offset, ctx->qiov.size,
|
||||||
ctx->qiov.size, 1, ctx->Cflag);
|
ctx->qiov.size, 1, ctx->Cflag);
|
||||||
out:
|
out:
|
||||||
qemu_io_free(ctx->buf);
|
if (!ctx->zflag) {
|
||||||
qemu_iovec_destroy(&ctx->qiov);
|
qemu_io_free(ctx->buf);
|
||||||
|
qemu_iovec_destroy(&ctx->qiov);
|
||||||
|
}
|
||||||
g_free(ctx);
|
g_free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1612,6 +1615,7 @@ static void aio_write_help(void)
|
||||||
" -P, -- use different pattern to fill file\n"
|
" -P, -- use different pattern to fill file\n"
|
||||||
" -C, -- report statistics in a machine parsable format\n"
|
" -C, -- report statistics in a machine parsable format\n"
|
||||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||||
|
" -z, -- write zeroes using blk_aio_write_zeroes\n"
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1622,7 +1626,7 @@ static const cmdinfo_t aio_write_cmd = {
|
||||||
.cfunc = aio_write_f,
|
.cfunc = aio_write_f,
|
||||||
.argmin = 2,
|
.argmin = 2,
|
||||||
.argmax = -1,
|
.argmax = -1,
|
||||||
.args = "[-Cq] [-P pattern ] off len [len..]",
|
.args = "[-Cqz] [-P pattern ] off len [len..]",
|
||||||
.oneline = "asynchronously writes a number of bytes",
|
.oneline = "asynchronously writes a number of bytes",
|
||||||
.help = aio_write_help,
|
.help = aio_write_help,
|
||||||
};
|
};
|
||||||
|
@ -1634,7 +1638,7 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||||
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
|
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
|
||||||
|
|
||||||
ctx->blk = blk;
|
ctx->blk = blk;
|
||||||
while ((c = getopt(argc, argv, "CqP:")) != -1) {
|
while ((c = getopt(argc, argv, "CqP:z")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'C':
|
case 'C':
|
||||||
ctx->Cflag = 1;
|
ctx->Cflag = 1;
|
||||||
|
@ -1649,6 +1653,9 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'z':
|
||||||
|
ctx->zflag = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
g_free(ctx);
|
g_free(ctx);
|
||||||
return qemuio_command_usage(&aio_write_cmd);
|
return qemuio_command_usage(&aio_write_cmd);
|
||||||
|
@ -1660,6 +1667,18 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||||
return qemuio_command_usage(&aio_write_cmd);
|
return qemuio_command_usage(&aio_write_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ctx->zflag && optind != argc - 2) {
|
||||||
|
printf("-z supports only a single length parameter\n");
|
||||||
|
g_free(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->zflag && ctx->Pflag) {
|
||||||
|
printf("-z and -P cannot be specified at the same time\n");
|
||||||
|
g_free(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ctx->offset = cvtnum(argv[optind]);
|
ctx->offset = cvtnum(argv[optind]);
|
||||||
if (ctx->offset < 0) {
|
if (ctx->offset < 0) {
|
||||||
print_cvtnum_err(ctx->offset, argv[optind]);
|
print_cvtnum_err(ctx->offset, argv[optind]);
|
||||||
|
@ -1676,19 +1695,33 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nr_iov = argc - optind;
|
if (ctx->zflag) {
|
||||||
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, pattern);
|
int64_t count = cvtnum(argv[optind]);
|
||||||
if (ctx->buf == NULL) {
|
if (count < 0) {
|
||||||
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
|
print_cvtnum_err(count, argv[optind]);
|
||||||
g_free(ctx);
|
return 0;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gettimeofday(&ctx->t1, NULL);
|
ctx->qiov.size = count;
|
||||||
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
|
blk_aio_write_zeroes(blk, ctx->offset >> 9, count >> 9, 0,
|
||||||
BLOCK_ACCT_WRITE);
|
aio_write_done, ctx);
|
||||||
blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
|
} else {
|
||||||
ctx->qiov.size >> 9, aio_write_done, ctx);
|
nr_iov = argc - optind;
|
||||||
|
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov,
|
||||||
|
pattern);
|
||||||
|
if (ctx->buf == NULL) {
|
||||||
|
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
|
||||||
|
g_free(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&ctx->t1, NULL);
|
||||||
|
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
|
||||||
|
BLOCK_ACCT_WRITE);
|
||||||
|
|
||||||
|
blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
|
||||||
|
ctx->qiov.size >> 9, aio_write_done, ctx);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue