[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co
From: |
Jeff Cody |
Subject: |
Re: [Qemu-devel] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read() |
Date: |
Mon, 13 Aug 2018 23:39:23 -0400 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
On Mon, Aug 13, 2018 at 04:19:52AM +0200, Max Reitz wrote:
> Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
> ---
> block/mirror.c | 54 +++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 36 insertions(+), 18 deletions(-)
>
> diff --git a/block/mirror.c b/block/mirror.c
> index c28b6159d5..34cb8293b2 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -305,42 +305,60 @@ static inline void coroutine_fn
> mirror_co_wait_for_any_operation(s, false);
> }
>
> -/* Perform a mirror copy operation.
> +/*
> + * Restrict *bytes to how much we can actually handle, and align the
> + * [*offset, *bytes] range to clusters if COW is needed.
> *
> - * *op->bytes_handled is set to the number of bytes copied after and
> + * *bytes_handled is set to the number of bytes copied after and
> * including offset, excluding any bytes copied prior to offset due
> - * to alignment. This will be op->bytes if no alignment is necessary,
> - * or (new_end - op->offset) if the tail is rounded up or down due to
> + * to alignment. This will be *bytes if no alignment is necessary, or
> + * (new_end - *offset) if the tail is rounded up or down due to
> * alignment or buffer limit.
> */
> -static void coroutine_fn mirror_co_read(void *opaque)
> +static void mirror_align_for_copy(MirrorBlockJob *s,
> + int64_t *offset, uint64_t *bytes,
> + int64_t *bytes_handled)
> {
> - MirrorOp *op = opaque;
> - MirrorBlockJob *s = op->s;
> - int nb_chunks;
> - uint64_t ret;
> uint64_t max_bytes;
>
> max_bytes = s->granularity * s->max_iov;
>
> /* We can only handle as much as buf_size at a time. */
> - op->bytes = MIN(s->buf_size, MIN(max_bytes, op->bytes));
> - assert(op->bytes);
> - assert(op->bytes < BDRV_REQUEST_MAX_BYTES);
> - *op->bytes_handled = op->bytes;
> + *bytes = MIN(s->buf_size, MIN(max_bytes, *bytes));
> + assert(*bytes);
> + assert(*bytes < BDRV_REQUEST_MAX_BYTES);
> + *bytes_handled = *bytes;
>
> if (s->cow_bitmap) {
> - *op->bytes_handled += mirror_cow_align(s, &op->offset, &op->bytes);
> + *bytes_handled += mirror_cow_align(s, offset, bytes);
> }
> /* Cannot exceed BDRV_REQUEST_MAX_BYTES + INT_MAX */
> - assert(*op->bytes_handled <= UINT_MAX);
> - assert(op->bytes <= s->buf_size);
> + assert(*bytes_handled <= UINT_MAX);
> + assert(*bytes <= s->buf_size);
> /* The offset is granularity-aligned because:
> * 1) Caller passes in aligned values;
> * 2) mirror_cow_align is used only when target cluster is larger. */
> - assert(QEMU_IS_ALIGNED(op->offset, s->granularity));
> + assert(QEMU_IS_ALIGNED(*offset, s->granularity));
> /* The range is sector-aligned, since bdrv_getlength() rounds up. */
> - assert(QEMU_IS_ALIGNED(op->bytes, BDRV_SECTOR_SIZE));
> + assert(QEMU_IS_ALIGNED(*bytes, BDRV_SECTOR_SIZE));
> +}
> +
> +/* Perform a mirror copy operation.
> + *
> + * *op->bytes_handled is set to the number of bytes copied after and
> + * including offset, excluding any bytes copied prior to offset due
> + * to alignment. This will be op->bytes if no alignment is necessary,
> + * or (new_end - op->offset) if the tail is rounded up or down due to
> + * alignment or buffer limit.
> + */
> +static void coroutine_fn mirror_co_read(void *opaque)
> +{
> + MirrorOp *op = opaque;
> + MirrorBlockJob *s = op->s;
> + int nb_chunks;
> + uint64_t ret;
> +
> + mirror_align_for_copy(s, &op->offset, &op->bytes, op->bytes_handled);
> nb_chunks = DIV_ROUND_UP(op->bytes, s->granularity);
>
> while (s->buf_free_count < nb_chunks) {
> --
> 2.17.1
>
- [Qemu-devel] [PATCH 00/17] mirror: Mainly coroutine refinements, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 01/17] iotests: Try reading while mirroring in 156, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 02/17] mirror: Make wait_for_any_operation() coroutine_fn, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read(), Max Reitz, 2018/08/12
- Re: [Qemu-devel] [PATCH 03/17] mirror: Pull *_align_for_copy() from *_co_read(),
Jeff Cody <=
- [Qemu-devel] [PATCH 04/17] mirror: Remove bytes_handled, part 1, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 06/17] mirror: Create mirror_co_perform(), Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 05/17] mirror: Remove bytes_handled, part 2, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 07/17] mirror: Make mirror_co_zero() nicer, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 08/17] mirror: Make mirror_co_discard() nicer, Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 09/17] mirror: Lock AioContext in mirror_co_perform(), Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 10/17] mirror: Create mirror_co_alloc_qiov(), Max Reitz, 2018/08/12
- [Qemu-devel] [PATCH 11/17] mirror: Inline mirror_write_complete(), part 1, Max Reitz, 2018/08/12