aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2-cluster.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2020-02-11 10:48:59 +0100
committerKevin Wolf <kwolf@redhat.com>2020-02-18 10:53:56 +0100
commitc3b6658c1a5a3fb24d6c27b2594cf86146f75b22 (patch)
tree40a4b799ffa403c07ae3046aabff5c1c86cd5929 /block/qcow2-cluster.c
parentdea9052ef1ba12c83f17d394c70d7d710ea1dec9 (diff)
downloadqemu-c3b6658c1a5a3fb24d6c27b2594cf86146f75b22.zip
qemu-c3b6658c1a5a3fb24d6c27b2594cf86146f75b22.tar.gz
qemu-c3b6658c1a5a3fb24d6c27b2594cf86146f75b22.tar.bz2
qcow2: Fix qcow2_alloc_cluster_abort() for external data file
For external data file, cluster allocations return an offset in the data file and are not refcounted. In this case, there is nothing to do for qcow2_alloc_cluster_abort(). Freeing the same offset in the qcow2 file is wrong and causes crashes in the better case or image corruption in the worse case. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20200211094900.17315-3-kwolf@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow2-cluster.c')
-rw-r--r--block/qcow2-cluster.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 1947f13..78c95df 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1026,8 +1026,11 @@ err:
void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m)
{
BDRVQcow2State *s = bs->opaque;
- qcow2_free_clusters(bs, m->alloc_offset, m->nb_clusters << s->cluster_bits,
- QCOW2_DISCARD_NEVER);
+ if (!has_data_file(bs)) {
+ qcow2_free_clusters(bs, m->alloc_offset,
+ m->nb_clusters << s->cluster_bits,
+ QCOW2_DISCARD_NEVER);
+ }
}
/*