From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MN7Ya-00082R-9P for qemu-devel@nongnu.org; Sat, 04 Jul 2009 11:53:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MN7YV-0007yI-Id for qemu-devel@nongnu.org; Sat, 04 Jul 2009 11:53:39 -0400 Received: from [199.232.76.173] (port=50233 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MN7YV-0007y9-Al for qemu-devel@nongnu.org; Sat, 04 Jul 2009 11:53:35 -0400 Received: from verein.lst.de ([213.95.11.210]:33635) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MN7YU-0005b6-QG for qemu-devel@nongnu.org; Sat, 04 Jul 2009 11:53:35 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id n64FrU68004972 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Sat, 4 Jul 2009 17:53:31 +0200 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id n64FrUfr004971 for qemu-devel@nongnu.org; Sat, 4 Jul 2009 17:53:30 +0200 Date: Sat, 4 Jul 2009 17:53:30 +0200 From: Christoph Hellwig Message-ID: <20090704155330.GA4825@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] qemu-io: add flag to mark files growable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Add a -g flag to the open command and the main qemu-io command line to allow opening a file growable. This is only allowed for protocols, mirroring the limitation exposed through bdrv_file_open. Signed-off-by: Christoph Hellwig Index: qemu/qemu-io.c =================================================================== --- qemu.orig/qemu-io.c 2009-07-04 17:42:16.505239002 +0200 +++ qemu/qemu-io.c 2009-07-04 17:52:26.432241152 +0200 @@ -1172,7 +1172,7 @@ static const cmdinfo_t close_cmd = { .oneline = "close the current open file", }; -static int openfile(char *name, int flags) +static int openfile(char *name, int flags, int growable) { if (bs) { fprintf(stderr, "file open already, try 'help close'\n"); @@ -1189,6 +1189,16 @@ static int openfile(char *name, int flag return 1; } + + if (growable) { + if (!bs->drv || !bs->drv->protocol_name) { + fprintf(stderr, + "%s: only protocols can be opened growable\n", + progname); + } + bs->growable = 1; + } + return 0; } @@ -1207,6 +1217,7 @@ open_help(void) " -r, -- open file read-only\n" " -s, -- use snapshot file\n" " -n, -- disable host cache\n" +" -g, -- allow file to grow (only applies to protocols)" "\n"); } @@ -1217,9 +1228,10 @@ open_f(int argc, char **argv) { int flags = 0; int readonly = 0; + int growable = 0; int c; - while ((c = getopt(argc, argv, "snCr")) != EOF) { + while ((c = getopt(argc, argv, "snCrg")) != EOF) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; @@ -1233,6 +1245,9 @@ open_f(int argc, char **argv) case 'r': readonly = 1; break; + case 'g': + growable = 1; + break; default: return command_usage(&open_cmd); } @@ -1246,7 +1261,7 @@ open_f(int argc, char **argv) if (optind != argc - 1) return command_usage(&open_cmd); - return openfile(argv[optind], flags); + return openfile(argv[optind], flags, growable); } static const cmdinfo_t open_cmd = { @@ -1306,7 +1321,8 @@ static void usage(const char *name) int main(int argc, char **argv) { int readonly = 0; - const char *sopt = "hVc:Crsnm"; + int growable = 0; + const char *sopt = "hVc:Crsnmg"; struct option lopt[] = { { "help", 0, 0, 'h' }, { "version", 0, 0, 'V' }, @@ -1317,6 +1333,7 @@ int main(int argc, char **argv) { "snapshot", 0, 0, 's' }, { "nocache", 0, 0, 'n' }, { "misalign", 0, 0, 'm' }, + { "growable", 0, 0, 'g' }, { NULL, 0, 0, 0 } }; int c; @@ -1345,6 +1362,9 @@ int main(int argc, char **argv) case 'm': misalign = 1; break; + case 'g': + growable = 1; + break; case 'V': printf("%s version %s\n", progname, VERSION); exit(0); @@ -1392,7 +1412,7 @@ int main(int argc, char **argv) flags |= BDRV_O_RDWR; if ((argc - optind) == 1) - openfile(argv[optind], flags); + openfile(argv[optind], flags, growable); command_loop(); /*