From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699807; cv=none; d=zohomail.com; s=zohoarc; b=dUSq3H9jYgl6IAaD0qx0PibUtuCLUdnB7i8OZ+aI0VB2GDBA+wTVyCKSqsj1TJcjXYMr64FsYKjsg8Vwnqj/Hmkpa8SD1AKwRMqQ5PLJgn8UqV+oCQG/8SR3iKLXn5lPiyqA039s2oKvNvElBz0nm1LiCVXEswgGxzJBQxmLoxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699807; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ASEWbji9VcwguJPfjtBLkf7FtuwZdlQI7NL93pihyFM=; b=XFv9Ady5262fUmbSuv1WqQ8WUgJMX+h58egLcGBgbDgcjx03faKxw8Bs8MQR/2ix5wSOBT7aVZj2wpygCWQH5PdqRevxnQ1e8elu3ixXhP4KSPcAEuItIHBNgqHQHLxApcqm5AircLMS4JsbCEf8voEM3kT1u6KrlVnVaCak/Ts= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699807549958.1550834261662; Wed, 22 Jan 2020 05:30:07 -0800 (PST) Received: from localhost ([::1]:42112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG58-0006F4-4P for importer@patchew.org; Wed, 22 Jan 2020 08:30:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51943) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyx-0006nv-Hi for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002NF-WC for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from relay.sw.ru ([185.231.240.75]:42294) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002I0-Mu; Wed, 22 Jan 2020 08:23:38 -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 1iuFyj-00057B-8h; Wed, 22 Jan 2020 16:23:29 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 1/7] migration/block-dirty-bitmap: refactor incoming state to be one struct Date: Wed, 22 Jan 2020 16:23:22 +0300 Message-Id: <20200122132328.31156-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Move enabled_bitmaps and finish_lock, which are part of incoming state to DirtyBitmapLoadState, and make static global variable to store state instead of static local one. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/block-dirty-bitmap.c | 77 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 7eafface61..281d20f41d 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -125,6 +125,13 @@ typedef struct DirtyBitmapMigState { BlockDriverState *prev_bs; BdrvDirtyBitmap *prev_bitmap; } DirtyBitmapMigState; +static DirtyBitmapMigState dirty_bitmap_mig_state; + +typedef struct DirtyBitmapLoadBitmapState { + BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; + bool migrated; +} DirtyBitmapLoadBitmapState; =20 typedef struct DirtyBitmapLoadState { uint32_t flags; @@ -132,21 +139,15 @@ typedef struct DirtyBitmapLoadState { char bitmap_name[256]; BlockDriverState *bs; BdrvDirtyBitmap *bitmap; -} DirtyBitmapLoadState; =20 -static DirtyBitmapMigState dirty_bitmap_mig_state; - -typedef struct DirtyBitmapLoadBitmapState { - BlockDriverState *bs; - BdrvDirtyBitmap *bitmap; - bool migrated; -} DirtyBitmapLoadBitmapState; -static GSList *enabled_bitmaps; -QemuMutex finish_lock; + GSList *enabled_bitmaps; + QemuMutex finish_lock; +} DirtyBitmapLoadState; +static DirtyBitmapLoadState dbm_load_state; =20 void init_dirty_bitmap_incoming_migration(void) { - qemu_mutex_init(&finish_lock); + qemu_mutex_init(&dbm_load_state.finish_lock); } =20 static uint32_t qemu_get_bitmap_flags(QEMUFile *f) @@ -439,8 +440,9 @@ static void dirty_bitmap_save_pending(QEMUFile *f, void= *opaque, } =20 /* First occurrence of this bitmap. It should be created if doesn't exist = */ -static int dirty_bitmap_load_start(QEMUFile *f, DirtyBitmapLoadState *s) +static int dirty_bitmap_load_start(QEMUFile *f) { + DirtyBitmapLoadState *s =3D &dbm_load_state; Error *local_err =3D NULL; uint32_t granularity =3D qemu_get_be32(f); uint8_t flags =3D qemu_get_byte(f); @@ -482,7 +484,8 @@ static int dirty_bitmap_load_start(QEMUFile *f, DirtyBi= tmapLoadState *s) b->bs =3D s->bs; b->bitmap =3D s->bitmap; b->migrated =3D false; - enabled_bitmaps =3D g_slist_prepend(enabled_bitmaps, b); + dbm_load_state.enabled_bitmaps =3D + g_slist_prepend(dbm_load_state.enabled_bitmaps, b); } =20 return 0; @@ -492,9 +495,11 @@ void dirty_bitmap_mig_before_vm_start(void) { GSList *item; =20 - qemu_mutex_lock(&finish_lock); + qemu_mutex_lock(&dbm_load_state.finish_lock); =20 - for (item =3D enabled_bitmaps; item; item =3D g_slist_next(item)) { + for (item =3D dbm_load_state.enabled_bitmaps; item; + item =3D g_slist_next(item)) + { DirtyBitmapLoadBitmapState *b =3D item->data; =20 if (b->migrated) { @@ -506,21 +511,24 @@ void dirty_bitmap_mig_before_vm_start(void) g_free(b); } =20 - g_slist_free(enabled_bitmaps); - enabled_bitmaps =3D NULL; + g_slist_free(dbm_load_state.enabled_bitmaps); + dbm_load_state.enabled_bitmaps =3D NULL; =20 - qemu_mutex_unlock(&finish_lock); + qemu_mutex_unlock(&dbm_load_state.finish_lock); } =20 -static void dirty_bitmap_load_complete(QEMUFile *f, DirtyBitmapLoadState *= s) +static void dirty_bitmap_load_complete(QEMUFile *f) { + DirtyBitmapLoadState *s =3D &dbm_load_state; GSList *item; trace_dirty_bitmap_load_complete(); bdrv_dirty_bitmap_deserialize_finish(s->bitmap); =20 - qemu_mutex_lock(&finish_lock); + qemu_mutex_lock(&dbm_load_state.finish_lock); =20 - for (item =3D enabled_bitmaps; item; item =3D g_slist_next(item)) { + for (item =3D dbm_load_state.enabled_bitmaps; item; + item =3D g_slist_next(item)) + { DirtyBitmapLoadBitmapState *b =3D item->data; =20 if (b->bitmap =3D=3D s->bitmap) { @@ -531,7 +539,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f, Dir= tyBitmapLoadState *s) =20 if (bdrv_dirty_bitmap_has_successor(s->bitmap)) { bdrv_dirty_bitmap_lock(s->bitmap); - if (enabled_bitmaps =3D=3D NULL) { + if (dbm_load_state.enabled_bitmaps =3D=3D NULL) { /* in postcopy */ bdrv_reclaim_dirty_bitmap_locked(s->bitmap, &error_abort); bdrv_enable_dirty_bitmap_locked(s->bitmap); @@ -550,11 +558,12 @@ static void dirty_bitmap_load_complete(QEMUFile *f, D= irtyBitmapLoadState *s) bdrv_dirty_bitmap_unlock(s->bitmap); } =20 - qemu_mutex_unlock(&finish_lock); + qemu_mutex_unlock(&dbm_load_state.finish_lock); } =20 -static int dirty_bitmap_load_bits(QEMUFile *f, DirtyBitmapLoadState *s) +static int dirty_bitmap_load_bits(QEMUFile *f) { + DirtyBitmapLoadState *s =3D &dbm_load_state; uint64_t first_byte =3D qemu_get_be64(f) << BDRV_SECTOR_BITS; uint64_t nr_bytes =3D (uint64_t)qemu_get_be32(f) << BDRV_SECTOR_BITS; trace_dirty_bitmap_load_bits_enter(first_byte >> BDRV_SECTOR_BITS, @@ -598,8 +607,9 @@ static int dirty_bitmap_load_bits(QEMUFile *f, DirtyBit= mapLoadState *s) return 0; } =20 -static int dirty_bitmap_load_header(QEMUFile *f, DirtyBitmapLoadState *s) +static int dirty_bitmap_load_header(QEMUFile *f) { + DirtyBitmapLoadState *s =3D &dbm_load_state; Error *local_err =3D NULL; bool nothing; s->flags =3D qemu_get_bitmap_flags(f); @@ -647,7 +657,6 @@ static int dirty_bitmap_load_header(QEMUFile *f, DirtyB= itmapLoadState *s) =20 static int dirty_bitmap_load(QEMUFile *f, void *opaque, int version_id) { - static DirtyBitmapLoadState s; int ret =3D 0; =20 trace_dirty_bitmap_load_enter(); @@ -657,17 +666,17 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaqu= e, int version_id) } =20 do { - ret =3D dirty_bitmap_load_header(f, &s); + ret =3D dirty_bitmap_load_header(f); if (ret < 0) { return ret; } =20 - if (s.flags & DIRTY_BITMAP_MIG_FLAG_START) { - ret =3D dirty_bitmap_load_start(f, &s); - } else if (s.flags & DIRTY_BITMAP_MIG_FLAG_COMPLETE) { - dirty_bitmap_load_complete(f, &s); - } else if (s.flags & DIRTY_BITMAP_MIG_FLAG_BITS) { - ret =3D dirty_bitmap_load_bits(f, &s); + if (dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_START) { + ret =3D dirty_bitmap_load_start(f); + } else if (dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_COMPLETE) { + dirty_bitmap_load_complete(f); + } else if (dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_BITS) { + ret =3D dirty_bitmap_load_bits(f); } =20 if (!ret) { @@ -677,7 +686,7 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque,= int version_id) if (ret) { return ret; } - } while (!(s.flags & DIRTY_BITMAP_MIG_FLAG_EOS)); + } while (!(dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_EOS)); =20 trace_dirty_bitmap_load_success(); return 0; --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699695; cv=none; d=zohomail.com; s=zohoarc; b=G7vhGhZ8DJTEzKqsLVcG7AXErUiclz3CPlIrWHhSzRt2jawSWEgqqrnNcgBSw96TAJHcJnUDjia42ULl7hr5KD8nQIQcSbJF+6BX6SEvz/YmNCiC6y9KFbEr3SPFmYmTNSr0+uJukjdIYit6y9iEw9Hj3DnmePSYu0JLBjniOZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699695; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HhRKZF5xkwoUmXR6p1s0uGZfm8avV9lK5akxQfjTPJQ=; b=gw5tnufsKPqpY43sNyQiezXrcN/iiEfOJ8wR2/EYiUFlpyh2+PHVujCv6rUnr9qx5xJC3XKNe4cOQMzMm/7Qu5/KHbrWRTG1If2PoezueU365Llz2I3DG+Q4zYi+n45W7ZuoY5YI/AwZ2kKdRDhqM6lCn5ixQGCmdikGkZkm7xw= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699695038632.0242857666013; Wed, 22 Jan 2020 05:28:15 -0800 (PST) Received: from localhost ([::1]:42070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG3J-0003oW-IY for importer@patchew.org; Wed, 22 Jan 2020 08:28:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51912) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyw-0006mj-M2 for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002Mh-IX for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:42300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002I1-VO; Wed, 22 Jan 2020 08:23:39 -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 1iuFyj-00057B-EI; Wed, 22 Jan 2020 16:23:29 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 2/7] migration/block-dirty-bitmap: rename finish_lock to just lock Date: Wed, 22 Jan 2020 16:23:23 +0300 Message-Id: <20200122132328.31156-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" finish_lock is bad name, as lock used not only on process end. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Juan Quintela --- migration/block-dirty-bitmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 281d20f41d..502e858c31 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -141,13 +141,13 @@ typedef struct DirtyBitmapLoadState { BdrvDirtyBitmap *bitmap; =20 GSList *enabled_bitmaps; - QemuMutex finish_lock; + QemuMutex lock; /* protect enabled_bitmaps */ } DirtyBitmapLoadState; static DirtyBitmapLoadState dbm_load_state; =20 void init_dirty_bitmap_incoming_migration(void) { - qemu_mutex_init(&dbm_load_state.finish_lock); + qemu_mutex_init(&dbm_load_state.lock); } =20 static uint32_t qemu_get_bitmap_flags(QEMUFile *f) @@ -495,7 +495,7 @@ void dirty_bitmap_mig_before_vm_start(void) { GSList *item; =20 - qemu_mutex_lock(&dbm_load_state.finish_lock); + qemu_mutex_lock(&dbm_load_state.lock); =20 for (item =3D dbm_load_state.enabled_bitmaps; item; item =3D g_slist_next(item)) @@ -514,7 +514,7 @@ void dirty_bitmap_mig_before_vm_start(void) g_slist_free(dbm_load_state.enabled_bitmaps); dbm_load_state.enabled_bitmaps =3D NULL; =20 - qemu_mutex_unlock(&dbm_load_state.finish_lock); + qemu_mutex_unlock(&dbm_load_state.lock); } =20 static void dirty_bitmap_load_complete(QEMUFile *f) @@ -524,7 +524,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f) trace_dirty_bitmap_load_complete(); bdrv_dirty_bitmap_deserialize_finish(s->bitmap); =20 - qemu_mutex_lock(&dbm_load_state.finish_lock); + qemu_mutex_lock(&dbm_load_state.lock); =20 for (item =3D dbm_load_state.enabled_bitmaps; item; item =3D g_slist_next(item)) @@ -558,7 +558,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f) bdrv_dirty_bitmap_unlock(s->bitmap); } =20 - qemu_mutex_unlock(&dbm_load_state.finish_lock); + qemu_mutex_unlock(&dbm_load_state.lock); } =20 static int dirty_bitmap_load_bits(QEMUFile *f) --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699703; cv=none; d=zohomail.com; s=zohoarc; b=GqdsH/WzIieMQESM81Ctl7c3UsxgcvlEmJvW+XBrgTtCqM3Ld6tpxMkFmvdmtNeEYKlRucAPUmx0gbN+x/CP+99UcWbfdXaKSi/3SLPVXQWyN+pp4qsTcnYEIv3Qyqo7tRwG5AYhka++2AkIIeEYqq0V1PkbUjd1yW1BRwWrcNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699703; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EzMZ3emWwGVjTdPXOFAbLD57bd9UC28ecmIXsH6btTk=; b=WhzvmU9RcgXzdK9/qXtzAuJ0QsSjas/RI+vuZglizMvIYM1prBeboBFzeYrxTn5iOpL+hAZFeyuPZdX63iQ+THSfMiozMv3emrbULpSurlR36GTM6xIKWYJeaR8z6uPIxUTQoOtKU4qszSpbkF4LZ4kJzkdBcs897H1gAZJKNYM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699703890924.5907087604564; Wed, 22 Jan 2020 05:28:23 -0800 (PST) Received: from localhost ([::1]:42072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG3S-000402-AJ for importer@patchew.org; Wed, 22 Jan 2020 08:28:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51914) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyw-0006ml-My for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002Mn-Io for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:42304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002I3-NB; Wed, 22 Jan 2020 08:23:38 -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 1iuFyj-00057B-Ol; Wed, 22 Jan 2020 16:23:29 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 3/7] migration/block-dirty-bitmap: simplify dirty_bitmap_load_complete Date: Wed, 22 Jan 2020 16:23:24 +0300 Message-Id: <20200122132328.31156-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_enable_dirty_bitmap_locked() call does nothing, as if we are in postcopy, bitmap successor must be enabled, and reclaim operation will enable the bitmap. So, actually we need just call _reclaim_ in both if branches, and making differences only to add an assertion seems not really good. The logic becomes simple: on load complete we do reclaim and that's all. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/block-dirty-bitmap.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 502e858c31..eeaab2174e 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -526,6 +526,10 @@ static void dirty_bitmap_load_complete(QEMUFile *f) =20 qemu_mutex_lock(&dbm_load_state.lock); =20 + if (bdrv_dirty_bitmap_has_successor(s->bitmap)) { + bdrv_reclaim_dirty_bitmap(s->bitmap, &error_abort); + } + for (item =3D dbm_load_state.enabled_bitmaps; item; item =3D g_slist_next(item)) { @@ -537,27 +541,6 @@ static void dirty_bitmap_load_complete(QEMUFile *f) } } =20 - if (bdrv_dirty_bitmap_has_successor(s->bitmap)) { - bdrv_dirty_bitmap_lock(s->bitmap); - if (dbm_load_state.enabled_bitmaps =3D=3D NULL) { - /* in postcopy */ - bdrv_reclaim_dirty_bitmap_locked(s->bitmap, &error_abort); - bdrv_enable_dirty_bitmap_locked(s->bitmap); - } else { - /* target not started, successor must be empty */ - int64_t count =3D bdrv_get_dirty_count(s->bitmap); - BdrvDirtyBitmap *ret =3D bdrv_reclaim_dirty_bitmap_locked(s->b= itmap, - NULL); - /* bdrv_reclaim_dirty_bitmap can fail only on no successor (it - * must be) or on merge fail, but merge can't fail when second - * bitmap is empty - */ - assert(ret =3D=3D s->bitmap && - count =3D=3D bdrv_get_dirty_count(s->bitmap)); - } - bdrv_dirty_bitmap_unlock(s->bitmap); - } - qemu_mutex_unlock(&dbm_load_state.lock); } =20 --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699570; cv=none; d=zohomail.com; s=zohoarc; b=Q1PbQj1EIgIJzwOe7bMkg1nwvWytr22H5WZPl3M44RBuQ3jr12OvCHvDBuIXpCWru3cH3Tn3lvs/3oO/A6Abxbkxg2v9RNtYiSHYk43k7Odko44+6NpkcMiy230ixJhruSvEzPSlBp+PTIwMOriJ/xw09aCGNTpJfN04QMr7ncE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699570; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qLYk2TpJYA/s+Q5Q78BeLwH5/S6gmEmnaKOdCTJGo5Y=; b=Rnd+MCLbJqY8O+rLHmUwqH3vtdtg9IF8f+KR3aAKVsWiZaGcqKOf/Bb5IPKOPLbQDGUkAYc0lemVXCv59HJn2hyxzfvBloAdZyr1GJx0yji1db7z5YWh2VDTA60b8ImwgQm20mTZLX8KHRGIIwE0BLOOXgYf2f1IKqrJDz3JR6c= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157969957057261.467636680810756; Wed, 22 Jan 2020 05:26:10 -0800 (PST) Received: from localhost ([::1]:42055 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG1J-00012m-1z for importer@patchew.org; Wed, 22 Jan 2020 08:26:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51932) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyx-0006nO-9i for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002N6-QF for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from relay.sw.ru ([185.231.240.75]:42292) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002Hy-GT; Wed, 22 Jan 2020 08:23:38 -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 1iuFyk-00057B-1u; Wed, 22 Jan 2020 16:23:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 4/7] migration/block-dirty-bitmap: keep bitmap state for all bitmaps Date: Wed, 22 Jan 2020 16:23:25 +0300 Message-Id: <20200122132328.31156-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com 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. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/block-dirty-bitmap.c | 59 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index eeaab2174e..f96458113c 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -131,6 +131,7 @@ typedef struct DirtyBitmapLoadBitmapState { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; bool migrated; + bool enabled; } DirtyBitmapLoadBitmapState; =20 typedef struct DirtyBitmapLoadState { @@ -140,8 +141,11 @@ typedef struct DirtyBitmapLoadState { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; =20 - GSList *enabled_bitmaps; - QemuMutex lock; /* protect enabled_bitmaps */ + bool bitmaps_enabled; /* set in dirty_bitmap_mig_before_vm_start */ + bool stream_ended; /* set when all migrated data handled */ + + GSList *bitmaps; + QemuMutex lock; /* protect bitmaps */ } DirtyBitmapLoadState; static DirtyBitmapLoadState dbm_load_state; =20 @@ -446,6 +450,7 @@ static int dirty_bitmap_load_start(QEMUFile *f) Error *local_err =3D NULL; uint32_t granularity =3D qemu_get_be32(f); uint8_t flags =3D qemu_get_byte(f); + DirtyBitmapLoadBitmapState *b; =20 if (s->bitmap) { error_report("Bitmap with the same name ('%s') already exists on " @@ -472,22 +477,23 @@ static int dirty_bitmap_load_start(QEMUFile *f) =20 bdrv_disable_dirty_bitmap(s->bitmap); if (flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED) { - DirtyBitmapLoadBitmapState *b; - bdrv_dirty_bitmap_create_successor(s->bitmap, &local_err); if (local_err) { error_report_err(local_err); return -EINVAL; } - - b =3D g_new(DirtyBitmapLoadBitmapState, 1); - b->bs =3D s->bs; - b->bitmap =3D s->bitmap; - b->migrated =3D false; - dbm_load_state.enabled_bitmaps =3D - g_slist_prepend(dbm_load_state.enabled_bitmaps, b); } =20 + b =3D g_new(DirtyBitmapLoadBitmapState, 1); + *b =3D (DirtyBitmapLoadBitmapState) { + .bs =3D s->bs, + .bitmap =3D s->bitmap, + .migrated =3D false, + .enabled =3D flags & DIRTY_BITMAP_MIG_START_FLAG_ENABLED, + }; + + dbm_load_state.bitmaps =3D g_slist_prepend(dbm_load_state.bitmaps, b); + return 0; } =20 @@ -497,22 +503,25 @@ void dirty_bitmap_mig_before_vm_start(void) =20 qemu_mutex_lock(&dbm_load_state.lock); =20 - for (item =3D dbm_load_state.enabled_bitmaps; item; - item =3D g_slist_next(item)) - { + for (item =3D dbm_load_state.bitmaps; item; item =3D g_slist_next(item= )) { DirtyBitmapLoadBitmapState *b =3D item->data; =20 + if (!b->enabled) { + continue; + } + if (b->migrated) { bdrv_enable_dirty_bitmap_locked(b->bitmap); } else { bdrv_dirty_bitmap_enable_successor(b->bitmap); } - - g_free(b); } =20 - g_slist_free(dbm_load_state.enabled_bitmaps); - dbm_load_state.enabled_bitmaps =3D NULL; + dbm_load_state.bitmaps_enabled =3D true; + if (dbm_load_state.stream_ended) { + g_slist_free_full(dbm_load_state.bitmaps, g_free); + dbm_load_state.bitmaps =3D NULL; + } =20 qemu_mutex_unlock(&dbm_load_state.lock); } @@ -530,9 +539,7 @@ static void dirty_bitmap_load_complete(QEMUFile *f) bdrv_reclaim_dirty_bitmap(s->bitmap, &error_abort); } =20 - for (item =3D dbm_load_state.enabled_bitmaps; item; - item =3D g_slist_next(item)) - { + for (item =3D dbm_load_state.bitmaps; item; item =3D g_slist_next(item= )) { DirtyBitmapLoadBitmapState *b =3D item->data; =20 if (b->bitmap =3D=3D s->bitmap) { @@ -671,6 +678,16 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque= , int version_id) } } while (!(dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_EOS)); =20 + qemu_mutex_lock(&dbm_load_state.lock); + + dbm_load_state.stream_ended =3D true; + if (dbm_load_state.bitmaps_enabled) { + g_slist_free_full(dbm_load_state.bitmaps, g_free); + dbm_load_state.bitmaps =3D NULL; + } + + qemu_mutex_unlock(&dbm_load_state.lock); + trace_dirty_bitmap_load_success(); return 0; } --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699802; cv=none; d=zohomail.com; s=zohoarc; b=HzzgfQYkvFv5ZFSj/z/elKbWc0FxZh8t/vIzGgwAL5CNEqc+LAhsne+odH7kg6tke7UH3PDnQM+z1b8KqE1DvtyCk+glnhWlgkm34xIB06gvTwka4K/KtBUCd8LGeq5IIUnvPrXiT5RHvXfxPVtuLaRk5ydugs0BpfxuKr4EguE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699802; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jr/CuEii/5juAma14CzhOGKbXmigY9umWzzvZw5Zph8=; b=ZIL8zpBijP/lHPFarmiwRr6wp2PWL/W3iEIYPw69zBR1JW7tmPlcmJed1DKjdfyeCjzDKHcREzBNcDpbDDPZfV7K6P7FkQSfUYss+pfAF4q0VAj32wI26EXhKFymTKTMPTGTcvwn/ULokmy9jj3MbWw9HyA7nBphNtC/3h5+qww= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699802623568.6261876547981; Wed, 22 Jan 2020 05:30:02 -0800 (PST) Received: from localhost ([::1]:42110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG53-00068g-3I for importer@patchew.org; Wed, 22 Jan 2020 08:30:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51925) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyx-0006n4-0N for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002Mu-M5 for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:42280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002Hv-Ny; Wed, 22 Jan 2020 08:23:38 -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 1iuFyk-00057B-8v; Wed, 22 Jan 2020 16:23:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 5/7] migration/block-dirty-bitmap: cancel migration on shutdown Date: Wed, 22 Jan 2020 16:23:26 +0300 Message-Id: <20200122132328.31156-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If target is turned of prior to postcopy finished, we crash because busy bitmaps are found at shutdown. Let's fix it by removing all unfinished bitmaps on shutdown. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/migration.h | 1 + migration/block-dirty-bitmap.c | 44 ++++++++++++++++++++++++++++++---- migration/migration.c | 7 ++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index aa9ff6f27b..a3927b93bb 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -331,6 +331,7 @@ void migrate_send_rp_recv_bitmap(MigrationIncomingState= *mis, void migrate_send_rp_resume_ack(MigrationIncomingState *mis, uint32_t valu= e); =20 void dirty_bitmap_mig_before_vm_start(void); +void dirty_bitmap_mig_cancel_incoming(void); void init_dirty_bitmap_incoming_migration(void); void migrate_add_address(SocketAddress *address); =20 diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index f96458113c..5a98543672 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -143,6 +143,7 @@ typedef struct DirtyBitmapLoadState { =20 bool bitmaps_enabled; /* set in dirty_bitmap_mig_before_vm_start */ bool stream_ended; /* set when all migrated data handled */ + bool cancelled; =20 GSList *bitmaps; QemuMutex lock; /* protect bitmaps */ @@ -533,8 +534,6 @@ static void dirty_bitmap_load_complete(QEMUFile *f) trace_dirty_bitmap_load_complete(); bdrv_dirty_bitmap_deserialize_finish(s->bitmap); =20 - qemu_mutex_lock(&dbm_load_state.lock); - if (bdrv_dirty_bitmap_has_successor(s->bitmap)) { bdrv_reclaim_dirty_bitmap(s->bitmap, &error_abort); } @@ -547,8 +546,6 @@ static void dirty_bitmap_load_complete(QEMUFile *f) break; } } - - qemu_mutex_unlock(&dbm_load_state.lock); } =20 static int dirty_bitmap_load_bits(QEMUFile *f) @@ -656,6 +653,13 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque= , int version_id) } =20 do { + qemu_mutex_lock(&dbm_load_state.lock); + + if (dbm_load_state.cancelled) { + qemu_mutex_unlock(&dbm_load_state.lock); + break; + } + ret =3D dirty_bitmap_load_header(f); if (ret < 0) { return ret; @@ -676,6 +680,8 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque,= int version_id) if (ret) { return ret; } + + qemu_mutex_unlock(&dbm_load_state.lock); } while (!(dbm_load_state.flags & DIRTY_BITMAP_MIG_FLAG_EOS)); =20 qemu_mutex_lock(&dbm_load_state.lock); @@ -692,6 +698,36 @@ static int dirty_bitmap_load(QEMUFile *f, void *opaque= , int version_id) return 0; } =20 +void dirty_bitmap_mig_cancel_incoming(void) +{ + GSList *item; + + qemu_mutex_lock(&dbm_load_state.lock); + + if (dbm_load_state.bitmaps_enabled && dbm_load_state.stream_ended) { + qemu_mutex_unlock(&dbm_load_state.lock); + return; + } + + dbm_load_state.cancelled =3D true; + + for (item =3D dbm_load_state.bitmaps; item; item =3D g_slist_next(item= )) { + DirtyBitmapLoadBitmapState *b =3D item->data; + + if (!dbm_load_state.bitmaps_enabled || !b->migrated) { + if (bdrv_dirty_bitmap_has_successor(b->bitmap)) { + bdrv_reclaim_dirty_bitmap(b->bitmap, &error_abort); + } + bdrv_release_dirty_bitmap(b->bitmap); + } + } + + g_slist_free_full(dbm_load_state.bitmaps, g_free); + dbm_load_state.bitmaps =3D NULL; + + qemu_mutex_unlock(&dbm_load_state.lock); +} + static int dirty_bitmap_save_setup(QEMUFile *f, void *opaque) { DirtyBitmapMigBitmapState *dbms =3D NULL; diff --git a/migration/migration.c b/migration/migration.c index 990bff00c0..12d161165d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -182,6 +182,13 @@ void migration_shutdown(void) */ migrate_fd_cancel(current_migration); object_unref(OBJECT(current_migration)); + + /* + * Cancel incoming migration of dirty bitmaps. Dirty bitmaps + * are non-critical data, and their loss never considered as + * something serious. + */ + dirty_bitmap_mig_cancel_incoming(); } =20 /* For outgoing */ --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699550; cv=none; d=zohomail.com; s=zohoarc; b=IYql/Uz+4UgHdrwaGBr2yWzxXf0X8r+G06PwEQ+rF28xPp3v6345AFrDXfUUu3vKh4huLqSra0pLkT6Npew7q/bqqvsSRNhApHZ63HBckvhiohoufUdqBlS2GVuPb8bDamJLzuajEhFPpKt6n6DuTL9dyP4kGa/BxgAdjNBchJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699550; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mb1Xy6fedr24AAtQeQS/OuDzymj6nwepxM+P1De6GYo=; b=aC50k3bXOKZgt7JXQBnpNuqlAzNtZutL6gX2druPydInEKUQNSHzLO5pBUQcYgnEg+peXZKEBaiX9YXUJMjme7cmWWqk/bskHq+34mFj3gTw46F1DLjcBlU8f41bGlaBMbQq5dgGzSat4aMNSwcfRc5tLB9RFn5mC0kzipdel9c= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699550095338.44379822293354; Wed, 22 Jan 2020 05:25:50 -0800 (PST) Received: from localhost ([::1]:42040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG0y-0000d1-1k for importer@patchew.org; Wed, 22 Jan 2020 08:25:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51913) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyw-0006mk-Mb for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002Ma-Fh for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:42290) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002Hz-Mk; Wed, 22 Jan 2020 08:23:38 -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 1iuFyk-00057B-F8; Wed, 22 Jan 2020 16:23:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 6/7] migration: handle to_src_file on target only for ram postcopy Date: Wed, 22 Jan 2020 16:23:27 +0300 Message-Id: <20200122132328.31156-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If only bitmaps postcopy migration enabled and not ram, this assertion will fire, as we don't have to_src_file for bitmaps postcopy migration. migrate_postcopy_ram() accesses migrations state, which may be freed in main thread, so, we should ref/unref it in postcopy incoming thread. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/savevm.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index adfdca26ac..143755389e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1832,6 +1832,9 @@ static void *postcopy_ram_listen_thread(void *opaque) MigrationIncomingState *mis =3D migration_incoming_get_current(); QEMUFile *f =3D mis->from_src_file; int load_res; + MigrationState *migr =3D migrate_get_current(); + + object_ref(OBJECT(migr)); =20 migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); @@ -1898,6 +1901,8 @@ static void *postcopy_ram_listen_thread(void *opaque) mis->have_listen_thread =3D false; postcopy_state_set(POSTCOPY_INCOMING_END); =20 + object_unref(OBJECT(migr)); + return NULL; } =20 @@ -2457,12 +2462,14 @@ static bool postcopy_pause_incoming(MigrationIncomi= ngState *mis) qemu_fclose(mis->from_src_file); mis->from_src_file =3D NULL; =20 - assert(mis->to_src_file); - qemu_file_shutdown(mis->to_src_file); - qemu_mutex_lock(&mis->rp_mutex); - qemu_fclose(mis->to_src_file); - mis->to_src_file =3D NULL; - qemu_mutex_unlock(&mis->rp_mutex); + if (migrate_postcopy_ram()) { + assert(mis->to_src_file); + qemu_file_shutdown(mis->to_src_file); + qemu_mutex_lock(&mis->rp_mutex); + qemu_fclose(mis->to_src_file); + mis->to_src_file =3D NULL; + qemu_mutex_unlock(&mis->rp_mutex); + } =20 migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_POSTCOPY_PAUSED); --=20 2.21.0 From nobody Sat May 18 20:37:10 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1579699556; cv=none; d=zohomail.com; s=zohoarc; b=KjhcjPwqtT4suFEZlSnK+DjZVtQ42LXd6dSz5DxhkUsFb6kscH8ii+yoxFuX4xmJOSiARZLYqTsNYj5f267Va+27usSSXL1YJkyax2Ut3yIyeHhUnkAFp/HDKG8X086RF3Y8npf8K/KoEVEkAPicc3t2chDTTYWxkXUZEK7j5Mw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579699556; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ej2wIaq+QVyZyRIZMfVepneS+Pt9H89tHu5MlPbFp1U=; b=J5TXO4gHSzKv2oNto3zCMjh82DgDxh5+kxAWt7vFFdf9wbmrDNBl6Wma9L+Y/es87eJWNq04g3vPf0fOgOZCQFncf8/KC9a9lTesbppjCM+rkOCijLjy3misC2gAt2LffOCJ5MXDnJ/KpzgnvlJkUDBKAKuxQM4Qde5ypsKsy1Y= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1579699556017398.5702638956051; Wed, 22 Jan 2020 05:25:56 -0800 (PST) Received: from localhost ([::1]:42052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuG14-0000su-Ko for importer@patchew.org; Wed, 22 Jan 2020 08:25:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51908) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuFyw-0006mi-Ie for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuFyv-0002MV-F8 for qemu-devel@nongnu.org; Wed, 22 Jan 2020 08:23:42 -0500 Received: from relay.sw.ru ([185.231.240.75]:42306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iuFys-0002I2-R0; Wed, 22 Jan 2020 08:23:39 -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 1iuFyk-00057B-Oq; Wed, 22 Jan 2020 16:23:30 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 7/7] qemu-iotests/199: add early shutdown case to bitmaps postcopy Date: Wed, 22 Jan 2020 16:23:28 +0300 Message-Id: <20200122132328.31156-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200122132328.31156-1-vsementsov@virtuozzo.com> References: <20200122132328.31156-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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, quintela@redhat.com, dgilbert@redhat.com, mreitz@redhat.com, stefanha@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Previous patches fixed two crashes which may occur on shutdown prior to bitmaps postcopy finished. Check that it works now. Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/199 | 12 +++++++++++- tests/qemu-iotests/199.out | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/199 b/tests/qemu-iotests/199 index a2c8ecab5a..a3f6c73aed 100755 --- a/tests/qemu-iotests/199 +++ b/tests/qemu-iotests/199 @@ -47,7 +47,7 @@ class TestDirtyBitmapPostcopyMigration(iotests.QMPTestCas= e): self.vm_a.launch() self.vm_b.launch() =20 - def test_postcopy(self): + def do_test_postcopy(self, early_shutdown): write_size =3D 0x40000000 granularity =3D 512 chunk =3D 4096 @@ -99,6 +99,10 @@ class TestDirtyBitmapPostcopyMigration(iotests.QMPTestCa= se): if event['data']['status'] =3D=3D 'completed': break =20 + if early_shutdown: + self.vm_b.qmp('quit') + return + s =3D 0x8000 while s < write_size: self.vm_b.hmp_qemu_io('drive0', 'write %d %d' % (s, chunk)) @@ -114,6 +118,12 @@ class TestDirtyBitmapPostcopyMigration(iotests.QMPTest= Case): =20 self.assert_qmp(result, 'return/sha256', sha256); =20 + def test_postcopy(self): + self.do_test_postcopy(False) + + def test_postcopy_early_shutdown(self): + self.do_test_postcopy(True) + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], supported_cache_modes=3D['non= e'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/199.out b/tests/qemu-iotests/199.out index ae1213e6f8..fbc63e62f8 100644 --- a/tests/qemu-iotests/199.out +++ b/tests/qemu-iotests/199.out @@ -1,5 +1,5 @@ -. +.. ---------------------------------------------------------------------- -Ran 1 tests +Ran 2 tests =20 OK --=20 2.21.0