qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init
@ 2015-10-01 13:14 Jeff Cody
  2015-10-01 13:35 ` Paolo Bonzini
  2015-10-01 19:05 ` Jeff Cody
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff Cody @ 2015-10-01 13:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, qemu-block, mreitz, stefanha, pbonzini

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 <jcody@redhat.com>
---
 block/mirror.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index a258926..ce367e0 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -455,6 +455,8 @@ static void coroutine_fn mirror_run(void *opaque)
     if (!s->is_none_mode) {
         /* First part, loop on the sectors and initialize the dirty bitmap.  */
         BlockDriverState *base = s->base;
+        bool mark_all_dirty = s->base == NULL && !bdrv_has_zero_init(s->target);
+
         for (sector_num = 0; sector_num < end; ) {
             /* Just to make sure we are not exceeding int limit. */
             int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
@@ -477,7 +479,7 @@ static void coroutine_fn mirror_run(void *opaque)
             }
 
             assert(n > 0);
-            if (ret == 1) {
+            if (ret == 1 || mark_all_dirty) {
                 bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
             }
             sector_num += n;
@@ -767,8 +769,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *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,
+                     cb, opaque, errp, &mirror_job_driver, is_none_mode, base);
 }
 
 void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init
  2015-10-01 13:14 [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init Jeff Cody
@ 2015-10-01 13:35 ` Paolo Bonzini
  2015-10-01 14:08   ` Jeff Cody
  2015-10-01 19:05 ` Jeff Cody
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2015-10-01 13:35 UTC (permalink / raw)
  To: Jeff Cody, qemu-devel; +Cc: kwolf, stefanha, qemu-block, mreitz



On 01/10/2015 15:14, 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 <jcody@redhat.com>
> ---
>  block/mirror.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index a258926..ce367e0 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -455,6 +455,8 @@ static void coroutine_fn mirror_run(void *opaque)
>      if (!s->is_none_mode) {
>          /* First part, loop on the sectors and initialize the dirty bitmap.  */
>          BlockDriverState *base = s->base;
> +        bool mark_all_dirty = s->base == NULL && !bdrv_has_zero_init(s->target);
> +
>          for (sector_num = 0; sector_num < end; ) {
>              /* Just to make sure we are not exceeding int limit. */
>              int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
> @@ -477,7 +479,7 @@ static void coroutine_fn mirror_run(void *opaque)
>              }
>  
>              assert(n > 0);
> -            if (ret == 1) {
> +            if (ret == 1 || mark_all_dirty) {
>                  bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
>              }
>              sector_num += n;
> @@ -767,8 +769,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *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,
> +                     cb, opaque, errp, &mirror_job_driver, is_none_mode, base);
>  }
>  
>  void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
> 

Unnecessary last hunk, but the patch is good anyway.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init
  2015-10-01 13:35 ` Paolo Bonzini
@ 2015-10-01 14:08   ` Jeff Cody
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-10-01 14:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kwolf, qemu-block, qemu-devel, mreitz, stefanha

On Thu, Oct 01, 2015 at 03:35:15PM +0200, Paolo Bonzini wrote:
> 
> 
> On 01/10/2015 15:14, 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 <jcody@redhat.com>
> > ---
> >  block/mirror.c | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> > 
> > diff --git a/block/mirror.c b/block/mirror.c
> > index a258926..ce367e0 100644
> > --- a/block/mirror.c
> > +++ b/block/mirror.c
> > @@ -455,6 +455,8 @@ static void coroutine_fn mirror_run(void *opaque)
> >      if (!s->is_none_mode) {
> >          /* First part, loop on the sectors and initialize the dirty bitmap.  */
> >          BlockDriverState *base = s->base;
> > +        bool mark_all_dirty = s->base == NULL && !bdrv_has_zero_init(s->target);
> > +
> >          for (sector_num = 0; sector_num < end; ) {
> >              /* Just to make sure we are not exceeding int limit. */
> >              int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
> > @@ -477,7 +479,7 @@ static void coroutine_fn mirror_run(void *opaque)
> >              }
> >  
> >              assert(n > 0);
> > -            if (ret == 1) {
> > +            if (ret == 1 || mark_all_dirty) {
> >                  bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
> >              }
> >              sector_num += n;
> > @@ -767,8 +769,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *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,
> > +                     cb, opaque, errp, &mirror_job_driver, is_none_mode, base);
> >  }
> >  
> >  void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
> > 
> 
> Unnecessary last hunk, but the patch is good anyway.
> 
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Thanks,

I'll go ahead and drop the last hunk when applying.

Jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init
  2015-10-01 13:14 [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init Jeff Cody
  2015-10-01 13:35 ` Paolo Bonzini
@ 2015-10-01 19:05 ` Jeff Cody
  1 sibling, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-10-01 19:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, qemu-block, mreitz, stefanha, pbonzini

On Thu, Oct 01, 2015 at 09:14:51AM -0400, 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 <jcody@redhat.com>
> ---
>  block/mirror.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index a258926..ce367e0 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -455,6 +455,8 @@ static void coroutine_fn mirror_run(void *opaque)
>      if (!s->is_none_mode) {
>          /* First part, loop on the sectors and initialize the dirty bitmap.  */
>          BlockDriverState *base = s->base;
> +        bool mark_all_dirty = s->base == NULL && !bdrv_has_zero_init(s->target);
> +
>          for (sector_num = 0; sector_num < end; ) {
>              /* Just to make sure we are not exceeding int limit. */
>              int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS,
> @@ -477,7 +479,7 @@ static void coroutine_fn mirror_run(void *opaque)
>              }
>  
>              assert(n > 0);
> -            if (ret == 1) {
> +            if (ret == 1 || mark_all_dirty) {
>                  bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n);
>              }
>              sector_num += n;
> @@ -767,8 +769,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *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,
> +                     cb, opaque, errp, &mirror_job_driver, is_none_mode, base);
>  }
>  
>  void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
> -- 
> 1.9.3
>

Applied to my block branch (with the last hunk removed):

git git://github.com/codyprime/qemu-kvm-jtc.git block

Thanks,
Jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-01 19:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-01 13:14 [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init Jeff Cody
2015-10-01 13:35 ` Paolo Bonzini
2015-10-01 14:08   ` Jeff Cody
2015-10-01 19:05 ` Jeff Cody

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).