From patchwork Fri Jan 18 08:53:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 213525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 711B22C0084 for ; Fri, 18 Jan 2013 19:54:05 +1100 (EST) Received: from localhost ([::1]:43624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw7i7-0004az-KL for incoming@patchwork.ozlabs.org; Fri, 18 Jan 2013 03:54:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw7hz-0004ar-Ja for qemu-devel@nongnu.org; Fri, 18 Jan 2013 03:53:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tw7hx-00013I-TA for qemu-devel@nongnu.org; Fri, 18 Jan 2013 03:53:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tw7hx-000114-M0 for qemu-devel@nongnu.org; Fri, 18 Jan 2013 03:53:53 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0I8rqS7023004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Jan 2013 03:53:52 -0500 Received: from blackfin.pond.sub.org (ovpn-116-65.ams2.redhat.com [10.36.116.65]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0I8rpCg015164; Fri, 18 Jan 2013 03:53:51 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A8FBD200A9; Fri, 18 Jan 2013 09:53:50 +0100 (CET) From: Markus Armbruster To: Stefan Weil References: <1358455528-29813-1-git-send-email-sw@weilnetz.de> <1358455528-29813-3-git-send-email-sw@weilnetz.de> Date: Fri, 18 Jan 2013 09:53:50 +0100 In-Reply-To: <1358455528-29813-3-git-send-email-sw@weilnetz.de> (Stefan Weil's message of "Thu, 17 Jan 2013 21:45:25 +0100") Message-ID: <871udizxb5.fsf@blackfin.pond.sub.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: Re: [Qemu-devel] [PATCH v2 2/5] block: Use error code EMEDIUMTYPE for wrong format in some block drivers 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 Stefan Weil writes: > This improves error reports for bochs, cow, qcow, qcow2, qed and vmdk > when a file with the wrong format is selected. > > Signed-off-by: Stefan Weil > --- > block/bochs.c | 2 +- > block/cow.c | 2 +- > block/qcow.c | 2 +- > block/qcow2.c | 2 +- > block/qed.c | 2 +- > block/vmdk.c | 4 ++-- > 6 files changed, 7 insertions(+), 7 deletions(-) > > diff --git a/block/bochs.c b/block/bochs.c > index 1b1d9cd..3737583 100644 > --- a/block/bochs.c > +++ b/block/bochs.c > @@ -126,7 +126,7 @@ static int bochs_open(BlockDriverState *bs, int flags) > strcmp(bochs.subtype, GROWING_TYPE) || > ((le32_to_cpu(bochs.version) != HEADER_VERSION) && > (le32_to_cpu(bochs.version) != HEADER_V1))) { > - goto fail; > + return -EMEDIUMTYPE; > } > > if (le32_to_cpu(bochs.version) == HEADER_V1) { You make the function return either 0, -1 or -EMEDIUMTYPE. Please make it return either 0 or a negative errno code, like this (untested): Same for all the other bdrv_open() methods. diff --git a/block/bochs.c b/block/bochs.c index 1b1d9cd..a9eb338 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -111,14 +111,15 @@ static int bochs_probe(const uint8_t *buf, int buf_size, const char *filename) static int bochs_open(BlockDriverState *bs, int flags) { BDRVBochsState *s = bs->opaque; - int i; + int ret, i; struct bochs_header bochs; struct bochs_header_v1 header_v1; bs->read_only = 1; // no write support yet - if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) { - goto fail; + ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); + if (ret < 0) { + return ret; } if (strcmp(bochs.magic, HEADER_MAGIC) || @@ -126,7 +127,7 @@ static int bochs_open(BlockDriverState *bs, int flags) strcmp(bochs.subtype, GROWING_TYPE) || ((le32_to_cpu(bochs.version) != HEADER_VERSION) && (le32_to_cpu(bochs.version) != HEADER_V1))) { - goto fail; + return -EMEDIUMTYPE; } if (le32_to_cpu(bochs.version) == HEADER_V1) { @@ -138,9 +139,11 @@ static int bochs_open(BlockDriverState *bs, int flags) s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog); s->catalog_bitmap = g_malloc(s->catalog_size * 4); - if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, - s->catalog_size * 4) != s->catalog_size * 4) - goto fail; + ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, + s->catalog_size * 4); + if (ret < 0) { + return ret; + } for (i = 0; i < s->catalog_size; i++) le32_to_cpus(&s->catalog_bitmap[i]); @@ -153,8 +156,6 @@ static int bochs_open(BlockDriverState *bs, int flags) qemu_co_mutex_init(&s->lock); return 0; - fail: - return -1; } static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)