From patchwork Mon Jan 18 12:11:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 43068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02EC8B7C8E for ; Mon, 18 Jan 2010 23:31:12 +1100 (EST) Received: from localhost ([127.0.0.1]:49656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWqlB-0004HA-4z for incoming@patchwork.ozlabs.org; Mon, 18 Jan 2010 07:31:09 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NWqTS-0006mf-Os for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NWqTM-0006jE-6K for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:48 -0500 Received: from [199.232.76.173] (port=51043 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWqTL-0006j1-TT for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47281) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NWqTL-0001c4-G4 for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:43 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0ICCgdH020592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 Jan 2010 07:12:42 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0ICCV9v011108; Mon, 18 Jan 2010 07:12:41 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 18 Jan 2010 13:11:35 +0100 Message-Id: <1263816696-24122-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1263816696-24122-1-git-send-email-kwolf@redhat.com> References: <1263816696-24122-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH 09/10] qcow2: Don't ignore update_refcount return value X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org update_refcount can return errors that need to be handled by the callers. Signed-off-by: Kevin Wolf Reviewed-by: Christoph Hellwig --- block/qcow2-refcount.c | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3dfadf1..b9a825b 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -269,9 +269,8 @@ static int write_refcount_block_entries(BDRVQcowState *s, } /* XXX: cache several refcount block clusters ? */ -static int update_refcount(BlockDriverState *bs, - int64_t offset, int64_t length, - int addend) +static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, + int64_t offset, int64_t length, int addend) { BDRVQcowState *s = bs->opaque; int64_t start, last, cluster_offset; @@ -413,9 +412,13 @@ retry: int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size) { int64_t offset; + int ret; offset = alloc_clusters_noref(bs, size); - update_refcount(bs, offset, size, 1); + ret = update_refcount(bs, offset, size, 1); + if (ret < 0) { + return ret; + } return offset; } @@ -462,7 +465,13 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size) void qcow2_free_clusters(BlockDriverState *bs, int64_t offset, int64_t size) { - update_refcount(bs, offset, size, -1); + int ret; + + ret = update_refcount(bs, offset, size, -1); + if (ret < 0) { + fprintf(stderr, "qcow2_free_clusters failed: %s\n", strerror(-ret)); + abort(); + } } /* @@ -571,9 +580,15 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, if (offset & QCOW_OFLAG_COMPRESSED) { nb_csectors = ((offset >> s->csize_shift) & s->csize_mask) + 1; - if (addend != 0) - update_refcount(bs, (offset & s->cluster_offset_mask) & ~511, - nb_csectors * 512, addend); + if (addend != 0) { + int ret; + ret = update_refcount(bs, + (offset & s->cluster_offset_mask) & ~511, + nb_csectors * 512, addend); + if (ret < 0) { + goto fail; + } + } /* compressed clusters are never modified */ refcount = 2; } else {