qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption.
@ 2009-03-31 22:40 Nolan
  2009-04-05 17:42 ` Anthony Liguori
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nolan @ 2009-03-31 22:40 UTC (permalink / raw)
  To: qemu-devel@nongnu.org

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>

Index: block-qcow2.c
===================================================================
--- block-qcow2.c	(revision 6963)
+++ block-qcow2.c	(working copy)
@@ -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 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption.
  2009-03-31 22:40 [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption Nolan
@ 2009-04-05 17:42 ` Anthony Liguori
  2009-04-05 18:18 ` Anthony Liguori
  2009-04-09 20:44 ` Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2009-04-05 17:42 UTC (permalink / raw)
  To: qemu-devel

Nolan wrote:
> 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>
>   

Applied.  Very good work.  Thanks!

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption.
  2009-03-31 22:40 [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption Nolan
  2009-04-05 17:42 ` Anthony Liguori
@ 2009-04-05 18:18 ` Anthony Liguori
  2009-04-09 20:44 ` Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2009-04-05 18:18 UTC (permalink / raw)
  To: qemu-devel

Nolan wrote:
> 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>
>   
Applied to stable.  Thanks

-- 
Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption.
  2009-03-31 22:40 [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption Nolan
  2009-04-05 17:42 ` Anthony Liguori
  2009-04-05 18:18 ` Anthony Liguori
@ 2009-04-09 20:44 ` Christoph Hellwig
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2009-04-09 20:44 UTC (permalink / raw)
  To: qemu-devel

On Tue, Mar 31, 2009 at 03:40:54PM -0700, Nolan wrote:
> 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.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-04-09 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-31 22:40 [Qemu-devel] [PATCH] Fix (at least one cause of) qcow2 corruption Nolan
2009-04-05 17:42 ` Anthony Liguori
2009-04-05 18:18 ` Anthony Liguori
2009-04-09 20:44 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).