From 97595ffd7741564e445c11b7e5c2906e263159d1 Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Fri, 2 Oct 2015 14:04:57 +0200 Subject: [PATCH 5/5] block: mirror - fix full sync mode when target does not support zero init Message-id: Patchwork-id: 68061 O-Subject: [RHEV-7.2 qemu-kvm-rhev PATCH] block: mirror - fix full sync mode when target does not support zero init Bugzilla: 1136382 RH-Acked-by: Kevin Wolf RH-Acked-by: Max Reitz RH-Acked-by: Paolo Bonzini 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. Reviewed-by: Paolo Bonzini Message-id: 91ed4bc5bda7e2b09eb508b07c83f4071fe0b3c9.1443705220.git.jcody@redhat.com Signed-off-by: Jeff Cody (cherry picked from commit 5279efebcf8f8fbf2ed2feed63cdb9d375c7cd07) Signed-off-by: Miroslav Rezanina Conflicts: block/mirror.c Signed-off-by: Jeff Cody --- block/mirror.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 7c2c27d..9729877 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -459,6 +459,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, @@ -481,7 +483,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(bs, s->dirty_bitmap, sector_num, n); } sector_num += n; -- 1.8.3.1