From nobody Mon Feb 9 11:30:36 2026 Delivered-To: importer@patchew.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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1605699034; cv=none; d=zohomail.com; s=zohoarc; b=b7t88ahGWfgFSIPirjPl1lkJcXelr9sNIp/Qqv4cgXSJjdWqYEjDZIuXFakA7PK/8uiL4xEAWRifogOl0dOkMzDvFgxW0wCx4SKqBALNinxe37wNSBgygcGirgWNUA0uErmqydXpAtb8LvDirzXmBhwzCAE/XiQI9l5lcVWWFf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605699034; 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:Reply-To:References:Sender:Subject:To; bh=jxf0EGkTc4KD3dtE6n3aalqNKTqoBoTIUSAeJQPTufU=; b=kRIrisrAVdd+WqayFLn95ioRHQau7XRRno5SxhOfEvZAHi0iu76XKz7oVD2ii7rEp178ymicvxkw8oO1qvnxbz0QOcOT2765qw1hkpINGBr6ZCOsLQPYdPLqsNYTPbF+AfXYcF/nwr9++gNSsAcpv8/oh7Vh5vhl+l/c072y08E= 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=pass 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 1605699034663564.0257420125002; Wed, 18 Nov 2020 03:30:34 -0800 (PST) Received: from localhost ([::1]:36846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfLfV-0004g6-H9 for importer@patchew.org; Wed, 18 Nov 2020 06:30:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfLY1-00055r-DT for qemu-devel@nongnu.org; Wed, 18 Nov 2020 06:22:49 -0500 Received: from relay.sw.ru ([185.231.240.75]:41854 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfLXq-0003Og-O7 for qemu-devel@nongnu.org; Wed, 18 Nov 2020 06:22:48 -0500 Received: from [192.168.15.76] (helo=andrey-MS-7B54.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kfLXb-009A89-D4; Wed, 18 Nov 2020 14:22:23 +0300 To: qemu-devel@nongnu.org Cc: Den Lunev , Eric Blake , Paolo Bonzini , Juan Quintela , "Dr . David Alan Gilbert" , Markus Armbruster , Andrey Gruzdev Subject: [PATCH 6/7] The rest of write tracking migration code. Date: Wed, 18 Nov 2020 14:22:32 +0300 Message-Id: <20201118112233.264530-7-andrey.gruzdev@virtuozzo.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201118112233.264530-1-andrey.gruzdev@virtuozzo.com> References: <20201118112233.264530-1-andrey.gruzdev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=185.231.240.75; envelope-from=andrey.gruzdev@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/18 06:22:34 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Gruzdev From: Andrey Gruzdev via Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrey Gruzdev --- migration/migration.c | 72 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 381da4a4d3..92bcb9105d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3212,6 +3212,48 @@ fail: MIGRATION_STATUS_FAILED); } =20 +/** + * wt_migration_completion: Used by wt_migration_thread when after all the= RAM has been saved. + * The caller 'breaks' the loop when this returns. + * + * @s: Current migration state + */ +static void wt_migration_completion(MigrationState *s) +{ + int current_active_state =3D s->state; + + /* Stop tracking RAM writes - un-protect memory, un-register UFFD memo= ry ranges, + * flush kernel wait queues and wake up threads waiting for write faul= t to be + * resolved. All of this is essentially done by closing UFFD file desc= riptor */ + ram_write_tracking_stop(); + + if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { + /* + * By this moment we have RAM content saved into the migration str= eam. + * The next step is to flush the non-RAM content (device state) + * right after the ram content. The device state has been stored i= nto + * the temporary buffer before RAM saving started. + */ + qemu_put_buffer(s->to_dst_file, s->bioc->data, s->bioc->usage); + qemu_fflush(s->to_dst_file); + } else if (s->state =3D=3D MIGRATION_STATUS_CANCELLING) { + goto fail; + } + + if (qemu_file_get_error(s->to_dst_file)) { + trace_migration_completion_file_err(); + goto fail; + } + + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_COMPLETED); + return; + +fail: + migrate_set_state(&s->state, current_active_state, + MIGRATION_STATUS_FAILED); +} + bool migrate_colo_enabled(void) { MigrationState *s =3D migrate_get_current(); @@ -3554,7 +3596,26 @@ static void migration_iteration_finish(MigrationStat= e *s) =20 static void wt_migration_iteration_finish(MigrationState *s) { - /* TODO: implement */ + qemu_mutex_lock_iothread(); + switch (s->state) { + case MIGRATION_STATUS_COMPLETED: + migration_calculate_complete(s); + break; + + case MIGRATION_STATUS_ACTIVE: + case MIGRATION_STATUS_FAILED: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_CANCELLING: + break; + + default: + /* Should not reach here, but if so, forgive the VM. */ + error_report("%s: Unknown ending state %d", __func__, s->state= ); + break; + } + + migrate_fd_cleanup_schedule(s); + qemu_mutex_unlock_iothread(); } =20 /* @@ -3563,7 +3624,14 @@ static void wt_migration_iteration_finish(MigrationS= tate *s) */ static MigIterateState wt_migration_iteration_run(MigrationState *s) { - /* TODO: implement */ + int res; + + res =3D qemu_savevm_state_iterate(s->to_dst_file, false); + if (res) { + wt_migration_completion(s); + return MIG_ITERATE_BREAK; + } + return MIG_ITERATE_RESUME; } =20 --=20 2.25.1