From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LKEJj-0005j3-Rt for qemu-devel@nongnu.org; Tue, 06 Jan 2009 10:58:07 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LKEJh-0005in-E3 for qemu-devel@nongnu.org; Tue, 06 Jan 2009 10:58:06 -0500 Received: from [199.232.76.173] (port=38552 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LKEJh-0005ik-9C for qemu-devel@nongnu.org; Tue, 06 Jan 2009 10:58:05 -0500 Received: from mx2.redhat.com ([66.187.237.31]:41733) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LKEJg-0005Fe-P4 for qemu-devel@nongnu.org; Tue, 06 Jan 2009 10:58:05 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n06Fw3mO002042 for ; Tue, 6 Jan 2009 10:58:03 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n06Fw2qI003049 for ; Tue, 6 Jan 2009 10:58:03 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n06Fw1vU031648 for ; Tue, 6 Jan 2009 10:58:02 -0500 Date: Tue, 6 Jan 2009 17:59:13 +0200 From: Gleb Natapov Message-ID: <20090106155913.GD3267@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH][RESEND] Fix compressed qcow2. 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 Correctly calculate number of contiguous clusters. Signed-off-by: Gleb Natapov Acked-by: Kevin Wolf diff --git a/block-qcow2.c b/block-qcow2.c index b3b5f8f..d8ac647 100644 --- a/block-qcow2.c +++ b/block-qcow2.c @@ -620,6 +620,9 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, int i; uint64_t offset = be64_to_cpu(l2_table[0]) & ~mask; + if (!offset) + return 0; + for (i = 0; i < nb_clusters; i++) if (offset + i * cluster_size != (be64_to_cpu(l2_table[i]) & ~mask)) break; @@ -981,6 +984,12 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, /* how many available clusters ? */ while (i < nb_clusters) { + i += count_contiguous_clusters(nb_clusters - i, s->cluster_size, + &l2_table[l2_index + i], 0); + + if(be64_to_cpu(l2_table[l2_index + i])) + break; + i += count_contiguous_free_clusters(nb_clusters - i, &l2_table[l2_index + i]); @@ -989,12 +998,6 @@ static uint64_t alloc_cluster_offset(BlockDriverState *bs, if ((cluster_offset & QCOW_OFLAG_COPIED) || (cluster_offset & QCOW_OFLAG_COMPRESSED)) break; - - i += count_contiguous_clusters(nb_clusters - i, s->cluster_size, - &l2_table[l2_index + i], 0); - - if(be64_to_cpu(l2_table[l2_index + i])) - break; } nb_clusters = i; -- Gleb.