From nobody Sun Feb 8 17:48:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581952220996820.3321816588749; Mon, 17 Feb 2020 07:10:20 -0800 (PST) Received: from localhost ([::1]:46856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3i2N-000175-Q5 for importer@patchew.org; Mon, 17 Feb 2020 10:10:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39308) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j3hvo-00058H-AL for qemu-devel@nongnu.org; Mon, 17 Feb 2020 10:03:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j3hvj-0007Zy-1X for qemu-devel@nongnu.org; Mon, 17 Feb 2020 10:03:32 -0500 Received: from relay.sw.ru ([185.231.240.75]:47552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j3hvi-0007RX-Ow; Mon, 17 Feb 2020 10:03:26 -0500 Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1j3hvE-0007Zt-8n; Mon, 17 Feb 2020 18:02:56 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [PATCH v2 08/22] migration/block-dirty-bitmap: keep bitmap state for all bitmaps Date: Mon, 17 Feb 2020 18:02:32 +0300 Message-Id: <20200217150246.29180-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200217150246.29180-1-vsementsov@virtuozzo.com> References: <20200217150246.29180-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , vsementsov@virtuozzo.com, qemu-block@nongnu.org, quintela@redhat.com, dgilbert@redhat.com, Stefan Hajnoczi , andrey.shinkevich@virtuozzo.com, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Keep bitmap state for disabled bitmaps too. Keep the state until the end of the process. It's needed for the following commit to implement bitmap postcopy canceling. To clean-up the new list the following logic is used: We need two events to consider bitmap migration finished: 1. chunk with DIRTY_BITMAP_MIG_FLAG_COMPLETE flag should be received 2. dirty_bitmap_mig_before_vm_start should be called These two events may come in any order, so we understand which one is last, and on the last of them we remove bitmap migration state from the list. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Andrey Shinkevich --- migration/block-dirty-bitmap.c | 64 +++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 9cc750d93b..1329db8d7d 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -132,6 +132,7 @@ typedef struct LoadBitmapState { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; bool migrated; + bool enabled; } LoadBitmapState; =20 /* State of the dirty bitmap migration (DBM) during load process */ @@ -142,8 +143,10 @@ typedef struct DBMLoadState { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; =20 - GSList *enabled_bitmaps; - QemuMutex lock; /* protect enabled_bitmaps */ + bool before_vm_start_handled; /* set in dirty_bitmap_mig_before_vm_sta= rt */ + + GSList *bitmaps; + QemuMutex lock; /* protect bitmaps */ } DBMLoadState; =20 typedef struct DBMState { @@ -458,6 +461,7 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLoad= State *s) Error *local_err =3D NULL; uint32_t granularity =3D qemu_get_be32(f); uint8_t flags =3D qemu_get_byte(f); + LoadBitmapState *b; =20 if (s->bitmap) { error_report("Bitmap with the same name ('%s') already exists on " @@ -484,45 +488,59 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLo= adState *s) =20 bdrv_disable_dirty_bitmap(s->bitmap); if (flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED) { - LoadBitmapState *b; - bdrv_dirty_bitmap_create_successor(s->bitmap, &local_err); if (local_err) { error_report_err(local_err); return -EINVAL; } - - b =3D g_new(LoadBitmapState, 1); - b->bs =3D s->bs; - b->bitmap =3D s->bitmap; - b->migrated =3D false; - s->enabled_bitmaps =3D g_slist_prepend(s->enabled_bitmaps, b); } =20 + b =3D g_new(LoadBitmapState, 1); + b->bs =3D s->bs; + b->bitmap =3D s->bitmap; + b->migrated =3D false; + b->enabled =3D flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED, + + s->bitmaps =3D g_slist_prepend(s->bitmaps, b); + return 0; } =20 -void dirty_bitmap_mig_before_vm_start(void) +/* + * before_vm_start_handle_item + * + * g_slist_foreach helper + * + * item is LoadBitmapState* + * opaque is DBMLoadState* + */ +static void before_vm_start_handle_item(void *item, void *opaque) { - DBMLoadState *s =3D &dbm_state.load; - GSList *item; - - qemu_mutex_lock(&s->lock); - - for (item =3D s->enabled_bitmaps; item; item =3D g_slist_next(item)) { - LoadBitmapState *b =3D item->data; + DBMLoadState *s =3D opaque; + LoadBitmapState *b =3D item; =20 + if (b->enabled) { if (b->migrated) { bdrv_enable_dirty_bitmap(b->bitmap); } else { bdrv_dirty_bitmap_enable_successor(b->bitmap); } + } =20 + if (b->migrated) { + s->bitmaps =3D g_slist_remove(s->bitmaps, b); g_free(b); } +} =20 - g_slist_free(s->enabled_bitmaps); - s->enabled_bitmaps =3D NULL; +void dirty_bitmap_mig_before_vm_start(void) +{ + DBMLoadState *s =3D &dbm_state.load; + qemu_mutex_lock(&s->lock); + + assert(!s->before_vm_start_handled); + g_slist_foreach(s->bitmaps, before_vm_start_handle_item, s); + s->before_vm_start_handled =3D true; =20 qemu_mutex_unlock(&s->lock); } @@ -539,11 +557,15 @@ static void dirty_bitmap_load_complete(QEMUFile *f, D= BMLoadState *s) bdrv_reclaim_dirty_bitmap(s->bitmap, &error_abort); } =20 - for (item =3D s->enabled_bitmaps; item; item =3D g_slist_next(item)) { + for (item =3D s->bitmaps; item; item =3D g_slist_next(item)) { LoadBitmapState *b =3D item->data; =20 if (b->bitmap =3D=3D s->bitmap) { b->migrated =3D true; + if (s->before_vm_start_handled) { + s->bitmaps =3D g_slist_remove(s->bitmaps, b); + g_free(b); + } break; } } --=20 2.21.0