From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhe1A-0006D6-5R for qemu-devel@nongnu.org; Thu, 01 Oct 2015 09:35:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhe18-0000xl-II for qemu-devel@nongnu.org; Thu, 01 Oct 2015 09:35:27 -0400 References: <91ed4bc5bda7e2b09eb508b07c83f4071fe0b3c9.1443705220.git.jcody@redhat.com> From: Paolo Bonzini Message-ID: <560D3693.7090108@redhat.com> Date: Thu, 1 Oct 2015 15:35:15 +0200 MIME-Version: 1.0 In-Reply-To: <91ed4bc5bda7e2b09eb508b07c83f4071fe0b3c9.1443705220.git.jcody@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3] block: mirror - fix full sync mode when target does not support zero init List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeff Cody , qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com 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 > --- > 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