diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-07 16:43:13 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-01-07 16:43:13 +0000 |
commit | ab5ccbd65de369d34f7bf2996530876790efef43 (patch) | |
tree | 83c6c426fe43113b603dd6504753584ea03963ae /block-qcow2.c | |
parent | 181a29c5b2f5eacdc8c5fdf30bf46a04abedffde (diff) |
Fix compressed qcow2 (Gleb Natapov)
Correctly calculate number of contiguous clusters.
Acked-by: Kevin Wolf <kwolf@suse.de>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6212 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block-qcow2.c')
-rw-r--r-- | block-qcow2.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/block-qcow2.c b/block-qcow2.c index b3b5f8f090..d8ac647283 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; |