qemu-io: Add 'write -z -u' to test MAY_UNMAP flag

Make it easier to control whether the BDRV_REQ_MAY_UNMAP flag
can be passed through a write_zeroes command, by adding the '-u'
flag to qemu-io 'write -z' and 'aio_write -z'.  To be useful,
the device has to be opened with BDRV_O_UNMAP (done by default
in qemu-io, but can be made explicit with '-d unmap').

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-id: 1462677405-4752-7-git-send-email-eblake@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Eric Blake 2016-05-07 21:16:45 -06:00 committed by Max Reitz
parent 770e0e0e80
commit c2e001cc82

View File

@ -943,6 +943,7 @@ static void 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"
" -u, -- with -z, allow unmapping\n"
" -z, -- write zeroes using blk_co_write_zeroes\n" " -z, -- write zeroes using blk_co_write_zeroes\n"
"\n"); "\n");
} }
@ -955,7 +956,7 @@ static const cmdinfo_t write_cmd = {
.cfunc = write_f, .cfunc = write_f,
.argmin = 2, .argmin = 2,
.argmax = -1, .argmax = -1,
.args = "[-bcCfqz] [-P pattern] off len", .args = "[-bcCfquz] [-P pattern] off len",
.oneline = "writes a number of bytes at a specified offset", .oneline = "writes a number of bytes at a specified offset",
.help = write_help, .help = write_help,
}; };
@ -974,7 +975,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
int64_t total = 0; int64_t total = 0;
int pattern = 0xcd; int pattern = 0xcd;
while ((c = getopt(argc, argv, "bcCfpP:qz")) != -1) { while ((c = getopt(argc, argv, "bcCfpP:quz")) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
bflag = true; bflag = true;
@ -1001,6 +1002,9 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
case 'q': case 'q':
qflag = true; qflag = true;
break; break;
case 'u':
flags |= BDRV_REQ_MAY_UNMAP;
break;
case 'z': case 'z':
zflag = true; zflag = true;
break; break;
@ -1023,6 +1027,11 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
return 0; return 0;
} }
if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {
printf("-u requires -z to be specified\n");
return 0;
}
if (zflag && Pflag) { if (zflag && Pflag) {
printf("-z and -P cannot be specified at the same time\n"); printf("-z and -P cannot be specified at the same time\n");
return 0; return 0;
@ -1561,6 +1570,7 @@ static void aio_write_help(void)
" -C, -- report statistics in a machine parsable format\n" " -C, -- report statistics in a machine parsable format\n"
" -f, -- use Force Unit Access semantics\n" " -f, -- use Force Unit Access semantics\n"
" -q, -- quiet mode, do not show I/O statistics\n" " -q, -- quiet mode, do not show I/O statistics\n"
" -u, -- with -z, allow unmapping\n"
" -z, -- write zeroes using blk_aio_write_zeroes\n" " -z, -- write zeroes using blk_aio_write_zeroes\n"
"\n"); "\n");
} }
@ -1572,7 +1582,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 = "[-Cfqz] [-P pattern] off len [len..]", .args = "[-Cfquz] [-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,
}; };
@ -1596,6 +1606,9 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
case 'q': case 'q':
ctx->qflag = true; ctx->qflag = true;
break; break;
case 'u':
flags |= BDRV_REQ_MAY_UNMAP;
break;
case 'P': case 'P':
pattern = parse_pattern(optarg); pattern = parse_pattern(optarg);
if (pattern < 0) { if (pattern < 0) {
@ -1623,6 +1636,11 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
return 0; return 0;
} }
if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
printf("-u requires -z to be specified\n");
return 0;
}
if (ctx->zflag && ctx->Pflag) { if (ctx->zflag && ctx->Pflag) {
printf("-z and -P cannot be specified at the same time\n"); printf("-z and -P cannot be specified at the same time\n");
g_free(ctx); g_free(ctx);