From patchwork Tue Apr 6 13:30:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 49519 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 C19F9B7D0E for ; Tue, 6 Apr 2010 23:43:34 +1000 (EST) Received: from localhost ([127.0.0.1]:52029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nz93y-00077D-F9 for incoming@patchwork.ozlabs.org; Tue, 06 Apr 2010 09:43:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nz8sA-0002UD-3O for qemu-devel@nongnu.org; Tue, 06 Apr 2010 09:31:18 -0400 Received: from [140.186.70.92] (port=34582 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nz8rw-0002N5-0S for qemu-devel@nongnu.org; Tue, 06 Apr 2010 09:31:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nz8rt-0006t6-4X for qemu-devel@nongnu.org; Tue, 06 Apr 2010 09:31:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57740) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nz8rs-0006sX-Kq for qemu-devel@nongnu.org; Tue, 06 Apr 2010 09:31:01 -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.13.8/8.13.8) with ESMTP id o36DV0mL021328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 6 Apr 2010 09:31:00 -0400 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o36DUixM011039; Tue, 6 Apr 2010 09:30:58 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 6 Apr 2010 15:30:13 +0200 Message-Id: <1270560614-31030-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1270560614-31030-1-git-send-email-kwolf@redhat.com> References: <1270560614-31030-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH 5/6] qcow2: Return 0/-errno in l2_allocate 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 Returning NULL on error doesn't allow distinguishing between different errors. Change the interface to return an integer for -errno. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 40 +++++++++++++++++++++++----------------- 1 files changed, 23 insertions(+), 17 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a2d3962..ace3b85 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -220,13 +220,14 @@ static int write_l1_entry(BDRVQcowState *s, int l1_index) * */ -static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) +static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table) { BDRVQcowState *s = bs->opaque; int min_index; uint64_t old_l2_offset; uint64_t *l2_table; int64_t l2_offset; + int ret; old_l2_offset = s->l1_table[l1_index]; @@ -234,14 +235,15 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) l2_offset = qcow2_alloc_clusters(bs, s->l2_size * sizeof(uint64_t)); if (l2_offset < 0) { - return NULL; + return l2_offset; } /* update the L1 entry */ s->l1_table[l1_index] = l2_offset | QCOW_OFLAG_COPIED; - if (write_l1_entry(s, l1_index) < 0) { - return NULL; + ret = write_l1_entry(s, l1_index); + if (ret < 0) { + return ret; } /* allocate a new entry in the l2 cache */ @@ -255,24 +257,27 @@ static uint64_t *l2_allocate(BlockDriverState *bs, int l1_index) } else { /* if there was an old l2 table, read it from the disk */ BLKDBG_EVENT(s->hd, BLKDBG_L2_ALLOC_COW_READ); - if (bdrv_pread(s->hd, old_l2_offset, - l2_table, s->l2_size * sizeof(uint64_t)) != - s->l2_size * sizeof(uint64_t)) - return NULL; + ret = bdrv_pread(s->hd, old_l2_offset, l2_table, + s->l2_size * sizeof(uint64_t)); + if (ret < 0) { + return ret; + } } /* write the l2 table to the file */ BLKDBG_EVENT(s->hd, BLKDBG_L2_ALLOC_WRITE); - if (bdrv_pwrite(s->hd, l2_offset, - l2_table, s->l2_size * sizeof(uint64_t)) != - s->l2_size * sizeof(uint64_t)) - return NULL; + ret = bdrv_pwrite(s->hd, l2_offset, l2_table, + s->l2_size * sizeof(uint64_t)); + if (ret < 0) { + return ret; + } /* update the l2 cache entry */ s->l2_cache_offsets[min_index] = l2_offset; s->l2_cache_counts[min_index] = 1; - return l2_table; + *table = l2_table; + return 0; } static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, @@ -510,7 +515,8 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, { BDRVQcowState *s = bs->opaque; unsigned int l1_index, l2_index; - uint64_t l2_offset, *l2_table; + uint64_t l2_offset; + uint64_t *l2_table = NULL; int ret; /* seek the the l2 offset in the l1 table */ @@ -536,9 +542,9 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset, } else { if (l2_offset) qcow2_free_clusters(bs, l2_offset, s->l2_size * sizeof(uint64_t)); - l2_table = l2_allocate(bs, l1_index); - if (l2_table == NULL) { - return -EIO; + ret = l2_allocate(bs, l1_index, &l2_table); + if (ret < 0) { + return ret; } l2_offset = s->l1_table[l1_index] & ~QCOW_OFLAG_COPIED; }