Blame SOURCES/kvm-qcow2-Fix-qcow2_alloc_cluster_abort-for-external-dat.patch

902636
From ecc4fb6e1941035e1d9def1f69b779fbea216caf Mon Sep 17 00:00:00 2001
902636
From: Kevin Wolf <kwolf@redhat.com>
902636
Date: Mon, 24 Feb 2020 16:13:07 +0000
902636
Subject: [PATCH 7/9] qcow2: Fix qcow2_alloc_cluster_abort() for external data
902636
 file
902636
902636
RH-Author: Kevin Wolf <kwolf@redhat.com>
902636
Message-id: <20200224161307.29783-2-kwolf@redhat.com>
902636
Patchwork-id: 94042
902636
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 1/1] qcow2: Fix qcow2_alloc_cluster_abort() for external data file
902636
Bugzilla: 1703907
902636
RH-Acked-by: John Snow <jsnow@redhat.com>
902636
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
902636
For external data file, cluster allocations return an offset in the data
902636
file and are not refcounted. In this case, there is nothing to do for
902636
qcow2_alloc_cluster_abort(). Freeing the same offset in the qcow2 file
902636
is wrong and causes crashes in the better case or image corruption in
902636
the worse case.
902636
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Message-Id: <20200211094900.17315-3-kwolf@redhat.com>
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
(cherry picked from commit c3b6658c1a5a3fb24d6c27b2594cf86146f75b22)
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 block/qcow2-cluster.c | 7 +++++--
902636
 1 file changed, 5 insertions(+), 2 deletions(-)
902636
902636
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
902636
index 8982b7b..dc3c270 100644
902636
--- a/block/qcow2-cluster.c
902636
+++ b/block/qcow2-cluster.c
902636
@@ -1015,8 +1015,11 @@ err:
902636
 void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
902636
 {
902636
     BDRVQcow2State *s = bs->opaque;
902636
-    qcow2_free_clusters(bs, m->alloc_offset, m->nb_clusters << s->cluster_bits,
902636
-                        QCOW2_DISCARD_NEVER);
902636
+    if (!has_data_file(bs)) {
902636
+        qcow2_free_clusters(bs, m->alloc_offset,
902636
+                            m->nb_clusters << s->cluster_bits,
902636
+                            QCOW2_DISCARD_NEVER);
902636
+    }
902636
 }
902636
 
902636
 /*
902636
-- 
902636
1.8.3.1
902636