* [Qemu-devel] [PATCH][RESEND] Fix compressed qcow2.
@ 2009-01-06 15:59 Gleb Natapov
2009-01-07 16:43 ` Anthony Liguori
0 siblings, 1 reply; 2+ messages in thread
From: Gleb Natapov @ 2009-01-06 15:59 UTC (permalink / raw)
To: qemu-devel
Correctly calculate number of contiguous clusters.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Acked-by: Kevin Wolf <kwolf@suse.de>
diff --git a/block-qcow2.c b/block-qcow2.c
index b3b5f8f..d8ac647 100644
--- a/block-qcow2.c
+++ b/block-qcow2.c
@@ -620,6 +620,9 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
int i;
uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask;
+ if (!offset)
+ return 0;
+
for (i = 0; i < nb_clusters; i++)
if (offset + i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask))
break;
@@ -981,6 +984,12 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
/* how many available clusters ? */
while (i < nb_clusters) {
+ i += count_contiguous_clusters(nb_clusters - i, s->cluster_size,
+ &l2_table[l2_index + i], 0);
+
+ if(be64_to_cpu(l2_table[l2_index + i]))
+ break;
+
i += count_contiguous_free_clusters(nb_clusters - i,
&l2_table[l2_index + i]);
@@ -989,12 +998,6 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
if ((cluster_offset & QCOW_OFLAG_COPIED) ||
(cluster_offset & QCOW_OFLAG_COMPRESSED))
break;
-
- i += count_contiguous_clusters(nb_clusters - i, s->cluster_size,
- &l2_table[l2_index + i], 0);
-
- if(be64_to_cpu(l2_table[l2_index + i]))
- break;
}
nb_clusters = i;
--
Gleb.
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-07 16:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-06 15:59 [Qemu-devel] [PATCH][RESEND] Fix compressed qcow2 Gleb Natapov
2009-01-07 16:43 ` Anthony Liguori
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).