From patchwork Thu Mar 28 16:40:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 232122 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 28A862C007C for ; Fri, 29 Mar 2013 03:50:18 +1100 (EST) Received: from localhost ([::1]:50328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULG1o-0001Tu-CC for incoming@patchwork.ozlabs.org; Thu, 28 Mar 2013 12:50:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULFt1-0005dD-6Q for qemu-devel@nongnu.org; Thu, 28 Mar 2013 12:41:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ULFsy-0002DV-94 for qemu-devel@nongnu.org; Thu, 28 Mar 2013 12:41:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27224) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ULFsy-0002DP-0r for qemu-devel@nongnu.org; Thu, 28 Mar 2013 12:41:08 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2SGf7XW014271 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Mar 2013 12:41:07 -0400 Received: from localhost (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2SGf6QW010563; Thu, 28 Mar 2013 12:41:06 -0400 From: Stefan Hajnoczi To: Date: Thu, 28 Mar 2013 17:40:24 +0100 Message-Id: <1364488837-15916-11-git-send-email-stefanha@redhat.com> In-Reply-To: <1364488837-15916-1-git-send-email-stefanha@redhat.com> References: <1364488837-15916-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 10/23] qcow2: handle_alloc(): Get rid of nb_clusters parameter 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 From: Kevin Wolf We already communicate the same information in *bytes. Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block/qcow2-cluster.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 454a30c..009f62a 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -876,17 +876,18 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset, * * -errno: in error cases * - * TODO Get rid of nb_clusters, keep_clusters, n_start, n_end + * TODO Get rid of keep_clusters, n_start, n_end * TODO Make *bytes actually behave as specified above */ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m, - unsigned int nb_clusters, int keep_clusters, int n_start, int n_end) + int keep_clusters, int n_start, int n_end) { BDRVQcowState *s = bs->opaque; int l2_index; uint64_t *l2_table; uint64_t entry; + unsigned int nb_clusters; int ret; uint64_t alloc_offset; @@ -897,6 +898,13 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, *bytes); assert(*bytes > 0); + /* + * Calculate the number of clusters to look for. We stop at L2 table + * boundaries to keep things simple. + */ + l2_index = offset_to_l2_index(s, guest_offset); + nb_clusters = MIN(size_to_clusters(s, *bytes), s->l2_size - l2_index); + /* Find L2 entry for the first involved cluster */ ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index); if (ret < 0) { @@ -1103,6 +1111,7 @@ again: } cluster_offset &= L2E_OFFSET_MASK; + *host_offset = cluster_offset; /* * The L2 table isn't used any more after this. As long as the cache works @@ -1123,11 +1132,14 @@ again: cur_bytes = nb_clusters * s->cluster_size; ret = handle_alloc(bs, offset, &cluster_offset, &cur_bytes, m, - nb_clusters, keep_clusters, n_start, n_end); + keep_clusters, n_start, n_end); if (ret < 0) { return ret; } + if (!*host_offset) { + *host_offset = cluster_offset; + } nb_clusters = size_to_clusters(s, cur_bytes); /* Some cleanup work */ @@ -1139,7 +1151,6 @@ done: assert(sectors > n_start); *num = sectors - n_start; - *host_offset = cluster_offset; return 0; }