From nobody Wed Nov 12 11:51:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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=1570204441; cv=none; d=zoho.com; s=zohoarc; b=dQcp+W3/5mAwrSF+LNzanL8yNj2ZfI4heTUUohZNKNsJscDrcCHlKoqFdyA7mPOETBSgLN6+oUnjc+yrE+ZYt5sZNQPEbsY55hKLEMjDvLE8+ThyqVHYxdE0yrnMHqPCQ6rsMBsgROzE0qY3xawH+bv2RPw6WeA8cHs246MzXFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570204441; 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:ARC-Authentication-Results; bh=qOsmMFnziNAFcgYyCgOCljYBfpcgImzI9Fw4l6LkhZo=; b=CGiqtrptyfVDQjZOuyu/sg5vrug+UL2b0Q1CnLh2LJBWLpRm3jSIMCdZFrGhZ6/9/IVrhi5R8zwyl9tQu2ZGrNTOfGypPaTU9c2yY/lE3kdnbXCu08C4IxYs0M8sgxN8KUpjFJeCFKH8nxbDWyrc3mB6T8+V/SM9fY6kRVDA9sI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1570204441070941.9430928973987; Fri, 4 Oct 2019 08:54:01 -0700 (PDT) Received: from localhost ([::1]:49982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGPu0-0005Mc-Gt for importer@patchew.org; Fri, 04 Oct 2019 11:53:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41127) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGPni-00037F-GU for qemu-devel@nongnu.org; Fri, 04 Oct 2019 11:47:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iGPnh-0005e2-2u for qemu-devel@nongnu.org; Fri, 04 Oct 2019 11:47:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:36332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iGPnR-0005Eb-Hf; Fri, 04 Oct 2019 11:47:21 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iGPnK-00019e-VT; Fri, 04 Oct 2019 18:47:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 2/5] migretion/block-dirty-bitmap: refactor init_dirty_bitmap_migration Date: Fri, 4 Oct 2019 18:46:58 +0300 Message-Id: <20191004154701.3202-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191004154701.3202-1-vsementsov@virtuozzo.com> References: <20191004154701.3202-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@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, quintela@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Split out handling one bs, it is needed for the following commit, which will handle BlockBackends in separate. Signed-off-by: Vladimir Sementsov-Ogievskiy --- migration/block-dirty-bitmap.c | 93 +++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 5121f86d73..46641b7861 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -268,59 +268,68 @@ static void dirty_bitmap_mig_cleanup(void) } =20 /* Called with iothread lock taken. */ -static int init_dirty_bitmap_migration(void) +static int add_bitmaps_to_list(BlockDriverState *bs, const char *bs_name) { - BlockDriverState *bs; BdrvDirtyBitmap *bitmap; DirtyBitmapMigBitmapState *dbms; Error *local_err =3D NULL; =20 - dirty_bitmap_mig_state.bulk_completed =3D false; - dirty_bitmap_mig_state.prev_bs =3D NULL; - dirty_bitmap_mig_state.prev_bitmap =3D NULL; - dirty_bitmap_mig_state.no_bitmaps =3D false; + for (bitmap =3D bdrv_dirty_bitmap_next(bs, NULL); bitmap; + bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap)) + { + if (!bdrv_dirty_bitmap_name(bitmap)) { + continue; + } =20 - for (bs =3D bdrv_next_all_states(NULL); bs; bs =3D bdrv_next_all_state= s(bs)) { - const char *name =3D bdrv_get_device_or_node_name(bs); + if (!bs_name || strcmp(bs_name, "") =3D=3D 0) { + error_report("Found bitmap '%s' in unnamed node %p. It can't " + "be migrated", bdrv_dirty_bitmap_name(bitmap), bs= ); + return -1; + } =20 - for (bitmap =3D bdrv_dirty_bitmap_next(bs, NULL); bitmap; - bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap)) - { - if (!bdrv_dirty_bitmap_name(bitmap)) { - continue; - } + if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, &local_er= r)) { + error_report_err(local_err); + return -1; + } =20 - if (!name || strcmp(name, "") =3D=3D 0) { - error_report("Found bitmap '%s' in unnamed node %p. It can= 't " - "be migrated", bdrv_dirty_bitmap_name(bitmap)= , bs); - goto fail; - } + bdrv_ref(bs); + bdrv_dirty_bitmap_set_busy(bitmap, true); + + dbms =3D g_new0(DirtyBitmapMigBitmapState, 1); + dbms->bs =3D bs; + dbms->node_name =3D bs_name; + dbms->bitmap =3D bitmap; + dbms->total_sectors =3D bdrv_nb_sectors(bs); + dbms->sectors_per_chunk =3D CHUNK_SIZE * 8 * + bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; + if (bdrv_dirty_bitmap_enabled(bitmap)) { + dbms->flags |=3D DIRTY_BITMAP_MIG_START_FLAG_ENABLED; + } + if (bdrv_dirty_bitmap_get_persistence(bitmap)) { + dbms->flags |=3D DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT; + } =20 - if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_DEFAULT, - &local_err)) { - error_report_err(local_err); - goto fail; - } + QSIMPLEQ_INSERT_TAIL(&dirty_bitmap_mig_state.dbms_list, + dbms, entry); + } =20 - bdrv_ref(bs); - bdrv_dirty_bitmap_set_busy(bitmap, true); - - dbms =3D g_new0(DirtyBitmapMigBitmapState, 1); - dbms->bs =3D bs; - dbms->node_name =3D name; - dbms->bitmap =3D bitmap; - dbms->total_sectors =3D bdrv_nb_sectors(bs); - dbms->sectors_per_chunk =3D CHUNK_SIZE * 8 * - bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; - if (bdrv_dirty_bitmap_enabled(bitmap)) { - dbms->flags |=3D DIRTY_BITMAP_MIG_START_FLAG_ENABLED; - } - if (bdrv_dirty_bitmap_get_persistence(bitmap)) { - dbms->flags |=3D DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT; - } + return 0; +} + +/* Called with iothread lock taken. */ +static int init_dirty_bitmap_migration(void) +{ + BlockDriverState *bs; + DirtyBitmapMigBitmapState *dbms; + + dirty_bitmap_mig_state.bulk_completed =3D false; + dirty_bitmap_mig_state.prev_bs =3D NULL; + dirty_bitmap_mig_state.prev_bitmap =3D NULL; + dirty_bitmap_mig_state.no_bitmaps =3D false; =20 - QSIMPLEQ_INSERT_TAIL(&dirty_bitmap_mig_state.dbms_list, - dbms, entry); + for (bs =3D bdrv_next_all_states(NULL); bs; bs =3D bdrv_next_all_state= s(bs)) { + if (add_bitmaps_to_list(bs, bdrv_get_device_or_node_name(bs))) { + goto fail; } } =20 --=20 2.21.0