qcow2: release refcount table clusters of the old table, after growing the refcount table
PATCH 1/1 qcow2: release refcount table clusters of the old table, after growing the refcount table
Another patch for qcow2: when the refcount table is grown, clusters for the new refcount table are allocated, but the clusters for the old (now unused) refcount table are not released.
This isn't a big problem, it just wastes a few clusters.
But it results in error messages when block-qcow2.c is compiled with DEBUG_ALLOC / DEBUG_ALLOC2 error checking, and a qcow2 image has ever grown the refcount table:
/* compare ref counts */
for(i = 0; i < nb_clusters; i++) {
refcount1 = get_refcount(bs, i);
refcount2 = refcount_table[i];
if (refcount1 != refcount2)
printf("ERROR cluster %d refcount=%d reference=%d\n",
i, refcount1, refcount2);
}% qemu-img info sol11-b60.img
ERROR cluster 9 refcount=1 reference=0 <<<<<<<<<<<<<<<<<<<<<<<<<<<
image: sol11-b60.img
file format: qcow2
virtual size: 8.0G (8589934592 bytes)
disk size: 2.6Gcluster_size: 4096
Index: block-qcow2.c
===================================================================
RCS file: /cvsroot/qemu/qemu/block-qcow2.c,v
retrieving revision 1.5
block-qcow2.c +5 -0
@@ -1886,6 +1894,8 @@int64_t table_offset;uint64_t data64;uint32_t data32; +int old_table_size; +int64_t old_table_offset;if (min_size <= s->refcount_table_size)return 0 ;
@@ -1931,11 +1941,14 @@ &data32, sizeof(data32)) != sizeof(data32)) goto fail;qemu_free (s->refcount_table); + old_table_offset = s->refcount_table_offset; + old_table_size = s->refcount_table_size; s->refcount_table = new_table; s->refcount_table_size = new_table_size; s->refcount_table_offset = table_offset;update_refcount (bs, table_offset, new_table_size2,1 ); +free_clusters (bs, old_table_offset, old_table_size *sizeof (uint64_t ));return 0 ; fail:free_clusters (bs, table_offset, new_table_size2);