From 60d898190e07911768fc8bbfaec1eefb4104c444 Mon Sep 17 00:00:00 2001 Message-Id: <60d898190e07911768fc8bbfaec1eefb4104c444.1379425497.git.minovotn@redhat.com> In-Reply-To: References: From: Li Zhi Hui Date: Fri, 6 Sep 2013 18:12:25 +0200 Subject: [PATCH 05/25] block/cow: Return real error code Signed-off-by: Li Zhi Hui Signed-off-by: Kevin Wolf (cherry picked from commit 16d2fc002a01cdd77e696ecc69de54db6720476a) [RHEL6: only touch parts that are already calling bdrv_* functions] Signed-off-by: Michal Novotny --- block/cow.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/block/cow.c b/block/cow.c index 2c5b08d..05d6448 100644 --- a/block/cow.c +++ b/block/cow.c @@ -64,15 +64,26 @@ 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) { + ret = -EINVAL; goto fail; } - if (be32_to_cpu(cow_header.magic) != COW_MAGIC || - be32_to_cpu(cow_header.version) != COW_VERSION) { + if (be32_to_cpu(cow_header.version) != COW_VERSION) { + char version[64]; + snprintf(version, sizeof(version), + "COW version %d", cow_header.version); + qerror_report(QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, + bs->device_name, "cow", version); + ret = -ENOTSUP; goto fail; } @@ -88,7 +99,7 @@ static int cow_open(BlockDriverState *bs, int flags) qemu_co_mutex_init(&s->lock); return 0; fail: - return -1; + return ret; } /* @@ -180,17 +191,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; @@ -218,8 +231,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); } -- 1.7.11.7