From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887389; cv=none; d=zohomail.com; s=zohoarc; b=UQ6BmkjLikKgtv2nqFbCmqnYBvbcp/RCvkvF7qQDY3dJly1aVFa7pICLpVrpWB5q4R7Z31RRj68AhfQ+Mr063DSYmYQTB2HpgwwHpM/wXjmTDuAC07pxBshlTavyFhPJ2ZGt7GUh/1UQQEwJ0vOHWtQ0na6w0avSZXOFkH6/VRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887389; 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=oJF5O7EmDwv6m28nykB6f/nZh10KH48Qx+3g0d6GRcw=; b=KbfB44ZJhK0Jx+m1lURRCus/lyKStvP22CyefOVk1MjDL7aUroB0k608lJJ5v7zCgL3Vbqz4DGPFO5RWqq4HRuv0+jchqyvvof5N+/vbZiywzi7sL75fmxfDn72eR7WDJUU1MYENcik3L+ac16N2dp3YwCQipxvWFeNu2guK5Og= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887389663935.5196023365744; Tue, 4 Oct 2022 05:43:09 -0700 (PDT) Received: from localhost ([::1]:43090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhGO-0002vL-2U for importer@patchew.org; Tue, 04 Oct 2022 08:43:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBC-0006m0-67 for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:36490) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005r9-TP for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:45 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9C7BD2188C; Tue, 4 Oct 2022 12:37:38 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3033B139EF; Tue, 4 Oct 2022 12:37:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kHoFCRIpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887058; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJF5O7EmDwv6m28nykB6f/nZh10KH48Qx+3g0d6GRcw=; b=LVCZ/r1951xwnPmzL5TFQxEhk4ruurEJWF5Ju7JWBIc0F3V8RlMGkWePvG2mIfPyLAEzZG oCmV+kn8/rESgNfm+XyXExYdfR4Wks6DCQ4rRhljuAYQPH7fts/beKXZVvTtLSm6Su+n13 Po3XjSTS0Vb760DVaaPM10IElBBelkw= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 01/11] migration: support file: uri for source migration Date: Tue, 4 Oct 2022 15:37:23 +0300 Message-Id: <20221004123733.2745519-2-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1c; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887390516100001 Content-Type: text/plain; charset="utf-8" Implement support for a "file:" uri so that a migration can be initiated directly to a file from QEMU. Signed-off-by: Nikolay Borisov --- migration/file.c | 23 +++++++++++++++++++++++ migration/file.h | 9 +++++++++ migration/meson.build | 1 + migration/migration.c | 3 +++ 4 files changed, 36 insertions(+) create mode 100644 migration/file.c create mode 100644 migration/file.h diff --git a/migration/file.c b/migration/file.c new file mode 100644 index 000000000000..02896a7cab99 --- /dev/null +++ b/migration/file.c @@ -0,0 +1,23 @@ +#include "qemu/osdep.h" +#include "channel.h" +#include "io/channel-file.h" +#include "file.h" +#include "qemu/error-report.h" + + +void file_start_outgoing_migration(MigrationState *s, const char *fname, E= rror **errp) +{ + QIOChannelFile *ioc; + + ioc =3D qio_channel_file_new_path(fname, O_CREAT|O_TRUNC|O_WRONLY, 0660, = errp); + if (!ioc) { + error_report("Error creating a channel"); + return; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-outgoing"); + migration_channel_connect(s, QIO_CHANNEL(ioc), NULL, NULL); + object_unref(OBJECT(ioc)); +} + + diff --git a/migration/file.h b/migration/file.h new file mode 100644 index 000000000000..d476eb1157f9 --- /dev/null +++ b/migration/file.h @@ -0,0 +1,9 @@ +#ifndef QEMU_MIGRATION_FILE_H +#define QEMU_MIGRATION_FILE_H + +void file_start_outgoing_migration(MigrationState *s, + const char *filename, + Error **errp); + +#endif + diff --git a/migration/meson.build b/migration/meson.build index 690487cf1a81..30a8392701c3 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -17,6 +17,7 @@ softmmu_ss.add(files( 'colo.c', 'exec.c', 'fd.c', + 'file.c', 'global_state.c', 'migration.c', 'multifd.c', diff --git a/migration/migration.c b/migration/migration.c index bb8bbddfe467..8813b78b9a6b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -20,6 +20,7 @@ #include "migration/blocker.h" #include "exec.h" #include "fd.h" +#include "file.h" #include "socket.h" #include "sysemu/runstate.h" #include "sysemu/sysemu.h" @@ -2414,6 +2415,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool = blk, exec_start_outgoing_migration(s, p, &local_err); } else if (strstart(uri, "fd:", &p)) { fd_start_outgoing_migration(s, p, &local_err); + } else if (strstart(uri, "file:", &p)) { + file_start_outgoing_migration(s, p, &local_err); } else { if (!(has_resume && resume)) { yank_unregister_instance(MIGRATION_YANK_INSTANCE); --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887689; cv=none; d=zohomail.com; s=zohoarc; b=gxMb9WPjHoqJEC8wgLTW7Kgbvbm8vDJRkU0z1FIWfKwa26IU5kx0HlLWPA07uqHzAoEZaQRt7NepJJAqJGNGnsgh7kGq7vvuQ/93PdaZvK7vZ4itRlmk35GPVeSSNxZYH2jiY8XJEiHnRevdwSnSfbHx+CqPOz5mR7b+o4IewGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887689; 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=0C6zIHlvsOwNHoKLjVfG9Y4tnfVGgpb6vsEK+n6Ucb0=; b=NxgktXCtsTqc2MAj2IdRYrSJ8SEXSY1WPFITPwMb2Q7PXIO3GS5+7mj/V3pnnPBN/4ej/GxqbfcyqFueLx5CC2jvdUzYnfsID6lCsPIM3mxHJuyZqVXrvXqT5LxX7Wq4NzcxJQjvuS/lydFZoc1qu6pacEVBR1eBQznXd3D1hnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887689931474.34440164303544; Tue, 4 Oct 2022 05:48:09 -0700 (PDT) Received: from localhost ([::1]:47774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhLE-0000Pw-My for importer@patchew.org; Tue, 04 Oct 2022 08:48:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBE-0006me-Ft for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:36500) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rN-Tw for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:48 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 242272188D; Tue, 4 Oct 2022 12:37:39 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AE0C0139EF; Tue, 4 Oct 2022 12:37:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kE/kJxIpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887059; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0C6zIHlvsOwNHoKLjVfG9Y4tnfVGgpb6vsEK+n6Ucb0=; b=hW3ZbXSxmCb6kdv5sEzHbWhEI/GHnIN9cAuhjHixVo8VlaKXJImNxNJdZbwFCGAggkyJUb RLhQk0eXKFTjMBI1HS5h5AkVQd6UtukoL1xQRKQ7FntFdyyDDaLz1iByZouVJTsxMQNpWE kgkI9dSYLg2eDE3cSptixx0hMJwFxNk= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 02/11] migration: Add support for 'file:' uri for incoming migration Date: Tue, 4 Oct 2022 15:37:24 +0300 Message-Id: <20221004123733.2745519-3-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1c; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887691910100001 Content-Type: text/plain; charset="utf-8" This is a counterpart to the 'file:' uri support for source migration, now a file can also serve as the source of an incoming migration. Signed-off-by: Nikolay Borisov --- migration/file.c | 15 +++++++++++++++ migration/file.h | 1 + migration/migration.c | 2 ++ 3 files changed, 18 insertions(+) diff --git a/migration/file.c b/migration/file.c index 02896a7cab99..93eb718aa0f4 100644 --- a/migration/file.c +++ b/migration/file.c @@ -21,3 +21,18 @@ void file_start_outgoing_migration(MigrationState *s, co= nst char *fname, Error * } =20 =20 +void file_start_incoming_migration(const char *fname, Error **errp) +{ + QIOChannelFile *ioc; + + ioc =3D qio_channel_file_new_path(fname, O_RDONLY, 0, errp); + if (!ioc) { + error_report("Error creating a channel"); + return; + } + + qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-incoming"); + migration_channel_process_incoming(QIO_CHANNEL(ioc)); + object_unref(OBJECT(ioc)); +} + diff --git a/migration/file.h b/migration/file.h index d476eb1157f9..cdbd291322d4 100644 --- a/migration/file.h +++ b/migration/file.h @@ -5,5 +5,6 @@ void file_start_outgoing_migration(MigrationState *s, const char *filename, Error **errp); =20 +void file_start_incoming_migration(const char *fname, Error **errp); #endif =20 diff --git a/migration/migration.c b/migration/migration.c index 8813b78b9a6b..140b0f1a54bd 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -506,6 +506,8 @@ static void qemu_start_incoming_migration(const char *u= ri, Error **errp) exec_start_incoming_migration(p, errp); } else if (strstart(uri, "fd:", &p)) { fd_start_incoming_migration(p, errp); + } else if (strstart(uri, "file:", &p)) { + file_start_incoming_migration(p, errp); } else { error_setg(errp, "unknown migration protocol: %s", uri); } --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887396; cv=none; d=zohomail.com; s=zohoarc; b=it4JvExjBjPN+4xqOaAuNQV5Z4V6QwSx1qWLuocPL48AEnWMvZjY1D5wXwj2wWWCZnDBeVaVqePSHitLazhrWsCYr2enA/APmx5NUTQla/A9soInYCMhOZvretpUB75rHQcSX+v+CBO99UHN80566oBjXHuFwYj2pWBEdp9hfnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887396; 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=h5OBUZNH7NOyqSuyiWgAKL7M/7/MeSlkQLE3XtRV5eo=; b=eZPXpD6kiGCNfaYS7I7K75OVeAInjMb94Ea3bYsGBLzMwzqwFX6bxV3ttO2mdG3MJfceved+sHzlncZjzki508D7bYb2q0noTuCvDzbMA6mAx/IXI6Bibb3miDVLUMOyS4lMfbUicrGn/DjbLMWPSH/dU5PPRu+iSExD5QVLeuc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887396922320.3327442595096; Tue, 4 Oct 2022 05:43:16 -0700 (PDT) Received: from localhost ([::1]:59684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhGU-00036U-Ty for importer@patchew.org; Tue, 04 Oct 2022 08:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBD-0006mS-9l for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:49910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rM-TO for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A1BFD1F899; Tue, 4 Oct 2022 12:37:39 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 36118139EF; Tue, 4 Oct 2022 12:37:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OAB3ChMpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887059; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h5OBUZNH7NOyqSuyiWgAKL7M/7/MeSlkQLE3XtRV5eo=; b=YiEdGV7EXcYA3GqZwRbPRM8/eioreQQZeZ3B4XcuPk3CRpMpFjlwxNmJXSPwxlAjWYKHz/ C+HRF2VbhQadUks7MvpsX+Qg3n/3jXKEH4ZS7X8NRTDEXwwGDtfdPiEF+JpsLJzOgcwaSN h9IrdMzpkdBwDSQahHwGUB5z5SkPpvI= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 03/11] migration: Make migration json writer part of MigrationState struct Date: Tue, 4 Oct 2022 15:37:25 +0300 Message-Id: <20221004123733.2745519-4-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1d; envelope-from=nborisov@suse.com; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887398541100001 Content-Type: text/plain; charset="utf-8" This is required so that migration stream configuration is written to the migration stream. This would allow analyze-migration to parse enabled capabilities for the migration and adjust its behavior accordingly. This is in preparation for analyze-migration.py to support 'fixed-ram' capability format changes. Signed-off-by: Nikolay Borisov --- migration/migration.c | 5 +++++ migration/migration.h | 3 +++ migration/savevm.c | 38 ++++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 140b0f1a54bd..d0779bbaf862 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1896,6 +1896,8 @@ static void migrate_fd_cleanup(MigrationState *s) g_free(s->hostname); s->hostname =3D NULL; =20 + json_writer_free(s->vmdesc); + qemu_savevm_state_cleanup(); =20 if (s->to_dst_file) { @@ -2154,6 +2156,7 @@ void migrate_init(MigrationState *s) error_free(s->error); s->error =3D NULL; s->hostname =3D NULL; + s->vmdesc =3D NULL; =20 migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_S= ETUP); =20 @@ -4269,6 +4272,8 @@ void migrate_fd_connect(MigrationState *s, Error *err= or_in) return; } =20 + s->vmdesc =3D json_writer_new(false); + if (multifd_save_setup(&local_err) !=3D 0) { error_report_err(local_err); migrate_set_state(&s->state, MIGRATION_STATUS_SETUP, diff --git a/migration/migration.h b/migration/migration.h index cdad8aceaaab..96f27aba2210 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -17,6 +17,7 @@ #include "exec/cpu-common.h" #include "hw/qdev-core.h" #include "qapi/qapi-types-migration.h" +#include "qapi/qmp/json-writer.h" #include "qemu/thread.h" #include "qemu/coroutine_int.h" #include "io/channel.h" @@ -261,6 +262,8 @@ struct MigrationState { =20 int state; =20 + JSONWriter *vmdesc; + /* State related to return path */ struct { /* Protected by qemu_file_lock */ diff --git a/migration/savevm.c b/migration/savevm.c index 48e85c052c2c..174cdbefc29d 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1137,13 +1137,18 @@ void qemu_savevm_non_migratable_list(strList **reas= ons) =20 void qemu_savevm_state_header(QEMUFile *f) { + MigrationState *s =3D migrate_get_current(); trace_savevm_state_header(); qemu_put_be32(f, QEMU_VM_FILE_MAGIC); qemu_put_be32(f, QEMU_VM_FILE_VERSION); =20 - if (migrate_get_current()->send_configuration) { + if (s->send_configuration) { qemu_put_byte(f, QEMU_VM_CONFIGURATION); - vmstate_save_state(f, &vmstate_configuration, &savevm_state, 0); + json_writer_start_object(s->vmdesc, NULL); + json_writer_start_object(s->vmdesc, "configuration"); + vmstate_save_state(f, &vmstate_configuration, &savevm_state, s->vm= desc); + json_writer_end_object(s->vmdesc); + } } =20 @@ -1364,15 +1369,16 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, bool in_postcopy, bool inactivate_disks) { - g_autoptr(JSONWriter) vmdesc =3D NULL; + MigrationState *s =3D migrate_get_current(); int vmdesc_len; SaveStateEntry *se; int ret; =20 - vmdesc =3D json_writer_new(false); - json_writer_start_object(vmdesc, NULL); - json_writer_int64(vmdesc, "page_size", qemu_target_page_size()); - json_writer_start_array(vmdesc, "devices"); + if (!s->send_configuration) { + json_writer_start_object(s->vmdesc, NULL); + } + json_writer_int64(s->vmdesc, "page_size", qemu_target_page_size()); + json_writer_start_array(s->vmdesc, "devices"); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { =20 if ((!se->ops || !se->ops->save_state) && !se->vmsd) { @@ -1385,12 +1391,12 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, =20 trace_savevm_section_start(se->idstr, se->section_id); =20 - json_writer_start_object(vmdesc, NULL); - json_writer_str(vmdesc, "name", se->idstr); - json_writer_int64(vmdesc, "instance_id", se->instance_id); + json_writer_start_object(s->vmdesc, NULL); + json_writer_str(s->vmdesc, "name", se->idstr); + json_writer_int64(s->vmdesc, "instance_id", se->instance_id); =20 save_section_header(f, se, QEMU_VM_SECTION_FULL); - ret =3D vmstate_save(f, se, vmdesc); + ret =3D vmstate_save(f, se, s->vmdesc); if (ret) { qemu_file_set_error(f, ret); return ret; @@ -1398,7 +1404,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(Q= EMUFile *f, trace_savevm_section_end(se->idstr, se->section_id, 0); save_section_footer(f, se); =20 - json_writer_end_object(vmdesc); + json_writer_end_object(s->vmdesc); } =20 if (inactivate_disks) { @@ -1417,14 +1423,14 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, qemu_put_byte(f, QEMU_VM_EOF); } =20 - json_writer_end_array(vmdesc); - json_writer_end_object(vmdesc); - vmdesc_len =3D strlen(json_writer_get(vmdesc)); + json_writer_end_array(s->vmdesc); + json_writer_end_object(s->vmdesc); + vmdesc_len =3D strlen(json_writer_get(s->vmdesc)); =20 if (should_send_vmdesc()) { qemu_put_byte(f, QEMU_VM_VMDESCRIPTION); qemu_put_be32(f, vmdesc_len); - qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); + qemu_put_buffer(f, (uint8_t *)json_writer_get(s->vmdesc), vmdesc_l= en); } =20 return 0; --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887693; cv=none; d=zohomail.com; s=zohoarc; b=Fo34dj0vnnHTGFIZnlK4n9dmbY+66a4njzS+f4jDBgZDhlk3i+kjl6Ud/eKW7MGi/D4zVe7Ul4f58LtKetdGs+xrkBqpiG5bHyFvI/EHs0ODUwlhAJ+3ZLGdCQ5uMShhIO1zcxId4sk1j+d6WP2iV4T1wpwPvD4DGplnL02PQSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887693; 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=wQIQjZe3/s5Z7h2Qk9gj7o9NRBQIR6PIhbUVeetfc3Q=; b=bHRSiPuPJ4clu5PQs/e7qMR58pgzsxjFzg5De6mCQMZ7upP5bxHoLVvYRDgm2HVvbbCnckjc9eExu5Qa6/bX6xw2ORLsK8HUFlyeRFDzqcKggdsF0+LOzcALWux642oCnDD81G8WiZM3bwcAR5XYVLxisV420mcjv+LLUDk0hwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887693087883.89907883348; Tue, 4 Oct 2022 05:48:13 -0700 (PDT) Received: from localhost ([::1]:57920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhLH-0000cz-QS for importer@patchew.org; Tue, 04 Oct 2022 08:48:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBD-0006mJ-2M for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:49898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rE-Th for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3BC611F8D9; Tue, 4 Oct 2022 12:37:40 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C3A4D139EF; Tue, 4 Oct 2022 12:37:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kHECKRMpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQIQjZe3/s5Z7h2Qk9gj7o9NRBQIR6PIhbUVeetfc3Q=; b=fWDEKSou/ayPfjtVJct0NFmqyC0qUEvtrD/lRbw8hCl7ajkvSdu6xgynEWXy4P37sivwJr wlbBvRWBerF6VQhU/1aKCl35RSFkkxTfOPp9rPMTjpTCjcCWR4mtC5iYDL7RxX5WakOBbJ flk1R2SFfYDYHNEb0GYvq4x9L00P/bo= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 04/11] io: add pwritev support to QIOChannelFile Date: Tue, 4 Oct 2022 15:37:26 +0300 Message-Id: <20221004123733.2745519-5-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1d; envelope-from=nborisov@suse.com; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887693919100003 Content-Type: text/plain; charset="utf-8" The upcoming 'fixed-ram' feature would require qemu to write data at specific offsets of the file. This is currently missing so this patch adds it. I've chosen to implement it as a type-specific function rather than plumb it through the generic channel interface as it relies on being able to do seeks. Signed-off-by: Nikolay Borisov --- include/io/channel-file.h | 5 +++++ io/channel-file.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/io/channel-file.h b/include/io/channel-file.h index 50e8eb113868..0a5d54f5e58e 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -89,4 +89,9 @@ qio_channel_file_new_path(const char *path, mode_t mode, Error **errp); =20 +ssize_t qio_channel_file_pwritev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); #endif /* QIO_CHANNEL_FILE_H */ diff --git a/io/channel-file.c b/io/channel-file.c index b67687c2aa64..da17d0a11ba7 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -136,6 +136,30 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, return ret; } =20 +ssize_t qio_channel_file_pwritev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); + ssize_t ret; + + retry: + ret =3D pwritev(fioc->fd, iov, niov, offset); + if (ret <=3D 0) { + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + if (errno =3D=3D EINTR) { + goto retry; + } + error_setg_errno(errp, errno, "Unable to write to file"); + return -1; + } + return ret; +} + static int qio_channel_file_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664888297; cv=none; d=zohomail.com; s=zohoarc; b=k3Ouc1EFyTtu+/9Ey7+m0RSHXZtVl+Vgjx0onA/H3kTeAsRjgLnabjTxObmUP0GHIM1R4wb3lEwtdZr7AMdwSlt7LScLXNQcLsoWnXYGxe3cPeqRB08W4HwDmPKuGkaxGV1EmsiMrGyH3qQ2LojK4MhpxAfiXJ2iqyrVy3CCsYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664888297; 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=n54rH4YDXB8vXHb7YAUSB9HNvXKeghEj2yhto3fIlko=; b=Au16zlY/AHt30dW8SuqJLuF3bbTmjpgH527A5mI1KXRwzBRV6ETV0ctgI2PRiI39r2/KaAHJsskNGpLih4P46vZK+X1lP6j0ZAVDMfhH3cnkF4xKJ46KYZ14kt4vrbOo9NFt6pq5+0HpwtLA+nmqLhYDxXIORcj/KpWQK14belQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664888297497216.9501298561661; Tue, 4 Oct 2022 05:58:17 -0700 (PDT) Received: from localhost ([::1]:39024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhV1-00049n-Rf for importer@patchew.org; Tue, 04 Oct 2022 08:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBD-0006mN-FF for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:36496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rJ-TN for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BA036218EA; Tue, 4 Oct 2022 12:37:40 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4DBA2139EF; Tue, 4 Oct 2022 12:37:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wMZKEBQpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n54rH4YDXB8vXHb7YAUSB9HNvXKeghEj2yhto3fIlko=; b=oB84RhDc/P+5yhDCR/mBJ3U2jxd2nBMKz4Dwd/v7WV8w7wNlUBTmy6EV3m7a0Ggq6vykWL XD47NRc7pS6vTeQbI/UUuyy3SsHPYAY7I2pmbWgmDV+WSH9g1R7Ris0XtQX3tWOYTlmrTP 5jlO4cN8KcjbXjvuYhkAcH5LY86ezhc= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 05/11] io: Add support for seekable channels Date: Tue, 4 Oct 2022 15:37:27 +0300 Message-Id: <20221004123733.2745519-6-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1c; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664888298805100001 Content-Type: text/plain; charset="utf-8" Add a bunch of auxiliarry methods and a feature flag to work with SEEKABLE channels. Currently the only channel considered seekable is QIOChannelFile. Also add a bunch of helper functions to QEMUFile that can make use of this channel feature. All of this is in prepration for supporting 'fixed-ram' migration stream feature. Signed-off-by: Nikolay Borisov --- include/io/channel.h | 1 + include/migration/qemu-file-types.h | 2 + io/channel-file.c | 5 +++ migration/qemu-file.c | 59 +++++++++++++++++++++++++++++ migration/qemu-file.h | 3 ++ 5 files changed, 70 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index c680ee748021..4fc37c78e68c 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -41,6 +41,7 @@ enum QIOChannelFeature { QIO_CHANNEL_FEATURE_SHUTDOWN, QIO_CHANNEL_FEATURE_LISTEN, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, + QIO_CHANNEL_FEATURE_SEEKABLE, }; =20 =20 diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-f= ile-types.h index 2867e3da84ab..eb0325ee8687 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -50,6 +50,8 @@ unsigned int qemu_get_be16(QEMUFile *f); unsigned int qemu_get_be32(QEMUFile *f); uint64_t qemu_get_be64(QEMUFile *f); =20 +bool qemu_file_is_seekable(QEMUFile *f); + static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv) { qemu_put_be64(f, *pv); diff --git a/io/channel-file.c b/io/channel-file.c index da17d0a11ba7..d84a6737f2f7 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -35,6 +35,7 @@ qio_channel_file_new_fd(int fd) =20 ioc->fd =3D fd; =20 + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE= ); trace_qio_channel_file_new_fd(ioc, fd); =20 return ioc; @@ -59,6 +60,10 @@ qio_channel_file_new_path(const char *path, return NULL; } =20 + if (lseek(ioc->fd, 0, SEEK_CUR) !=3D (off_t)-1) { + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEK= ABLE); + } + trace_qio_channel_file_new_path(ioc, path, flags, mode, ioc->fd); =20 return ioc; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 4f400c2e5265..07ba1125e83f 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -30,6 +30,7 @@ #include "qemu-file.h" #include "trace.h" #include "qapi/error.h" +#include "io/channel-file.h" =20 #define IO_BUF_SIZE 32768 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) @@ -260,6 +261,10 @@ static void qemu_iovec_release_ram(QEMUFile *f) memset(f->may_free, 0, sizeof(f->may_free)); } =20 +bool qemu_file_is_seekable(QEMUFile *f) +{ + return qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SEEKABLE); +} =20 /** * Flushes QEMUFile buffer @@ -538,6 +543,60 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, = size_t size) } } =20 +void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, of= f_t pos) +{ + Error *err =3D NULL; + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buflen = }; + + if (f->last_error) { + return; + } + + qemu_fflush(f); + + if (qio_channel_file_pwritev(f->ioc, &iov, 1, pos, &err) =3D=3D (off_t= )-1) + goto error; + + return; + + error: + qemu_file_set_error_obj(f, -EIO, err); + return; +} + +void qemu_set_offset(QEMUFile *f, off_t off, int whence) +{ + Error *err =3D NULL; + off_t ret; + + qemu_fflush(f); + + if (!qemu_file_is_writable(f)) { + f->buf_index =3D 0; + f->buf_size =3D 0; + } + + ret =3D qio_channel_io_seek(f->ioc, off, whence, &err); + if (ret =3D=3D (off_t)-1) { + qemu_file_set_error_obj(f, -EIO, err); + } +} + +off_t qemu_get_offset(QEMUFile *f) +{ + Error *err =3D NULL; + off_t ret; + + qemu_fflush(f); + + ret =3D qio_channel_io_seek(f->ioc, 0, SEEK_CUR, &err); + if (ret =3D=3D (off_t)-1) { + qemu_file_set_error_obj(f, -EIO, err); + } + return ret; +} + + void qemu_put_byte(QEMUFile *f, int v) { if (f->last_error) { diff --git a/migration/qemu-file.h b/migration/qemu-file.h index fa13d04d787c..33cfc07b81d1 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -148,6 +148,9 @@ int qemu_file_shutdown(QEMUFile *f); QEMUFile *qemu_file_get_return_path(QEMUFile *f); void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); +void qemu_set_offset(QEMUFile *f, off_t off, int whence); +off_t qemu_get_offset(QEMUFile *f); +void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, of= f_t pos); =20 void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887979; cv=none; d=zohomail.com; s=zohoarc; b=OJqFtiYodf7C1jWOOk6Y8SYzeuS9JPDVIhRYEu9Et7mf69UU6j8Jq1PTR66tjoDMoYlWCE71ASS4rJ/+un697AC4H0LfamI+cRinXJvN1GtcIU8Do2WWIayLEYhe12uHsVx/f3m3O9T+/jDaKkhQZj0bhJIITBq41L/TKTyL/zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887979; 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=w0bgJgCM33zbCqV4mVPXZ/sO1OZ9p9oU0UmvOIN5fLA=; b=cFEhJ+ra+50dAT2VpLztmaHESidQ8UEZJbykyVcORIbSwuyjJ/Ux35D+rioa2rflFz/Q10SC3DQtAC9KcEfGp3KDzz9KwO+OraipfxmkEOCFJNTdMmXRqKdBsSqQV1AcONELJxxRe4xw4399A9E9BfbGH0N9UMVYv8hmgotVR0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887979410244.10628371727182; Tue, 4 Oct 2022 05:52:59 -0700 (PDT) Received: from localhost ([::1]:36530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhPu-0006NM-Dd for importer@patchew.org; Tue, 04 Oct 2022 08:52:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBD-0006mL-7Q for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:36506) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rT-Ts for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 41DAF218EC; Tue, 4 Oct 2022 12:37:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CC259139EF; Tue, 4 Oct 2022 12:37:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oCkvLxQpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887061; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w0bgJgCM33zbCqV4mVPXZ/sO1OZ9p9oU0UmvOIN5fLA=; b=R86/kCvcVcaxlUxzA7dj1lNd2clgjTym3FjqDsAWkAHjCCT0YWAlm5otXKIUz5rN8Qnrfu efV1itr6MAqX3Bke4F3JMO9anZHK8Xaeb2uW/x98voxYIAw6kDyHkYHAUqg7xHAPsuSUWw cH8/Q2Yaj3Q6fOdIDdOYlN+TvGhaH3M= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 06/11] io: Add preadv support to QIOChannelFile Date: Tue, 4 Oct 2022 15:37:28 +0300 Message-Id: <20221004123733.2745519-7-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1c; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887980102100001 Content-Type: text/plain; charset="utf-8" preadv is going to be needed when 'fixed-ram'-enabled stream are to be restored. Simply add a wrapper around preadv that's specific to QIOChannelFile. Signed-off-by: Nikolay Borisov --- include/io/channel-file.h | 5 +++++ io/channel-file.c | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/io/channel-file.h b/include/io/channel-file.h index 0a5d54f5e58e..2187f5affd23 100644 --- a/include/io/channel-file.h +++ b/include/io/channel-file.h @@ -89,6 +89,11 @@ qio_channel_file_new_path(const char *path, mode_t mode, Error **errp); =20 +ssize_t qio_channel_file_preadv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); ssize_t qio_channel_file_pwritev(QIOChannel *ioc, const struct iovec *iov, size_t niov, diff --git a/io/channel-file.c b/io/channel-file.c index d84a6737f2f7..edca64ad63a7 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -141,6 +141,32 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, return ret; } =20 +ssize_t qio_channel_file_preadv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp) +{ + QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); + ssize_t ret; + + retry: + ret =3D preadv(fioc->fd, iov, niov, offset); + if (ret < 0) { + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + if (errno =3D=3D EINTR) { + goto retry; + } + + error_setg_errno(errp, errno, "Unable to read from file"); + return -1; + } + + return ret; +} + ssize_t qio_channel_file_pwritev(QIOChannel *ioc, const struct iovec *iov, size_t niov, --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887979; cv=none; d=zohomail.com; s=zohoarc; b=V2oIFdJPfy7SkhOuRB+ms+6zLUvDurza8xbnjDQZtUUPJQs+iq1WM7POHzj6jyArwNV1FO4sYD7rHTgovroeFhlh7rsvnsGoF+vuGRzeuWTvInT9S/Mby2dNk895s9j4jxFz3PYT6X0CEhKlwJJUBoWN2h8AV0Op4jaYM0+zIV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887979; 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=kPCQLiTt+xycLpMdzoecrm8X5xdA5JatxxJh/K6EFXQ=; b=O08MrNrauITRy9OY5dYOOPP84auZQ2EdKv2pClubuCeLZJViOqBsHUmOLzHDdmPUUEEy4H6REPTI2o9RGYKr3R0WnKadUamYt8SUW8ENS4wLuVMQG55dXNjTUFtUt1qVp4CKP1hC/kxh06yPv47uVwhU0HW8J3D3cjK8CPTUMcc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887979815266.43308057260515; Tue, 4 Oct 2022 05:52:59 -0700 (PDT) Received: from localhost ([::1]:36502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhPt-0006Jw-Fx for importer@patchew.org; Tue, 04 Oct 2022 08:52:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBD-0006mM-7z for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:46240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhB9-0005rh-Ts for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:46 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BF1FC218ED; Tue, 4 Oct 2022 12:37:41 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5502D139EF; Tue, 4 Oct 2022 12:37:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MAoOEhUpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887061; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kPCQLiTt+xycLpMdzoecrm8X5xdA5JatxxJh/K6EFXQ=; b=MbFNHK9R+gh1XGtklB9tDzKC7eKNI+YmEHZoGTS8Jla4VaCrLFSnmZG8g1rPwen2uI/csQ sIpARVnetbHgHXnPRqyXo2QCn96Tgs9E7Z1ZQYXuDXg6g3sB1cXQUHRXVDjSrPBar2fMKV u2kgXWE3LmmrtNMrm3vQ1XzhXYcPt5M= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 07/11] migration: add qemu_get_buffer_at Date: Tue, 4 Oct 2022 15:37:29 +0300 Message-Id: <20221004123733.2745519-8-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=195.135.220.28; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887980244100003 Content-Type: text/plain; charset="utf-8" Restoring a 'fixed-ram' enabled migration stream would require reading from specific offsets in the file so add a helper to QEMUFile that uses the newly introduced qio_channel_file_preadv. Signed-off-by: Nikolay Borisov --- migration/qemu-file.c | 23 +++++++++++++++++++++++ migration/qemu-file.h | 1 + 2 files changed, 24 insertions(+) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 07ba1125e83f..73fffbdb9b7e 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -564,6 +564,29 @@ void qemu_put_buffer_at(QEMUFile *f, const uint8_t *bu= f, size_t buflen, off_t po return; } =20 + +size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, = off_t pos) +{ + Error *err =3D NULL; + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buflen = }; + ssize_t ret; + + if (f->last_error) { + return 0; + } + + ret =3D qio_channel_file_preadv(f->ioc, &iov, 1, pos, &err); + if (ret =3D=3D -1) { + goto error; + } + + return (size_t)ret; + + error: + qemu_file_set_error_obj(f, -EIO, err); + return 0; +} + void qemu_set_offset(QEMUFile *f, off_t off, int whence) { Error *err =3D NULL; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 33cfc07b81d1..ab10c3ad7e42 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -151,6 +151,7 @@ void qemu_file_set_blocking(QEMUFile *f, bool block); void qemu_set_offset(QEMUFile *f, off_t off, int whence); off_t qemu_get_offset(QEMUFile *f); void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, of= f_t pos); +size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, = off_t pos); =20 void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887696; cv=none; d=zohomail.com; s=zohoarc; b=cWj99ftO+QmsnhMgfXGvfRXw7xYtVK8bzzDaDXX2bozto/+XFV3UbhxX6WeEKJQcw0kemfE2NSa6LKyYvsh+jVzS4wKavdoAwmslZmCwPh5yoUagbSseUn6J21jIFXQDQqIjy37LEZxrIHGAD9OFy2ODBM3OPXOJbMp4rEjuv3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887696; 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=TnBIDgAOB73AwhoERkLq/XrFQQ5f2F4I27B49w3KrVY=; b=mMvJiHTgAeL77Q1jatDw4Z+SuZ+cfmzbPlR+hZVtrFdva/RoIuoxPWALNNDRqJrM2Eiq32m0LmJ2rDsWYEfBwrs8BdL2FmzrPnXDSeJPoo4Dt5ih87mjtTrTGcBTZ0wjx0BwE0AzPgZ1WYbGG8n32BnN/qSrvhUuSpbwKekvQT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166488769624157.26313651288467; Tue, 4 Oct 2022 05:48:16 -0700 (PDT) Received: from localhost ([::1]:57924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhLL-0000pu-2M for importer@patchew.org; Tue, 04 Oct 2022 08:48:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBF-0006mj-3T for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:33654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhBA-0005rr-3W for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:48 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4571B1F8E4; Tue, 4 Oct 2022 12:37:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D17B0139EF; Tue, 4 Oct 2022 12:37:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uJh+MBUpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887062; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TnBIDgAOB73AwhoERkLq/XrFQQ5f2F4I27B49w3KrVY=; b=E4Zx602yEt7CC+ClSU5MdE4PWk72b8dpQRGIJ1dt7o/FFTc62Tn5WhtFJ8GM/i2JyITFaE g6+066hwm7KYAqTQs8HBGv5PaIkMGtctn3ciX4t4TnveEG5BVfghFBnO1B+hTe3rUwuJHd fKwjsOPPOade+D5bPrFGGBOukKtGLnk= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 08/11] migration/ram: Introduce 'fixed-ram' migration stream capability Date: Tue, 4 Oct 2022 15:37:30 +0300 Message-Id: <20221004123733.2745519-9-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=195.135.220.29; envelope-from=nborisov@suse.com; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887698053100001 Content-Type: text/plain; charset="utf-8" Implement 'fixed-ram' feature. The core of the feature is to ensure that each ram page of the migration stream has a specific offset in the resulting migration stream. The reason why we'd want such behavior are two fold: - When doing a 'fixed-ram' migration the resulting file will have a bounded size, since pages which are dirtied multiple times will always go to a fixed location in the file, rather than constantly being added to a sequential stream. This eliminates cases where a vm with, say, 1g of ram can result in a migration file that's 10s of Gbs, provided that the workload constantly redirties memory. - It paves the way to implement DIO-enabled save/restore of the migration stream as the pages are ensured to be written at aligned offsets. The features requires changing the format. First, a bitmap is introduced which tracks which pages have been written (i.e are dirtied) during migration and subsequently it's being written in the resultin file, again at a fixed location for every ramblock. Zero pages are ignored as they'd be zero in the destination migration as well. With the changed format data would look like the following: |name len|name|used_len|pc*|bitmap_size|pages_offset|bitmap|pages| * pc - refers to the page_size/mr->addr members, so newly added members begin from "bitmap_size". This layout is initialized during ram_save_setup so instead of having a sequential stream of pages that follow the ramblock headers the dirty pages for a ramblock follow its header. Since all pages have a fixed location RAM_SAVE_FLAG_EOS is no longer generated on every migration iteration but there is effectively a single RAM_SAVE_FLAG_EOS right at the end. Signed-off-by: Nikolay Borisov --- include/exec/ramblock.h | 7 +++ migration/migration.c | 51 +++++++++++++++++++- migration/migration.h | 1 + migration/ram.c | 100 ++++++++++++++++++++++++++++++++-------- migration/savevm.c | 1 + qapi/migration.json | 2 +- 6 files changed, 140 insertions(+), 22 deletions(-) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 6cbedf9e0c9a..30216c1a41d3 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -43,6 +43,13 @@ struct RAMBlock { size_t page_size; /* dirty bitmap used during migration */ unsigned long *bmap; + /* shadow dirty bitmap used when migrating to a file */ + unsigned long *shadow_bmap; + /* offset in the file pages belonging to this ramblock are saved, used + * only during migration to a file + */ + off_t bitmap_offset; + uint64_t pages_offset; /* bitmap of already received pages in postcopy */ unsigned long *receivedmap; =20 diff --git a/migration/migration.c b/migration/migration.c index d0779bbaf862..1d08664da5db 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -165,7 +165,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, MIGRATION_CAPABILITY_XBZRLE, MIGRATION_CAPABILITY_X_COLO, MIGRATION_CAPABILITY_VALIDATE_UUID, - MIGRATION_CAPABILITY_ZERO_COPY_SEND); + MIGRATION_CAPABILITY_ZERO_COPY_SEND, + MIGRATION_CAPABILITY_FIXED_RAM); =20 /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add @@ -1325,6 +1326,27 @@ static bool migrate_caps_check(bool *cap_list, } #endif =20 + if (cap_list[MIGRATION_CAPABILITY_FIXED_RAM]) { + if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, "Directly mapped memory incompatible with multifd"); + return false; + } + + if (cap_list[MIGRATION_CAPABILITY_XBZRLE]) { + error_setg(errp, "Directly mapped memory incompatible with xbzrle"); + return false; + } + + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Directly mapped memory incompatible with compressi= on"); + return false; + } + + if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + error_setg(errp, "Directly mapped memory incompatible with postcopy = ram"); + return false; + } + } =20 /* incoming side only */ if (runstate_check(RUN_STATE_INMIGRATE) && @@ -2629,6 +2651,11 @@ MultiFDCompression migrate_multifd_compression(void) return s->parameters.multifd_compression; } =20 +int migrate_fixed_ram(void) +{ + return migrate_get_current()->enabled_capabilities[MIGRATION_CAPABILIT= Y_FIXED_RAM]; +} + int migrate_multifd_zlib_level(void) { MigrationState *s; @@ -4189,6 +4216,21 @@ static void *bg_migration_thread(void *opaque) return NULL; } =20 +static int +migrate_check_fixed_ram(MigrationState *s, Error **errp) +{ + if (!s->enabled_capabilities[MIGRATION_CAPABILITY_FIXED_RAM]) + return 0; + + if (!qemu_file_is_seekable(s->to_dst_file)) { + error_setg(errp, "Directly mapped memory requires a seekable trans= port"); + return -1; + } + + return 0; +} + + void migrate_fd_connect(MigrationState *s, Error *error_in) { Error *local_err =3D NULL; @@ -4264,6 +4306,12 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) return; } =20 + if (migrate_check_fixed_ram(s, &local_err) < 0) { + migrate_fd_cleanup(s); + migrate_fd_error(s, local_err); + return; + } + if (resume) { /* Wakeup the main migration thread to do the recovery */ migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED, @@ -4397,6 +4445,7 @@ static Property migration_properties[] =3D { DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), =20 /* Migration capabilities */ + DEFINE_PROP_MIG_CAP("x-fixed-ram", MIGRATION_CAPABILITY_FIXED_RAM), DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_AL= L), DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVE= RGE), diff --git a/migration/migration.h b/migration/migration.h index 96f27aba2210..9aab1b16f407 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -410,6 +410,7 @@ bool migrate_zero_blocks(void); bool migrate_dirty_bitmaps(void); bool migrate_ignore_shared(void); bool migrate_validate_uuid(void); +int migrate_fixed_ram(void); =20 bool migrate_auto_converge(void); bool migrate_use_multifd(void); diff --git a/migration/ram.c b/migration/ram.c index dc1de9ddbc68..a42392f77981 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1261,10 +1261,15 @@ static int save_zero_page_to_file(RAMState *rs, QEM= UFile *file, int len =3D 0; =20 if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - len +=3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_= ZERO); - qemu_put_byte(file, 0); - len +=3D 1; - ram_release_page(block->idstr, offset); + if (migrate_fixed_ram()) { + /* for zero pages we don't need to do anything */ + len =3D 1; + } else { + len +=3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_ZERO); + qemu_put_byte(file, 0); + len +=3D 1; + } + ram_release_page(block->idstr, offset); } return len; } @@ -1342,15 +1347,22 @@ static bool control_save_page(RAMState *rs, RAMBloc= k *block, ram_addr_t offset, static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offs= et, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, rs->f, block, - offset | RAM_SAVE_FLAG_PAGE)); - if (async) { - qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, - migrate_release_ram() && - migration_in_postcopy()); - } else { - qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); - } + + if (migrate_fixed_ram()) { + qemu_put_buffer_at(rs->f, buf, TARGET_PAGE_SIZE, + block->pages_offset + offset); + set_bit(offset >> TARGET_PAGE_BITS, block->shadow_bmap); + } else { + ram_transferred_add(save_page_header(rs, rs->f, block, + offset | RAM_SAVE_FLAG_PAGE)); + if (async) { + qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, + migrate_release_ram() && + migration_in_postcopy()); + } else { + qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); + } + } ram_transferred_add(TARGET_PAGE_SIZE); ram_counters.normal++; return 1; @@ -2683,6 +2695,8 @@ static void ram_save_cleanup(void *opaque) block->clear_bmap =3D NULL; g_free(block->bmap); block->bmap =3D NULL; + g_free(block->shadow_bmap); + block->shadow_bmap =3D NULL; } =20 xbzrle_cleanup(); @@ -3044,6 +3058,8 @@ static void ram_list_init_bitmaps(void) */ block->bmap =3D bitmap_new(pages); bitmap_set(block->bmap, 0, pages); + block->shadow_bmap =3D bitmap_new(block->used_length >> TARGET= _PAGE_BITS); + bitmap_set(block->shadow_bmap, 0, block->used_length >> TARGET= _PAGE_BITS); block->clear_bmap_shift =3D shift; block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); } @@ -3226,12 +3242,34 @@ static int ram_save_setup(QEMUFile *f, void *opaque) qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idst= r)); qemu_put_be64(f, block->used_length); if (migrate_postcopy_ram() && block->page_size !=3D - qemu_host_page_size) { + qemu_host_page_size) { qemu_put_be64(f, block->page_size); } if (migrate_ignore_shared()) { qemu_put_be64(f, block->mr->addr); } + + if (migrate_fixed_ram()) { + long num_pages =3D block->used_length >> TARGET_PAGE_BITS; + long bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(uns= igned long); + + + /* Needed for external programs (think analyze-migration.p= y) */ + qemu_put_be32(f, bitmap_size); + + /* + * Make pages offset aligned to TARGET_PAGE_SIZE to enable + * DIO in the future. Also add 8 to account for the page o= ffset + * itself + */ + block->bitmap_offset =3D qemu_get_offset(f) + 8; + block->pages_offset =3D ROUND_UP(block->bitmap_offset + + bitmap_size, TARGET_PAGE_SI= ZE); + qemu_put_be64(f, block->pages_offset); + + /* Now prepare offset for next ramblock */ + qemu_set_offset(f, block->pages_offset + block->used_lengt= h, SEEK_SET); + } } } =20 @@ -3249,6 +3287,17 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return 0; } =20 +static void ram_save_shadow_bmap(QEMUFile *f) +{ + RAMBlock *block; + + RAMBLOCK_FOREACH_MIGRATABLE(block) { + long num_pages =3D block->used_length >> TARGET_PAGE_BITS; + long bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned lo= ng); + qemu_put_buffer_at(f, (uint8_t *)block->shadow_bmap, bitmap_size, = block->bitmap_offset); + } +} + /** * ram_save_iterate: iterative stage for migration * @@ -3358,9 +3407,15 @@ static int ram_save_iterate(QEMUFile *f, void *opaqu= e) return ret; } =20 - qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - qemu_fflush(f); - ram_transferred_add(8); + /* + * For fixed ram we don't want to pollute the migration stream with + * EOS flags. + */ + if (!migrate_fixed_ram()) { + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + ram_transferred_add(8); + } =20 ret =3D qemu_file_get_error(f); } @@ -3405,7 +3460,10 @@ static int ram_save_complete(QEMUFile *f, void *opaq= ue) pages =3D ram_find_and_save_block(rs); /* no more blocks to sent */ if (pages =3D=3D 0) { - break; + if (migrate_fixed_ram()) { + ram_save_shadow_bmap(f); + } + break; } if (pages < 0) { ret =3D pages; @@ -3428,8 +3486,10 @@ static int ram_save_complete(QEMUFile *f, void *opaq= ue) return ret; } =20 - qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - qemu_fflush(f); + if (!migrate_fixed_ram()) { + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + } =20 return 0; } diff --git a/migration/savevm.c b/migration/savevm.c index 174cdbefc29d..654f64dd08e2 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -240,6 +240,7 @@ static bool should_validate_capability(int capability) /* Validate only new capabilities to keep compatibility. */ switch (capability) { case MIGRATION_CAPABILITY_X_IGNORE_SHARED: + case MIGRATION_CAPABILITY_FIXED_RAM: return true; default: return false; diff --git a/qapi/migration.json b/qapi/migration.json index 88ecf86ac876..6196617171e8 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -485,7 +485,7 @@ ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', - 'compress', 'events', 'postcopy-ram', + 'compress', 'events', 'postcopy-ram', 'fixed-ram', { 'name': 'x-colo', 'features': [ 'unstable' ] }, 'release-ram', 'block', 'return-path', 'pause-before-switchover', 'multifd', --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664888332; cv=none; d=zohomail.com; s=zohoarc; b=GhT3opiOridNI92cWpoMIra/X6QPcOseQdLKETrgpMnuJs9KKgLISdNRLD5zuXFaTAWGjKUqOerCa+vXMlILS5b/BF4/+fpJgHZvj6SkrxKhGxaZCZbpoUzqsH4J4LigG0q8Dn6SQ4kWv3GZpeXOsVgiAmNXqZmF4MIpQXz0RH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664888332; 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=QyuSWspa7u/8i9qTsZ/HRPDrb/kDmhhIwuhZaZvDLX4=; b=htP9UdgVGpaDzWyWNheuaRIEJwOqcZIV9qB1UAFCnI5YX6R9xHCR+rRY596uWxPJJHg6u9xIHw/U2b7yBL0jIZe8bGXh5de16yblEcU9DVNNcC+4ESUv0JDAx9KJVKw9gzprcN4HuR+LFcW/oqlLjP2n0YK8Q4xp440E+7qyfIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664888332541361.69518944341905; Tue, 4 Oct 2022 05:58:52 -0700 (PDT) Received: from localhost ([::1]:43480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhVb-0004C1-Bo for importer@patchew.org; Tue, 04 Oct 2022 08:58:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBG-0006oL-8e for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:51 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:46250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhBC-0005sS-Kn for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C1F95218FB; Tue, 4 Oct 2022 12:37:42 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 57EC2139EF; Tue, 4 Oct 2022 12:37:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AJLJEhYpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887062; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QyuSWspa7u/8i9qTsZ/HRPDrb/kDmhhIwuhZaZvDLX4=; b=hgDdUwW8YOtoFjnqx0STeWSqm2QmbrJi9ACphzbWImTwKi9FWwrJhlPqy3ErQ2oo9Kk+N5 K41u47hkoCTZQ5mN6HlcIncVfb/a3TJCgEUkIsRHQk3+TrC8QDARw0Rrg/petua9xUsiQM h4dh0bMjDr7jOQJDUjGi8ZrZ9sMdzRA= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 09/11] migration: Refactor precopy ram loading code Date: Tue, 4 Oct 2022 15:37:31 +0300 Message-Id: <20221004123733.2745519-10-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=195.135.220.28; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664888334424100001 Content-Type: text/plain; charset="utf-8" To facilitate easier implementaiton of the 'fixed-ram' migration restore factor out the code responsible for parsing the ramblocks headers. This also makes ram_load_precopy easier to comprehend. Signed-off-by: Nikolay Borisov --- migration/ram.c | 142 +++++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 62 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index a42392f77981..951e6385e71c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4254,6 +4254,83 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) +{ + int ret =3D 0; + /* ADVISE is earlier, it shows the source has the postcopy capability = on */ + bool postcopy_advised =3D postcopy_is_advised(); + + assert(block); + + if (!qemu_ram_is_migratable(block)) { + error_report("block %s should not be migrated !", block->idstr); + ret =3D -EINVAL; + } + + if (length !=3D block->used_length) { + Error *local_err =3D NULL; + + ret =3D qemu_ram_resize(block, length, &local_err); + if (local_err) { + error_report_err(local_err); + } + } + /* For postcopy we need to check hugepage sizes match */ + if (postcopy_advised && migrate_postcopy_ram() && + block->page_size !=3D qemu_host_page_size) { + uint64_t remote_page_size =3D qemu_get_be64(f); + if (remote_page_size !=3D block->page_size) { + error_report("Mismatched RAM page size %s " + "(local) %zd !=3D %" PRId64, block->idstr, + block->page_size, remote_page_size); + ret =3D -EINVAL; + } + } + if (migrate_ignore_shared()) { + hwaddr addr =3D qemu_get_be64(f); + if (ramblock_is_ignored(block) && + block->mr->addr !=3D addr) { + error_report("Mismatched GPAs for block %s " + "%" PRId64 "!=3D %" PRId64, block->idstr, + (uint64_t)addr, + (uint64_t)block->mr->addr); + ret =3D -EINVAL; + } + } + ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, block->idstr); + + return ret; +} + +static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes) +{ + int ret =3D 0; + + /* Synchronize RAM block list */ + while (!ret && total_ram_bytes) { + char id[256]; + RAMBlock *block; + ram_addr_t length; + int len =3D qemu_get_byte(f); + + qemu_get_buffer(f, (uint8_t *)id, len); + id[len] =3D 0; + length =3D qemu_get_be64(f); + + block =3D qemu_ram_block_by_name(id); + if (block) { + ret =3D parse_ramblock(f, block, length); + } else { + error_report("Unknown ramblock \"%s\", cannot accept " + "migration", id); + ret =3D -EINVAL; + } + total_ram_bytes -=3D length; + } + + return ret; +} + /** * ram_load_precopy: load pages in precopy case * @@ -4268,14 +4345,13 @@ static int ram_load_precopy(QEMUFile *f) { MigrationIncomingState *mis =3D migration_incoming_get_current(); int flags =3D 0, ret =3D 0, invalid_flags =3D 0, len =3D 0, i =3D 0; - /* ADVISE is earlier, it shows the source has the postcopy capability = on */ - bool postcopy_advised =3D postcopy_is_advised(); + if (!migrate_use_compression()) { invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } =20 while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { - ram_addr_t addr, total_ram_bytes; + ram_addr_t addr; void *host =3D NULL, *host_bak =3D NULL; uint8_t ch; =20 @@ -4346,65 +4422,7 @@ static int ram_load_precopy(QEMUFile *f) =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: - /* Synchronize RAM block list */ - total_ram_bytes =3D addr; - while (!ret && total_ram_bytes) { - RAMBlock *block; - char id[256]; - ram_addr_t length; - - len =3D qemu_get_byte(f); - qemu_get_buffer(f, (uint8_t *)id, len); - id[len] =3D 0; - length =3D qemu_get_be64(f); - - block =3D qemu_ram_block_by_name(id); - if (block && !qemu_ram_is_migratable(block)) { - error_report("block %s should not be migrated !", id); - ret =3D -EINVAL; - } else if (block) { - if (length !=3D block->used_length) { - Error *local_err =3D NULL; - - ret =3D qemu_ram_resize(block, length, - &local_err); - if (local_err) { - error_report_err(local_err); - } - } - /* For postcopy we need to check hugepage sizes match = */ - if (postcopy_advised && migrate_postcopy_ram() && - block->page_size !=3D qemu_host_page_size) { - uint64_t remote_page_size =3D qemu_get_be64(f); - if (remote_page_size !=3D block->page_size) { - error_report("Mismatched RAM page size %s " - "(local) %zd !=3D %" PRId64, - id, block->page_size, - remote_page_size); - ret =3D -EINVAL; - } - } - if (migrate_ignore_shared()) { - hwaddr addr =3D qemu_get_be64(f); - if (ramblock_is_ignored(block) && - block->mr->addr !=3D addr) { - error_report("Mismatched GPAs for block %s " - "%" PRId64 "!=3D %" PRId64, - id, (uint64_t)addr, - (uint64_t)block->mr->addr); - ret =3D -EINVAL; - } - } - ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, - block->idstr); - } else { - error_report("Unknown ramblock \"%s\", cannot " - "accept migration", id); - ret =3D -EINVAL; - } - - total_ram_bytes -=3D length; - } + ret =3D parse_ramblocks(f, addr); break; =20 case RAM_SAVE_FLAG_ZERO: --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887377; cv=none; d=zohomail.com; s=zohoarc; b=EQFYdmmdJw/1T1olOYdq752vSXqIoJvj2wrpKAx7cAQPEMF50M+IH24QdGs/KzojOq5OiYEq92EGMcjY7AiJILWW+qCEZrBpIu3BPDBDjEEKDyqmgvVGZEIc3c+l7QCPieiWUc6+dm5oqdbuABTzeGtiTl9WDAbU6NDy+pYddi4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887377; 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=8Ovc7GuAoaC292+B0qn1KXIaWoLN9CJ+YBV1CJdubD4=; b=BC50rNeymVOE4OApVVE37DVyDkClbo3Tz5LtAkhCj3i9OJllij9Oc3tN8I3Mi8EnBsOCJG4FUqRTL8TByuxgJgZpV6hj43iKkZttYdOnTR8vnBFFDlraRV6wIo4Zfi3VkQ4uchLFrx//eKTdL2/ijYnz/7MUX943O1sOBubJPTs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166488737742038.02375234945953; Tue, 4 Oct 2022 05:42:57 -0700 (PDT) Received: from localhost ([::1]:43088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhGA-0002v4-EN for importer@patchew.org; Tue, 04 Oct 2022 08:42:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBE-0006mh-Nd for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:49918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhBA-0005rw-EQ for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:48 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 488D91F8FE; Tue, 4 Oct 2022 12:37:43 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D371C139EF; Tue, 4 Oct 2022 12:37:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mD79MBYpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887063; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Ovc7GuAoaC292+B0qn1KXIaWoLN9CJ+YBV1CJdubD4=; b=QCcnuC/Rmav/PpZ9rpXNFKi1UBICBBLdTMhIqGHw2J0gSJIt6j8wz9rasI2kaWdVT9+EBk uCpfBtOCV2vSm3emj9PHqDvF2HWslnmyoVF60oWLQGsPIHUwOyK6NG11yK0S6nTsfm6oeg D9QDQ6zhrIBOHw9snUO4mCWCiqphvZg= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 10/11] migration: Add support for 'fixed-ram' migration restore Date: Tue, 4 Oct 2022 15:37:32 +0300 Message-Id: <20221004123733.2745519-11-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1d; envelope-from=nborisov@suse.com; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887378429100001 Content-Type: text/plain; charset="utf-8" Add the necessary code to parse the format changes for 'fixed-ram' capability. One of the more notable changes in behavior is that in the 'fixed-ram' case ram pages are restored in one go rather than constantly looping through the migration stream. Also due to idiosyncrasies of the format I have added the 'ram_migrated' since it was easier to simply return directly from ->load_state rather than introducing more conditionals around the code to prevent ->load_state being called multiple times (from qemu_loadvm_section_start_full/qemu_loadvm_section_part_end i.e. from multiple QEMU_VM_SECTION_(PART|END) flags). Signed-off-by: Nikolay Borisov --- migration/migration.h | 2 + migration/ram.c | 86 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 9aab1b16f407..7a832d072415 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -96,6 +96,8 @@ struct MigrationIncomingState { bool have_listen_thread; QemuThread listen_thread; =20 + bool ram_migrated; + /* For the kernel to send us notifications */ int userfault_fd; /* To notify the fault_thread to wake, e.g., when need to quit */ diff --git a/migration/ram.c b/migration/ram.c index 951e6385e71c..cba94d01207c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4331,6 +4331,81 @@ static int parse_ramblocks(QEMUFile *f, ram_addr_t t= otal_ram_bytes) return ret; } =20 + +static int parse_ramblocks_fixed_ram(QEMUFile *f) +{ + int ret =3D 0; + + while (!ret) { + char id[256]; + RAMBlock *block; + ram_addr_t length; + unsigned long idx; + long num_pages; + int len =3D qemu_get_byte(f); + + qemu_get_buffer(f, (uint8_t *)id, len); + id[len] =3D 0; + length =3D qemu_get_be64(f); + + block =3D qemu_ram_block_by_name(id); + if (block) { + ret =3D parse_ramblock(f, block, length); + if (ret < 0) { + return ret; + } + } else { + error_report("Unknown ramblock \"%s\", cannot accept " + "migration", id); + ret =3D -EINVAL; + continue; + } + + /* 1. read the bitmap size */ + num_pages =3D length >> TARGET_PAGE_BITS; + long bitmap_size =3D qemu_get_be32(f); + + assert(bitmap_size =3D=3D BITS_TO_LONGS(num_pages)*sizeof(unsigned= long)); + + block->pages_offset =3D qemu_get_be64(f); + + /* 2. read the actual bitmap */ + unsigned long *dirty_bitmap =3D g_malloc0(bitmap_size); + if (qemu_get_buffer(f, (uint8_t *)dirty_bitmap, bitmap_size) !=3D = bitmap_size) { + error_report("Error parsing dirty bitmap"); + return -EINVAL; + } + + /* 3. load all pages from the bitmap */ + for (idx =3D find_next_bit(dirty_bitmap, num_pages, 0); idx < num_= pages; + idx =3D find_next_bit(dirty_bitmap, num_pages, idx + 1)) { + + ram_addr_t offset =3D idx << TARGET_PAGE_BITS; + void *host =3D host_from_ram_block_offset(block, offset); + + qemu_get_buffer_at(f, host, TARGET_PAGE_SIZE, + block->pages_offset + offset); + } + + /* Skip pages array */ + qemu_set_offset(f, block->pages_offset + length, SEEK_SET); + + /* Check if this is the last ramblock */ + if (qemu_get_be64(f) =3D=3D RAM_SAVE_FLAG_EOS) { + ret =3D 1; + } else { + /* + * If not, adjust the internal file index to account for the + * previous 64 bit read + */ + qemu_file_skip(f, -8); + ret =3D 0; + } + } + + return ret; +} + /** * ram_load_precopy: load pages in precopy case * @@ -4350,7 +4425,7 @@ static int ram_load_precopy(QEMUFile *f) invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } =20 - while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { + while (!ret && !(flags & RAM_SAVE_FLAG_EOS) && !mis->ram_migrated) { ram_addr_t addr; void *host =3D NULL, *host_bak =3D NULL; uint8_t ch; @@ -4422,7 +4497,14 @@ static int ram_load_precopy(QEMUFile *f) =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { case RAM_SAVE_FLAG_MEM_SIZE: - ret =3D parse_ramblocks(f, addr); + if (migrate_fixed_ram()) { + ret =3D parse_ramblocks_fixed_ram(f); + if (ret =3D=3D 1) { + mis->ram_migrated =3D true; + } + } else { + ret =3D parse_ramblocks(f, addr); + } break; =20 case RAM_SAVE_FLAG_ZERO: --=20 2.34.1 From nobody Sun May 12 10:39:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1664887392; cv=none; d=zohomail.com; s=zohoarc; b=iay6FCkT7N7FVXHIAJpr0NOj8RcySMUWDKQBwBx45O0FZiOa1qqR//hyv2a+Y6hbnPy4Oh3kjQumwdCWEAsumgWsNb3L7XsczhiK97/xRUMtvKXzKts3b70Fv3rRChs3i8SD4afx0z858AdDOeXbCU/0sExdwhgKgu1NpYy8+8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664887392; 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=A50mByhzWHrQsuuwumxFXgwiK/RPKzRr2vW+FrGIFeg=; b=Tegn+63wkX+9nsreijP55fAebt7fgMsvqFAFOFkBmQLMeA6FvkRrCMztCqv5hVz8uDtnl5zx39QrU98+6VefyhKfryop640FksKUZ5oz1IOfTU9wfCMyb6SgdirPNT30tBcKwu8K/VIyz6nIQpjDH9+4WNHuzmsidEirio3E/NE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664887392234964.9004978146152; Tue, 4 Oct 2022 05:43:12 -0700 (PDT) Received: from localhost ([::1]:43092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofhGQ-0002xz-7p for importer@patchew.org; Tue, 04 Oct 2022 08:43:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofhBG-0006oD-4u for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:51 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:36508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ofhBC-0005sT-KS for qemu-devel@nongnu.org; Tue, 04 Oct 2022 08:37:49 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C257A218FF; Tue, 4 Oct 2022 12:37:43 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5A647139EF; Tue, 4 Oct 2022 12:37:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sDdzExcpPGNlRQAAMHmgww (envelope-from ); Tue, 04 Oct 2022 12:37:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664887063; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A50mByhzWHrQsuuwumxFXgwiK/RPKzRr2vW+FrGIFeg=; b=qhcNDyuPLKZRwM/98NDoU4IhYrteE1yWw8vH9jDvV4gF51MfCGJl4PyRat8g6KvFwgfIF1 HxVQ7vt+XmAqem0lYwX63IUWV0CHB2DbwGbeh5/yI7mfmz/2mn2Fhfs8YyOYrZInLLq/7j RwnM541r9UB3HcXM1fJs7WZEHsGhgkM= From: Nikolay Borisov To: dgilbert@redhat.com, berrange@redhat.com Cc: qemu-devel@nongnu.org, jfehlig@suse.com, Claudio.Fontana@suse.com, dfaggioli@suse.com, Nikolay Borisov Subject: [PATCH 11/11] analyze-migration.py: add initial support for fixed ram streams Date: Tue, 4 Oct 2022 15:37:33 +0300 Message-Id: <20221004123733.2745519-12-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004123733.2745519-1-nborisov@suse.com> References: <20221004123733.2745519-1-nborisov@suse.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=2001:67c:2178:6::1c; envelope-from=nborisov@suse.com; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 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" X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1664887392521100003 Content-Type: text/plain; charset="utf-8" This commit introduces the minimum code necessary to support parsing migration strems with 'fixed-ram' capability set. The only thing really missing is the implementation of write_or_dump_fixed_ram() which deals with '-x'/'-m' options. Signed-off-by: Nikolay Borisov --- scripts/analyze-migration.py | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py index b82a1b0c58c4..9785a640fbf8 100755 --- a/scripts/analyze-migration.py +++ b/scripts/analyze-migration.py @@ -23,6 +23,7 @@ import collections import struct import sys +import math =20 =20 def mkdir_p(path): @@ -119,11 +120,16 @@ def __init__(self, file, version_id, ramargs, section= _key): self.file =3D file self.section_key =3D section_key self.TARGET_PAGE_SIZE =3D ramargs['page_size'] + self.TARGET_PAGE_BITS =3D math.log2(self.TARGET_PAGE_SIZE) self.dump_memory =3D ramargs['dump_memory'] self.write_memory =3D ramargs['write_memory'] + self.fixed_ram =3D ramargs['fixed-ram'] self.sizeinfo =3D collections.OrderedDict() + self.bitmap_offset =3D collections.OrderedDict() + self.pages_offset =3D collections.OrderedDict() self.data =3D collections.OrderedDict() self.data['section sizes'] =3D self.sizeinfo + self.ram_read =3D False self.name =3D '' if self.write_memory: self.files =3D { } @@ -140,7 +146,13 @@ def __str__(self): def getDict(self): return self.data =20 + def write_or_dump_fixed_ram(self): + pass + def read(self): + if self.fixed_ram and self.ram_read: + return + # Read all RAM sections while True: addr =3D self.file.read64() @@ -167,7 +179,25 @@ def read(self): f.truncate(0) f.truncate(len) self.files[self.name] =3D f + + if self.fixed_ram: + bitmap_len =3D self.file.read32() + # skip the pages_offset which we don't need + offset =3D self.file.tell() + 8 + self.bitmap_offset[self.name] =3D offset + offset =3D ((offset + bitmap_len + self.TARGET_PAG= E_SIZE - 1) // self.TARGET_PAGE_SIZE) * self.TARGET_PAGE_SIZE + self.pages_offset[self.name] =3D offset + self.file.file.seek(offset + len) + flags &=3D ~self.RAM_SAVE_FLAG_MEM_SIZE + if self.fixed_ram: + self.ram_read =3D True + # now we should rewind to the ram page offset of the first + # ram section + if self.fixed_ram: + if self.write_memory or self.dump_memory: + self.write_or_dump_fixed_ram() + return =20 if flags & self.RAM_SAVE_FLAG_COMPRESS: if flags & self.RAM_SAVE_FLAG_CONTINUE: @@ -208,7 +238,7 @@ def read(self): =20 # End of RAM section if flags & self.RAM_SAVE_FLAG_EOS: - break + return =20 if flags !=3D 0: raise Exception("Unknown RAM flags: %x" % flags) @@ -521,6 +551,7 @@ def read(self, desc_only =3D False, dump_memory =3D Fal= se, write_memory =3D False): ramargs['page_size'] =3D self.vmsd_desc['page_size'] ramargs['dump_memory'] =3D dump_memory ramargs['write_memory'] =3D write_memory + ramargs['fixed-ram'] =3D False self.section_classes[('ram',0)][1] =3D ramargs =20 while True: @@ -528,8 +559,20 @@ def read(self, desc_only =3D False, dump_memory =3D Fa= lse, write_memory =3D False): if section_type =3D=3D self.QEMU_VM_EOF: break elif section_type =3D=3D self.QEMU_VM_CONFIGURATION: - section =3D ConfigurationSection(file) - section.read() + config_desc =3D self.vmsd_desc.get('configuration') + if config_desc is not None: + config =3D VMSDSection(file, 1, config_desc, 'configur= ation') + config.read() + caps =3D config.data.get("configuration/capabilities") + if caps is not None: + caps =3D caps.data["capabilities"] + if type(caps) !=3D list: + caps =3D [caps] + for i in caps: + # chomp out string length + cap =3D i.data[1:].decode("utf8") + if cap =3D=3D "fixed-ram": + ramargs['fixed-ram'] =3D True elif section_type =3D=3D self.QEMU_VM_SECTION_START or section= _type =3D=3D self.QEMU_VM_SECTION_FULL: section_id =3D file.read32() name =3D file.readstr() --=20 2.34.1