Commit 9c4bab2668e6b5a9b69f77e3533380b6fd79034e

Authored by Christoph Hellwig
Committed by Anthony Liguori
1 parent cf57298a

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>
Showing 1 changed file with 26 additions and 5 deletions
qemu-io.c
... ... @@ -1172,7 +1172,7 @@ static const cmdinfo_t close_cmd = {
1172 1172 .oneline = "close the current open file",
1173 1173 };
1174 1174  
1175   -static int openfile(char *name, int flags)
  1175 +static int openfile(char *name, int flags, int growable)
1176 1176 {
1177 1177 if (bs) {
1178 1178 fprintf(stderr, "file open already, try 'help close'\n");
... ... @@ -1189,6 +1189,17 @@ static int openfile(char *name, int flags)
1189 1189 return 1;
1190 1190 }
1191 1191  
  1192 +
  1193 + if (growable) {
  1194 + if (!bs->drv || !bs->drv->protocol_name) {
  1195 + fprintf(stderr,
  1196 + "%s: only protocols can be opened growable\n",
  1197 + progname);
  1198 + return 1;
  1199 + }
  1200 + bs->growable = 1;
  1201 + }
  1202 +
1192 1203 return 0;
1193 1204 }
1194 1205  
... ... @@ -1207,6 +1218,7 @@ open_help(void)
1207 1218 " -r, -- open file read-only\n"
1208 1219 " -s, -- use snapshot file\n"
1209 1220 " -n, -- disable host cache\n"
  1221 +" -g, -- allow file to grow (only applies to protocols)"
1210 1222 "\n");
1211 1223 }
1212 1224  
... ... @@ -1217,9 +1229,10 @@ open_f(int argc, char **argv)
1217 1229 {
1218 1230 int flags = 0;
1219 1231 int readonly = 0;
  1232 + int growable = 0;
1220 1233 int c;
1221 1234  
1222   - while ((c = getopt(argc, argv, "snCr")) != EOF) {
  1235 + while ((c = getopt(argc, argv, "snCrg")) != EOF) {
1223 1236 switch (c) {
1224 1237 case 's':
1225 1238 flags |= BDRV_O_SNAPSHOT;
... ... @@ -1233,6 +1246,9 @@ open_f(int argc, char **argv)
1233 1246 case 'r':
1234 1247 readonly = 1;
1235 1248 break;
  1249 + case 'g':
  1250 + growable = 1;
  1251 + break;
1236 1252 default:
1237 1253 return command_usage(&open_cmd);
1238 1254 }
... ... @@ -1246,7 +1262,7 @@ open_f(int argc, char **argv)
1246 1262 if (optind != argc - 1)
1247 1263 return command_usage(&open_cmd);
1248 1264  
1249   - return openfile(argv[optind], flags);
  1265 + return openfile(argv[optind], flags, growable);
1250 1266 }
1251 1267  
1252 1268 static const cmdinfo_t open_cmd = {
... ... @@ -1306,7 +1322,8 @@ static void usage(const char *name)
1306 1322 int main(int argc, char **argv)
1307 1323 {
1308 1324 int readonly = 0;
1309   - const char *sopt = "hVc:Crsnm";
  1325 + int growable = 0;
  1326 + const char *sopt = "hVc:Crsnmg";
1310 1327 struct option lopt[] = {
1311 1328 { "help", 0, 0, 'h' },
1312 1329 { "version", 0, 0, 'V' },
... ... @@ -1317,6 +1334,7 @@ int main(int argc, char **argv)
1317 1334 { "snapshot", 0, 0, 's' },
1318 1335 { "nocache", 0, 0, 'n' },
1319 1336 { "misalign", 0, 0, 'm' },
  1337 + { "growable", 0, 0, 'g' },
1320 1338 { NULL, 0, 0, 0 }
1321 1339 };
1322 1340 int c;
... ... @@ -1345,6 +1363,9 @@ int main(int argc, char **argv)
1345 1363 case 'm':
1346 1364 misalign = 1;
1347 1365 break;
  1366 + case 'g':
  1367 + growable = 1;
  1368 + break;
1348 1369 case 'V':
1349 1370 printf("%s version %s\n", progname, VERSION);
1350 1371 exit(0);
... ... @@ -1392,7 +1413,7 @@ int main(int argc, char **argv)
1392 1413 flags |= BDRV_O_RDWR;
1393 1414  
1394 1415 if ((argc - optind) == 1)
1395   - openfile(argv[optind], flags);
  1416 + openfile(argv[optind], flags, growable);
1396 1417 command_loop();
1397 1418  
1398 1419 /*
... ...