aboutsummaryrefslogtreecommitdiff
path: root/block/stream.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2017-07-07 07:44:59 -0500
committerKevin Wolf <kwolf@redhat.com>2017-07-10 13:18:07 +0200
commit51b0a488882328f8f02519bb47ca7e0e7fbe12ff (patch)
tree36257cf2221ea7e4e54ab7deae446d02c46f326c /block/stream.c
parentc00716beb30ba996bd6fdfd5f41bb07e4414144f (diff)
block: Make bdrv_is_allocated_above() byte-based
We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the signature of the function to use int64_t *pnum ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status. Therefore, for the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_is_allocated(). But some code, particularly stream_run(), gets a lot simpler because it no longer has to mess with sectors. Leave comments where we can further simplify by switching to byte-based iterations, once later patches eliminate the need for sector-aligned operations. For ease of review, bdrv_is_allocated() was tackled separately. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/stream.c')
-rw-r--r--block/stream.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/block/stream.c b/block/stream.c
index df9679c0fc..e6f72346e5 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -111,7 +111,7 @@ static void coroutine_fn stream_run(void *opaque)
uint64_t delay_ns = 0;
int error = 0;
int ret = 0;
- int n = 0; /* sectors */
+ int64_t n = 0; /* bytes */
void *buf;
if (!bs->backing) {
@@ -135,9 +135,8 @@ static void coroutine_fn stream_run(void *opaque)
bdrv_enable_copy_on_read(bs);
}
- for ( ; offset < s->common.len; offset += n * BDRV_SECTOR_SIZE) {
+ for ( ; offset < s->common.len; offset += n) {
bool copy;
- int64_t count = 0;
/* Note that even when no rate limit is applied we need to yield
* with no pending I/O here so that bdrv_drain_all() returns.
@@ -149,28 +148,25 @@ static void coroutine_fn stream_run(void *opaque)
copy = false;
- ret = bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &count);
- /* TODO relax this once bdrv_is_allocated does not enforce sectors */
- assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE));
- n = count >> BDRV_SECTOR_BITS;
+ ret = bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n);
if (ret == 1) {
/* Allocated in the top, no need to copy. */
} else if (ret >= 0) {
/* Copy if allocated in the intermediate images. Limit to the
* known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE). */
ret = bdrv_is_allocated_above(backing_bs(bs), base,
- offset / BDRV_SECTOR_SIZE, n, &n);
+ offset, n, &n);
/* Finish early if end of backing file has been reached */
if (ret == 0 && n == 0) {
- n = (s->common.len - offset) / BDRV_SECTOR_SIZE;
+ n = s->common.len - offset;
}
copy = (ret == 1);
}
- trace_stream_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret);
+ trace_stream_one_iteration(s, offset, n, ret);
if (copy) {
- ret = stream_populate(blk, offset, n * BDRV_SECTOR_SIZE, buf);
+ ret = stream_populate(blk, offset, n, buf);
}
if (ret < 0) {
BlockErrorAction action =
@@ -189,10 +185,9 @@ static void coroutine_fn stream_run(void *opaque)
ret = 0;
/* Publish progress */
- s->common.offset += n * BDRV_SECTOR_SIZE;
+ s->common.offset += n;
if (copy && s->common.speed) {
- delay_ns = ratelimit_calculate_delay(&s->limit,
- n * BDRV_SECTOR_SIZE);
+ delay_ns = ratelimit_calculate_delay(&s->limit, n);
}
}