Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KTHpz-0000HY-TS for qemu-devel@nongnu.org; Wed, 13 Aug 2008 11:00:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KTHpy-0000Fv-0P for qemu-devel@nongnu.org; Wed, 13 Aug 2008 11:00:34 -0400 Received: from [199.232.76.173] (port=40065 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTHpx-0000FS-A2 for qemu-devel@nongnu.org; Wed, 13 Aug 2008 11:00:33 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:55346) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KTHpw-00055C-DC for qemu-devel@nongnu.org; Wed, 13 Aug 2008 11:00:32 -0400 Message-Id: <20080813145944.271603889@bull.net> References: <20080813145900.265987809@bull.net> Date: Wed, 13 Aug 2008 16:59:05 +0200 From: Laurent.Vivier@bull.net Content-Disposition: inline; filename=qcow2-extent-more.patch Subject: [Qemu-devel] [patch 5/5][v3] Try to aggregate free clusters and freed clusters Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Laurent Vivier , Kevin Wolf In alloc_cluster_offset(), ry to aggregate free clusters and freed clusters. Signed-off-by: Laurent Vivier --- block-qcow2.c | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) Index: qemu/block-qcow2.c =================================================================== --- qemu.orig/block-qcow2.c 2008-08-12 15:56:41.000000000 +0200 +++ qemu/block-qcow2.c 2008-08-12 16:02:22.000000000 +0200 @@ -871,7 +871,7 @@ static uint64_t alloc_cluster_offset(Blo BDRVQcowState *s = bs->opaque; int l2_index, ret; uint64_t l2_offset, *l2_table, cluster_offset; - int nb_available, nb_clusters, i; + int nb_available, nb_clusters, i, j; uint64_t start_sect, current; ret = get_cluster_table(bs, offset, &l2_table, &l2_offset, &l2_index); @@ -910,32 +910,50 @@ static uint64_t alloc_cluster_offset(Blo if (cluster_offset & QCOW_OFLAG_COMPRESSED) nb_clusters = 1; - /* how many empty or how many to free ? */ + /* how many available clusters ? */ - if (!cluster_offset) { + i = 0; + while (i < nb_clusters) { - /* how many free clusters ? */ + i++; - i = 1; - while (i < nb_clusters && - l2_table[l2_index + i] == 0) { - i++; - } - nb_clusters = i; + if (!cluster_offset) { - } else { + /* how many free clusters ? */ - /* how many contiguous clusters ? */ + while (i < nb_clusters) { + cluster_offset = l2_table[l2_index + i]; + if (cluster_offset != 0) + break; + i++; + } - for (i = 1; i < nb_clusters; i++) { - current = be64_to_cpu(l2_table[l2_index + i]); - if (cluster_offset + (i << s->cluster_bits) != current) + if ((cluster_offset & QCOW_OFLAG_COPIED) || + (cluster_offset & QCOW_OFLAG_COMPRESSED)) break; - } - nb_clusters = i; - free_any_clusters(bs, cluster_offset, i); + } else { + + /* how many contiguous clusters ? */ + + j = 1; + current = 0; + while (i < nb_clusters) { + current = be64_to_cpu(l2_table[l2_index + i]); + if (cluster_offset + (j << s->cluster_bits) != current) + break; + + i++; + j++; + } + + free_any_clusters(bs, cluster_offset, j); + if (current) + break; + cluster_offset = current; + } } + nb_clusters = i; /* allocate a new cluster */ --