From 353a5d84b25c335b259f37c4f43dad96e6d60ba8 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:37 +0100 Subject: block: Make bdrv_{pread,pwrite}() return 0 on success They currently return the value of their 'bytes' parameter on success. Make them return 0 instead, for consistency with other I/O functions and in preparation to implement them using generated_co_wrapper. This also makes it clear that short reads/writes are not possible. The few callers that rely on the previous behavior are adjusted accordingly by hand. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Message-Id: <20220609152744.3891847-4-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- block/dmg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'block/dmg.c') diff --git a/block/dmg.c b/block/dmg.c index 5a460c3eb1..98db18d82a 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -390,7 +390,7 @@ static int dmg_read_plist_xml(BlockDriverState *bs, DmgHeaderState *ds, buffer = g_malloc(info_length + 1); buffer[info_length] = '\0'; ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0); - if (ret != info_length) { + if (ret < 0) { ret = -EINVAL; goto fail; } @@ -611,7 +611,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) * inflated. */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], s->compressed_chunk, 0); - if (ret != s->lengths[chunk]) { + if (ret < 0) { return -1; } @@ -637,7 +637,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) * inflated. */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], s->compressed_chunk, 0); - if (ret != s->lengths[chunk]) { + if (ret < 0) { return -1; } @@ -658,7 +658,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) * inflated. */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], s->compressed_chunk, 0); - if (ret != s->lengths[chunk]) { + if (ret < 0) { return -1; } @@ -674,7 +674,7 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num) case UDRW: /* copy */ ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk], s->uncompressed_chunk, 0); - if (ret != s->lengths[chunk]) { + if (ret < 0) { return -1; } break; -- cgit v1.2.3