Blame SOURCES/kvm-qcow2-Free-only-newly-allocated-clusters-on-error.patch

0a122b
From f39d8d56b3cf31f293465bd912ae623ada8152c0 Mon Sep 17 00:00:00 2001
0a122b
From: Max Reitz <mreitz@redhat.com>
0a122b
Date: Tue, 7 Jan 2014 21:57:15 +0100
0a122b
Subject: [PATCH 10/14] qcow2: Free only newly allocated clusters on error
0a122b
0a122b
RH-Author: Max Reitz <mreitz@redhat.com>
0a122b
Message-id: <1389131839-12920-11-git-send-email-mreitz@redhat.com>
0a122b
Patchwork-id: 56546
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 10/14] qcow2: Free only newly allocated clusters on error
0a122b
Bugzilla: 1033490
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
BZ: 1033490
0a122b
0a122b
In expand_zero_clusters_in_l1, a new cluster is only allocated if it was
0a122b
not already preallocated. On error, such preallocated clusters should
0a122b
not be freed, but only the newly allocated ones.
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit 320c70666687db4dd4df8165f9fe6960de782ca9)
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
---
0a122b
 block/qcow2-cluster.c | 16 ++++++++++------
0a122b
 1 file changed, 10 insertions(+), 6 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/qcow2-cluster.c |   16 ++++++++++------
0a122b
 1 files changed, 10 insertions(+), 6 deletions(-)
0a122b
0a122b
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
0a122b
index bfdc83a..79c3ae0 100644
0a122b
--- a/block/qcow2-cluster.c
0a122b
+++ b/block/qcow2-cluster.c
0a122b
@@ -1552,6 +1552,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
0a122b
             uint64_t l2_entry = be64_to_cpu(l2_table[j]);
0a122b
             int64_t offset = l2_entry & L2E_OFFSET_MASK, cluster_index;
0a122b
             int cluster_type = qcow2_get_cluster_type(l2_entry);
0a122b
+            bool preallocated = offset != 0;
0a122b
 
0a122b
             if (cluster_type == QCOW2_CLUSTER_NORMAL) {
0a122b
                 cluster_index = offset >> s->cluster_bits;
0a122b
@@ -1577,8 +1578,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
0a122b
                 continue;
0a122b
             }
0a122b
 
0a122b
-            if (!offset) {
0a122b
-                /* not preallocated */
0a122b
+            if (!preallocated) {
0a122b
                 if (!bs->backing_hd) {
0a122b
                     /* not backed; therefore we can simply deallocate the
0a122b
                      * cluster */
0a122b
@@ -1596,16 +1596,20 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
0a122b
 
0a122b
             ret = qcow2_pre_write_overlap_check(bs, 0, offset, s->cluster_size);
0a122b
             if (ret < 0) {
0a122b
-                qcow2_free_clusters(bs, offset, s->cluster_size,
0a122b
-                        QCOW2_DISCARD_ALWAYS);
0a122b
+                if (!preallocated) {
0a122b
+                    qcow2_free_clusters(bs, offset, s->cluster_size,
0a122b
+                                        QCOW2_DISCARD_ALWAYS);
0a122b
+                }
0a122b
                 goto fail;
0a122b
             }
0a122b
 
0a122b
             ret = bdrv_write_zeroes(bs->file, offset / BDRV_SECTOR_SIZE,
0a122b
                                     s->cluster_sectors, 0);
0a122b
             if (ret < 0) {
0a122b
-                qcow2_free_clusters(bs, offset, s->cluster_size,
0a122b
-                        QCOW2_DISCARD_ALWAYS);
0a122b
+                if (!preallocated) {
0a122b
+                    qcow2_free_clusters(bs, offset, s->cluster_size,
0a122b
+                                        QCOW2_DISCARD_ALWAYS);
0a122b
+                }
0a122b
                 goto fail;
0a122b
             }
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b