From patchwork Wed Dec 7 12:10:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 129947 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0E1E21007D1 for ; Wed, 7 Dec 2011 23:11:35 +1100 (EST) Received: from localhost ([::1]:54209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGLT-0003Ic-Pm for incoming@patchwork.ozlabs.org; Wed, 07 Dec 2011 07:11:31 -0500 Received: from eggs.gnu.org ([140.186.70.92]:60017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGL9-0002Vg-OW for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYGL8-0005JW-KC for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:11 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:49193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYGL8-0005J9-8i for qemu-devel@nongnu.org; Wed, 07 Dec 2011 07:11:10 -0500 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 7 Dec 2011 12:11:09 -0000 Received: from d06nrmr1407.portsmouth.uk.ibm.com ([9.149.38.185]) by e06smtp11.uk.ibm.com ([192.168.101.141]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 7 Dec 2011 12:11:07 -0000 Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pB7CB60s2064540 for ; Wed, 7 Dec 2011 12:11:06 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pB7CB62p024439 for ; Wed, 7 Dec 2011 05:11:06 -0700 Received: from localhost (sig-9-145-136-175.de.ibm.com [9.145.136.175]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pB7CB5bM024400; Wed, 7 Dec 2011 05:11:06 -0700 From: Stefan Hajnoczi To: Date: Wed, 7 Dec 2011 12:10:59 +0000 Message-Id: <1323259859-8709-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1323259859-8709-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1323259859-8709-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 11120712-5024-0000-0000-0000010622B3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.107 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 3/3] qemu-io: add zero write detection option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- qemu-io.c | 29 ++++++++++++++++++++++------- 1 files changed, 22 insertions(+), 7 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index ffa62fb..1568870 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -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();