From patchwork Wed Feb 13 13:21:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 220142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 14AC82C00DC for ; Thu, 14 Feb 2013 01:12:11 +1100 (EST) Received: from localhost ([::1]:34834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cJ9-0007kR-0K for incoming@patchwork.ozlabs.org; Wed, 13 Feb 2013 08:23:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cID-0005j7-Kl for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5cIA-0002qc-Nd for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5cIA-0002qU-FE for qemu-devel@nongnu.org; Wed, 13 Feb 2013 08:22:30 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1DDMTf3004536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 13 Feb 2013 08:22:30 -0500 Received: from dhcp-5-188.str.redhat.com (dhcp-192-240.str.redhat.com [10.33.192.240]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1DDMGRb011418; Wed, 13 Feb 2013 08:22:27 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 13 Feb 2013 14:21:54 +0100 Message-Id: <1360761733-25347-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1360761733-25347-1-git-send-email-kwolf@redhat.com> References: <1360761733-25347-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, lersek@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [RFC PATCH v2 04/23] qcow2: Decouple cluster allocation from cluster reuse code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This moves some code that prepares the allocation of new clusters to where the actual allocation happens. This is the minimum required to be able to move it to a separate function in the next patch. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a3b2447..5c4b7cc 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -943,10 +943,7 @@ again: cluster_offset = be64_to_cpu(l2_table[l2_index]); - /* - * Check how many clusters are already allocated and don't need COW, and how - * many need a new allocation. - */ + /* Check how many clusters are already allocated and don't need COW */ if (qcow2_get_cluster_type(cluster_offset) == QCOW2_CLUSTER_NORMAL && (cluster_offset & QCOW_OFLAG_COPIED)) { @@ -962,17 +959,6 @@ again: cluster_offset = 0; } - if (nb_clusters > 0) { - /* For the moment, overwrite compressed clusters one by one */ - uint64_t entry = be64_to_cpu(l2_table[l2_index + keep_clusters]); - if (entry & QCOW_OFLAG_COMPRESSED) { - nb_clusters = 1; - } else { - nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, - l2_index + keep_clusters); - } - } - cluster_offset &= L2E_OFFSET_MASK; /* @@ -993,6 +979,25 @@ again: uint64_t alloc_cluster_offset; uint64_t keep_bytes = keep_clusters * s->cluster_size; + ret = get_cluster_table(bs, offset, &l2_table, &l2_index); + if (ret < 0) { + return ret; + } + + /* For the moment, overwrite compressed clusters one by one */ + uint64_t entry = be64_to_cpu(l2_table[l2_index + keep_clusters]); + if (entry & QCOW_OFLAG_COMPRESSED) { + nb_clusters = 1; + } else { + nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, + l2_index + keep_clusters); + } + + ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); + if (ret < 0) { + return ret; + } + /* Calculate start and size of allocation */ alloc_offset = offset + keep_bytes;