From nobody Sat Feb 7 15:29:47 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 1531929050296276.65786878556594; Wed, 18 Jul 2018 08:50:50 -0700 (PDT) Received: from localhost ([::1]:37297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffoj3-0002Rk-5p for importer@patchew.org; Wed, 18 Jul 2018 11:50:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffoal-0003Hk-GB for qemu-devel@nongnu.org; Wed, 18 Jul 2018 11:42:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffoag-0000H8-FR for qemu-devel@nongnu.org; Wed, 18 Jul 2018 11:42:15 -0400 Received: from relay.sw.ru ([185.231.240.75]:36374) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ffoag-0000F6-2a for qemu-devel@nongnu.org; Wed, 18 Jul 2018 11:42:10 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=dptest2.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1ffoad-0006bu-Qb; Wed, 18 Jul 2018 18:42:07 +0300 From: Denis Plotnikov To: dgilbert@redhat.com, quintela@redhat.com, pbonzini@redhat.com Date: Wed, 18 Jul 2018 18:41:49 +0300 Message-Id: <20180718154200.26777-7-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180718154200.26777-1-dplotnikov@virtuozzo.com> References: <20180718154200.26777-1-dplotnikov@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 v1 06/17] background snapshot: add helpers to manage a copy of ram block list 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: qemu-devel@nongnu.org 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" The VM ramblock list may be changed during the snapshotting. We want to make sure that we have the same ramblock list as it was at the time of snapshot beginning. So, we create a copy of the list at the beginning of the snapshotting and use it during the process. Signed-off-by: Denis Plotnikov --- migration/ram.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ migration/ram.h | 6 ++++++ 2 files changed, 57 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 021d583b9b..4399c31606 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1508,6 +1508,57 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss, return pages; } =20 +/* BackGround Snapshot Blocks */ +static RamBlockList bgs_blocks; + +static RamBlockList *ram_bgs_block_list_get(void) +{ + return &bgs_blocks; +} + +void ram_block_list_create(void) +{ + RAMBlock *block =3D NULL; + RamBlockList *block_list =3D ram_bgs_block_list_get(); + + qemu_mutex_lock_ramlist(); + QLIST_FOREACH(block, &ram_list.blocks, next) { + memory_region_ref(block->mr); + QLIST_INSERT_HEAD(block_list, block, bgs_next); + } + qemu_mutex_unlock_ramlist(); +} + +void ram_block_list_destroy(void) +{ + RAMBlock *next, *block; + RamBlockList *block_list =3D ram_bgs_block_list_get(); + + QLIST_FOREACH_SAFE(block, block_list, bgs_next, next) { + QLIST_REMOVE(block, bgs_next); + memory_region_unref(block->mr); + } +} + +RAMBlock *ram_bgs_block_find(uint8_t *address, ram_addr_t *page_offset) +{ + RAMBlock *block =3D NULL; + RamBlockList *block_list =3D ram_bgs_block_list_get(); + + QLIST_FOREACH(block, block_list, bgs_next) { + /* This case append when the block is not mapped. */ + if (block->host =3D=3D NULL) { + continue; + } + + if (address - block->host < block->max_length) { + *page_offset =3D (address - block->host) & TARGET_PAGE_MASK; + return block; + } + } + + return NULL; +} /** * ram_find_and_save_block: finds a dirty page and sends it to f * diff --git a/migration/ram.h b/migration/ram.h index 64d81e9f1d..385579cae9 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -31,6 +31,7 @@ =20 #include "qemu-common.h" #include "exec/cpu-common.h" +#include "exec/ramlist.h" =20 extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; @@ -61,5 +62,10 @@ void ram_handle_compressed(void *host, uint8_t ch, uint6= 4_t size); int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); void ramblock_recv_bitmap_set_range(RAMBlock *rb, void *host_addr, size_t = nr); +/* For background snapshot */ +void ram_block_list_create(void); +void ram_block_list_destroy(void); + +RAMBlock *ram_bgs_block_find(uint8_t *address, ram_addr_t *page_offset); =20 #endif --=20 2.17.0