qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org
Cc: kwolf@redhat.com, den@openvz.org, jsnow@redhat.com,
	qemu-devel@nongnu.org
Subject: Re: [PATCH 3/4] block/mirror: support unaligned write in active mirror
Date: Fri, 4 Oct 2019 18:31:51 +0200	[thread overview]
Message-ID: <6fd6a449-0443-ecfa-0eec-23e3b515b303@redhat.com> (raw)
In-Reply-To: <20190912151338.21225-4-vsementsov@virtuozzo.com>


[-- Attachment #1.1: Type: text/plain, Size: 3588 bytes --]

On 12.09.19 17:13, Vladimir Sementsov-Ogievskiy wrote:
> Prior 9adc1cb49af8d do_sync_target_write had a bug: it reset aligned-up
> region in the dirty bitmap, which means that we may not copy some bytes
> and assume them copied, which actually leads to producing corrupted
> target.
> 
> So 9adc1cb49af8d forced dirty bitmap granularity to be
> request_alignment for mirror-top filter, so we are not working with
> unaligned requests. However forcing large alignment obviously decreases
> performance of unaligned requests.
> 
> This commit provides another solution for the problem: if unaligned
> padding is already dirty, we can safely ignore it, as
> 1. It's dirty, it will be copied by mirror_iteration anyway
> 2. It's dirty, so skipping it now we don't increase dirtiness of the
>    bitmap and therefore don't damage "synchronicity" of the
>    write-blocking mirror.
> 
> If unaligned padding is not dirty, we just write it, no reason to touch
> dirty bitmap if we succeed (on failure we'll set the whole region
> ofcourse, but we loss "synchronicity" on failure anyway).
> 
> Note: we need to disable dirty_bitmap, otherwise we will not be able to
> see in do_sync_target_write bitmap state before current operation. We
> may of course check dirty bitmap before the operation in
> bdrv_mirror_top_do_write and remember it, but we don't need active
> dirty bitmap for write-blocking mirror anyway.
> 
> New code-path is unused until the following commit reverts
> 9adc1cb49af8d.
> 
> Suggested-by: Denis V. Lunev <den@openvz.org>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/mirror.c | 39 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index d176bf5920..d192f6a96b 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -1204,6 +1204,39 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMethod method,
>                       QEMUIOVector *qiov, int flags)
>  {
>      int ret;
> +    size_t qiov_offset = 0;
> +
> +    if (!QEMU_IS_ALIGNED(offset, job->granularity) &&
> +        bdrv_dirty_bitmap_get(job->dirty_bitmap, offset)) {
> +            /*
> +             * Dirty unaligned padding
> +             * 1. It's already dirty, no damage to "actively_synced" if we just
> +             *    skip unaligned part.
> +             * 2. If we copy it, we can't reset corresponding bit in
> +             *    dirty_bitmap as there may be some "dirty" bytes still not
> +             *    copied.
> +             * So, just ignore it.
> +             */
> +            qiov_offset = QEMU_ALIGN_UP(offset, job->granularity) - offset;
> +            if (bytes <= qiov_offset) {
> +                /* nothing to do after shrink */
> +                return;
> +            }
> +            offset += qiov_offset;
> +            bytes -= qiov_offset;
> +    }
> +
> +    if (!QEMU_IS_ALIGNED(offset + bytes, job->granularity) &&
> +        bdrv_dirty_bitmap_get(job->dirty_bitmap, offset + bytes - 1))
> +    {
> +        uint64_t tail = (offset + bytes) % job->granularity;
> +
> +        if (bytes <= tail) {
> +            /* nothing to do after shrink */
> +            return;
> +        }
> +        bytes -= tail;
> +    }
>  
>      bdrv_reset_dirty_bitmap(job->dirty_bitmap, offset, bytes);
>  

The bdrv_set_dirty_bitmap() in the error case below needs to use the
original offset/bytes, I suppose.

Apart from that, looks good to me.

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2019-10-04 16:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 15:13 [Qemu-devel] [PATCH 0/4] active-mirror: support unaligned guest operations Vladimir Sementsov-Ogievskiy
2019-09-12 15:13 ` [Qemu-devel] [PATCH 1/4] block/mirror: simplify do_sync_target_write Vladimir Sementsov-Ogievskiy
2019-10-02 14:57   ` Max Reitz
2019-09-12 15:13 ` [Qemu-devel] [PATCH 2/4] block/block-backend: add blk_co_pwritev_part Vladimir Sementsov-Ogievskiy
2019-10-02 14:57   ` Max Reitz
2019-09-12 15:13 ` [Qemu-devel] [PATCH 3/4] block/mirror: support unaligned write in active mirror Vladimir Sementsov-Ogievskiy
2019-10-02 14:57   ` Max Reitz
2019-10-02 15:03     ` Vladimir Sementsov-Ogievskiy
2019-10-02 15:06       ` Vladimir Sementsov-Ogievskiy
2019-10-02 15:52         ` Max Reitz
2019-10-03  9:34           ` Vladimir Sementsov-Ogievskiy
2019-10-04 12:59             ` Max Reitz
2019-10-04 13:22               ` Vladimir Sementsov-Ogievskiy
2019-10-04 14:48                 ` Max Reitz
2019-10-04 15:04                   ` Vladimir Sementsov-Ogievskiy
2019-10-04 15:27                     ` Max Reitz
2019-10-04 15:38                       ` Vladimir Sementsov-Ogievskiy
2019-10-04 16:31   ` Max Reitz [this message]
2019-10-11  8:33     ` Vladimir Sementsov-Ogievskiy
2019-10-11  8:58       ` Max Reitz
2019-10-11  9:09         ` Vladimir Sementsov-Ogievskiy
2019-10-11  9:10         ` Vladimir Sementsov-Ogievskiy
2019-09-12 15:13 ` [Qemu-devel] [PATCH 4/4] Revert "mirror: Only mirror granularity-aligned chunks" Vladimir Sementsov-Ogievskiy
2019-10-04 16:33   ` Max Reitz
2019-10-02  9:53 ` [PATCH 0/4] active-mirror: support unaligned guest operations Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6fd6a449-0443-ecfa-0eec-23e3b515b303@redhat.com \
    --to=mreitz@redhat.com \
    --cc=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).