~ubuntu-branches/ubuntu/jaunty/kvm/jaunty-proposed

« back to all changes in this revision

Viewing changes to debian/patches/fix-qcow-corruption.patch

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-04-17 09:59:58 UTC
  • Revision ID: james.westby@ubuntu.com-20090417095958-rklwa56xm7bmlc6l
* debian/patches/add-all-virtio-drives.patch: Fix bugs where the caller
  does not specify a perfectly defined list of virtio drives starting at
  index=0 and having no gaps in indices; LP: #360832, #360825
* debian/patches/fix-qcow-corruption: Cherry-pick from kvm stable git
  branch, fixes at least one cause of qcow2 image corruption; no reports
  yet of this in Ubuntu, but I'm being proactive about this one;
  LP: #361938
* debian/source_kvm.py: dpkg -l was a little too heavy, compress this
  output considerably

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
6
Fix (at least one cause of) qcow2 corruption. (Nolan Leake)
 
7
 
 
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().
 
11
 
 
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.
 
14
 
 
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.
 
18
 
 
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.
 
23
 
 
24
Signed-off-by: Nolan Leake <nolan <at> sigbus.net>
 
25
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
 
26
---
 
27
 
 
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,
 
33
 
 
34
     nb_available = (nb_available >> 9) + index_in_cluster;
 
35
 
 
36
+    if (nb_needed > nb_available) {
 
37
+        nb_needed = nb_available;
 
38
+    }
 
39
+
 
40
     cluster_offset = 0;
 
41
 
 
42
     /* seek the the l2 offset in the l1 table */