Commit 1585969c6e0e94ac9e67c126578a05aab1fa0218
1 parent
e97fc193
Introduce qemu-img check subcommand (Kevin Wolf)
From: Kevin Wolf <kwolf@redhat.com> Now that block drivers can provide check functions, expose them through qemu-img. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7215 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
62 additions
and
0 deletions
qemu-img.c
... | ... | @@ -58,6 +58,7 @@ static void help(void) |
58 | 58 | "QEMU disk image utility\n" |
59 | 59 | "\n" |
60 | 60 | "Command syntax:\n" |
61 | + " check [-f fmt] filename\n" | |
61 | 62 | " create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]\n" |
62 | 63 | " commit [-f fmt] filename\n" |
63 | 64 | " convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n" |
... | ... | @@ -315,6 +316,65 @@ static int img_create(int argc, char **argv) |
315 | 316 | return 0; |
316 | 317 | } |
317 | 318 | |
319 | +static int img_check(int argc, char **argv) | |
320 | +{ | |
321 | + int c, ret; | |
322 | + const char *filename, *fmt; | |
323 | + BlockDriver *drv; | |
324 | + BlockDriverState *bs; | |
325 | + | |
326 | + fmt = NULL; | |
327 | + for(;;) { | |
328 | + c = getopt(argc, argv, "f:h"); | |
329 | + if (c == -1) | |
330 | + break; | |
331 | + switch(c) { | |
332 | + case 'h': | |
333 | + help(); | |
334 | + break; | |
335 | + case 'f': | |
336 | + fmt = optarg; | |
337 | + break; | |
338 | + } | |
339 | + } | |
340 | + if (optind >= argc) | |
341 | + help(); | |
342 | + filename = argv[optind++]; | |
343 | + | |
344 | + bs = bdrv_new(""); | |
345 | + if (!bs) | |
346 | + error("Not enough memory"); | |
347 | + if (fmt) { | |
348 | + drv = bdrv_find_format(fmt); | |
349 | + if (!drv) | |
350 | + error("Unknown file format '%s'", fmt); | |
351 | + } else { | |
352 | + drv = NULL; | |
353 | + } | |
354 | + if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) { | |
355 | + error("Could not open '%s'", filename); | |
356 | + } | |
357 | + ret = bdrv_check(bs); | |
358 | + switch(ret) { | |
359 | + case 0: | |
360 | + printf("No errors were found on the image.\n"); | |
361 | + break; | |
362 | + case -ENOTSUP: | |
363 | + error("This image format does not support checks"); | |
364 | + break; | |
365 | + default: | |
366 | + if (ret < 0) { | |
367 | + error("An error occurred during the check"); | |
368 | + } else { | |
369 | + printf("%d errors were found on the image.\n", ret); | |
370 | + } | |
371 | + break; | |
372 | + } | |
373 | + | |
374 | + bdrv_delete(bs); | |
375 | + return 0; | |
376 | +} | |
377 | + | |
318 | 378 | static int img_commit(int argc, char **argv) |
319 | 379 | { |
320 | 380 | int c, ret; |
... | ... | @@ -888,6 +948,8 @@ int main(int argc, char **argv) |
888 | 948 | argc--; argv++; |
889 | 949 | if (!strcmp(cmd, "create")) { |
890 | 950 | img_create(argc, argv); |
951 | + } else if (!strcmp(cmd, "check")) { | |
952 | + img_check(argc, argv); | |
891 | 953 | } else if (!strcmp(cmd, "commit")) { |
892 | 954 | img_commit(argc, argv); |
893 | 955 | } else if (!strcmp(cmd, "convert")) { | ... | ... |