[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/3] qemu-io: add zero write detection option
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 3/3] qemu-io: add zero write detection option |
Date: |
Fri, 7 Oct 2011 16:49:49 +0100 |
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 <address@hidden>
---
qemu-io.c | 35 ++++++++++++++++++++++++++++-------
1 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/qemu-io.c b/qemu-io.c
index e91af37..94beaf6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1593,7 +1593,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");
@@ -1615,6 +1615,16 @@ static int openfile(char *name, int flags, int growable)
}
}
+ if (detect_zeroes) {
+ if (bdrv_set_zero_detection(bs, true) < 0) {
+ fprintf(stderr, "%s: format does not support zero detection\n",
+ progname);
+ bdrv_delete(bs);
+ bs = NULL;
+ return 1;
+ }
+ }
+
return 0;
}
@@ -1632,6 +1642,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");
}
@@ -1644,7 +1655,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,
};
@@ -1654,9 +1665,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;
@@ -1670,6 +1682,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);
}
@@ -1683,7 +1698,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)
@@ -1710,7 +1725,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"
@@ -1720,6 +1735,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",
@@ -1731,7 +1747,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' },
@@ -1743,6 +1760,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;
@@ -1774,6 +1792,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);
@@ -1823,7 +1844,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();
--
1.7.6.3