diff options
author | Kevin Wolf <kwolf@redhat.com> | 2012-05-11 16:07:02 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2012-06-15 14:03:42 +0200 |
commit | 4534ff5426afeeae5238ba10a696cafa9a0168ee (patch) | |
tree | 41cfe59d3c5b41f0e5d6c396a1c9563a2c21deab /qemu-img.c | |
parent | dfc65f1f780622d852ca8b9fb1421735ee56c48b (diff) | |
download | qemu-4534ff5426afeeae5238ba10a696cafa9a0168ee.zip qemu-4534ff5426afeeae5238ba10a696cafa9a0168ee.tar.gz qemu-4534ff5426afeeae5238ba10a696cafa9a0168ee.tar.bz2 |
qemu-img check -r for repairing images
The QED block driver already provides the functionality to not only
detect inconsistencies in images, but also fix them. However, this
functionality cannot be manually invoked with qemu-img, but the
check happens only automatically during bdrv_open().
This adds a -r switch to qemu-img check that allows manual invocation
of an image repair.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-img.c')
-rw-r--r-- | qemu-img.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -85,6 +85,12 @@ static void help(void) " '-S' indicates the consecutive number of bytes that must contain only zeros\n" " for qemu-img to create a sparse image during conversion\n" "\n" + "Parameters to check subcommand:\n" + " '-r' tries to repair any inconsistencies that are found during the check.\n" + " '-r leaks' repairs only cluster leaks, whereas '-r all' fixes all\n" + " kinds of errors, with a higher risk of choosing the wrong fix or\n" + " hiding corruption that has already occured.\n" + "\n" "Parameters to snapshot subcommand:\n" " 'snapshot' is the name of the snapshot to create, apply or delete\n" " '-a' applies a snapshot (revert disk to saved state)\n" @@ -372,10 +378,12 @@ static int img_check(int argc, char **argv) const char *filename, *fmt; BlockDriverState *bs; BdrvCheckResult result; + int fix = 0; + int flags = BDRV_O_FLAGS; fmt = NULL; for(;;) { - c = getopt(argc, argv, "f:h"); + c = getopt(argc, argv, "f:hr:"); if (c == -1) { break; } @@ -387,6 +395,17 @@ static int img_check(int argc, char **argv) case 'f': fmt = optarg; break; + case 'r': + flags |= BDRV_O_RDWR; + + if (!strcmp(optarg, "leaks")) { + fix = BDRV_FIX_LEAKS; + } else if (!strcmp(optarg, "all")) { + fix = BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; + } else { + help(); + } + break; } } if (optind >= argc) { @@ -394,11 +413,11 @@ static int img_check(int argc, char **argv) } filename = argv[optind++]; - bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS); + bs = bdrv_new_open(filename, fmt, flags); if (!bs) { return 1; } - ret = bdrv_check(bs, &result); + ret = bdrv_check(bs, &result, fix); if (ret == -ENOTSUP) { error_report("This image format does not support checks"); |