cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qcow2-Reuse-refcount-table-in-calculate_refcounts.patch

05bba0
From 2f67e26a87ace81cb7a9c122c39f4d8d667d69d1 Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Sat, 13 Jun 2015 16:22:19 +0200
05bba0
Subject: [PATCH 25/42] qcow2: Reuse refcount table in calculate_refcounts()
05bba0
MIME-Version: 1.0
05bba0
Content-Type: text/plain; charset=UTF-8
05bba0
Content-Transfer-Encoding: 8bit
05bba0
05bba0
Message-id: <1434212556-3927-26-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 66044
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 25/42] qcow2: Reuse refcount table in calculate_refcounts()
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
We will later call calculate_refcounts multiple times, so reuse the
05bba0
refcount table if possible.
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 9696df219a71c6608f058ade8873d6d0b4e352fe)
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 | 12 +++++++-----
05bba0
 1 file changed, 7 insertions(+), 5 deletions(-)
05bba0
05bba0
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
05bba0
index 7d03e65..8f1215c 100644
05bba0
--- a/block/qcow2-refcount.c
05bba0
+++ b/block/qcow2-refcount.c
05bba0
@@ -1631,10 +1631,12 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
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
+    if (!*refcount_table) {
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
 
05bba0
     /* header */
05bba0
@@ -1750,7 +1752,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
05bba0
 {
05bba0
     BDRVQcowState *s = bs->opaque;
05bba0
     int64_t size, highest_cluster, nb_clusters;
05bba0
-    uint16_t *refcount_table;
05bba0
+    uint16_t *refcount_table = NULL;
05bba0
     int ret;
05bba0
 
05bba0
     size = bdrv_getlength(bs->file);
05bba0
-- 
05bba0
1.8.3.1
05bba0