From patchwork Thu Oct 23 20:42:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 402671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5A05814008C for ; Fri, 24 Oct 2014 07:58:39 +1100 (AEDT) Received: from localhost ([::1]:43558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhPSv-0004Bj-3N for incoming@patchwork.ozlabs.org; Thu, 23 Oct 2014 16:58:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhPDy-00064j-Sv for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhPDt-0002QQ-N1 for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhPDt-0002QC-Fk for qemu-devel@nongnu.org; Thu, 23 Oct 2014 16:43:05 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9NKh4ti015650 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 23 Oct 2014 16:43:05 -0400 Received: from noname.redhat.com (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9NKgfhp013669; Thu, 23 Oct 2014 16:43:03 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 23 Oct 2014 22:42:23 +0200 Message-Id: <1414096959-14682-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1414096959-14682-1-git-send-email-kwolf@redhat.com> References: <1414096959-14682-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id s9NKh4ti015650 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 16/32] qcow2: Reuse refcount table in calculate_refcounts() 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: Max Reitz We will later call calculate_refcounts multiple times, so reuse the refcount table if possible. Signed-off-by: Max Reitz Reviewed-by: BenoƮt Canet Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/qcow2-refcount.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index d653124..c92e1fc 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1661,10 +1661,12 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res, QCowSnapshot *sn; int ret; - *refcount_table = g_try_new0(uint16_t, *nb_clusters); - if (*nb_clusters && *refcount_table == NULL) { - res->check_errors++; - return -ENOMEM; + if (!*refcount_table) { + *refcount_table = g_try_new0(uint16_t, *nb_clusters); + if (*nb_clusters && *refcount_table == NULL) { + res->check_errors++; + return -ENOMEM; + } } /* header */ @@ -1780,7 +1782,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, { BDRVQcowState *s = bs->opaque; int64_t size, highest_cluster, nb_clusters; - uint16_t *refcount_table; + uint16_t *refcount_table = NULL; int ret; size = bdrv_getlength(bs->file);