1
From: aliguori <aliguori>
2
Date: Sun, 5 Apr 2009 18:15:59 +0000 (+0000)
3
Subject: Fix (at least one cause of) qcow2 corruption. (Nolan Leake)
4
X-Git-Url: http://git.kernel.org/?p=virt%2Fkvm%2Fkvm-userspace.git;a=commitdiff_plain;h=385aae33c08e17ec63671b9fa1c503c21283bc1f;hp=b335c2b5762259c827bae487dca26441497a96cb
6
Fix (at least one cause of) qcow2 corruption. (Nolan Leake)
8
qcow2's get_cluster_offset() scans forward in the l2 table to find other
9
clusters that have the same allocation status as the first cluster.
10
This is used by (among others) qcow_is_allocated().
12
Unfortunately, it was not checking to be sure that it didn't fall off
13
the end of the l2 table. This patch adds that check.
15
The symptom that motivated me to look into this was that
16
bdrv_is_allocated() was returning false when there was in fact data
17
there. This is one of many ways this bug could lead to data corruption.
19
I checked the other place that scans for consecutive unallocated blocks
20
(alloc_cluster_offset()) and it appears to be OK:
21
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
22
appears to prevent the same problem from occurring.
24
Signed-off-by: Nolan Leake <nolan <at> sigbus.net>
25
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
28
diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
29
index 957e419..894b05a 100644
30
--- a/qemu/block-qcow2.c
31
+++ b/qemu/block-qcow2.c
32
@@ -670,6 +670,10 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
34
nb_available = (nb_available >> 9) + index_in_cluster;
36
+ if (nb_needed > nb_available) {
37
+ nb_needed = nb_available;
42
/* seek the the l2 offset in the l1 table */