From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYvME-0004tY-5L for qemu-devel@nongnu.org; Fri, 09 Dec 2011 02:59:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYvMD-0006wT-1P for qemu-devel@nongnu.org; Fri, 09 Dec 2011 02:59:02 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:58815) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYvMC-0006wH-GX for qemu-devel@nongnu.org; Fri, 09 Dec 2011 02:59:01 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Dec 2011 07:56:18 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pB97t2TM3604570 for ; Fri, 9 Dec 2011 18:55:02 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pB97wfiw002628 for ; Fri, 9 Dec 2011 18:58:41 +1100 From: Li Zhi Hui Date: Fri, 9 Dec 2011 15:58:38 +0800 Message-Id: <1323417518-10195-1-git-send-email-zhihuili@linux.vnet.ibm.com> Subject: [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: qemu-devel@nongnu.org Cc: kwolf@redhat.com, Li Zhi Hui , stefanha@linux.vnet.ibm.com 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; goto fail; } @@ -88,7 +90,7 @@ static int cow_open(BlockDriverState *bs, int flags) qemu_co_mutex_init(&s->lock); return 0; fail: - return -1; + return ret; } /* @@ -182,17 +184,19 @@ static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num, ret = bdrv_pread(bs->file, s->cow_sectors_offset + sector_num * 512, buf, n * 512); - if (ret != n * 512) - return -1; + if (ret < 0) { + return ret; + } } else { if (bs->backing_hd) { /* read from the base image */ ret = bdrv_read(bs->backing_hd, sector_num, buf, n); - if (ret < 0) - return -1; + if (ret < 0) { + return ret; + } } else { - memset(buf, 0, n * 512); - } + memset(buf, 0, n * 512); + } } nb_sectors -= n; sector_num += n; @@ -220,8 +224,9 @@ static int cow_write(BlockDriverState *bs, int64_t sector_num, ret = bdrv_pwrite(bs->file, s->cow_sectors_offset + sector_num * 512, buf, nb_sectors * 512); - if (ret != nb_sectors * 512) - return -1; + if (ret < 0) { + return ret; + } return cow_update_bitmap(bs, sector_num, nb_sectors); } @@ -288,14 +293,14 @@ static int cow_create(const char *filename, QEMUOptionParameter *options) cow_header.sectorsize = cpu_to_be32(512); cow_header.size = cpu_to_be64(image_sectors * 512); ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header)); - if (ret != sizeof(cow_header)) { + if (ret < 0) { goto exit; } /* resize to include at least all the bitmap */ ret = bdrv_truncate(cow_bs, sizeof(cow_header) + ((image_sectors + 7) >> 3)); - if (ret) { + if (ret < 0) { goto exit; } -- 1.7.4.1