@@ -1594,7 +1594,7 @@ static const cmdinfo_t close_cmd = {
.oneline = "close the current open file",
};
-static int openfile(char *name, int flags, int growable)
+static int openfile(char *name, int flags, int growable, int detect_zeroes)
{
if (bs) {
fprintf(stderr, "file open already, try 'help close'\n");
@@ -1617,6 +1617,10 @@ static int openfile(char *name, int flags, int growable)
}
}
+ if (detect_zeroes) {
+ bdrv_enable_zero_detection(bs);
+ }
+
return 0;
}
@@ -1634,6 +1638,7 @@ static void open_help(void)
" -s, -- use snapshot file\n"
" -n, -- disable host cache\n"
" -g, -- allow file to grow (only applies to protocols)"
+" -z -- use zero write detection (supported formats only)\n"
"\n");
}
@@ -1646,7 +1651,7 @@ static const cmdinfo_t open_cmd = {
.argmin = 1,
.argmax = -1,
.flags = CMD_NOFILE_OK,
- .args = "[-Crsn] [path]",
+ .args = "[-Crsnz] [path]",
.oneline = "open the file specified by path",
.help = open_help,
};
@@ -1656,9 +1661,10 @@ static int open_f(int argc, char **argv)
int flags = 0;
int readonly = 0;
int growable = 0;
+ int detect_zeroes = 0;
int c;
- while ((c = getopt(argc, argv, "snrg")) != EOF) {
+ while ((c = getopt(argc, argv, "snrgz")) != EOF) {
switch (c) {
case 's':
flags |= BDRV_O_SNAPSHOT;
@@ -1672,6 +1678,9 @@ static int open_f(int argc, char **argv)
case 'g':
growable = 1;
break;
+ case 'z':
+ detect_zeroes = 1;
+ break;
default:
return command_usage(&open_cmd);
}
@@ -1685,7 +1694,7 @@ static int open_f(int argc, char **argv)
return command_usage(&open_cmd);
}
- return openfile(argv[optind], flags, growable);
+ return openfile(argv[optind], flags, growable, detect_zeroes);
}
static int init_args_command(int index)
@@ -1712,7 +1721,7 @@ static int init_check_command(const cmdinfo_t *ct)
static void usage(const char *name)
{
printf(
-"Usage: %s [-h] [-V] [-rsnm] [-c cmd] ... [file]\n"
+"Usage: %s [-h] [-V] [-rsnmkz] [-c cmd] ... [file]\n"
"QEMU Disk exerciser\n"
"\n"
" -c, --cmd command to execute\n"
@@ -1722,6 +1731,7 @@ static void usage(const char *name)
" -g, --growable allow file to grow (only applies to protocols)\n"
" -m, --misalign misalign allocations for O_DIRECT\n"
" -k, --native-aio use kernel AIO implementation (on Linux only)\n"
+" -z, --detect-zeroes use zero write detection (supported formats only)\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n"
"\n",
@@ -1733,7 +1743,8 @@ int main(int argc, char **argv)
{
int readonly = 0;
int growable = 0;
- const char *sopt = "hVc:rsnmgk";
+ int detect_zeroes = 0;
+ const char *sopt = "hVc:rsnmgkz";
const struct option lopt[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
@@ -1745,6 +1756,7 @@ int main(int argc, char **argv)
{ "misalign", 0, NULL, 'm' },
{ "growable", 0, NULL, 'g' },
{ "native-aio", 0, NULL, 'k' },
+ { "detect-zeroes", 0, NULL, 'z' },
{ NULL, 0, NULL, 0 }
};
int c;
@@ -1776,6 +1788,9 @@ int main(int argc, char **argv)
case 'k':
flags |= BDRV_O_NATIVE_AIO;
break;
+ case 'z':
+ detect_zeroes = 1;
+ break;
case 'V':
printf("%s version %s\n", progname, VERSION);
exit(0);
@@ -1825,7 +1840,7 @@ int main(int argc, char **argv)
}
if ((argc - optind) == 1) {
- openfile(argv[optind], flags, growable);
+ openfile(argv[optind], flags, growable, detect_zeroes);
}
command_loop();
Add a -z option to qemu-io and the 'open' command to enable zero write detection. This is used by the qemu-iotests 029 test case and allows scripts to exercise zero write detection. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> --- qemu-io.c | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-)