From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYy5d-0003Qu-Gf for qemu-devel@nongnu.org; Fri, 09 Dec 2011 05:54:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYy5Z-0008Qw-Da for qemu-devel@nongnu.org; Fri, 09 Dec 2011 05:54:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYy5Z-0008Qs-28 for qemu-devel@nongnu.org; Fri, 09 Dec 2011 05:54:01 -0500 Message-ID: <4EE1E984.6070800@redhat.com> Date: Fri, 09 Dec 2011 11:57:08 +0100 From: Kevin Wolf MIME-Version: 1.0 References: <1323417518-10195-1-git-send-email-zhihuili@linux.vnet.ibm.com> In-Reply-To: <1323417518-10195-1-git-send-email-zhihuili@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2] block/cow.c : return real error code in cow.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Li Zhi Hui Cc: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com Am 09.12.2011 08:58, schrieb Li Zhi Hui: > v2: modify some errors > > Signed-off-by: Li Zhi Hui > --- > block/cow.c | 31 ++++++++++++++++++------------- > 1 files changed, 18 insertions(+), 13 deletions(-) > > diff --git a/block/cow.c b/block/cow.c > index 3c52735..51ca681 100644 > --- a/block/cow.c > +++ b/block/cow.c > @@ -64,15 +64,17 @@ static int cow_open(BlockDriverState *bs, int flags) > struct cow_header_v2 cow_header; > int bitmap_size; > int64_t size; > + int ret; > > /* see if it is a cow image */ > - if (bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)) != > - sizeof(cow_header)) { > + ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header)); > + if (ret < 0) { > goto fail; > } > > if (be32_to_cpu(cow_header.magic) != COW_MAGIC || > be32_to_cpu(cow_header.version) != COW_VERSION) { > + ret = -1; ret is interpreted as -errno by the caller, so usually on Linux systems you'll get a -EPERM (Operation not permitted) error message, which doesn't describe the error very well. I think a better return value for a wrong magic would be -EINVAL. For a wrong version have a look at the qcow2 code (qerror_report and -ENOTSUP). Kevin