From nobody Fri May 10 05:31:04 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=1665409079; cv=none; d=zohomail.com; s=zohoarc; b=M10PO3Q7MJh/Rr8BX44KnBKwmeB2wAZr7SalI1C9dyYYHKtwdBehjqv9hIpU+HdQHenvUS8KO5HTXMMnLMzLKk52aGW4v7Zk9RKrIfIwZSw2rr2zDMBzhDzTlDu1ogg4Y76rWG66B9JJOKkfVhavzZXiA+xFEWQFEtPc96/0s3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409079; 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=UeXjNVNNjwLwHCc/DUuSC8j+QXh78kQU3zQZaumHWl75wpMT/1vGfYKLy3jjxg1emMTkT3AbsDnucsQQypJE2YfT5npyCOReT3l3o1vEHDqIoTMLBZH03B4GewdbyiIidoDU2aSDNWEzwQF5I61VB1rK/ESV9ef8OYC02HdBhGc= 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 1665409079881991.3250949578023; Mon, 10 Oct 2022 06:37:59 -0700 (PDT) Received: from localhost ([::1]:52946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohsyk-0004Fx-2N for importer@patchew.org; Mon, 10 Oct 2022 09:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-0000zq-HH for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:48734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005Jr-0L for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:18 -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 F34571F8ED; Mon, 10 Oct 2022 13:34:13 +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 7CAF413479; Mon, 10 Oct 2022 13:34:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4ISdG1UfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408854; 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=gdbvmd8MaXoclmzgelt1a5xIZ1fMjJeIAuwS2O1uycvQINnIOp99GFWlBoOK3Va5sWtvaZ WdqDbpyX36TBvOG2fslCyNY6JR0wdwHKtv4e2gxA7zUJVoA5oZahzuxq/sThHktMGgS+pk b9jBpIO9p2niM/2XUCziO4Ggkz+BSl4= 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 v2 01/11] migration: support file: uri for source migration Date: Mon, 10 Oct 2022 16:33:58 +0300 Message-Id: <20221010133408.3214433-2-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409080545100001 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 Fri May 10 05:31:04 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=1665409338; cv=none; d=zohomail.com; s=zohoarc; b=WeIz7aqMFv172nL/m1i7g9nYYD+HkcHrf9NBPWfrkfO0JRRizdhq8fuhN3BlSjfVWEgwVGebT13PYRd6p3AE8Dyh2xNrRafDxbPr/Ow1CQf/dORXmdbuKSWkPue1c+Gsm2WB7o6BjseHl/lZ4voUcWxo+8OHL9ygSAaFCTnxkm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409338; 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=ZEGBdAV91Sq+0jhXCW7cZCv3DmAQ4lh8DuH703umqhgmrzeZ6bpYrsFqZa5+Jie28DApZtXZhr+7KmQHG8po1mkv/ggj8R3k8xrUbeX6seVG29kKomLTw6lIa3AuhVbqoL9SpWL2cHCq5Hgg0ZJz3E5BdRVYsrY04rEJii6MQJc= 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 1665409338114578.6282458421005; Mon, 10 Oct 2022 06:42:18 -0700 (PDT) Received: from localhost ([::1]:43982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht2v-0001lE-3C for importer@patchew.org; Mon, 10 Oct 2022 09:42:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-0000zo-93 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:45480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005Jx-0Z for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:19 -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 8E423219C2; Mon, 10 Oct 2022 13:34:14 +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 140F213479; Mon, 10 Oct 2022 13:34:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KKdhAVYfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408854; 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=pi0W9p4bga3LkR5Luh/Nc7b3X+HswvzxyhqLDq8Amxj3guSLyrZAMbAcxYOGBFMjNFCIK7 tx01YaHkluSuPwQLYlyn32D0hCUVhJ8lImUM4KHVy3+sH6O3RVjkl+DCOXXG8myfxm0Cve r6/ZWnmE/jh4tcDNhzkvU7gRPGS6I0U= 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 v2 02/11] migration: Add support for 'file:' uri for incoming migration Date: Mon, 10 Oct 2022 16:33:59 +0300 Message-Id: <20221010133408.3214433-3-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409338870100004 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 Reviewed-by: Daniel P. Berrang=C3=A9 --- 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 Fri May 10 05:31:04 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=1665409290; cv=none; d=zohomail.com; s=zohoarc; b=WVhzSbjstzTqtfskxgwo53na5XiUHujennFyaQSex7zr/Ytlcp5liWZQT2G8qX2JqfO7EifDK1ZNL2PXmYulpmrqy451ItCZ3xJev/EEoUu6/p+ckOBXBL+3j/BJEily5aa6+tungvKDFkbKR2fuN8aFOTvbSk69mG2TIkkW438= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409290; 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=a/HvKs1sNilBcgwvKH79q/AX2MgOJxthS0SG5vFnUKSuJf7kR943t7rbV/EAhNKpp5wSert3LBpWi9Nwq2Qd9S1JlnJ9lAY4hAXtA73JeRckC0Wbsiq1zckUEtoc4SxI/xT4sWDR9d63YRBImgwXXcHhNAAsZlEFMBDNKPK59tc= 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 1665409290875662.2386099526483; Mon, 10 Oct 2022 06:41:30 -0700 (PDT) Received: from localhost ([::1]:38014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht28-00011o-PT for importer@patchew.org; Mon, 10 Oct 2022 09:41:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-000108-M2 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:48746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005K8-0Z for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:20 -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 27E1C1F8EF; Mon, 10 Oct 2022 13:34:15 +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 9505B13479; Mon, 10 Oct 2022 13:34:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IGeYIVYfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408855; 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=P4eXW19zK5ZMbUuCwHd0mvM5Yz7CipvURjDaPZpmoF2McR0DxwB1fbPA8htliOKzdF3/A3 LNn1rz/kbCb7WNk/LeElTjmlHhKyV8z7tlRWEe5YbLoUYFWa5lKfXNaPvD/Qy3psnNRs6u +itgaSOBi+aXayfKUGNAegE3iNX8tq4= 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 v2 03/11] migration: Make migration json writer part of MigrationState struct Date: Mon, 10 Oct 2022 16:34:00 +0300 Message-Id: <20221010133408.3214433-4-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409292214100001 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 Fri May 10 05:31:04 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=1665409338; cv=none; d=zohomail.com; s=zohoarc; b=YSKWPWg8oGt1NbcUBL7d2JnkHD3MVazSKzpWXQ2CxaO4nU9/Rfg/ZhtQXtNBFBv4nF2Dc4m+XBLGX6epPyoBXpABSyywcRJizCOhichHHGKvgNYyV5jESEzBoOv8Ib0cAOGa6UKhUIM249k0FNGhkPf2Rb+YBm9RJf4HUHBC5N4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409338; 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=KzK9k55fSVBq054uTFi4NsqPtd33raBPSQmaZiUjDYVNryXtK3376ZNOeBejMMylntg+G/APJB8xI+DVMPqKF7v0HTbKjpC3acxzN4DxCVVJ3hRMWvIw3+p3WXc3GJfT/h6edcrgTYr6PJyPhHLdd+EaKpAZqSJ0Ssn4N5zgwcA= 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 1665409338602187.0470322146001; Mon, 10 Oct 2022 06:42:18 -0700 (PDT) Received: from localhost ([::1]:43980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht2t-0001j1-BW for importer@patchew.org; Mon, 10 Oct 2022 09:42:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-0000zu-NO for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:58906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005KD-0Z for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:18 -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 9A6DD219C4; Mon, 10 Oct 2022 13:34:15 +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 2B7AD13AF4; Mon, 10 Oct 2022 13:34:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gKGBB1cfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408855; 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=UjuzJSm2yR1T1iPvkR4a+LginrO7nRkQY5bk0Fczed//hmhpScHOjDiWk8ui+TR/wQNM7C SYnWdBT3rMIE2CGq7rmS4OU3hR4sIjR6Xgv4cZjh2559efzZi3rG5TKJJ8Zru82hA30cf7 JN11d/EVFWocXnn/pjSPdWhgTAGx8hE= 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 v2 04/11] io: add pwritev support to QIOChannelFile Date: Mon, 10 Oct 2022 16:34:01 +0300 Message-Id: <20221010133408.3214433-5-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: 1665409338862100003 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 Fri May 10 05:31:04 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=1665409751; cv=none; d=zohomail.com; s=zohoarc; b=M99wpIj/mzJIfst2i66wYSy+uFYjUcj5aSvIYHaWjwc0iib70gfJDBj4L4r3/RTsItZPK6Vip2DawU2lj7o36aj4qgJJacSjvXxxu3ieAKwxcPnAnC7QodGH/UWbUE9jRqdWjNQNMBhnMVzsrUg0pb2zLuicfTh4HNd7oDqSG9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409751; 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=Y0/N6mfKLtwSYVngl816bcQzCncVuWeNrww86XW3NL2XmTzq2AycEsY0AHl/2vA5z50McLs2aorEcV2760IpSAr1YGnkbonDLImn6Se8sqLfTzwDKCemVh9GXMYh9A8pCXHe246S62NFWKQeVh4+KXlJLh6FYhhT8FokbcH34wo= 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 1665409751682888.9915728736308; Mon, 10 Oct 2022 06:49:11 -0700 (PDT) Received: from localhost ([::1]:36610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht9a-0002lY-9Q for importer@patchew.org; Mon, 10 Oct 2022 09:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-0000zx-Nh for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:56060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005KH-JI for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:20 -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 2B1E81F8EE; Mon, 10 Oct 2022 13:34:16 +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 AD0D713479; Mon, 10 Oct 2022 13:34:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yMNgJ1cfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408856; 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=lEJGmMrtoAuFIpyrHfyaS9Zs3T+1k2kU9tXiSJ7ofl0+iLXsIdWgPwnZHlK8/uz34zAJkO FJGLGVqydoI89QpCLm9YWdB4k5nJbcZlujpcOpMdQGK0xxwo/Pu/Qy+JYLohfsG8bsKMvi d/DNPBcNBXdcTG6bgOBRePzGcOESQm4= 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 v2 05/11] io: Add support for seekable channels Date: Mon, 10 Oct 2022 16:34:02 +0300 Message-Id: <20221010133408.3214433-6-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: 1665409752493100001 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 Fri May 10 05:31:04 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=1665409511; cv=none; d=zohomail.com; s=zohoarc; b=GS6LrW1UHAUSm2mEdOqqYeqVqUiOyXyqLywLiKUCrQpthNhM6gMnztWWapNsEqhw/IiE78lCeWUkIcVA+IPx3tV8hPdWOVWNDq8J3hXTCWaFj0g1BKuT9otl3Bgf9dG00uVqMyQI4oAiC5MKaYVE5grkgkbcS7HNQZ63GnvWPYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409511; 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=c/zzXdBPH2gfJ5BnMgB/IfCRuGAep+wv6xGBhbyKJ3UIt2WYUkp01I+UPJ2nXvKBy8NmIVtshhTOENabsfXyT6lz44VlMdrHzawd0hgaNdd0kmlGJVjntp1iqb0bFEraQAv4+Xqxu2NS2uFTgG24fZjbh6DoCWPZ/zOpRv8OOhI= 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 1665409511941459.7377980421538; Mon, 10 Oct 2022 06:45:11 -0700 (PDT) Received: from localhost ([::1]:53324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht5i-00075h-Qm for importer@patchew.org; Mon, 10 Oct 2022 09:45:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-000107-Lp for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]:58910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvB-0005KM-SD for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:20 -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 B5F53219C6; Mon, 10 Oct 2022 13:34:16 +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 3CD1813479; Mon, 10 Oct 2022 13:34:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CNELDFgfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408856; 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=vSgf/FL5HbUkfAwCEfX8wTa+M+Ji6zn3REQK1hQWZ02fKIRtVLEWTceA4mKX7c713N6LHV dvA6tQUsGW4W8wh2SpLCBiotNr9/wlTTUVL1w3WB8Jm8eEq8L5nUticmt6ccZwtrx/ObTr srsnLMnlULLly6cGYFhrovNQz9khndI= 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 v2 06/11] io: Add preadv support to QIOChannelFile Date: Mon, 10 Oct 2022 16:34:03 +0300 Message-Id: <20221010133408.3214433-7-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: 1665409513538100001 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 Fri May 10 05:31:04 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=1665409065; cv=none; d=zohomail.com; s=zohoarc; b=HGNh/WfxC6j/koNeDFfhAZizUS0eVlGpQ53r2/xaICaikpm5TMh3orT9ofsUkIzhrtuc5B5tDIpvDUSAYaW5JqJHXQOzElBSe7pu9JZsesEGE/r5ZoRT91r8rVAAplgWUatcen5gu8P0vb6H54ceyCoGoUnEAIfmZ1LowQyqjlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409065; 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=Ft/zeRWiACRwrhMsakC2LZtt5fL8yDFvG5MynconYm7NsvMW7mmeOQ/p9Hb/jqVh+Pkgcrh2NPYDl42QlUrj8A3n99NFhPV73C/54duDaWGWkmhp42T04qycOqMMuxCvqyqZpiiAxhoT1MpQEPItFtdGF2drGnpdwr5yxL7pTvc= 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 1665409065487160.38983728709775; Mon, 10 Oct 2022 06:37:45 -0700 (PDT) Received: from localhost ([::1]:44764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohsyW-00044i-FS for importer@patchew.org; Mon, 10 Oct 2022 09:37:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvG-0000zv-Fc for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:48750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvC-0005KU-Em for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:21 -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 508661F8F2; Mon, 10 Oct 2022 13:34:17 +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 C180C13479; Mon, 10 Oct 2022 13:34:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MF1zLFgfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408857; 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=nbp8qs7V3CumbEVUcOBVCtHWoewLDq3+XiTsTXFiFWXOl733FNc1bGtafxUyzhz8Zgo5Yy GmvOZTx2yxJccB6oxXDBzowN5Y01s5EixuZOsL8fqBMte+oIGgYc0LLfL5tl79en4ri1TA e2IUyG0pY460uWeF4PwYAIlSLPPaBQI= 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 v2 07/11] migration: add qemu_get_buffer_at Date: Mon, 10 Oct 2022 16:34:04 +0300 Message-Id: <20221010133408.3214433-8-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409066210100002 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 Fri May 10 05:31:04 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=1665409336; cv=none; d=zohomail.com; s=zohoarc; b=kYOcQ261otbHr3oS3ttrqvZ+Kqqua/VUvfJhCyzaesYR0NZj9lApPeLFLacJHKOITX1EKguPtaW0msjjadk1d+fJjFZQF/j7NYOIM4Eig/rEp1bWLH/0l1sM2hhgBnPZ/cYktRnkBz2cM+D5dwTsde+IXewVmS8dj+6hqYwHOTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409336; 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=Mcxb1KkOXDsWsAQ+5oEd/2owC+DHHQstkS+CY/0AUxw=; b=R2rpIclUm4dj0NR4srjnkJQ9Uww6iW9Rs7kXZhMbf19XgZb8MBC0FAk67HNYYd6UH8/2Od78E/P9Mush6z8k7ppavTmRyd19Sldgw2NL2U6Aom961ve1hqBcQIklk50lKApt2i56R0dYALHd0ODmm0xymJLYjO2gEalz2MzpncI= 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 1665409336552454.79155362236975; Mon, 10 Oct 2022 06:42:16 -0700 (PDT) Received: from localhost ([::1]:47622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht2t-0001ck-8r for importer@patchew.org; Mon, 10 Oct 2022 09:42:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvL-00012A-Ah for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:27 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:49306) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvD-0005Kc-HD for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:26 -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 D4688219C7; Mon, 10 Oct 2022 13:34:17 +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 5781C13479; Mon, 10 Oct 2022 13:34:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OOqjEVkfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408857; 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=Mcxb1KkOXDsWsAQ+5oEd/2owC+DHHQstkS+CY/0AUxw=; b=CxBy4PMUI5M1F4h4UtJKkOdhSWOrmwuB5naGKiW5z3LUayPCHXLb7P+DeaXmZxceV4thil llSY5yOnAqWBqG6uP8rNP/mzqmOOOmQ5mInqpqRMnhzYQQV3OsejCUQW2Cgoqo2VkcKVZc yUS9dCFJpyHaqYd1/Rzwc7A8ukPlFw4= 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 v2 08/11] migration/ram: Introduce 'fixed-ram' migration stream capability Date: Mon, 10 Oct 2022 16:34:05 +0300 Message-Id: <20221010133408.3214433-9-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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, T_SPF_TEMPERROR=0.01 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: 1665409337169100001 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 | 97 +++++++++++++++++++++++++++++++++-------- migration/savevm.c | 1 + qapi/migration.json | 2 +- 6 files changed, 138 insertions(+), 21 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..4f5ddaff356b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1261,9 +1261,14 @@ static int save_zero_page_to_file(RAMState *rs, QEMU= File *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; + 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_F= LAG_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,7 @@ 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); block->clear_bmap_shift =3D shift; block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); } @@ -3226,12 +3241,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 +3286,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 +3406,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 +3459,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 +3485,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 Fri May 10 05:31:04 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=1665409987; cv=none; d=zohomail.com; s=zohoarc; b=lnJUTm5BF1umRaA+O1U9dfP0n1X4pNFbf/aF7I/43bS72GNT97DlvgTUIginoYUy5mjkZwv9JZ0sAdjn8ey1ntSLy1rZ4Yu+O+kXRxxuTUFLqlCv2ChXKvLDJkuHb38NDxJDyKGMDuAvEFM9NI4FtEPGihB39o8us1+5UlZGtjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409987; 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=/URCrYomxDofh61RepDYdpcp3wDN5Mzs6KVh2CPI3d0=; b=LqGGeioeZ6zo6BbpLPwbb+pVIT7CeAp22Mk7cAXMcs1O2V04QAz6R0cuHTdeCwtHNAlIytRq8uhgAo6hMinE/KVZdqiVjq8PMOYv+JU0GKaOR7IfuxlV88h5dA4N3bIECcB/HHdbrszawwFjSy77JaUpBSvcbrm+zrlRFDrmmkU= 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 1665409987846541.5716433657836; Mon, 10 Oct 2022 06:53:07 -0700 (PDT) Received: from localhost ([::1]:40994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohtDO-0005oF-No for importer@patchew.org; Mon, 10 Oct 2022 09:53:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvL-000128-A0 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:27 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:49314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvH-0005LS-J6 for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:26 -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 661A1219C8; Mon, 10 Oct 2022 13:34:18 +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 E57E813479; Mon, 10 Oct 2022 13:34:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IIYGNVkfRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408858; 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=/URCrYomxDofh61RepDYdpcp3wDN5Mzs6KVh2CPI3d0=; b=XsOy9aB7OOnyz67ZUmaoEPWWK/xNisbocXEHebrO2I12JcSAnksOrUnAGDScfyQeMZ3s5X G53n8bL9FWkyiuuWzJbvv+KZn10YfYKKFjCXxONjiTXjA7t2QLbhBx2zLLDmfGzvl0LbRm fEMBxJg1Ug5h09CnoFebXLFaRgVayKQ= 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 v2 09/11] migration: Refactor precopy ram loading code Date: Mon, 10 Oct 2022 16:34:06 +0300 Message-Id: <20221010133408.3214433-10-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409990237100001 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 4f5ddaff356b..1dd68c221667 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4253,6 +4253,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 * @@ -4267,14 +4344,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 @@ -4345,65 +4421,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 Fri May 10 05:31:04 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=1665409065; cv=none; d=zohomail.com; s=zohoarc; b=WbYGJcl2apBc0NUNUz7JG22Pd0MkAL/Q4U/TM1elMxuhpZ4XuY1yBv0HHri5GIxIlrDyItdjXjcCblJmR8T7d0rMCb5RJ7f8//PfszSR4OUJJkJyqmKADCqFhGF4/Tzbc3/Vw1ngy+DKuUAKA8Zy3NgisK+UEFKKjNYdxitMWp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409065; 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=UNbkYhbIU4ghtBPpn9ujfppn4XNmhzrWo/AukZfQa5k=; b=Dv1awDmg8CFfZcpIB1n3ihhQKSKxFwl1slwkZ+kKmrmKDnXfP+1k/03g9xJkKpRETArXhkFQb0F5/RF0R+U52a0bKtON/VU+ZR5p7PahAJLqxV5d0NZ0K2plqvpiI5Zi9/iOyB71rQp/drf+s1hcV2FhETE3rg6FLpQdpmz9WY8= 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 1665409065549900.3184530448876; Mon, 10 Oct 2022 06:37:45 -0700 (PDT) Received: from localhost ([::1]:44766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohsyV-00048v-Vn for importer@patchew.org; Mon, 10 Oct 2022 09:37:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvJ-00011R-LE for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:25 -0400 Received: from smtp-out2.suse.de ([2001:67c:2178:6::1d]:41698) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvF-0005Kn-DL for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:24 -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 E9D861F8F3; Mon, 10 Oct 2022 13:34:18 +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 758D713479; Mon, 10 Oct 2022 13:34:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OHgDGlofRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408858; 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=UNbkYhbIU4ghtBPpn9ujfppn4XNmhzrWo/AukZfQa5k=; b=B8vcZdrGlSDZrzDFYEUSs67IT1WanQ5CE5205WrxrQnVCyxOzTeohIP9W/1ZKkqXHmaRkC peCi7MaQk4ZHdHNWaZeLZQe6OncX4tztjbrCnrZUwznaN/no3s+7X8FkX0d237GKfMO/qA ldmx7OXetOWrm85yd19MZ7u2VNQIXTk= 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 v2 10/11] migration: Add support for 'fixed-ram' migration restore Date: Mon, 10 Oct 2022 16:34:07 +0300 Message-Id: <20221010133408.3214433-11-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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: 1665409066146100001 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 | 95 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 95 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 1dd68c221667..15441ed9f745 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4330,6 +4330,90 @@ 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 clear_bit_idx; + long num_pages, bitmap_size; + int len =3D qemu_get_byte(f); + g_autofree unsigned long *dirty_bitmap =3D NULL; + + 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; + 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 */ + 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; + } + +#define BUFSIZE (4*1024*1024) + for (unsigned long set_bit_idx =3D find_first_bit(dirty_bitmap, nu= m_pages); + set_bit_idx < num_pages; + set_bit_idx =3D find_next_bit(dirty_bitmap, num_pages, clear_= bit_idx + 1)) { + + clear_bit_idx =3D find_next_zero_bit(dirty_bitmap, num_pages, = set_bit_idx + 1); + unsigned long len =3D TARGET_PAGE_SIZE * (clear_bit_idx - set_= bit_idx); + ram_addr_t offset =3D set_bit_idx << TARGET_PAGE_BITS; + + for (size_t written =3D 0, completed =3D 0; completed < len; o= ffset +=3D written) { + void *host =3D host_from_ram_block_offset(block, offset); + size_t read_len =3D MIN(len, BUFSIZE); + + written =3D qemu_get_buffer_at(f, host, read_len, + block->pages_offset + offset); + completed +=3D written; + } + } + + /* 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 * @@ -4349,7 +4433,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; @@ -4421,7 +4505,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 Fri May 10 05:31:04 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=1665409756; cv=none; d=zohomail.com; s=zohoarc; b=DKotkiKPWe+1KEjNTNJWMZNkJbfqkTzxEDl2MU2RJ32T2VRVh8MLHIt1v1/+f5jYR36zyj7yM4QpfsUzwQFV9w1Ud9BJIBBr5QMsUsxNV9B42PHBVuAtzvf3F0ysKQBNQW2//nUI7xbDFmjPXZ6/EE1NmZnrY68ehVOQOdTNHAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665409756; 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=DnprjGRozoYEEjM5j7w+MaH0fCwrLgAxmgVE/2SK5TICUaRTKE0QWEBdDhyABbSXA4oLRm1OkTtYklisBDiUl4ZyJc76rdLXJrJqa0Z42E7pLJC1CMYrj9ZaF2eGhZt4SiBQ81VBNWEr741TwQrQbU7WDiKy/uLeQtuIkvvi7NY= 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 1665409756149271.15663423204126; Mon, 10 Oct 2022 06:49:16 -0700 (PDT) Received: from localhost ([::1]:36614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oht9d-0002rr-Vg for importer@patchew.org; Mon, 10 Oct 2022 09:49:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohsvL-000129-AJ for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:27 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:49140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohsvJ-0005LR-1k for qemu-devel@nongnu.org; Mon, 10 Oct 2022 09:34:26 -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 7BD811F8F4; Mon, 10 Oct 2022 13:34:19 +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 0710F13479; Mon, 10 Oct 2022 13:34:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aFt/OlofRGNsAwAAMHmgww (envelope-from ); Mon, 10 Oct 2022 13:34:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665408859; 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=WEQknGil4c6as8U/TYuG4+STQSZuKcACcuc5LYv7CK/qg+eDRpG4qez80e8rYGT0o0ql4M qumPqfQT3q3vBoopNEdRr7jygdkGFiXr7HIc/RXuTSkfG1Cr66LUpaaDgC6GZ0MySh7KPq qJ03g5CcTvmZRtBLBanYnmGL0TNa9zo= 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 v2 11/11] analyze-migration.py: add initial support for fixed ram streams Date: Mon, 10 Oct 2022 16:34:08 +0300 Message-Id: <20221010133408.3214433-12-nborisov@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221010133408.3214433-1-nborisov@suse.com> References: <20221010133408.3214433-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: 1665409756491100001 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