Commit ab5ccbd65de369d34f7bf2996530876790efef43

Authored by aliguori
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 620 int i;
621 621 uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask;
622 622  
  623 + if (!offset)
  624 + return 0;
  625 +
623 626 for (i = 0; i < nb_clusters; i++)
624 627 if (offset + i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask))
625 628 break;
... ... @@ -981,6 +984,12 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
981 984 /* how many available clusters ? */
982 985  
983 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 993 i += count_contiguous_free_clusters(nb_clusters - i,
985 994 &l2_table[l2_index + i]);
986 995  
... ... @@ -989,12 +998,6 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs,
989 998 if ((cluster_offset & QCOW_OFLAG_COPIED) ||
990 999 (cluster_offset & QCOW_OFLAG_COMPRESSED))
991 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 1002 nb_clusters = i;
1000 1003  
... ...