From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KThIj-0003oU-0Z for qemu-devel@nongnu.org; Thu, 14 Aug 2008 14:11:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KThIi-0003o6-DC for qemu-devel@nongnu.org; Thu, 14 Aug 2008 14:11:56 -0400 Received: from [199.232.76.173] (port=59505 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KThIi-0003o0-8R for qemu-devel@nongnu.org; Thu, 14 Aug 2008 14:11:56 -0400 Received: from savannah.gnu.org ([199.232.41.3]:52063 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KThIh-0001Mx-Lz for qemu-devel@nongnu.org; Thu, 14 Aug 2008 14:11:56 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1KThIf-0002CQ-MB for qemu-devel@nongnu.org; Thu, 14 Aug 2008 18:11:53 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1KThIf-0002CM-G7 for qemu-devel@nongnu.org; Thu, 14 Aug 2008 18:11:53 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 14 Aug 2008 18:11:53 +0000 Subject: [Qemu-devel] [5008] qcow2: Try to aggregate free clusters and freed clusters ( Laurent Vivier) 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 Revision: 5008 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5008 Author: aliguori Date: 2008-08-14 18:11:52 +0000 (Thu, 14 Aug 2008) Log Message: ----------- qcow2: Try to aggregate free clusters and freed clusters (Laurent Vivier) In alloc_cluster_offset(), try to aggregate free clusters and freed clusters. Signed-off-by: Laurent Vivier Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block-qcow2.c Modified: trunk/block-qcow2.c =================================================================== --- trunk/block-qcow2.c 2008-08-14 18:11:00 UTC (rev 5007) +++ trunk/block-qcow2.c 2008-08-14 18:11:52 UTC (rev 5008) @@ -870,7 +870,7 @@ 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); @@ -909,32 +909,50 @@ 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; + + } 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; - - free_any_clusters(bs, cluster_offset, i); } + nb_clusters = i; /* allocate a new cluster */