Commit ab5ccbd65de369d34f7bf2996530876790efef43
1 parent
181a29c5
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
Showing
1 changed file
with
9 additions
and
6 deletions
block-qcow2.c
@@ -620,6 +620,9 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, | @@ -620,6 +620,9 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, | ||
620 | int i; | 620 | int i; |
621 | uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask; | 621 | uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask; |
622 | 622 | ||
623 | + if (!offset) | ||
624 | + return 0; | ||
625 | + | ||
623 | for (i = 0; i < nb_clusters; i++) | 626 | for (i = 0; i < nb_clusters; i++) |
624 | if (offset + i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask)) | 627 | if (offset + i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask)) |
625 | break; | 628 | break; |
@@ -981,6 +984,12 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, | @@ -981,6 +984,12 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, | ||
981 | /* how many available clusters ? */ | 984 | /* how many available clusters ? */ |
982 | 985 | ||
983 | while (i < nb_clusters) { | 986 | while (i < nb_clusters) { |
987 | + i += count_contiguous_clusters(nb_clusters - i, s->cluster_size, | ||
988 | + &l2_table[l2_index + i], 0); | ||
989 | + | ||
990 | + if(be64_to_cpu(l2_table[l2_index + i])) | ||
991 | + break; | ||
992 | + | ||
984 | i += count_contiguous_free_clusters(nb_clusters - i, | 993 | i += count_contiguous_free_clusters(nb_clusters - i, |
985 | &l2_table[l2_index + i]); | 994 | &l2_table[l2_index + i]); |
986 | 995 | ||
@@ -989,12 +998,6 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, | @@ -989,12 +998,6 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, | ||
989 | if ((cluster_offset & QCOW_OFLAG_COPIED) || | 998 | if ((cluster_offset & QCOW_OFLAG_COPIED) || |
990 | (cluster_offset & QCOW_OFLAG_COMPRESSED)) | 999 | (cluster_offset & QCOW_OFLAG_COMPRESSED)) |
991 | break; | 1000 | break; |
992 | - | ||
993 | - i += count_contiguous_clusters(nb_clusters - i, s->cluster_size, | ||
994 | - &l2_table[l2_index + i], 0); | ||
995 | - | ||
996 | - if(be64_to_cpu(l2_table[l2_index + i])) | ||
997 | - break; | ||
998 | } | 1001 | } |
999 | nb_clusters = i; | 1002 | nb_clusters = i; |
1000 | 1003 |