summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorAlberto Faria <afaria@redhat.com>2022-07-05 17:15:09 +0100
committerHanna Reitz <hreitz@redhat.com>2022-07-12 12:14:56 +0200
commitbf5b16fa401633475d21d69c66532f5b29e8433d (patch)
tree60779d913b400906135b6bbce90d6128a52ac3ef /block
parent92529251d2333ea07176cdbd7273483064ba5a7b (diff)
block: Make blk_{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. Signed-off-by: Alberto Faria <afaria@redhat.com> Message-Id: <20220705161527.1054072-2-afaria@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/block-backend.c7
-rw-r--r--block/qcow.c6
2 files changed, 5 insertions, 8 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index f425b00793..4c5e130615 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1573,19 +1573,16 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes)
ret = blk_do_preadv(blk, offset, bytes, &qiov, 0);
blk_dec_in_flight(blk);
- return ret < 0 ? ret : bytes;
+ return ret;
}
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
BdrvRequestFlags flags)
{
- int ret;
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
- ret = blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
-
- return ret < 0 ? ret : bytes;
+ return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
}
int64_t blk_getlength(BlockBackend *blk)
diff --git a/block/qcow.c b/block/qcow.c
index c646d6b16d..25a43353c1 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -891,14 +891,14 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
/* write all the data */
ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0);
- if (ret != sizeof(header)) {
+ if (ret < 0) {
goto exit;
}
if (qcow_opts->has_backing_file) {
ret = blk_pwrite(qcow_blk, sizeof(header),
qcow_opts->backing_file, backing_filename_len, 0);
- if (ret != backing_filename_len) {
+ if (ret < 0) {
goto exit;
}
}
@@ -908,7 +908,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
i++) {
ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
tmp, BDRV_SECTOR_SIZE, 0);
- if (ret != BDRV_SECTOR_SIZE) {
+ if (ret < 0) {
g_free(tmp);
goto exit;
}