[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 024/100] stream: Switch stream_run() to byte-based
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 024/100] stream: Switch stream_run() to byte-based |
Date: |
Fri, 7 Jul 2017 19:07:39 +0200 |
From: Eric Blake <address@hidden>
We are gradually converting to byte-based interfaces, as they are
easier to reason about than sector-based. Change the internal
loop iteration of streaming to track by bytes instead of sectors
(although we are still guaranteed that we iterate by steps that
are sector-aligned).
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/stream.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/block/stream.c b/block/stream.c
index 12f1659..e3dd2ac 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -107,12 +107,11 @@ static void coroutine_fn stream_run(void *opaque)
BlockBackend *blk = s->common.blk;
BlockDriverState *bs = blk_bs(blk);
BlockDriverState *base = s->base;
- int64_t sector_num = 0;
- int64_t end = -1;
+ int64_t offset = 0;
uint64_t delay_ns = 0;
int error = 0;
int ret = 0;
- int n = 0;
+ int n = 0; /* sectors */
void *buf;
if (!bs->backing) {
@@ -125,7 +124,6 @@ static void coroutine_fn stream_run(void *opaque)
goto out;
}
- end = s->common.len >> BDRV_SECTOR_BITS;
buf = qemu_blockalign(bs, STREAM_BUFFER_SIZE);
/* Turn on copy-on-read for the whole block device so that guest read
@@ -137,7 +135,7 @@ static void coroutine_fn stream_run(void *opaque)
bdrv_enable_copy_on_read(bs);
}
- for (sector_num = 0; sector_num < end; sector_num += n) {
+ for ( ; offset < s->common.len; offset += n * BDRV_SECTOR_SIZE) {
bool copy;
/* Note that even when no rate limit is applied we need to yield
@@ -150,28 +148,26 @@ static void coroutine_fn stream_run(void *opaque)
copy = false;
- ret = bdrv_is_allocated(bs, sector_num,
+ ret = bdrv_is_allocated(bs, offset / BDRV_SECTOR_SIZE,
STREAM_BUFFER_SIZE / BDRV_SECTOR_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 [sector_num, sector_num+n). */
+ * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE). */
ret = bdrv_is_allocated_above(backing_bs(bs), base,
- sector_num, n, &n);
+ offset / BDRV_SECTOR_SIZE, n, &n);
/* Finish early if end of backing file has been reached */
if (ret == 0 && n == 0) {
- n = end - sector_num;
+ n = (s->common.len - offset) / BDRV_SECTOR_SIZE;
}
copy = (ret == 1);
}
- trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE,
- n * BDRV_SECTOR_SIZE, ret);
+ trace_stream_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret);
if (copy) {
- ret = stream_populate(blk, sector_num * BDRV_SECTOR_SIZE,
- n * BDRV_SECTOR_SIZE, buf);
+ ret = stream_populate(blk, offset, n * BDRV_SECTOR_SIZE, buf);
}
if (ret < 0) {
BlockErrorAction action =
--
1.8.3.1
- [Qemu-block] [PULL 015/100] vvfat: limit number of entries in root directory in FAT12/FAT16, (continued)
- [Qemu-block] [PULL 015/100] vvfat: limit number of entries in root directory in FAT12/FAT16, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 016/100] vvfat: handle KANJI lead byte 0xe5, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 006/100] vvfat: replace tabs by 8 spaces, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 018/100] qemu-img: drop -e and -6 options from the 'create' & 'convert' commands, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 020/100] blockjob: Track job ratelimits via bytes, not sectors, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 017/100] vvfat: change OEM name to 'MSWIN4.1', Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 019/100] blockdev: Print a warning for legacy drive options that belong to -device, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 022/100] stream: Switch stream_populate() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 021/100] trace: Show blockjob actions via bytes, not sectors, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 023/100] stream: Drop reached_end for stream_complete(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 024/100] stream: Switch stream_run() to byte-based,
Kevin Wolf <=
- [Qemu-block] [PULL 025/100] commit: Switch commit_populate() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 028/100] mirror: Switch mirror_do_zero_or_discard() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 026/100] commit: Switch commit_run() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 029/100] mirror: Update signature of mirror_clip_sectors(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 027/100] mirror: Switch MirrorBlockJob to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 030/100] mirror: Switch mirror_cow_align() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 031/100] mirror: Switch mirror_do_read() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 032/100] mirror: Switch mirror_iteration() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 033/100] block: Drop unused bdrv_round_sectors_to_clusters(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 034/100] backup: Switch BackupBlockJob to byte-based, Kevin Wolf, 2017/07/07