aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2009-07-10 13:33:47 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-07-10 12:25:36 -0500
commit9c4bab2668e6b5a9b69f77e3533380b6fd79034e (patch)
treee7abea856abc7fe883d06696ae253ca6daaa520e /qemu-io.c
parentqemu-io: better input validation for vector-based commands (diff)
downloadqemu-kvm-9c4bab2668e6b5a9b69f77e3533380b6fd79034e.tar.gz
qemu-kvm-9c4bab2668e6b5a9b69f77e3533380b6fd79034e.tar.bz2
qemu-kvm-9c4bab2668e6b5a9b69f77e3533380b6fd79034e.zip
qemu-io: add flag to mark files growable
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 <hch@lst.de> Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-io.c')
-rw-r--r--qemu-io.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/qemu-io.c b/qemu-io.c
index e6759dbc4..08c33f275 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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,17 @@ static int openfile(char *name, int flags)
return 1;
}
+
+ if (growable) {
+ if (!bs->drv || !bs->drv->protocol_name) {
+ fprintf(stderr,
+ "%s: only protocols can be opened growable\n",
+ progname);
+ return 1;
+ }
+ bs->growable = 1;
+ }
+
return 0;
}
@@ -1207,6 +1218,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 +1229,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 +1246,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 +1262,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 +1322,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 +1334,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 +1363,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 +1413,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();
/*