From nobody Mon Feb 9 06:01:44 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 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