diff options
author | Eric Blake <eblake@redhat.com> | 2017-10-11 22:47:08 -0500 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-10-26 14:45:57 +0200 |
commit | 3182664220571d11d4fe03ecdc10fcc1e842ed32 (patch) | |
tree | a156b5da4a97164b0620bf8067130088a4cfe2f1 /block/mirror.c | |
parent | 5b648c67e3acea3e0136d0bb1bd47341996e0e4e (diff) | |
download | qemu-3182664220571d11d4fe03ecdc10fcc1e842ed32.zip qemu-3182664220571d11d4fe03ecdc10fcc1e842ed32.tar.gz qemu-3182664220571d11d4fe03ecdc10fcc1e842ed32.tar.bz2 |
block: Convert bdrv_get_block_status_above() to bytes
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 name of the function from bdrv_get_block_status_above()
to bdrv_block_status_above() ensures that the compiler enforces that
all callers are updated. Likewise, since it a byte interface allows
an offset mapping that might not be sector aligned, split the mapping
out of the return value and into a pass-by-reference parameter. For
now, the io.c layer still assert()s that all uses are sector-aligned,
but that can be relaxed when a later patch implements byte-based
block status in the drivers.
For the most part this patch is just the addition of scaling at the
callers followed by inverse scaling at bdrv_block_status(), plus
updates for the new split return interface. But some code,
particularly bdrv_block_status(), gets a lot simpler because it no
longer has to mess with sectors. Likewise, mirror code no longer
computes s->granularity >> BDRV_SECTOR_BITS, and can therefore drop
an assertion about alignment because the loop no longer depends on
alignment (never mind that we don't really have a driver that
reports sub-sector alignments, so it's not really possible to test
the effect of sub-sector mirroring). Fix a neighboring assertion to
use is_power_of_2 while there.
For ease of review, bdrv_get_block_status() was tackled separately.
Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/mirror.c')
-rw-r--r-- | block/mirror.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/block/mirror.c b/block/mirror.c index d11706c..307b639 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -328,7 +328,6 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) uint64_t delay_ns = 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks = 1; - int sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS; bool write_zeroes_ok = bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)); int max_io_bytes = MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); @@ -376,7 +375,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } /* Clear dirty bits before querying the block status, because - * calling bdrv_get_block_status_above could yield - if some blocks are + * calling bdrv_block_status_above could yield - if some blocks are * marked dirty in this window, we need to know. */ bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset, @@ -385,8 +384,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks); while (nb_chunks > 0 && offset < s->bdev_length) { - int64_t ret; - int io_sectors; + int ret; int64_t io_bytes; int64_t io_bytes_acct; enum MirrorMethod { @@ -396,11 +394,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) } mirror_method = MIRROR_METHOD_COPY; assert(!(offset % s->granularity)); - ret = bdrv_get_block_status_above(source, NULL, - offset >> BDRV_SECTOR_BITS, - nb_chunks * sectors_per_chunk, - &io_sectors, NULL); - io_bytes = io_sectors * BDRV_SECTOR_SIZE; + ret = bdrv_block_status_above(source, NULL, offset, + nb_chunks * s->granularity, + &io_bytes, NULL, NULL); if (ret < 0) { io_bytes = MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { @@ -1131,9 +1127,7 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs, granularity = bdrv_get_default_bitmap_granularity(target); } - assert ((granularity & (granularity - 1)) == 0); - /* Granularity must be large enough for sector-based dirty bitmap */ - assert(granularity >= BDRV_SECTOR_SIZE); + assert(is_power_of_2(granularity)); if (buf_size < 0) { error_setg(errp, "Invalid parameter 'buf-size'"); |