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.6G cluster_size: 4096
Index: block-qcow2.c =================================================================== RCS file: /cvsroot/qemu/qemu/block-qcow2.c,v retrieving revision 1.5 diff -u -B -r1.5 block-qcow2.c --- block-qcow2.c 1 Apr 2007 19:01:40 -0000 1.5 +++ block-qcow2.c 2 Apr 2007 10:17:54 -0000 @@ -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);