diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 353889d41ba58da3a2c0be0bb1a973030d91548b..10c22fe12b4b5f439b5bc3e52be6035f02a6fda8 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -883,15 +883,19 @@ again: assert(keep_clusters <= nb_clusters); nb_clusters -= keep_clusters; } else { + keep_clusters = 0; + cluster_offset = 0; + } + + if (nb_clusters > 0) { /* For the moment, overwrite compressed clusters one by one */ - if (cluster_offset & QCOW_OFLAG_COMPRESSED) { + uint64_t entry = be64_to_cpu(l2_table[l2_index + keep_clusters]); + if (entry & QCOW_OFLAG_COMPRESSED) { nb_clusters = 1; } else { - nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index); + nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, + l2_index + keep_clusters); } - - keep_clusters = 0; - cluster_offset = 0; } cluster_offset &= L2E_OFFSET_MASK;