From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021320016146.81679603608438; Tue, 26 Jun 2018 06:55:20 -0700 (PDT) Received: from localhost ([::1]:52853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoR9-0007Iw-4C for importer@patchew.org; Tue, 26 Jun 2018 09:55:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoMo-00042v-GH for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoMl-0006Gg-Ap for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:46 -0400 Received: from relay.sw.ru ([185.231.240.75]:52514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoMl-0006Fc-2u; Tue, 26 Jun 2018 09:50:43 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMg-000357-W9; Tue, 26 Jun 2018 16:50:39 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:30 +0300 Message-Id: <20180626135035.133432-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/6] iotests: 169: drop deprecated 'autoload' parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- tests/qemu-iotests/169 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/qemu-iotests/169 b/tests/qemu-iotests/169 index f243db9955..df408f8367 100755 --- a/tests/qemu-iotests/169 +++ b/tests/qemu-iotests/169 @@ -58,7 +58,6 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): 'granularity': granularity} if persistent: params['persistent'] =3D True - params['autoload'] =3D True =20 result =3D vm.qmp('block-dirty-bitmap-add', **params) self.assert_qmp(result, 'return', {}); --=20 2.11.1 From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021428704382.44032880423424; Tue, 26 Jun 2018 06:57:08 -0700 (PDT) Received: from localhost ([::1]:52871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoSy-0000PF-21 for importer@patchew.org; Tue, 26 Jun 2018 09:57:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoMp-00043Y-K7 for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoMo-0006Hz-WD for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:47 -0400 Received: from relay.sw.ru ([185.231.240.75]:52506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoMo-0006HG-In; Tue, 26 Jun 2018 09:50:46 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMh-000357-5K; Tue, 26 Jun 2018 16:50:39 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:31 +0300 Message-Id: <20180626135035.133432-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/6] block/qcow2: improve error message in qcow2_inactivate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 945132f692..46194a33ca 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2114,9 +2114,9 @@ static int qcow2_inactivate(BlockDriverState *bs) qcow2_store_persistent_dirty_bitmaps(bs, &local_err); if (local_err !=3D NULL) { result =3D -EINVAL; - error_report_err(local_err); - error_report("Persistent bitmaps are lost for node '%s'", - bdrv_get_device_or_node_name(bs)); + error_reportf_err(local_err, "Persistent bitmaps are lost for node= " + "'%s', because failed to store them on qcow2 " + "inactivation: ", bdrv_get_device_or_node_name(b= s)); } =20 ret =3D qcow2_cache_flush(bs, s->l2_table_cache); --=20 2.11.1 From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021306580720.7769106234464; Tue, 26 Jun 2018 06:55:06 -0700 (PDT) Received: from localhost ([::1]:52851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoQu-0006zO-MN for importer@patchew.org; Tue, 26 Jun 2018 09:55:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoMy-00049p-BU for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoMv-0006KQ-3z for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:56 -0400 Received: from relay.sw.ru ([185.231.240.75]:52512) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoMu-0006Ji-CY; Tue, 26 Jun 2018 09:50:53 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMh-000357-PV; Tue, 26 Jun 2018 16:50:39 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:32 +0300 Message-Id: <20180626135035.133432-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 3/6] bloc/qcow2: drop dirty_bitmaps_loaded state variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This variable doesn't work as it should, because it is actually cleared in qcow2_co_invalidate_cache() by memset(). Drop it, as the following patch will introduce new behavior. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/qcow2.h | 1 - block/qcow2.c | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 01b5250415..c9df19b6e6 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -294,7 +294,6 @@ typedef struct BDRVQcow2State { uint32_t nb_bitmaps; uint64_t bitmap_directory_size; uint64_t bitmap_directory_offset; - bool dirty_bitmaps_loaded; =20 int flags; int qcow_version; diff --git a/block/qcow2.c b/block/qcow2.c index 46194a33ca..0044ff58e7 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1149,7 +1149,6 @@ static int coroutine_fn qcow2_do_open(BlockDriverStat= e *bs, QDict *options, uint64_t ext_end; uint64_t l1_vm_state_index; bool update_header =3D false; - bool header_updated =3D false; =20 ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { @@ -1488,23 +1487,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, s->autoclear_features &=3D QCOW2_AUTOCLEAR_MASK; } =20 - if (s->dirty_bitmaps_loaded) { - /* It's some kind of reopen. There are no known cases where we nee= d to - * reload bitmaps in such a situation, so it's safer to skip them. - * - * Moreover, if we have some readonly bitmaps and we are reopening= for - * rw we should reopen bitmaps correspondingly. - */ - if (bdrv_has_readonly_bitmaps(bs) && - !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTI= VE)) - { - qcow2_reopen_bitmaps_rw_hint(bs, &header_updated, &local_err); - } - } else { - header_updated =3D qcow2_load_dirty_bitmaps(bs, &local_err); - s->dirty_bitmaps_loaded =3D true; + if (qcow2_load_dirty_bitmaps(bs, &local_err)) { + update_header =3D false; } - update_header =3D update_header && !header_updated; if (local_err !=3D NULL) { error_propagate(errp, local_err); ret =3D -EINVAL; --=20 2.11.1 From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021165243824.6603904867865; Tue, 26 Jun 2018 06:52:45 -0700 (PDT) Received: from localhost ([::1]:52841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoOi-0005DK-Bi for importer@patchew.org; Tue, 26 Jun 2018 09:52:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoMt-00046D-EW for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoMr-0006J2-Fy for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:51 -0400 Received: from relay.sw.ru ([185.231.240.75]:52520) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoMp-0006H2-Jf; Tue, 26 Jun 2018 09:50:49 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMh-000357-UA; Tue, 26 Jun 2018 16:50:39 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:33 +0300 Message-Id: <20180626135035.133432-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 4/6] dirty-bitmaps: clean-up bitmaps loading and migration logic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch aims to bring the following behavior: 1. We don't load bitmaps, when started in inactive mode. It's the case of incoming migration. In this case we wait for bitmaps migration through migration channel (if 'dirty-bitmaps' capability is enabled) or for invalidation (to load bitmaps from the image). 2. We don't remove persistent bitmaps on inactivation. Instead, we only remove bitmaps after storing. This is the only way to restore bitmaps, if we decided to resume source after [failed] migration with 'dirty-bitmaps' capability enabled (which means, that bitmaps were not stored). 3. We load bitmaps on open and any invalidation, it's ok for all cases: - normal open - migration target invalidation with dirty-bitmaps capability (bitmaps are migrating through migration channel, the are not stored, so they should have IN_USE flag set and will be skipped when loading. However, it would fail if bitmaps are read-only[1]) - migration target invalidation without dirty-bitmaps capability (normal load of the bitmaps, if migrated with shared storage) - source invalidation with dirty-bitmaps capability (skip because IN_USE) - source invalidation without dirty-bitmaps capability (bitmaps were dropped, reload them) [1]: to accurately handle this, migration of read-only bitmaps is explicitly forbidden in this patch. New mechanism for not storing bitmaps when migrate with dirty-bitmaps capability is introduced: migration filed in BdrvDirtyBitmap. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/dirty-bitmap.h | 2 +- block.c | 11 ++++--- block/dirty-bitmap.c | 36 +++++++++-------------- block/qcow2-bitmap.c | 16 +++++++++++ block/qcow2.c | 65 ++++++++++++++++++++++++++++++++++++++= ++-- migration/block-dirty-bitmap.c | 10 +++++-- 6 files changed, 109 insertions(+), 31 deletions(-) diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 259bd27c40..95c7847ec6 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -26,7 +26,6 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState = *bs, const char *name); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); -void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs); void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp); @@ -72,6 +71,7 @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *b= itmap, void bdrv_dirty_bitmap_set_qmp_locked(BdrvDirtyBitmap *bitmap, bool qmp_lo= cked); void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, Error **errp); +void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migrati= on); =20 /* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); diff --git a/block.c b/block.c index 1b8147c1b3..07d7a974d2 100644 --- a/block.c +++ b/block.c @@ -4396,6 +4396,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, uint64_t perm, shared_perm; Error *local_err =3D NULL; int ret; + BdrvDirtyBitmap *bm; =20 if (!bs->drv) { return; @@ -4445,6 +4446,12 @@ static void coroutine_fn bdrv_co_invalidate_cache(Bl= ockDriverState *bs, } } =20 + for (bm =3D bdrv_dirty_bitmap_next(bs, NULL); bm; + bm =3D bdrv_dirty_bitmap_next(bs, bm)) + { + bdrv_dirty_bitmap_set_migration(bm, false); + } + ret =3D refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; @@ -4559,10 +4566,6 @@ static int bdrv_inactivate_recurse(BlockDriverState = *bs, } } =20 - /* At this point persistent bitmaps should be already stored by the fo= rmat - * driver */ - bdrv_release_persistent_dirty_bitmaps(bs); - return 0; } =20 diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index c9b8a6fd52..a13c3bdcfa 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -55,6 +55,10 @@ struct BdrvDirtyBitmap { and this bitmap must remain unchanged w= hile this flag is set. */ bool persistent; /* bitmap must be saved to owner disk imag= e */ + bool migration; /* Bitmap is selected for migration, it sh= ould + not be stored on the next inactivation + (persistent flag doesn't matter until n= ext + invalidation).*/ QLIST_ENTRY(BdrvDirtyBitmap) list; }; =20 @@ -384,26 +388,6 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState= *bs) } =20 /** - * Release all persistent dirty bitmaps attached to a BDS (for use in - * bdrv_inactivate_recurse()). - * There must not be any frozen bitmaps attached. - * This function does not remove persistent bitmaps from the storage. - * Called with BQL taken. - */ -void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs) -{ - BdrvDirtyBitmap *bm, *next; - - bdrv_dirty_bitmaps_lock(bs); - QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { - if (bdrv_dirty_bitmap_get_persistance(bm)) { - bdrv_release_dirty_bitmap_locked(bm); - } - } - bdrv_dirty_bitmaps_unlock(bs); -} - -/** * Remove persistent dirty bitmap from the storage if it exists. * Absence of bitmap is not an error, because we have the following scenar= io: * BdrvDirtyBitmap can have .persistent =3D true but not yet saved and hav= e no @@ -756,16 +740,24 @@ void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitma= p *bitmap, bool persistent) qemu_mutex_unlock(bitmap->mutex); } =20 +/* Called with BQL taken. */ +void bdrv_dirty_bitmap_set_migration(BdrvDirtyBitmap *bitmap, bool migrati= on) +{ + qemu_mutex_lock(bitmap->mutex); + bitmap->migration =3D migration; + qemu_mutex_unlock(bitmap->mutex); +} + bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap) { - return bitmap->persistent; + return bitmap->persistent && !bitmap->migration; } =20 bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs) { BdrvDirtyBitmap *bm; QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { - if (bm->persistent && !bm->readonly) { + if (bm->persistent && !bm->readonly && !bm->migration) { return true; } } diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 69485aa1de..c9662b21c7 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1413,6 +1413,22 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDrive= rState *bs, Error **errp) g_free(tb); } =20 + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + /* For safety, we remove bitmap after storing. + * We may be here in two cases: + * 1. bdrv_close. It's ok to drop bitmap. + * 2. inactivation. It means migration without 'dirty-bitmaps' + * capability, so bitmaps are not marked with + * BdrvDirtyBitmap.migration flags. It's not bad to drop them t= oo, + * and reload on invalidation. + */ + if (bm->dirty_bitmap =3D=3D NULL) { + continue; + } + + bdrv_release_dirty_bitmap(bs, bm->dirty_bitmap); + } + bitmap_list_free(bm_list); return; =20 diff --git a/block/qcow2.c b/block/qcow2.c index 0044ff58e7..f5c99f4ed4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1487,8 +1487,69 @@ static int coroutine_fn qcow2_do_open(BlockDriverSta= te *bs, QDict *options, s->autoclear_features &=3D QCOW2_AUTOCLEAR_MASK; } =20 - if (qcow2_load_dirty_bitmaps(bs, &local_err)) { - update_header =3D false; + /* =3D=3D Handle persistent dirty bitmaps =3D=3D + * + * We want load dirty bitmaps in three cases: + * + * 1. Normal open of the disk in active mode, not related to invalidat= ion + * after migration. + * + * 2. Invalidation of the target vm after pre-copy phase of migration,= if + * bitmaps are _not_ migrating through migration channel, i.e. + * 'dirty-bitmaps' capability is disabled. + * + * 3. Invalidation of source vm after failed or canceled migration. + * This is a very interesting case. There are two possible types of + * bitmaps: + * + * A. Stored on inactivation and removed. They should be loaded fro= m the + * image. + * + * B. Not stored: not-persistent bitmaps and bitmaps, migrated thro= ugh + * the migration channel (with dirty-bitmaps capability). + * + * On the other hand, there are two possible sub-cases: + * + * 3.1 disk was changed by somebody else while were inactive. In th= is + * case all in-RAM dirty bitmaps (both persistent and not) are + * definitely invalid. And we don't have any method to determine + * this. + * + * Simple and safe thing is to just drop all the bitmaps of typ= e B on + * inactivation. But in this case we lose bitmaps in valid 4.2 = case. + * + * On the other hand, resuming source vm, if disk was already c= hanged + * is a bad thing anyway: not only bitmaps, the whole vm state = is + * out of sync with disk. + * + * This means, that user or management tool, who for some reason + * decided to resume source vm, after disk was already changed = by + * target vm, should at least drop all dirty bitmaps by hand. + * + * So, we can ignore this case for now, but TODO: "generation" + * extension for qcow2, to determine, that image was changed af= ter + * last inactivation. And if it is changed, we will drop (or at= least + * mark as 'invalid' all the bitmaps of type B, both persistent + * and not). + * + * 3.2 disk was _not_ changed while were inactive. Bitmaps may be s= aved + * to disk ('dirty-bitmaps' capability disabled), or not saved + * ('dirty-bitmaps' capability enabled), but we don't need to c= are + * of: let's load bitmaps as always: stored bitmaps will be loa= ded, + * and not stored has flag IN_USE=3D1 in the image and will be = skipped + * on loading. + * + * One remaining possible case when we don't want load bitmaps: + * + * 4. Open disk in inactive mode in target vm (bitmaps are migrating or + * will be loaded on invalidation, no needs try loading them before) + */ + + if (!(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) { + /* It's case 1, 2 or 3.2. Or 3.1 which is BUG in management layer.= */ + bool header_updated =3D qcow2_load_dirty_bitmaps(bs, &local_err); + + update_header =3D update_header && !header_updated; } if (local_err !=3D NULL) { error_propagate(errp, local_err); diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 477826330c..ae4e88354a 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -313,6 +313,12 @@ static int init_dirty_bitmap_migration(void) goto fail; } =20 + if (bdrv_dirty_bitmap_readonly(bitmap)) { + error_report("Can't migrate read-only dirty bitmap: '%s", + bdrv_dirty_bitmap_name(bitmap)); + goto fail; + } + bdrv_ref(bs); bdrv_dirty_bitmap_set_qmp_locked(bitmap, true); =20 @@ -335,9 +341,9 @@ static int init_dirty_bitmap_migration(void) } } =20 - /* unset persistance here, to not roll back it */ + /* unset migration flags here, to not roll back it */ QSIMPLEQ_FOREACH(dbms, &dirty_bitmap_mig_state.dbms_list, entry) { - bdrv_dirty_bitmap_set_persistance(dbms->bitmap, false); + bdrv_dirty_bitmap_set_migration(dbms->bitmap, true); } =20 if (QSIMPLEQ_EMPTY(&dirty_bitmap_mig_state.dbms_list)) { --=20 2.11.1 From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021164996919.9306934062234; Tue, 26 Jun 2018 06:52:44 -0700 (PDT) Received: from localhost ([::1]:52839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoOb-00058o-Ue for importer@patchew.org; Tue, 26 Jun 2018 09:52:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoMr-00044m-FR for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoMq-0006Ij-Pu for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:50:49 -0400 Received: from relay.sw.ru ([185.231.240.75]:52510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoMq-0006HA-I0; Tue, 26 Jun 2018 09:50:48 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMi-000357-2U; Tue, 26 Jun 2018 16:50:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:34 +0300 Message-Id: <20180626135035.133432-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 5/6] iotests: improve 169 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before previous patch, iotest 169 was actually broken for the case test_persistent__not_migbitmap__offline_shared, while formally passing. After migration log of vm_b had message: qemu-system-x86_64: Could not reopen qcow2 layer: Bitmap already exists: bitmap0 which means that invalidation failed and bs->drv =3D NULL. It was because we've loaded bitmap twice: on open and on invalidation. Add code to 169, to catch such fails. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/169 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/qemu-iotests/169 b/tests/qemu-iotests/169 index df408f8367..8b7947d650 100755 --- a/tests/qemu-iotests/169 +++ b/tests/qemu-iotests/169 @@ -24,6 +24,7 @@ import time import itertools import operator import new +import re from iotests import qemu_img =20 =20 @@ -133,6 +134,14 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): =20 if should_migrate: self.vm_b.shutdown() + + # catch 'Could not reopen qcow2 layer: Bitmap already exists' + # possible error + log =3D self.vm_b.get_log() + log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + self.assertEqual(log, '') + # recreate vm_b, as we don't want -incoming option (this will = lead # to "cat" process left alive after test finish) self.vm_b =3D iotests.VM(path_suffix=3D'b') --=20 2.11.1 From nobody Sun Feb 8 19:51:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530021304909718.6864938497307; Tue, 26 Jun 2018 06:55:04 -0700 (PDT) Received: from localhost ([::1]:52852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoQx-00071m-Bm for importer@patchew.org; Tue, 26 Jun 2018 09:55:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fXoN9-0004MD-SL for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:51:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fXoN6-0006Qj-KC for qemu-devel@nongnu.org; Tue, 26 Jun 2018 09:51:07 -0400 Received: from relay.sw.ru ([185.231.240.75]:52548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fXoN5-0006NT-Jo; Tue, 26 Jun 2018 09:51:04 -0400 Received: from mwa-fw01.virtuozzo.com ([185.231.240.15] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fXoMi-000357-6O; Tue, 26 Jun 2018 16:50:40 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 26 Jun 2018 16:50:35 +0300 Message-Id: <20180626135035.133432-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180626135035.133432-1-vsementsov@virtuozzo.com> References: <20180626135035.133432-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 6/6] iotests: 169: add cases for source vm resuming X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test that we can resume source vm after [failed] migration, and bitmaps are ok. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/169 | 60 ++++++++++++++++++++++++++++++++++++++++++= +++- tests/qemu-iotests/169.out | 4 ++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/169 b/tests/qemu-iotests/169 index 8b7947d650..69850c4c67 100755 --- a/tests/qemu-iotests/169 +++ b/tests/qemu-iotests/169 @@ -77,6 +77,58 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): self.assert_qmp(result, 'error/desc', "Dirty bitmap 'bitmap0' not found"); =20 + def do_test_migration_resume_source(self, persistent, migrate_bitmaps): + granularity =3D 512 + + # regions =3D ((start, count), ...) + regions =3D ((0, 0x10000), + (0xf0000, 0x10000), + (0xa0201, 0x1000)) + + mig_caps =3D [{'capability': 'events', 'state': True}] + if migrate_bitmaps: + mig_caps.append({'capability': 'dirty-bitmaps', 'state': True}) + + result =3D self.vm_a.qmp('migrate-set-capabilities', + capabilities=3Dmig_caps) + self.assert_qmp(result, 'return', {}) + + self.add_bitmap(self.vm_a, granularity, persistent) + for r in regions: + self.vm_a.hmp_qemu_io('drive0', 'write %d %d' % r) + sha256 =3D self.get_bitmap_hash(self.vm_a) + + result =3D self.vm_a.qmp('migrate', uri=3Dmig_cmd) + while True: + event =3D self.vm_a.event_wait('MIGRATION') + if event['data']['status'] =3D=3D 'completed': + break + + # test that bitmap is still here + removed =3D (not migrate_bitmaps) and persistent + self.check_bitmap(self.vm_a, False if removed else sha256) + + self.vm_a.qmp('cont') + + # test that bitmap is still here after invalidation + self.check_bitmap(self.vm_a, sha256) + + # shutdown and check that invalidation didn't fail + self.vm_a.shutdown() + + # catch 'Could not reopen qcow2 layer: Bitmap already exists' + # possible error + log =3D self.vm_a.get_log() + log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D re.sub(r'^(wrote .* bytes at offset .*\n.*KiB.*ops.*sec.*\= n){3}', + '', log) + log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + self.assertEqual(log, '') + + # test that bitmap is still persistent + self.vm_a.launch() + self.check_bitmap(self.vm_a, sha256 if persistent else False) + def do_test_migration(self, persistent, migrate_bitmaps, online, shared_storage): granularity =3D 512 @@ -152,7 +204,7 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase): =20 def inject_test_case(klass, name, method, *args, **kwargs): mc =3D operator.methodcaller(method, *args, **kwargs) - setattr(klass, 'test_' + name, new.instancemethod(mc, None, klass)) + setattr(klass, 'test_' + method + name, new.instancemethod(mc, None, k= lass)) =20 for cmb in list(itertools.product((True, False), repeat=3D4)): name =3D ('_' if cmb[0] else '_not_') + 'persistent_' @@ -163,6 +215,12 @@ for cmb in list(itertools.product((True, False), repea= t=3D4)): inject_test_case(TestDirtyBitmapMigration, name, 'do_test_migration', *list(cmb)) =20 +for cmb in list(itertools.product((True, False), repeat=3D2)): + name =3D ('_' if cmb[0] else '_not_') + 'persistent_' + name +=3D ('_' if cmb[1] else '_not_') + 'migbitmap' + + inject_test_case(TestDirtyBitmapMigration, name, + 'do_test_migration_resume_source', *list(cmb)) =20 if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2']) diff --git a/tests/qemu-iotests/169.out b/tests/qemu-iotests/169.out index b6f257674e..3a89159833 100644 --- a/tests/qemu-iotests/169.out +++ b/tests/qemu-iotests/169.out @@ -1,5 +1,5 @@ -................ +.................... ---------------------------------------------------------------------- -Ran 16 tests +Ran 20 tests =20 OK --=20 2.11.1