From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwot-00019s-NL for qemu-devel@nongnu.org; Fri, 06 Sep 2013 10:15:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHwon-0001HO-NY for qemu-devel@nongnu.org; Fri, 06 Sep 2013 10:15:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHwon-0001HI-Ex for qemu-devel@nongnu.org; Fri, 06 Sep 2013 10:15:25 -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.14.4/8.14.4) with ESMTP id r86EFNPA027812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 6 Sep 2013 10:15:24 -0400 Date: Fri, 6 Sep 2013 16:15:20 +0200 From: Kevin Wolf Message-ID: <20130906141520.GM2588@dhcp-200-207.str.redhat.com> References: <1378389342-4749-1-git-send-email-mreitz@redhat.com> <1378389342-4749-6-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1378389342-4749-6-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [RFC v2 5/6] qcow2: Use Error parameter List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Am 05.09.2013 um 15:55 hat Max Reitz geschrieben: > Employ usage of the new Error ** parameter in qcow2_open, qcow2_create > and associated functions. > > Signed-off-by: Max Reitz > --- > block/qcow2.c | 135 ++++++++++++++++++++++++++++++++++++++-------------------- > 1 file changed, 88 insertions(+), 47 deletions(-) > > diff --git a/block/qcow2.c b/block/qcow2.c > index e16d352..9a96188 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1,4 +1,5 @@ > /* > + * error_setg(errp, " > * Block driver for the QCOW version 2 format > * > * Copyright (c) 2004-2006 Fabrice Bellard Uhm... No? :-) > @@ -79,7 +80,8 @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename) > * return 0 upon success, non-0 otherwise > */ > static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, > - uint64_t end_offset, void **p_feature_table) > + uint64_t end_offset, void **p_feature_table, > + Error **errp) > { > BDRVQcowState *s = bs->opaque; > QCowExtension ext; > @@ -100,10 +102,10 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, > printf("attempting to read extended header in offset %lu\n", offset); > #endif > > - if (bdrv_pread(bs->file, offset, &ext, sizeof(ext)) != sizeof(ext)) { > - fprintf(stderr, "qcow2_read_extension: ERROR: " > - "pread fail from offset %" PRIu64 "\n", > - offset); > + ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext)); > + if (ret < 0) { > + error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: " > + "pread fail from offset %" PRIu64, offset); > return 1; > } > be32_to_cpus(&ext.magic); > @@ -113,7 +115,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, > printf("ext.magic = 0x%x\n", ext.magic); > #endif > if (ext.len > end_offset - offset) { > - error_report("Header extension too large"); > + error_setg(errp, "Header extension too large"); > return -EINVAL; > } > > @@ -123,17 +125,19 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, > > case QCOW2_EXT_MAGIC_BACKING_FORMAT: > if (ext.len >= sizeof(bs->backing_format)) { > - fprintf(stderr, "ERROR: ext_backing_format: len=%u too large" > - " (>=%zu)\n", > - ext.len, sizeof(bs->backing_format)); > + error_setg(errp, "ERROR: ext_backing_format: len=%u too large" > + " (>=%zu)", ext.len, sizeof(bs->backing_format)); > return 2; > } > - if (bdrv_pread(bs->file, offset , bs->backing_format, > - ext.len) != ext.len) > + ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len); > + if (ret < 0) { > + error_setg_errno(errp, -ret, "ERROR: ext_backing_format: " > + "Could not read format name"); > return 3; > + } > bs->backing_format[ext.len] = '\0'; > #ifdef DEBUG_EXT > - printf("Qcow2: Got format extension %s\n", bs->backing_format); > + printf("Qcow2: Got format extension %s", bs->backing_format); Huh? > #endif > break; > > @@ -1412,8 +1442,9 @@ static int qcow2_create2(const char *filename, int64_t total_size, > BlockDriver* drv = bdrv_find_format("qcow2"); > assert(drv != NULL); > ret = bdrv_open(bs, filename, NULL, > - BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, NULL); > + BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, drv, &local_err); > if (ret < 0) { > + error_propagate(errp, local_err); > goto out; > } More context: ret = qcow2_alloc_clusters(bs, 2 * cluster_size); if (ret < 0) { goto out; Missing error_setg_errno()? Kevin