From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLHQn-00025F-IQ for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLHQm-0006qy-8W for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42412) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLHQm-0006qq-0V for qemu-devel@nongnu.org; Tue, 10 Feb 2015 15:29:12 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1AKTBwd006217 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 10 Feb 2015 15:29:11 -0500 From: Max Reitz Date: Tue, 10 Feb 2015 15:28:45 -0500 Message-Id: <1423600146-7642-4-git-send-email-mreitz@redhat.com> In-Reply-To: <1423600146-7642-1-git-send-email-mreitz@redhat.com> References: <1423600146-7642-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v6 03/24] qcow2: Do not return new value after refcount update List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz qcow2_update_cluster_refcount() does not have any quick access to the new refcount value, it has to call qcow2_get_refcount(). Some callers do not need that new value at all, others call qcow2_get_refcount() themselves anyway (albeit in a different code path, which can however be easily changed), therefore there is no advantage in making qcow2_update_cluster_refcount() return the new value. Drop it. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index f43093f..69c6822 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -643,8 +643,7 @@ fail: /* * Increases or decreases the refcount of a given cluster. * - * If the return value is non-negative, it is the new refcount of the cluster. - * If it is negative, it is -errno and indicates an error. + * On success 0 is returned; on failure -errno is returned. */ int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index, @@ -660,7 +659,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs, return ret; } - return qcow2_get_refcount(bs, cluster_index); + return 0; } @@ -988,13 +987,15 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, break; } if (addend != 0) { - refcount = qcow2_update_cluster_refcount(bs, + ret = qcow2_update_cluster_refcount(bs, cluster_index, addend, QCOW2_DISCARD_SNAPSHOT); - } else { - refcount = qcow2_get_refcount(bs, cluster_index); + if (ret < 0) { + goto fail; + } } + refcount = qcow2_get_refcount(bs, cluster_index); if (refcount < 0) { ret = refcount; goto fail; @@ -1029,11 +1030,15 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, if (addend != 0) { - refcount = qcow2_update_cluster_refcount(bs, l2_offset >> - s->cluster_bits, addend, QCOW2_DISCARD_SNAPSHOT); - } else { - refcount = qcow2_get_refcount(bs, l2_offset >> s->cluster_bits); + ret = qcow2_update_cluster_refcount(bs, l2_offset >> + s->cluster_bits, + addend, + QCOW2_DISCARD_SNAPSHOT); + if (ret < 0) { + goto fail; + } } + refcount = qcow2_get_refcount(bs, l2_offset >> s->cluster_bits); if (refcount < 0) { ret = refcount; goto fail; -- 2.1.0