* [Qemu-devel] [PATCH v2] block/cow.c : return real error code in cow.c
@ 2011-12-09 7:58 Li Zhi Hui
2011-12-09 10:57 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Li Zhi Hui @ 2011-12-09 7:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, Li Zhi Hui, stefanha
v2: modify some errors
Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] block/cow.c : return real error code in cow.c
2011-12-09 7:58 [Qemu-devel] [PATCH v2] block/cow.c : return real error code in cow.c Li Zhi Hui
@ 2011-12-09 10:57 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2011-12-09 10:57 UTC (permalink / raw)
To: Li Zhi Hui; +Cc: qemu-devel, stefanha
Am 09.12.2011 08:58, schrieb Li Zhi Hui:
> v2: modify some errors
>
> Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-09 10:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-09 7:58 [Qemu-devel] [PATCH v2] block/cow.c : return real error code in cow.c Li Zhi Hui
2011-12-09 10:57 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).