[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring |
Date: |
Thu, 14 Sep 2017 16:57:38 +0100 |
User-agent: |
Mutt/1.8.3 (2017-05-23) |
On Wed, Sep 13, 2017 at 08:19:07PM +0200, Max Reitz wrote:
> This patch implements active synchronous mirroring. In active mode, the
> passive mechanism will still be in place and is used to copy all
> initially dirty clusters off the source disk; but every write request
> will write data both to the source and the target disk, so the source
> cannot be dirtied faster than data is mirrored to the target. Also,
> once the block job has converged (BLOCK_JOB_READY sent), source and
> target are guaranteed to stay in sync (unless an error occurs).
>
> Optionally, dirty data can be copied to the target disk on read
> operations, too.
>
> Active mode is completely optional and currently disabled at runtime. A
> later patch will add a way for users to enable it.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> qapi/block-core.json | 23 +++++++
> block/mirror.c | 187
> +++++++++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 205 insertions(+), 5 deletions(-)
>
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index bb11815608..e072cfa67c 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -938,6 +938,29 @@
> 'data': ['top', 'full', 'none', 'incremental'] }
>
> ##
> +# @MirrorCopyMode:
> +#
> +# An enumeration whose values tell the mirror block job when to
> +# trigger writes to the target.
> +#
> +# @passive: copy data in background only.
> +#
> +# @active-write: when data is written to the source, write it
> +# (synchronously) to the target as well. In addition,
> +# data is copied in background just like in @passive
> +# mode.
> +#
> +# @active-read-write: write data to the target (synchronously) both
> +# when it is read from and written to the source.
> +# In addition, data is copied in background just
> +# like in @passive mode.
I'm not sure the terms "active"/"passive" are helpful. "Active commit"
means committing the top-most BDS while the guest is accessing it. The
"passive" mirror block still works on the top-most BDS while the guest
is accessing it.
Calling it "asynchronous" and "synchronous" is clearer to me. It's also
the terminology used in disk replication (e.g. DRBD).
Ideally the user wouldn't have to worry about async vs sync because QEMU
would switch modes as appropriate in order to converge. That way
libvirt also doesn't have to worry about this.
> static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs,
> uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
> {
> - return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
> + MirrorOp *op = NULL;
> + MirrorBDSOpaque *s = bs->opaque;
> + int ret = 0;
> + bool copy_to_target;
> +
> + copy_to_target = s->job->ret >= 0 &&
> + s->job->copy_mode == MIRROR_COPY_MODE_ACTIVE_READ_WRITE;
> +
> + if (copy_to_target) {
> + op = active_write_prepare(s->job, offset, bytes);
> + }
> +
> + ret = bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
> + if (ret < 0) {
> + goto out;
> + }
> +
> + if (copy_to_target) {
> + do_sync_target_write(s->job, offset, bytes, qiov, 0);
> + }
This mode is dangerous. See bdrv_co_do_copy_on_readv():
/* Perform I/O through a temporary buffer so that users who scribble over
* their read buffer while the operation is in progress do not end up
* modifying the image file. This is critical for zero-copy guest I/O
* where anything might happen inside guest memory.
*/
void *bounce_buffer;
Stefan
- [Qemu-block] [PATCH 10/18] block/mirror: Make source the file child, (continued)
- [Qemu-block] [PATCH 10/18] block/mirror: Make source the file child, Max Reitz, 2017/09/13
- [Qemu-block] [PATCH 11/18] hbitmap: Add @advance param to hbitmap_iter_next(), Max Reitz, 2017/09/13
- [Qemu-block] [PATCH 12/18] block/dirty-bitmap: Add bdrv_dirty_iter_next_area, Max Reitz, 2017/09/13
- [Qemu-block] [PATCH 13/18] block/mirror: Keep write perm for pending writes, Max Reitz, 2017/09/13
- [Qemu-block] [PATCH 14/18] block/mirror: Distinguish active from passive ops, Max Reitz, 2017/09/13
- [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring, Max Reitz, 2017/09/13
- Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring,
Stefan Hajnoczi <=
- Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring, Max Reitz, 2017/09/16
- Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring, Stefan Hajnoczi, 2017/09/18
- Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring, Max Reitz, 2017/09/18
- Re: [Qemu-block] [PATCH 15/18] block/mirror: Add active mirroring, Stefan Hajnoczi, 2017/09/19
- Re: [Qemu-block] [Qemu-devel] [PATCH 15/18] block/mirror: Add active mirroring, Daniel P. Berrange, 2017/09/19
- Re: [Qemu-block] [Qemu-devel] [PATCH 15/18] block/mirror: Add active mirroring, Stefan Hajnoczi, 2017/09/20
[Qemu-block] [PATCH 16/18] block/mirror: Add copy mode QAPI interface, Max Reitz, 2017/09/13
[Qemu-block] [PATCH 17/18] qemu-io: Add background write, Max Reitz, 2017/09/13