05bba0
From 0a8f6084033d307f4e60104be1da0da99e8775b6 Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Sat, 13 Jun 2015 16:22:14 +0200
05bba0
Subject: [PATCH 20/42] qcow2: Pull check_refblocks() up
05bba0
MIME-Version: 1.0
05bba0
Content-Type: text/plain; charset=UTF-8
05bba0
Content-Transfer-Encoding: 8bit
05bba0
05bba0
Message-id: <1434212556-3927-21-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 66039
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 20/42] qcow2: Pull check_refblocks() up
05bba0
Bugzilla: 1129893
05bba0
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
BZ: 1129893
05bba0
05bba0
Pull check_refblocks() before calculate_refcounts() so we can drop its
05bba0
static declaration.
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
Reviewed-by: BenoƮt Canet <benoit.canet@nodalink.com>
05bba0
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
(cherry picked from commit 057a3fe57e740e5e1cc3d62c9b8e0085e9fffa74)
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/qcow2-refcount.c | 102 ++++++++++++++++++++++++-------------------------
05bba0
 1 file changed, 49 insertions(+), 53 deletions(-)
05bba0
05bba0
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
05bba0
index cb78f05..0d10865 100644
05bba0
--- a/block/qcow2-refcount.c
05bba0
+++ b/block/qcow2-refcount.c
05bba0
@@ -1501,59 +1501,6 @@ fail:
05bba0
     return new_offset;
05bba0
 }
05bba0
 
05bba0
-static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
05bba0
-                           BdrvCheckMode fix, uint16_t **refcount_table,
05bba0
-                           int64_t *nb_clusters);
05bba0
-
05bba0
-/*
05bba0
- * Calculates an in-memory refcount table.
05bba0
- */
05bba0
-static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
05bba0
-                               BdrvCheckMode fix, uint16_t **refcount_table,
05bba0
-                               int64_t *nb_clusters)
05bba0
-{
05bba0
-    BDRVQcowState *s = bs->opaque;
05bba0
-    int64_t i;
05bba0
-    QCowSnapshot *sn;
05bba0
-    int ret;
05bba0
-
05bba0
-    *refcount_table = g_try_new0(uint16_t, *nb_clusters);
05bba0
-    if (*nb_clusters && *refcount_table == NULL) {
05bba0
-        res->check_errors++;
05bba0
-        return -ENOMEM;
05bba0
-    }
05bba0
-
05bba0
-    /* header */
05bba0
-    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
-        0, s->cluster_size);
05bba0
-
05bba0
-    /* current L1 table */
05bba0
-    ret = check_refcounts_l1(bs, res, *refcount_table, *nb_clusters,
05bba0
-                             s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);
05bba0
-    if (ret < 0) {
05bba0
-        return ret;
05bba0
-    }
05bba0
-
05bba0
-    /* snapshots */
05bba0
-    for (i = 0; i < s->nb_snapshots; i++) {
05bba0
-        sn = s->snapshots + i;
05bba0
-        ret = check_refcounts_l1(bs, res, *refcount_table, *nb_clusters,
05bba0
-            sn->l1_table_offset, sn->l1_size, 0);
05bba0
-        if (ret < 0) {
05bba0
-            return ret;
05bba0
-        }
05bba0
-    }
05bba0
-    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
-        s->snapshots_offset, s->snapshots_size);
05bba0
-
05bba0
-    /* refcount data */
05bba0
-    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
-        s->refcount_table_offset,
05bba0
-        s->refcount_table_size * sizeof(uint64_t));
05bba0
-
05bba0
-    return check_refblocks(bs, res, fix, refcount_table, nb_clusters);
05bba0
-}
05bba0
-
05bba0
 /*
05bba0
  * Checks consistency of refblocks and accounts for each refblock in
05bba0
  * *refcount_table.
05bba0
@@ -1631,6 +1578,55 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
05bba0
 }
05bba0
 
05bba0
 /*
05bba0
+ * Calculates an in-memory refcount table.
05bba0
+ */
05bba0
+static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
05bba0
+                               BdrvCheckMode fix, uint16_t **refcount_table,
05bba0
+                               int64_t *nb_clusters)
05bba0
+{
05bba0
+    BDRVQcowState *s = bs->opaque;
05bba0
+    int64_t i;
05bba0
+    QCowSnapshot *sn;
05bba0
+    int ret;
05bba0
+
05bba0
+    *refcount_table = g_try_new0(uint16_t, *nb_clusters);
05bba0
+    if (*nb_clusters && *refcount_table == NULL) {
05bba0
+        res->check_errors++;
05bba0
+        return -ENOMEM;
05bba0
+    }
05bba0
+
05bba0
+    /* header */
05bba0
+    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
+        0, s->cluster_size);
05bba0
+
05bba0
+    /* current L1 table */
05bba0
+    ret = check_refcounts_l1(bs, res, *refcount_table, *nb_clusters,
05bba0
+                             s->l1_table_offset, s->l1_size, CHECK_FRAG_INFO);
05bba0
+    if (ret < 0) {
05bba0
+        return ret;
05bba0
+    }
05bba0
+
05bba0
+    /* snapshots */
05bba0
+    for (i = 0; i < s->nb_snapshots; i++) {
05bba0
+        sn = s->snapshots + i;
05bba0
+        ret = check_refcounts_l1(bs, res, *refcount_table, *nb_clusters,
05bba0
+            sn->l1_table_offset, sn->l1_size, 0);
05bba0
+        if (ret < 0) {
05bba0
+            return ret;
05bba0
+        }
05bba0
+    }
05bba0
+    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
+        s->snapshots_offset, s->snapshots_size);
05bba0
+
05bba0
+    /* refcount data */
05bba0
+    inc_refcounts(bs, res, *refcount_table, *nb_clusters,
05bba0
+        s->refcount_table_offset,
05bba0
+        s->refcount_table_size * sizeof(uint64_t));
05bba0
+
05bba0
+    return check_refblocks(bs, res, fix, refcount_table, nb_clusters);
05bba0
+}
05bba0
+
05bba0
+/*
05bba0
  * Compares the actual reference count for each cluster in the image against the
05bba0
  * refcount as reported by the refcount structures on-disk.
05bba0
  */
05bba0
-- 
05bba0
1.8.3.1
05bba0