qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-block@nongnu.org, wangxiaolong@ucloud.cn
Subject: Re: [Qemu-devel] [PATCH v3 1/6] mirror: Do zero write on target if sectors not allocated
Date: Thu, 14 May 2015 12:30:46 +0200	[thread overview]
Message-ID: <55547956.1050701@redhat.com> (raw)
In-Reply-To: <1431431315-32079-2-git-send-email-famz@redhat.com>



On 12/05/2015 13:48, Fam Zheng wrote:
> +    if (!bdrv_is_allocated_above(source, NULL, sector_num,
> +                                 nb_sectors, &pnum)) {
> +        op->nb_sectors = pnum;
> +        if (s->source_may_unmap) {

Can you avoid this check by introducing bdrv_get_block_status_above?  Then:

- if BDRV_ZERO, you use bdrv_aio_write_zeroes

- if BDRV_ALLOCATED, you use bdrv_aio_readv

- else you use bdrv_aio_discard

> +            /*
> +             * Source unallocated sectors have zero data. We can't discard
> +             * target even if s->target_may_unmap, because the discard
> +             * granularity may be different.
> +             */
> +            bdrv_aio_write_zeroes(s->target, sector_num, op->nb_sectors,
> +                                  s->target_may_unmap ? BDRV_REQ_MAY_UNMAP : 0,

You can set the flag unconditionally.  But it's probably better to make
this a drive-mirror argument instead of checking the target's
BlockDriverInfo.

Paolo

> +                                  mirror_write_complete,
> +                                  op);
> +        } else {
> +            /*
> +             * Source has irrelevant data in unmapped sectors, it's safe to
> +             * discard target.
> +             * */
> +            bdrv_aio_discard(s->target, sector_num, op->nb_sectors,
> +                             mirror_write_complete, op);
> +        }
> +    } else {
> +        bdrv_aio_readv(source, sector_num, &op->qiov, nb_sectors,
> +                       mirror_read_complete, op);
> +    }
>      return delay_ns;
>  }
>  
> @@ -399,6 +428,22 @@ static void coroutine_fn mirror_run(void *opaque)
>      length = DIV_ROUND_UP(s->bdev_length, s->granularity);
>      s->in_flight_bitmap = bitmap_new(length);
>  
> +    ret = bdrv_get_info(bs, &bdi);
> +    if (ret < 0) {
> +        /* Safe side. */
> +        s->source_may_unmap = true;
> +    } else {
> +        s->source_may_unmap = bdi.can_write_zeroes_with_unmap;
> +    }
> +
> +    ret = bdrv_get_info(s->target, &bdi);
> +    if (ret < 0) {
> +        /* Safe side. */
> +        s->target_may_unmap = false;
> +    } else {
> +        s->target_may_unmap = bdi.can_write_zeroes_with_unmap;
> +    }
> +

  reply	other threads:[~2015-05-14 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-12 11:48 [Qemu-devel] [PATCH v3 0/6] block: Mirror discarded sectors Fam Zheng
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 1/6] mirror: Do zero write on target if sectors not allocated Fam Zheng
2015-05-14 10:30   ` Paolo Bonzini [this message]
2015-05-14 13:52     ` Fam Zheng
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 2/6] block: Fix dirty bitmap in bdrv_co_discard Fam Zheng
2015-05-14 10:31   ` Paolo Bonzini
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 3/6] block: Remove bdrv_reset_dirty Fam Zheng
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 4/6] qemu-iotests: Make block job methods common Fam Zheng
2015-05-14 10:31   ` Paolo Bonzini
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 5/6] qemu-iotests: Add test case for mirror with unmap Fam Zheng
2015-05-14 10:37   ` Paolo Bonzini
2015-05-14 13:50     ` Fam Zheng
2015-05-12 11:48 ` [Qemu-devel] [PATCH v3 6/6] iotests: Use event_wait in wait_ready Fam Zheng
2015-05-14  6:27 ` [Qemu-devel] [PATCH v3 0/6] block: Mirror discarded sectors Fam Zheng

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=55547956.1050701@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wangxiaolong@ucloud.cn \
    /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).