aboutsummaryrefslogtreecommitdiff
path: root/block/stream.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2018-01-18 18:08:22 +0100
committerKevin Wolf <kwolf@redhat.com>2018-05-15 16:11:49 +0200
commit05df8a6a2b4e36e8d69de2130e616d5ac28e8837 (patch)
tree69a1ee332e3b77767f2df4ced3066b08e9baae7b /block/stream.c
parent37aa19b63c46d933f1e4ea944cfccee54e2caf4a (diff)
blockjob: Wrappers for progress counter access
Block job drivers are not expected to mess with the internals of the BlockJob object, so provide wrapper functions for one of the cases where they still do it: Updating the progress counter. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'block/stream.c')
-rw-r--r--block/stream.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/block/stream.c b/block/stream.c
index 1a85708fcf..8369852bda 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -107,6 +107,7 @@ static void coroutine_fn stream_run(void *opaque)
BlockBackend *blk = s->common.blk;
BlockDriverState *bs = blk_bs(blk);
BlockDriverState *base = s->base;
+ int64_t len;
int64_t offset = 0;
uint64_t delay_ns = 0;
int error = 0;
@@ -118,11 +119,12 @@ static void coroutine_fn stream_run(void *opaque)
goto out;
}
- s->common.len = bdrv_getlength(bs);
- if (s->common.len < 0) {
- ret = s->common.len;
+ len = bdrv_getlength(bs);
+ if (len < 0) {
+ ret = len;
goto out;
}
+ block_job_progress_set_remaining(&s->common, len);
buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
@@ -135,7 +137,7 @@ static void coroutine_fn stream_run(void *opaque)
bdrv_enable_copy_on_read(bs);
}
- for ( ; offset < s->common.len; offset += n) {
+ for ( ; offset < len; offset += n) {
bool copy;
/* Note that even when no rate limit is applied we need to yield
@@ -159,7 +161,7 @@ static void coroutine_fn stream_run(void *opaque)
/* Finish early if end of backing file has been reached */
if (ret == 0 && n == 0) {
- n = s->common.len - offset;
+ n = len - offset;
}
copy = (ret == 1);
@@ -185,7 +187,7 @@ static void coroutine_fn stream_run(void *opaque)
ret = 0;
/* Publish progress */
- s->common.offset += n;
+ block_job_progress_update(&s->common, n);
if (copy && s->common.speed) {
delay_ns = ratelimit_calculate_delay(&s->limit, n);
} else {