summaryrefslogtreecommitdiffstats
path: root/qemu-img.c
diff options
context:
space:
mode:
authorAlberto Faria2022-07-05 18:15:09 +0200
committerHanna Reitz2022-07-12 12:14:56 +0200
commitbf5b16fa401633475d21d69c66532f5b29e8433d (patch)
tree60779d913b400906135b6bbce90d6128a52ac3ef /qemu-img.c
parenttests/qemu-iotests: skip 108 when FUSE is not loaded (diff)
downloadqemu-bf5b16fa401633475d21d69c66532f5b29e8433d.tar.gz
qemu-bf5b16fa401633475d21d69c66532f5b29e8433d.tar.xz
qemu-bf5b16fa401633475d21d69c66532f5b29e8433d.zip
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 'qemu-img.c')
-rw-r--r--qemu-img.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 4cf4d2423d..2dc07e5ac3 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -5120,30 +5120,23 @@ static int img_dd(int argc, char **argv)
in.buf = g_new(uint8_t, in.bsz);
for (out_pos = 0; in_pos < size; block_count++) {
- int in_ret, out_ret;
+ int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
- if (in_pos + in.bsz > size) {
- in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
- } else {
- in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
- }
- if (in_ret < 0) {
+ ret = blk_pread(blk1, in_pos, in.buf, bytes);
+ if (ret < 0) {
error_report("error while reading from input image file: %s",
- strerror(-in_ret));
- ret = -1;
+ strerror(-ret));
goto out;
}
- in_pos += in_ret;
+ in_pos += bytes;
- out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
-
- if (out_ret < 0) {
+ ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
+ if (ret < 0) {
error_report("error while writing to output image file: %s",
- strerror(-out_ret));
- ret = -1;
+ strerror(-ret));
goto out;
}
- out_pos += out_ret;
+ out_pos += bytes;
}
out: