From d301bd07fccb35b79b54350c41c6bd7fe1857a13 Mon Sep 17 00:00:00 2001
Message-Id: <d301bd07fccb35b79b54350c41c6bd7fe1857a13.1366117835.git.minovotn@redhat.com>
In-Reply-To: <8a8dc925d6cdb62aba736eb1551195551e09271b.1366117835.git.minovotn@redhat.com>
References: <8a8dc925d6cdb62aba736eb1551195551e09271b.1366117835.git.minovotn@redhat.com>
From: Kevin Wolf <kwolf@redhat.com>
Date: Thu, 7 Mar 2013 15:29:15 +0100
Subject: [PATCH 07/19] qemu-img check: Print fixed clusters and recheck

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1362670164-15796-4-git-send-email-kwolf@redhat.com>
Patchwork-id: 49305
O-Subject: [RHEL-6.5 qemu-kvm PATCH 03/12] qemu-img check: Print fixed clusters and recheck
Bugzilla: 888008
RH-Acked-by: Eric Blake <eblake@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>

When any inconsistencies have been fixed, print the statistics and run
another check to make sure everything is correct now.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit ccf34716eeda0e3ad203c8a28f01efb412c56763)

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.h           |  2 ++
 block/qed-check.c |  2 ++
 qemu-img.c        | 10 ++++++++++
 3 files changed, 14 insertions(+)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 block.h           |  2 ++
 block/qed-check.c |  2 ++
 qemu-img.c        | 10 ++++++++++
 3 files changed, 14 insertions(+)

diff --git a/block.h b/block.h
index 1ef82b6..4f06abf 100644
--- a/block.h
+++ b/block.h
@@ -211,6 +211,8 @@ typedef struct BdrvCheckResult {
     int corruptions;
     int leaks;
     int check_errors;
+    int corruptions_fixed;
+    int leaks_fixed;
     BlockFragInfo bfi;
 } BdrvCheckResult;
 
diff --git a/block/qed-check.c b/block/qed-check.c
index e4a49ce..9ac7322 100644
--- a/block/qed-check.c
+++ b/block/qed-check.c
@@ -81,6 +81,7 @@ static unsigned int qed_check_l2_table(QEDCheck *check, QEDTable *table)
         if (!qed_check_cluster_offset(s, offset)) {
             if (check->fix) {
                 table->offsets[i] = 0;
+                check->result->corruptions_fixed++;
             } else {
                 check->result->corruptions++;
             }
@@ -121,6 +122,7 @@ static int qed_check_l1_table(QEDCheck *check, QEDTable *table)
             /* Clear invalid offset */
             if (check->fix) {
                 table->offsets[i] = 0;
+                check->result->corruptions_fixed++;
             } else {
                 check->result->corruptions++;
             }
diff --git a/qemu-img.c b/qemu-img.c
index 40afeff..6a10db6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -448,6 +448,16 @@ static int img_check(int argc, char **argv)
         return 1;
     }
 
+    if (result.corruptions_fixed || result.leaks_fixed) {
+        printf("The following inconsistencies were found and repaired:\n\n"
+               "    %d leaked clusters\n"
+               "    %d corruptions\n\n"
+               "Double checking the fixed image now...\n",
+               result.leaks_fixed,
+               result.corruptions_fixed);
+        ret = bdrv_check(bs, &result, 0);
+    }
+
     if (!(result.corruptions || result.leaks || result.check_errors)) {
         printf("No errors were found on the image.\n");
     } else {
-- 
1.7.11.7

