Skip to contentSkip to conversation

Fix (at least one cause of) qcow2 corruption.

PATCH Applied Nolan 3 participants 4 messages Mar 31, 2009 – Apr 9, 2009

lore
Share & tools
lore

Nolan

author
#0 lore raw

PATCH 1/1 Fix (at least one cause of) qcow2 corruption.

qcow2's get_cluster_offset() scans forward in the l2 table to find other clusters that have the same allocation status as the first cluster. This is used by (among others) qcow_is_allocated().

Unfortunately, it was not checking to be sure that it didn't fall off the end of the l2 table. This patch adds that check.

The symptom that motivated me to look into this was that bdrv_is_allocated() was returning false when there was in fact data there. This is one of many ways this bug could lead to data corruption.

I checked the other place that scans for consecutive unallocated blocks (alloc_cluster_offset()) and it appears to be OK:

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);

appears to prevent the same problem from occurring.

Signed-off-by Nolan Leake <nolan <at> sigbus.net>
block-qcow2.c +4 -0
Index: block-qcow2.c
===================================================================
@@ -761,6 +761,10 @@
 
     nb_available = (nb_available >> 9) + index_in_cluster;
 
+    if (nb_needed > nb_available) {
+        nb_needed = nb_available;
+    }
+
     cluster_offset = 0;
 
     /* seek the the l2 offset in the l1 table */
#1 lore raw
Quoted 11 lines · Nolan

qcow2's get_cluster_offset() scans forward in the l2 table to find other clusters that have the same allocation status as the first cluster. This is used by (among others) qcow_is_allocated().

Unfortunately, it was not checking to be sure that it didn't fall off the end of the l2 table. This patch adds that check.

The symptom that motivated me to look into this was that bdrv_is_allocated() was returning false when there was in fact data there. This is one of many ways this bug could lead to data corruption.

Quoted 7 lines

I checked the other place that scans for consecutive unallocated blocks (alloc_cluster_offset()) and it appears to be OK:

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);

appears to prevent the same problem from occurring.

Signed-off-by Nolan Leake <nolan <at> sigbus.net>

Applied. Very good work. Thanks!

Regards,

Anthony Liguori

#2 lore raw
In reply to Nolan
Quoted 11 lines · Nolan

qcow2's get_cluster_offset() scans forward in the l2 table to find other clusters that have the same allocation status as the first cluster. This is used by (among others) qcow_is_allocated().

Unfortunately, it was not checking to be sure that it didn't fall off the end of the l2 table. This patch adds that check.

The symptom that motivated me to look into this was that bdrv_is_allocated() was returning false when there was in fact data there. This is one of many ways this bug could lead to data corruption.

Quoted 7 lines

I checked the other place that scans for consecutive unallocated blocks (alloc_cluster_offset()) and it appears to be OK:

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);

appears to prevent the same problem from occurring.

Signed-off-by Nolan Leake <nolan <at> sigbus.net>

Applied to stable. Thanks

Signature · 3 lines
Regards,

Anthony Liguori
#3 lore raw
In reply to Nolan
Quoted 7 lines · Nolan

qcow2's get_cluster_offset() scans forward in the l2 table to find other clusters that have the same allocation status as the first cluster. This is used by (among others) qcow_is_allocated().

Unfortunately, it was not checking to be sure that it didn't fall off the end of the l2 table. This patch adds that check.

Quoted 8 lines

The symptom that motivated me to look into this was that bdrv_is_allocated() was returning false when there was in fact data there. This is one of many ways this bug could lead to data corruption.

I checked the other place that scans for consecutive unallocated blocks (alloc_cluster_offset()) and it appears to be OK:

    nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);

appears to prevent the same problem from occurring.

Do you have a specific I/O patter nthat would trigger this issue?