block/cow : return real error code in cow.c
PATCH 1/1 block/cow : return real error code in cow.c
Signed-off-by Li Zhi Hui <[email protected]>
--- block/cow.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-)
block/cow.c +12 -10
@@ -64,10 +64,11 @@ 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; }
@@ -88,7 +89,7 @@ static int cow_open(BlockDriverState *bs, int flags)qemu_co_mutex_init (&s->lock);return 0 ; fail: -return -1 ; +return ret; }/*
@@ -182,14 +183,14 @@ 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 ; +return ret; }else {memset (buf,0 , n *512 ); }
@@ -220,8 +221,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 +290,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; }
Signature · 1 line
1.7.4.1
Am 08.12.2011 06:40, schrieb Li Zhi Hui:
Quoted 13 lines
Signed-off-by Li Zhi Hui <[email protected]>--- block/cow.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-)block/cow.c +0
-0@@ -64,10 +64,11 @@ static int cow_open(BlockDriverState *bs, int flags)struct cow_header_v2 cow_header;int bitmap_size;int64_t size;
block/cow.c static int cow_open(BlockDriverState *bs, int flags) · line 74
Quoted 10 lines
block/cow.c +3
-2+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; }
More context:
if (be32_to_cpu(cow_header.magic) != COW_MAGIC ||
be32_to_cpu(cow_header.version) != COW_VERSION) {
goto fail;
}This jumps to fail: with uninitialised ret. Needs to be fixed.
Quoted 10 lines
block/cow.c +1
-1@@ -88,7 +89,7 @@ static int cow_open(BlockDriverState *bs, int flags)qemu_co_mutex_init (&s->lock);return 0 ; fail: -return -1 ; +return ret; }/*
block/cow.c static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num, · line 187
Quoted 7 lines
block/cow.c +2
-2@@ -182,14 +183,14 @@ 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;
Please add braces here while touching the code.
block/cow.c static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num, · line 193
Quoted 7 lines
block/cow.c +1
-1}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 ; +return ret;
And here.
Otherwise the patch looks good to me.
Kevin