qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v2] block: mirror - fix full sync mode when targ


From: Paolo Bonzini
Subject: Re: [Qemu-block] [PATCH v2] block: mirror - fix full sync mode when target does not support zero init
Date: Thu, 1 Oct 2015 12:13:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0


On 01/10/2015 06:31, Jeff Cody wrote:
> During mirror, if the target device does not support zero init, a
> mirror may result in a corrupted image for sync="full" mode.
> 
> This is due to how the initial dirty bitmap is set up prior to copying
> data - we did not mark sectors as dirty that are unallocated.  This
> means those unallocated sectors are skipped over on the target, and for
> a device without zero init, invalid data may reside in those holes.
> 
> If both of the following conditions are true, then we will explicitly
> mark all sectors as dirty:
> 
>     1.) sync = "full"
>     2.) bdrv_has_zero_init(target) == false
> 
> If the target does support zero init, but a target image is passed in
> with data already present (i.e. an "existing" image), it is assumed the
> data present in the existing image is valid data for those sectors.
> 
> Signed-off-by: Jeff Cody <address@hidden>
> ---
>  block/mirror.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index a258926..5d7828b 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -61,6 +61,7 @@ typedef struct MirrorBlockJob {
>      int ret;
>      bool unmap;
>      bool waiting_for_io;
> +    bool mark_all_dirty;
>  } MirrorBlockJob;
>  
>  typedef struct MirrorOp {
> @@ -477,7 +478,7 @@ static void coroutine_fn mirror_run(void *opaque)
>              }
>  
>              assert(n > 0);
> -            if (ret == 1) {
> +            if (ret == 1 || s->mark_all_dirty) {

We can get the information directly in mirror_run, since we have target
and we have the sync mode (it is 'full' if s->base == NULL).  This
avoids adding a zillionth argument to mirror_start_job. :)

Paolo

>                  bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
>              }
>              sector_num += n;
> @@ -688,7 +689,7 @@ static void mirror_start_job(BlockDriverState *bs, 
> BlockDriverState *target,
>                               int64_t buf_size,
>                               BlockdevOnError on_source_error,
>                               BlockdevOnError on_target_error,
> -                             bool unmap,
> +                             bool unmap, bool mark_all_dirty,
>                               BlockCompletionFunc *cb,
>                               void *opaque, Error **errp,
>                               const BlockJobDriver *driver,
> @@ -732,6 +733,7 @@ static void mirror_start_job(BlockDriverState *bs, 
> BlockDriverState *target,
>      s->granularity = granularity;
>      s->buf_size = ROUND_UP(buf_size, granularity);
>      s->unmap = unmap;
> +    s->mark_all_dirty = mark_all_dirty;
>  
>      s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp);
>      if (!s->dirty_bitmap) {
> @@ -757,6 +759,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState 
> *target,
>                    void *opaque, Error **errp)
>  {
>      bool is_none_mode;
> +    bool mark_all_dirty;
>      BlockDriverState *base;
>  
>      if (mode == MIRROR_SYNC_MODE_INCREMENTAL) {
> @@ -764,11 +767,13 @@ void mirror_start(BlockDriverState *bs, 
> BlockDriverState *target,
>          return;
>      }
>      is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
> +    mark_all_dirty = mode == MIRROR_SYNC_MODE_FULL &&
> +                    !bdrv_has_zero_init(target);
>      base = mode == MIRROR_SYNC_MODE_TOP ? bs->backing_hd : NULL;
>      mirror_start_job(bs, target, replaces,
>                       speed, granularity, buf_size,
> -                     on_source_error, on_target_error, unmap, cb, opaque, 
> errp,
> -                     &mirror_job_driver, is_none_mode, base);
> +                     on_source_error, on_target_error, unmap, mark_all_dirty,
> +                     cb, opaque, errp, &mirror_job_driver, is_none_mode, 
> base);
>  }
>  
>  void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
> @@ -815,7 +820,7 @@ void commit_active_start(BlockDriverState *bs, 
> BlockDriverState *base,
>  
>      bdrv_ref(base);
>      mirror_start_job(bs, base, NULL, speed, 0, 0,
> -                     on_error, on_error, false, cb, opaque, &local_err,
> +                     on_error, on_error, false, false, cb, opaque, 
> &local_err,
>                       &commit_active_job_driver, false, base);
>      if (local_err) {
>          error_propagate(errp, local_err);
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]