From patchwork Fri Aug 22 16:31:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 382291 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 A26721400A0 for ; Sat, 23 Aug 2014 02:33:55 +1000 (EST) Received: from localhost ([::1]:38354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKrmj-0005iK-Pf for incoming@patchwork.ozlabs.org; Fri, 22 Aug 2014 12:33:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKrlv-0004CS-Pv for qemu-devel@nongnu.org; Fri, 22 Aug 2014 12:33:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKrlo-0004Vw-DW for qemu-devel@nongnu.org; Fri, 22 Aug 2014 12:33:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKrlo-0004Vq-3y for qemu-devel@nongnu.org; Fri, 22 Aug 2014 12:32:56 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7MGWr5g030703 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 22 Aug 2014 12:32:53 -0400 Received: from localhost (ovpn-116-46.ams2.redhat.com [10.36.116.46]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7MGWjG7013163 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Fri, 22 Aug 2014 12:32:51 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Fri, 22 Aug 2014 18:31:38 +0200 Message-Id: <1408725104-17176-5-git-send-email-mreitz@redhat.com> In-Reply-To: <1408725104-17176-1-git-send-email-mreitz@redhat.com> References: <1408725104-17176-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , =?UTF-8?q?Beno=C3=AEt=20Canet?= , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v3 04/10] 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 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 --- 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 2b728ef..babe6cb 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1584,10 +1584,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 */ @@ -1694,7 +1696,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);