From nobody Wed Nov 27 02:19:16 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116804; cv=none; d=zohomail.com; s=zohoarc; b=EJgSGWqMf5k12J1OYhUUbi1Qxgyr/LWdjG1DiG8Q8lnyPBTAJlXUsh+ZFFL2gDyorUnNknbJe4aTV8jdWWehY/XhUAbP8JFnA+nz9VlDizlmivMhnT6BaH5GKbgAd9G90bfxJqbUD5B1fO/2RhLlaFLEU4jLYRfdROajUoapl8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116804; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HANNei1RIw7D6aPro8oCqEXXgEDARrXt4Bkj7ntOXS4=; b=aphPfoy3y9me0lbUUCegNr5w79GoAvjAx+qJugsc+8dj30vV4PVWWpWbENlkh7KXDE/5PVzz8b+KLhwIYSdjpOePKWxHy/r8VyIybVSD3E0Ju/7OkF4UWOj6SfQE18d2qLiIl+Jd7+0qoHnoeKgylMtA3H1gjmI+N4bS89CVo8s= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116804440241.82713533982144; Mon, 27 Nov 2023 12:26:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBW-0002Qb-R7; Mon, 27 Nov 2023 15:26:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBV-0002QE-9l for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:25 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBT-0002gW-RR for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:25 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9EEAD21B2A; Mon, 27 Nov 2023 20:26:19 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 53DA513ABA; Mon, 27 Nov 2023 20:26:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id II/gBmn7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116779; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HANNei1RIw7D6aPro8oCqEXXgEDARrXt4Bkj7ntOXS4=; b=aldUc8gN42kdgnlfby54ohBpLLj78uS4Qv1om4JypIxNP4V9W3ODA7Ze3KBNu9tzf9Ehg/ bsPvitl92ZWUg226INjOQAvvzrpSqTSLWMdrKx0HFBZTy3DjI/T8as4wU4pj2OMznDN+fk bUnlagefy/Qdlyz9xFNm1E0DsDhhS3k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116779; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HANNei1RIw7D6aPro8oCqEXXgEDARrXt4Bkj7ntOXS4=; b=69z3sYpBnWUBc0SixwsBt2mu8CAwTxEjB8d28mbqOxG/JXuJWuaTB3i4V7iLUopKT98+D8 rzXeaJ5LjwtrPJAw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: [RFC PATCH v3 01/30] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file Date: Mon, 27 Nov 2023 17:25:43 -0300 Message-Id: <20231127202612.23012-2-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: -0.26 X-Spamd-Result: default: False [-0.26 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_SEVEN(0.00)[8]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.16)[69.09%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116806443000001 From: Nikolay Borisov Add a generic QIOChannel feature SEEKABLE which would be used by the qemu_file* apis. For the time being this will be only implemented for file channels. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu --- include/io/channel.h | 1 + io/channel-file.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 5f9dbaab65..fcb19fd672 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -44,6 +44,7 @@ enum QIOChannelFeature { QIO_CHANNEL_FEATURE_LISTEN, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, QIO_CHANNEL_FEATURE_READ_MSG_PEEK, + QIO_CHANNEL_FEATURE_SEEKABLE, }; =20 =20 diff --git a/io/channel-file.c b/io/channel-file.c index 4a12c61886..f91bf6db1c 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -36,6 +36,10 @@ qio_channel_file_new_fd(int fd) =20 ioc->fd =3D fd; =20 + if (lseek(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_fd(ioc, fd); =20 return ioc; @@ -60,6 +64,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; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116979448876.7211875997301; Mon, 27 Nov 2023 12:29:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBX-0002Qz-NN; Mon, 27 Nov 2023 15:26:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBW-0002QO-A2 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:26 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBU-0002hY-F6 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:26 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6C6E91FB79; Mon, 27 Nov 2023 20:26:22 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1FD631379A; Mon, 27 Nov 2023 20:26:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id yPXUNWv7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:19 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: [RFC PATCH v3 02/30] io: Add generic pwritev/preadv interface Date: Mon, 27 Nov 2023 17:25:44 -0300 Message-Id: <20231127202612.23012-3-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.79 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-1.00)[-0.996]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.79 X-Rspamd-Queue-Id: 6C6E91FB79 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701116980425000001 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov Introduce basic pwritev/preadv support in the generic channel layer. Specific implementation will follow for the file channel as this is required in order to support migration streams with fixed location of each ram page. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu --- - fixed naming: s/pwritev_full/pwritev --- include/io/channel.h | 82 ++++++++++++++++++++++++++++++++++++++++++++ io/channel.c | 58 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index fcb19fd672..7986c49c71 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -131,6 +131,16 @@ struct QIOChannelClass { Error **errp); =20 /* Optional callbacks */ + ssize_t (*io_pwritev)(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); + ssize_t (*io_preadv)(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + off_t offset, + Error **errp); int (*io_shutdown)(QIOChannel *ioc, QIOChannelShutdown how, Error **errp); @@ -529,6 +539,78 @@ void qio_channel_set_follow_coroutine_ctx(QIOChannel *= ioc, bool enabled); int qio_channel_close(QIOChannel *ioc, Error **errp); =20 +/** + * qio_channel_pwritev + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + * Behaves as qio_channel_writev_full, apart from not supporting + * sending of file handles as well as beginning the write at the + * passed @offset + * + */ +ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + +/** + * qio_channel_pwrite + * @ioc: the channel object + * @buf: the memory region to write data into + * @buflen: the number of bytes to @buf + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + */ +ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp); + +/** + * qio_channel_preadv + * @ioc: the channel object + * @iov: the array of memory regions to read data into + * @niov: the length of the @iov array + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + * Behaves as qio_channel_readv_full, apart from not supporting + * receiving of file handles as well as beginning the read at the + * passed @offset + * + */ +ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + +/** + * qio_channel_pread + * @ioc: the channel object + * @buf: the memory region to write data into + * @buflen: the number of bytes to @buf + * @offset: offset in the channel where writes should begin + * @errp: pointer to a NULL-initialized error object + * + * Not all implementations will support this facility, so may report + * an error. To avoid errors, the caller may check for the feature + * flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method. + * + */ +ssize_t qio_channel_pread(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp); + /** * qio_channel_shutdown: * @ioc: the channel object diff --git a/io/channel.c b/io/channel.c index 86c5834510..a1f12f8e90 100644 --- a/io/channel.c +++ b/io/channel.c @@ -454,6 +454,64 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc, } =20 =20 +ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + + if (!klass->io_pwritev) { + error_setg(errp, "Channel does not support pwritev"); + return -1; + } + + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) { + error_setg_errno(errp, EINVAL, "Requested channel is not seekable"= ); + return -1; + } + + return klass->io_pwritev(ioc, iov, niov, offset, errp); +} + +ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp) +{ + struct iovec iov =3D { + .iov_base =3D buf, + .iov_len =3D buflen + }; + + return qio_channel_pwritev(ioc, &iov, 1, offset, errp); +} + +ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + + if (!klass->io_preadv) { + error_setg(errp, "Channel does not support preadv"); + return -1; + } + + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) { + error_setg_errno(errp, EINVAL, "Requested channel is not seekable"= ); + return -1; + } + + return klass->io_preadv(ioc, iov, niov, offset, errp); +} + +ssize_t qio_channel_pread(QIOChannel *ioc, char *buf, size_t buflen, + off_t offset, Error **errp) +{ + struct iovec iov =3D { + .iov_base =3D buf, + .iov_len =3D buflen + }; + + return qio_channel_preadv(ioc, &iov, 1, offset, errp); +} + int qio_channel_shutdown(QIOChannel *ioc, QIOChannelShutdown how, Error **errp) --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116860; cv=none; d=zohomail.com; s=zohoarc; b=ZfG6hxALUAplaF78lqdvPDA+hF2rVtJooqHSxLP+9El8LagsDOpg9EjbZkKqHjv0dsuI15Z9V91TdSZoZ9RbXbjYnolDo50uJvGZXjGY38eEIR8dYjzBAUA+XTYeZ/962Ldks1D1JBygEeFgAYbGzTvmCZ36JJEdeqaUIsn6k0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116860; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3xOfyGHNhjnJWHtphQ8OBnaMWdX1lLvdQcv8Sfp7HSk=; b=UTmSaLdy1LAj9UzqwtbVyOlpYj9Y/0zlK9nRPFk9D+3y4Vcq8amuBB2Bynup5hZjSTfyMpEzGKfCj1eozPoCx9hNZ8o2Ldn/qzB7Ux/hDukrTLor27z3C+7YXAQeqv1y+3ytle3MAoQtZUM4b/Cyl8uQ27Z5k/ocIC+JEeCqyIk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111686001488.21389616126874; Mon, 27 Nov 2023 12:27:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBZ-0002RN-5c; Mon, 27 Nov 2023 15:26:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBX-0002R0-Ql for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:27 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBW-0002jB-AR for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:27 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3826221B2A; Mon, 27 Nov 2023 20:26:25 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E07DB1379A; Mon, 27 Nov 2023 20:26:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id CCEhKW77ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116785; 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=3xOfyGHNhjnJWHtphQ8OBnaMWdX1lLvdQcv8Sfp7HSk=; b=TuhxSYxvuEisI/0gsD2kC1SGn61bofQ+zXkX2oXfcc0Oc1OAkP60rbbz3wRTsub9Aw3y60 ssqCTWV+gx2xwHDnTLoRX1U/Ve1LkukctDVLO5E6b6LF/N32inPwDFvhGUUI7fofqIoJQE By5wq7OKKhx4pdgJ4iedBbS0Q8dbgAM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116785; 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=3xOfyGHNhjnJWHtphQ8OBnaMWdX1lLvdQcv8Sfp7HSk=; b=sfcvA5hRqeMK9EYcFqdKNyCwTFZbXzuLTJVS9YyAkoRiWRhB81Q3H8zGWwmVbD/sb2v0ft Dy36n4hgOvLc0wBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: [RFC PATCH v3 03/30] io: implement io_pwritev/preadv for QIOChannelFile Date: Mon, 27 Nov 2023 17:25:45 -0300 Message-Id: <20231127202612.23012-4-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 3.87 X-Spamd-Result: default: False [3.87 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.03)[55.67%] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116861857000001 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov The upcoming 'fixed-ram' feature will require qemu to write data to (and restore from) specific offsets of the migration file. Add a minimal implementation of pwritev/preadv and expose them via the io_pwritev and io_preadv interfaces. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu --- - check CONFIG_PREADV to avoid breaking Windows --- io/channel-file.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/io/channel-file.c b/io/channel-file.c index f91bf6db1c..a6ad7770c6 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -146,6 +146,58 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, return ret; } =20 +#ifdef CONFIG_PREADV +static 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; +} + +static 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; +} +#endif /* CONFIG_PREADV */ + static int qio_channel_file_set_blocking(QIOChannel *ioc, bool enabled, Error **errp) @@ -231,6 +283,10 @@ static void qio_channel_file_class_init(ObjectClass *k= lass, ioc_klass->io_writev =3D qio_channel_file_writev; ioc_klass->io_readv =3D qio_channel_file_readv; ioc_klass->io_set_blocking =3D qio_channel_file_set_blocking; +#ifdef CONFIG_PREADV + ioc_klass->io_pwritev =3D qio_channel_file_pwritev; + ioc_klass->io_preadv =3D qio_channel_file_preadv; +#endif ioc_klass->io_seek =3D qio_channel_file_seek; ioc_klass->io_close =3D qio_channel_file_close; ioc_klass->io_create_watch =3D qio_channel_file_create_watch; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117039; cv=none; d=zohomail.com; s=zohoarc; b=Q4hRgzC1A+muRtF+fNsCG/rABunbhfa6sT9k48hjq8jhWqYaHph/0M7Q5Qf7iW/UFPXiqQxSokDQLoxqQ59iZtHEse4UXxZAawPx6dzJlKxhqq+v2HuUPPmo7uQKkvnyzuKBjpOoWB/tIPfw4iA0ITvDVCxQ//3i8QONYNHWNws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117039; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cn2LdI9lfuWBQrYf9ji9MVz/jbVtLECSf9bAPcJ3XRI=; b=lG8kwVJfhsaGrio9mjZaDjE/fnF5Zni0GL0SZP0QNeio7JiVH7IQxQ6i8jxzaNTnjFM2dTOZ5yxME2y+C33aHo8GCRiEu/dmaEazfVSpNcEc1zOanCDQvvwm+Pw82bFVozdo3C2682tdhhSpYWZXAtcS7n86sJEqChUqjozqiZk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117039056903.9125790287318; Mon, 27 Nov 2023 12:30:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBc-0002SU-Lv; Mon, 27 Nov 2023 15:26:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBa-0002Rp-Mn for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:30 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBZ-0002jh-5z for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:30 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BD1101FB79; Mon, 27 Nov 2023 20:26:27 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A9B181379A; Mon, 27 Nov 2023 20:26:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6CzjG3H7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116787; 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=cn2LdI9lfuWBQrYf9ji9MVz/jbVtLECSf9bAPcJ3XRI=; b=apocxe0fkSGTHALYySzXFnk7e3EtHLbe0FtBE9aWyl5ejH2Uc8jLaOkeP1aegXWGxULwUK IESWqawpaFy1X5Eu6/qBHCr7yXNZma8K/zkdTzL/umEMNSroXtUzkxZ29sNHVRttULbj2Z dDRSj7Voy+C2UK34HGxQWLUwOyi6Uks= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116787; 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=cn2LdI9lfuWBQrYf9ji9MVz/jbVtLECSf9bAPcJ3XRI=; b=mwMe+nmpUdGmP7tF9iQdhY5tG97zX5XgKsQocCcCRW7dUpnlLfcVj2umat7WkzoCNFjI/X 4N2ww2V+hWY5ZjBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 04/30] io: fsync before closing a file channel Date: Mon, 27 Nov 2023 17:25:46 -0300 Message-Id: <20231127202612.23012-5-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.90 X-Spamd-Result: default: False [3.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[11.13%] 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117039580000001 Content-Type: text/plain; charset="utf-8" Make sure the data is flushed to disk before closing file channels. This will ensure data is on disk at the end of a migration to file. Signed-off-by: Fabiano Rosas Acked-by: Daniel P. Berrang=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 --- io/channel-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/channel-file.c b/io/channel-file.c index a6ad7770c6..d4706fa592 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -242,6 +242,11 @@ static int qio_channel_file_close(QIOChannel *ioc, { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); =20 + if (qemu_fdatasync(fioc->fd) < 0) { + error_setg_errno(errp, errno, + "Unable to synchronize file data with storage dev= ice"); + return -1; + } if (qemu_close(fioc->fd) < 0) { error_setg_errno(errp, errno, "Unable to close file"); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116862752758.4783323113165; Mon, 27 Nov 2023 12:27:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBg-0002TD-Ab; Mon, 27 Nov 2023 15:26:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBd-0002Sm-DJ for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:33 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBb-0002jx-MA for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:33 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8CC1521B2A; Mon, 27 Nov 2023 20:26:30 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3F2CB1379A; Mon, 27 Nov 2023 20:26:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id wJCtAXT7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:28 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: [RFC PATCH v3 05/30] migration/qemu-file: add utility methods for working with seekable channels Date: Mon, 27 Nov 2023 17:25:47 -0300 Message-Id: <20231127202612.23012-6-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [3.79 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-0.998]; MIME_GOOD(-0.10)[text/plain]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 3.79 X-Rspamd-Queue-Id: 8CC1521B2A 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701116863881000007 From: Nikolay Borisov Add utility methods that will be needed when implementing 'fixed-ram' migration capability. qemu_file_is_seekable qemu_put_buffer_at qemu_get_buffer_at qemu_set_offset qemu_get_offset Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Daniel P. Berrang=C3=A9 --- include/migration/qemu-file-types.h | 2 + migration/qemu-file.c | 82 +++++++++++++++++++++++++++++ migration/qemu-file.h | 6 +++ 3 files changed, 90 insertions(+) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-f= ile-types.h index 9ba163f333..adec5abc07 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/migration/qemu-file.c b/migration/qemu-file.c index 94231ff295..faf6427b91 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -33,6 +33,7 @@ #include "options.h" #include "qapi/error.h" #include "rdma.h" +#include "io/channel-file.h" =20 #define IO_BUF_SIZE 32768 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) @@ -255,6 +256,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 @@ -447,6 +452,83 @@ 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, + off_t pos) +{ + Error *err =3D NULL; + + if (f->last_error) { + return; + } + + qemu_fflush(f); + qio_channel_pwrite(f->ioc, (char *)buf, buflen, pos, &err); + + if (err) { + qemu_file_set_error_obj(f, -EIO, err); + } else { + stat64_add(&mig_stats.qemu_file_transferred, buflen); + } + + return; +} + + +size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, + off_t pos) +{ + Error *err =3D NULL; + ssize_t ret; + + if (f->last_error) { + return 0; + } + + ret =3D qio_channel_pread(f->ioc, (char *)buf, buflen, pos, &err); + if (ret =3D=3D -1 || err) { + 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; + 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 8aec9fabf7..32fd4a34fd 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -75,6 +75,12 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f); int qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); +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, + off_t pos); +size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, + off_t pos); =20 QIOChannel *qemu_file_get_ioc(QEMUFile *file); =20 --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116869; cv=none; d=zohomail.com; s=zohoarc; b=iF+LRk0bGEzlW7yjc5oKwgtYdeDkLMrgC0OUUBsRARzAs0p5bRqegsTV0iXoLyLq1AaKJ5Xi1i4iqVRisUEvuZwD2A/GETFWF0pTthE9Kcnb2CahnbR3M8Yc+PRVSN9H6r67S4PqyOyRksBIJmASGAo28snYEcRVKlKOEZ0blHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116869; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s3xNLf0T59698o5pwcOOswB8tpTOmTYEsBTx8/X3ZJI=; b=B/JGCusOXhWKoWnbb++wJBS6i0eGndAZ0H0TU+hhhR+RCBDKx0Rc+9fBN8BraxFvoTpZkHzy49338zNVhS1EGAJMJ9D/459RCFeK8r6BFOw7QwFhidxtf7cYbydOYCbWYlPvH6IGNOGW0ZFm4JTo4Bs7HcETVARxJCkPEAABymA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111686909963.073268416096084; Mon, 27 Nov 2023 12:27:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBp-0002Vd-RE; Mon, 27 Nov 2023 15:26:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBh-0002TN-8g for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:38 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBe-0002kI-G9 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:37 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5D5D01FB71; Mon, 27 Nov 2023 20:26:33 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0FD991379A; Mon, 27 Nov 2023 20:26:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id WMDxMXb7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116793; 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=s3xNLf0T59698o5pwcOOswB8tpTOmTYEsBTx8/X3ZJI=; b=g9xVl8T+J4UuvoWidO7j6b/e0lYoihgko+kdB8rqNuHjGCdYyxq5PayGCJ47dIvt8VYn+J N5odBGsLATCNOltbPxbylsm111tKsDhoWyNIuxcz5IXkYAyCG7b+O9EmuNZp1JLTK/pI0k dlMgJ3GrG6rPCsJ5zObwYPzYgCoFp5A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116793; 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=s3xNLf0T59698o5pwcOOswB8tpTOmTYEsBTx8/X3ZJI=; b=I68yqGmrcMm/BKgdk4cBUjUzg2yBwGjgxo6TsM1PGgyLpGaxODxhnBlgdPk/a/fzqwE4dk KneBwDoEqskqGlDA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Eric Blake Subject: [RFC PATCH v3 06/30] migration/ram: Introduce 'fixed-ram' migration capability Date: Mon, 27 Nov 2023 17:25:48 -0300 Message-Id: <20231127202612.23012-7-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116869938000005 Content-Type: text/plain; charset="utf-8" Add a new migration capability 'fixed-ram'. The core of the feature is to ensure that each RAM page has a specific offset in the resulting migration stream. The reasons why we'd want such behavior are: - 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 O_DIRECT-enabled save/restore of the migration stream as the pages are ensured to be written at aligned offsets. - It allows the usage of multifd so we can write RAM pages to the migration file in parallel. For now, enabling the capability has no effect. The next couple of patches implement the core functionality. Signed-off-by: Fabiano Rosas --- - mentioned seeking on docs --- docs/devel/migration.rst | 21 +++++++++++++++++++++ migration/options.c | 34 ++++++++++++++++++++++++++++++++++ migration/options.h | 1 + migration/savevm.c | 1 + qapi/migration.json | 6 +++++- 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index ec55089b25..eeb4fec31f 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -572,6 +572,27 @@ Others (especially either older devices or system devi= ces which for some reason don't have a bus concept) make use of the ``instance id`` for otherwise identically named devices. =20 +Fixed-ram format +---------------- + +When the ``fixed-ram`` capability is enabled, a slightly different +stream format is used for the RAM section. Instead of having a +sequential stream of pages that follow the RAMBlock headers, the dirty +pages for a RAMBlock follow its header. This ensures that each RAM +page has a fixed offset in the resulting migration file. + +The ``fixed-ram`` capability must be enabled in both source and +destination with: + + ``migrate_set_capability fixed-ram on`` + +Since pages are written to their relative offsets and out of order +(due to the memory dirtying patterns), streaming channels such as +sockets are not supported. A seekable channel such as a file is +required. This can be verified in the QIOChannel by the presence of +the QIO_CHANNEL_FEATURE_SEEKABLE. In more practical terms, this +migration format requires the ``file:`` URI when migrating. + Return path ----------- =20 diff --git a/migration/options.c b/migration/options.c index 8d8ec73ad9..775428a8a5 100644 --- a/migration/options.c +++ b/migration/options.c @@ -204,6 +204,7 @@ Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-switchover-ack", MIGRATION_CAPABILITY_SWITCHOVER_ACK), DEFINE_PROP_MIG_CAP("x-dirty-limit", MIGRATION_CAPABILITY_DIRTY_LIMIT), + DEFINE_PROP_MIG_CAP("x-fixed-ram", MIGRATION_CAPABILITY_FIXED_RAM), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -263,6 +264,13 @@ bool migrate_events(void) return s->capabilities[MIGRATION_CAPABILITY_EVENTS]; } =20 +bool migrate_fixed_ram(void) +{ + MigrationState *s =3D migrate_get_current(); + + return s->capabilities[MIGRATION_CAPABILITY_FIXED_RAM]; +} + bool migrate_ignore_shared(void) { MigrationState *s =3D migrate_get_current(); @@ -645,6 +653,32 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps= , Error **errp) } } =20 + if (new_caps[MIGRATION_CAPABILITY_FIXED_RAM]) { + if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { + error_setg(errp, + "Fixed-ram migration is incompatible with multifd"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { + error_setg(errp, + "Fixed-ram migration is incompatible with xbzrle"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, + "Fixed-ram migration is incompatible with compressi= on"); + return false; + } + + if (new_caps[MIGRATION_CAPABILITY_POSTCOPY_RAM]) { + error_setg(errp, + "Fixed-ram migration is incompatible with postcopy = ram"); + return false; + } + } + return true; } =20 diff --git a/migration/options.h b/migration/options.h index 246c160aee..8680a10b79 100644 --- a/migration/options.h +++ b/migration/options.h @@ -31,6 +31,7 @@ bool migrate_compress(void); bool migrate_dirty_bitmaps(void); bool migrate_dirty_limit(void); bool migrate_events(void); +bool migrate_fixed_ram(void); bool migrate_ignore_shared(void); bool migrate_late_block_activate(void); bool migrate_multifd(void); diff --git a/migration/savevm.c b/migration/savevm.c index eec5503a42..48c37bd198 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -245,6 +245,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 eb2f883513..3b93e13743 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -531,6 +531,10 @@ # and can result in more stable read performance. Requires KVM # with accelerator property "dirty-ring-size" set. (Since 8.1) # +# @fixed-ram: Migrate using fixed offsets for each RAM page. Requires +# a migration URI that supports seeking, such as a file. (since +# 8.2) +# # Features: # # @deprecated: Member @block is deprecated. Use blockdev-mirror with @@ -555,7 +559,7 @@ { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', 'zero-copy-send', 'postcopy-preempt', 'switchover-ack', - 'dirty-limit'] } + 'dirty-limit', 'fixed-ram'] } =20 ## # @MigrationCapabilityStatus: --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116985; cv=none; d=zohomail.com; s=zohoarc; b=LxwPJBzOetZAA6l96W+VOgJeML6mjeMAlMwob9cQo5PIT5mMcZFy63uaH+E+dnMPkjorSnW36/4ANpQWWwHOe7FXKPF1viGp+xmAdwh0tggUjoRV8ASQYYoJEO1kySxq6PakzPr3SOoer2iAeqPvgPCWE54LyP7UCUlCSADC0BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116985; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ka60Ny7VzSASvob+/kR6dtngsegYM7LZ1xk+kD+azpo=; b=cj+hmVbbxKOioIr36Ffk3GvEwUnLkVOf9TpHfN6YWWPWksgnTSPmZIEvhYMZUFDlZZh9JDgnviou6UuvAk/AzSe80FPjkZu6PHutCQm9rOOt4ziuSKWac04HCvLz+Hf1FpXSU501Yp7Wkf0xWLzNrwA7u57Uj635oGAF3ebJevU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116985272287.85638193229863; Mon, 27 Nov 2023 12:29:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBr-0002Vq-P9; Mon, 27 Nov 2023 15:26:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBk-0002TP-0A for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:40 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBh-0002kg-IM for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:38 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E45101FB54; Mon, 27 Nov 2023 20:26:35 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CF8541379A; Mon, 27 Nov 2023 20:26:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id SPUGJXn7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ka60Ny7VzSASvob+/kR6dtngsegYM7LZ1xk+kD+azpo=; b=w4IbmlLfcIs82i+6RzE2AOPmQYhQz1dKPnRCGTMuyNWN/qnIye8suskCYpuREQcVOz1NFe V2AXYzbwmZn7w1lhqBlGeKF4KUN+EKM6BKdr0WMqAdcoKv8B3SZqMlFNjmf2/U88Tgt1u8 Z3ZV/n32uehyTXuS018ykPGGn4a6RNA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116795; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ka60Ny7VzSASvob+/kR6dtngsegYM7LZ1xk+kD+azpo=; b=rHjMVFDMEzk5bJVQkdUrN5VhqP5FPrPAF5NQYtcNFPJpE3STOPNIYHWNBcGYvR3PeNhMFF AxyL2GSvI4SoCwAw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 07/30] migration: Add fixed-ram URI compatibility check Date: Mon, 27 Nov 2023 17:25:49 -0300 Message-Id: <20231127202612.23012-8-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: -2.98 X-Spamd-Result: default: False [-2.98 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-2.88)[99.47%] 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116986451000003 The fixed-ram migration format needs a channel that supports seeking to be able to write each page to an arbitrary offset in the migration stream. Signed-off-by: Fabiano Rosas Reviewed-by: Daniel P. Berrang=C3=A9 --- - avoided overwriting errp in compatibility check --- migration/migration.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 28a34c9068..897ed1db67 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -135,10 +135,26 @@ static bool transport_supports_multi_channels(SocketA= ddress *saddr) saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK; } =20 +static bool migration_needs_seekable_channel(void) +{ + return migrate_fixed_ram(); +} + +static bool transport_supports_seeking(MigrationAddress *addr) +{ + return addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE; +} + static bool migration_channels_and_transport_compatible(MigrationAddress *addr, Error **errp) { + if (migration_needs_seekable_channel() && + !transport_supports_seeking(addr)) { + error_setg(errp, "Migration requires seekable transport (e.g. file= )"); + return false; + } + if (migration_needs_multiple_sockets() && (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) && !transport_supports_multi_channels(&addr->u.socket)) { --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116877; cv=none; d=zohomail.com; s=zohoarc; b=jF+RoT9YKziF38cePs08867UW4ebxY22EOypLxefr1i9/vXzVt1y3ZqIRkJbPYqFiQkLWMXJSczl1hkYo8INv3ZlaaLC3NSGHGQTByfFW5WYhTxkwzf1SjUs9ihzb8tlW2Lnr8eGQOKu5ZipCLHqsz4ENPE73L3BxC2V2mM01/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116877; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EUjd+KKO1a0SIehqfLmmOxI1GH8hjBJlH4OWswskEH8=; b=IH2LsSOsvDnVNbCmpe9s33FwYZO8x14+h+QRBmjisoGNJN7GtrpRIsITMa5pD62RmvfD6yARFp9fEfMFh1m76QtXVJ2p+qu/NuTg9ZLnLv80HiD2fAISg3Nv10SU+/PehoAiIiOG8mv1WJsnAY5slTDQK+qFksXe8gY+AT0JHPU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116877851195.23472150714224; Mon, 27 Nov 2023 12:27:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iBw-0002Xv-34; Mon, 27 Nov 2023 15:26:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBm-0002Tp-JS for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:43 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBk-0002kz-GV for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:42 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 61F1821B2A; Mon, 27 Nov 2023 20:26:39 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6388D1379A; Mon, 27 Nov 2023 20:26:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id uDW3Cnz7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116799; 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=EUjd+KKO1a0SIehqfLmmOxI1GH8hjBJlH4OWswskEH8=; b=Na42/nziHYOau5dLtU4U1YahrBBmjKbU6XbybaVU7soxco5amQkmOTgUPqpayNeNyEj8mW ixMfytWJFo6YXUrnBud8Yz5D9oVnuD9o27wvQSVuGKopBfl6QuTs295Adz6e3eBZQeVZc0 TpHM/jWPesVceO1nFvAu8ksbFPRcDa0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116799; 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=EUjd+KKO1a0SIehqfLmmOxI1GH8hjBJlH4OWswskEH8=; b=fQBPVpkru1rRKuDGTuxmINvJeoAlWYLiWecXr9+9iuavxBPN1uK+HSc3LBn7cVHMvKf6sF 9/18XuszpgQNr5DA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov , Paolo Bonzini , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 08/30] migration/ram: Add outgoing 'fixed-ram' migration Date: Mon, 27 Nov 2023 17:25:50 -0300 Message-Id: <20231127202612.23012-9-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[11]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116878200000001 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov Implement the outgoing migration side for the 'fixed-ram' capability. A bitmap is introduced to track which pages have been written in the migration file. Pages are written at a fixed location for every ramblock. Zero pages are ignored as they'd be zero in the destination migration as well. The migration stream is altered to put the dirty pages for a ramblock after its header instead of having a sequential stream of pages that follow the ramblock headers. Since all pages have a fixed location, RAM_SAVE_FLAG_EOS is no longer generated on every migration iteration. Without fixed-ram (current): With fixed-ram (new): --------------------- -------------------------------- | ramblock 1 header | | ramblock 1 header | --------------------- -------------------------------- | ramblock 2 header | | ramblock 1 fixed-ram header | --------------------- -------------------------------- | ... | | padding to next 1MB boundary | --------------------- | ... | | ramblock n header | -------------------------------- --------------------- | ramblock 1 pages | | RAM_SAVE_FLAG_EOS | | ... | --------------------- -------------------------------- | stream of pages | | ramblock 2 header | | (iter 1) | -------------------------------- | ... | | ramblock 2 fixed-ram header | --------------------- -------------------------------- | RAM_SAVE_FLAG_EOS | | padding to next 1MB boundary | --------------------- | ... | | stream of pages | -------------------------------- | (iter 2) | | ramblock 2 pages | | ... | | ... | --------------------- -------------------------------- | ... | | ... | --------------------- -------------------------------- | RAM_SAVE_FLAG_EOS | -------------------------------- | ... | -------------------------------- where: - ramblock header: the generic information for a ramblock, such as idstr, used_len, etc. - ramblock fixed-ram header: the new information added by this feature: bitmap of pages written, bitmap size and offset of pages in the migration file. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas --- - used a macro for alignment value - documented alignment assumptions - moved shadow_bmap debug code to multifd patch - did NOT use used_length for bmap, it breaks dirty page tracking somehow - uncommented the capability enabling - accounted for the bitmap size with ram_transferred_add() --- include/exec/ramblock.h | 8 +++ migration/ram.c | 121 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 120 insertions(+), 9 deletions(-) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 69c6a53902..e0e3f16852 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -44,6 +44,14 @@ 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/ram.c b/migration/ram.c index 8c7886ab79..4a0ab8105f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -94,6 +94,18 @@ #define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x200 /* We can't use any flag that is bigger than 0x200 */ =20 +/* + * fixed-ram migration supports O_DIRECT, so we need to make sure the + * userspace buffer, the IO operation size and the file offset are + * aligned according to the underlying device's block size. The first + * two are already aligned to page size, but we need to add padding to + * the file to align the offset. We cannot read the block size + * dynamically because the migration file can be moved between + * different systems, so use 1M to cover most block sizes and to keep + * the file offset aligned at page size as well. + */ +#define FIXED_RAM_FILE_OFFSET_ALIGNMENT 0x100000 + XBZRLECacheStats xbzrle_counters; =20 /* used by the search for pages to send */ @@ -1127,12 +1139,18 @@ static int save_zero_page(RAMState *rs, PageSearchS= tatus *pss, return 0; } =20 + stat64_add(&mig_stats.zero_pages, 1); + + if (migrate_fixed_ram()) { + /* zero pages are not transferred with fixed-ram */ + clear_bit(offset >> TARGET_PAGE_BITS, pss->block->shadow_bmap); + return 1; + } + len +=3D save_page_header(pss, file, pss->block, offset | RAM_SAVE_FLA= G_ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(pss->block->idstr, offset); - - stat64_add(&mig_stats.zero_pages, 1); ram_transferred_add(len); =20 /* @@ -1190,14 +1208,20 @@ static int save_normal_page(PageSearchStatus *pss, = RAMBlock *block, { QEMUFile *file =3D pss->pss_channel; =20 - ram_transferred_add(save_page_header(pss, pss->pss_channel, block, - offset | RAM_SAVE_FLAG_PAGE)); - if (async) { - qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, - migrate_release_ram() && - migration_in_postcopy()); + if (migrate_fixed_ram()) { + qemu_put_buffer_at(file, buf, TARGET_PAGE_SIZE, + block->pages_offset + offset); + set_bit(offset >> TARGET_PAGE_BITS, block->shadow_bmap); } else { - qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); + ram_transferred_add(save_page_header(pss, pss->pss_channel, block, + offset | RAM_SAVE_FLAG_PAGE)); + if (async) { + qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, + migrate_release_ram() && + migration_in_postcopy()); + } else { + qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); + } } ram_transferred_add(TARGET_PAGE_SIZE); stat64_add(&mig_stats.normal_pages, 1); @@ -2413,6 +2437,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(); @@ -2780,6 +2806,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(pages); block->clear_bmap_shift =3D shift; block->clear_bmap =3D bitmap_new(clear_bmap_size(pages, shift)= ); } @@ -2917,6 +2944,58 @@ void qemu_guest_free_page_hint(void *addr, size_t le= n) } } =20 +#define FIXED_RAM_HDR_VERSION 1 +struct FixedRamHeader { + uint32_t version; + /* + * The target's page size, so we know how many pages are in the + * bitmap. + */ + uint64_t page_size; + /* + * The offset in the migration file where the pages bitmap is + * found. + */ + uint64_t bitmap_offset; + /* + * The offset in the migration file where the actual pages (data) + * are found. + */ + uint64_t pages_offset; + /* end of v1 */ +} QEMU_PACKED; +typedef struct FixedRamHeader FixedRamHeader; + +static void fixed_ram_insert_header(QEMUFile *file, RAMBlock *block) +{ + g_autofree FixedRamHeader *header; + size_t header_size, bitmap_size; + long num_pages; + + header =3D g_new0(FixedRamHeader, 1); + header_size =3D sizeof(FixedRamHeader); + + num_pages =3D block->used_length >> TARGET_PAGE_BITS; + bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); + + /* + * Save the file offsets of where the bitmap and the pages should + * go as they are written at the end of migration and during the + * iterative phase, respectively. + */ + block->bitmap_offset =3D qemu_get_offset(file) + header_size; + block->pages_offset =3D ROUND_UP(block->bitmap_offset + + bitmap_size, + FIXED_RAM_FILE_OFFSET_ALIGNMENT); + + header->version =3D cpu_to_be32(FIXED_RAM_HDR_VERSION); + header->page_size =3D cpu_to_be64(TARGET_PAGE_SIZE); + header->bitmap_offset =3D cpu_to_be64(block->bitmap_offset); + header->pages_offset =3D cpu_to_be64(block->pages_offset); + + qemu_put_buffer(file, (uint8_t *) header, header_size); +} + /* * Each of ram_save_setup, ram_save_iterate and ram_save_complete has * long-running RCU critical section. When rcu-reclaims in the code @@ -2966,6 +3045,13 @@ static int ram_save_setup(QEMUFile *f, void *opaque) if (migrate_ignore_shared()) { qemu_put_be64(f, block->mr->addr); } + + if (migrate_fixed_ram()) { + fixed_ram_insert_header(f, block); + /* prepare offset for next ramblock */ + qemu_set_offset(f, block->pages_offset + block->used_lengt= h, + SEEK_SET); + } } } =20 @@ -2999,6 +3085,19 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return qemu_fflush(f); } =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_transferred_add(bitmap_size); + } +} + /** * ram_save_iterate: iterative stage for migration * @@ -3188,6 +3287,10 @@ static int ram_save_complete(QEMUFile *f, void *opaq= ue) return ret; } =20 + if (migrate_fixed_ram()) { + ram_save_shadow_bmap(f); + } + if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) { qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); } --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117101; cv=none; d=zohomail.com; s=zohoarc; b=j6QZGHv5GBGSQTYOKMJteyO2v19KCfXFBo4rzCZGDDAgg1Zd2I/Za9oF9VVuZHjtSb6YA1ZxHQub+vdBVhfJ4b2n1M/gXOAzr4kwYPF129ZG8eiid2MQ3aNh8LfIReSFQQJ/NR5Q2IFuSBoV05Uwv0Wz10R1jQL3np5eFqpshp4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117101; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=u3Y3JvwparVu6jz/rrX6XYg3Vvu0prcpcfTxv1yblC0=; b=QldgsKUlRwSEe4+MLW0AoCD000pYv/yitYgYKqeI2Q4fNJn3ItoUyLcFOLH2b7biZ//wUvO+xu9npLHkPUZ+/6jJdFwfVIz2tefsvX0FD1PCdwpObka1m5HUlAEaMeF7ZSvhD8xHID9DvQ9TQWdwJ4b0rmS9UEgB2CYMULJ3B+U= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111710172572.97262609806694; Mon, 27 Nov 2023 12:31:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC1-0002dZ-6c; Mon, 27 Nov 2023 15:26:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBw-0002ag-Lt for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:53 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBr-0002lO-Ex for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:52 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2C89D21B4C; Mon, 27 Nov 2023 20:26:42 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D4E4F1379A; Mon, 27 Nov 2023 20:26:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id cFVfJn/7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116802; 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=u3Y3JvwparVu6jz/rrX6XYg3Vvu0prcpcfTxv1yblC0=; b=W/xsn22sKvYa/xiVM1HSkVg2Nkbf9cNwSyiuCdJwjs9M7e/YSKQaaWvF/em43fQYXd1EBn lx2JZazgdyuSX9elJZwksF2UKPptFJ6+sUfgRZ8cJBYurTIjdAGhhRWDYRtrvY8eJFfiB1 1szZK3yXobe03XsSikYtKi10zjr7XGs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116802; 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=u3Y3JvwparVu6jz/rrX6XYg3Vvu0prcpcfTxv1yblC0=; b=HPd2KiQd3fShUEv0HXYM3lhE6gnTfAKIsI70VvJWnsA1pTmJAbNYKvhlkKRj1Reie7cnoY jPonGWU/5A2AzDAg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov Subject: [RFC PATCH v3 09/30] migration/ram: Add incoming 'fixed-ram' migration Date: Mon, 27 Nov 2023 17:25:51 -0300 Message-Id: <20231127202612.23012-10-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[8]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117103293000001 Content-Type: text/plain; charset="utf-8" Add the necessary code to parse the format changes for the '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. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas --- - added sanity check for pages_offset alignment - s/parsing/reading - used Error - fixed buffer size computation, now allowing an arbitrary limit - fixed dereference of pointer to packed struct member in endianness conversion --- migration/ram.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 4a0ab8105f..08604222f2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -106,6 +106,12 @@ */ #define FIXED_RAM_FILE_OFFSET_ALIGNMENT 0x100000 =20 +/* + * When doing fixed-ram migration, this is the amount we read from the + * pages region in the migration file at a time. + */ +#define FIXED_RAM_LOAD_BUF_SIZE 0x100000 + XBZRLECacheStats xbzrle_counters; =20 /* used by the search for pages to send */ @@ -2996,6 +3002,35 @@ static void fixed_ram_insert_header(QEMUFile *file, = RAMBlock *block) qemu_put_buffer(file, (uint8_t *) header, header_size); } =20 +static bool fixed_ram_read_header(QEMUFile *file, FixedRamHeader *header, + Error **errp) +{ + size_t ret, header_size =3D sizeof(FixedRamHeader); + + ret =3D qemu_get_buffer(file, (uint8_t *)header, header_size); + if (ret !=3D header_size) { + error_setg(errp, "Could not read whole fixed-ram migration header " + "(expected %zd, got %zd bytes)", header_size, ret); + return false; + } + + /* migration stream is big-endian */ + header->version =3D be32_to_cpu(header->version); + + if (header->version > FIXED_RAM_HDR_VERSION) { + error_setg(errp, "Migration fixed-ram capability version mismatch " + "(expected %d, got %d)", FIXED_RAM_HDR_VERSION, + header->version); + return false; + } + + header->page_size =3D be64_to_cpu(header->page_size); + header->bitmap_offset =3D be64_to_cpu(header->bitmap_offset); + header->pages_offset =3D be64_to_cpu(header->pages_offset); + + return true; +} + /* * Each of ram_save_setup, ram_save_iterate and ram_save_complete has * long-running RCU critical section. When rcu-reclaims in the code @@ -3892,6 +3927,80 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +static void read_ramblock_fixed_ram(QEMUFile *f, RAMBlock *block, + long num_pages, unsigned long *bitmap) +{ + unsigned long set_bit_idx, clear_bit_idx; + ram_addr_t offset; + void *host; + size_t read, unread, size, buf_size =3D FIXED_RAM_LOAD_BUF_SIZE; + + for (set_bit_idx =3D find_first_bit(bitmap, num_pages); + set_bit_idx < num_pages; + set_bit_idx =3D find_next_bit(bitmap, num_pages, clear_bit_idx + = 1)) { + + clear_bit_idx =3D find_next_zero_bit(bitmap, num_pages, set_bit_id= x + 1); + + unread =3D TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx); + offset =3D set_bit_idx << TARGET_PAGE_BITS; + + while (unread > 0) { + host =3D host_from_ram_block_offset(block, offset); + size =3D MIN(unread, buf_size); + + read =3D qemu_get_buffer_at(f, host, size, + block->pages_offset + offset); + offset +=3D read; + unread -=3D read; + } + } +} + +static int parse_ramblock_fixed_ram(QEMUFile *f, RAMBlock *block, + ram_addr_t length, Error **errp) +{ + g_autofree unsigned long *bitmap =3D NULL; + FixedRamHeader header; + size_t bitmap_size; + long num_pages; + + if (!fixed_ram_read_header(f, &header, errp)) { + return -EINVAL; + } + + block->pages_offset =3D header.pages_offset; + + /* + * Check the alignment of the file region that contains pages. We + * don't enforce FIXED_RAM_FILE_OFFSET_ALIGNMENT to allow that + * value to change in the future. Do only a sanity check with page + * size alignment. + */ + if (!QEMU_IS_ALIGNED(block->pages_offset, TARGET_PAGE_SIZE)) { + error_setg(errp, + "Error reading ramblock %s pages, region has bad alignm= ent", + block->idstr); + return -EINVAL; + } + + num_pages =3D length / header.page_size; + bitmap_size =3D BITS_TO_LONGS(num_pages) * sizeof(unsigned long); + + bitmap =3D g_malloc0(bitmap_size); + if (qemu_get_buffer_at(f, (uint8_t *)bitmap, bitmap_size, + header.bitmap_offset) !=3D bitmap_size) { + error_setg(errp, "Error reading dirty bitmap"); + return -EINVAL; + } + + read_ramblock_fixed_ram(f, block, num_pages, bitmap); + + /* Skip pages array */ + qemu_set_offset(f, block->pages_offset + length, SEEK_SET); + + return 0; +} + static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length) { int ret =3D 0; @@ -3900,6 +4009,16 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *blo= ck, ram_addr_t length) =20 assert(block); =20 + if (migrate_fixed_ram()) { + Error *local_err =3D NULL; + + ret =3D parse_ramblock_fixed_ram(f, block, length, &local_err); + if (local_err) { + error_report_err(local_err); + } + return ret; + } + if (!qemu_ram_is_migratable(block)) { error_report("block %s should not be migrated !", block->idstr); return -EINVAL; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117085656542.7545980556998; Mon, 27 Nov 2023 12:31:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC1-0002db-I5; Mon, 27 Nov 2023 15:26:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBw-0002Ym-FK for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:53 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBr-0002ld-M2 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:52 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9C5021FB54; Mon, 27 Nov 2023 20:26:45 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9DC6D1379A; Mon, 27 Nov 2023 20:26:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6E8EGYL7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:42 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Nikolay Borisov , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [RFC PATCH v3 10/30] tests/qtest: migration-test: Add tests for fixed-ram file-based migration Date: Mon, 27 Nov 2023 17:25:52 -0300 Message-Id: <20231127202612.23012-11-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.79 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-1.00)[-0.996]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[11]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.79 X-Rspamd-Queue-Id: 9C5021FB54 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117086898000017 Content-Type: text/plain; charset="utf-8" From: Nikolay Borisov Add basic tests for 'fixed-ram' migration. Signed-off-by: Nikolay Borisov Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- tests/qtest/migration-test.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 0fbaa6a90f..96a6217af0 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2135,6 +2135,14 @@ static void *test_mode_reboot_start(QTestState *from= , QTestState *to) return NULL; } =20 +static void *migrate_fixed_ram_start(QTestState *from, QTestState *to) +{ + migrate_set_capability(from, "fixed-ram", true); + migrate_set_capability(to, "fixed-ram", true); + + return NULL; +} + static void test_mode_reboot(void) { g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, @@ -2149,6 +2157,32 @@ static void test_mode_reboot(void) test_file_common(&args, true); } =20 +static void test_precopy_file_fixed_ram_live(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_fixed_ram_start, + }; + + test_file_common(&args, false); +} + +static void test_precopy_file_fixed_ram(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_fixed_ram_start, + }; + + test_file_common(&args, true); +} + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -3392,6 +3426,11 @@ int main(int argc, char **argv) qtest_add_func("/migration/mode/reboot", test_mode_reboot); } =20 + qtest_add_func("/migration/precopy/file/fixed-ram", + test_precopy_file_fixed_ram); + qtest_add_func("/migration/precopy/file/fixed-ram/live", + test_precopy_file_fixed_ram_live); + #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117035046461.02030069845387; Mon, 27 Nov 2023 12:30:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC2-0002di-6q; Mon, 27 Nov 2023 15:26:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBy-0002bJ-6e for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:56 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBu-0002m4-K8 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:53 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3546121B59; Mon, 27 Nov 2023 20:26:48 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1E80D1379A; Mon, 27 Nov 2023 20:26:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id oEwaNYX7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:45 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 11/30] migration/multifd: Allow multifd without packets Date: Mon, 27 Nov 2023 17:25:53 -0300 Message-Id: <20231127202612.23012-12-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.989]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: 3546121B59 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117035527000001 Content-Type: text/plain; charset="utf-8" For the upcoming support to the new 'fixed-ram' migration stream format, we cannot use multifd packets because each write into the ramblock section in the migration file is expected to contain only the guest pages. They are written at their respective offsets relative to the ramblock section header. There is no space for the packet information and the expected gains from the new approach come partly from being able to write the pages sequentially without extraneous data in between. The new format also doesn't need the packets and all necessary information can be taken from the standard migration headers with some (future) changes to multifd code. Use the presence of the fixed-ram capability to decide whether to send packets. For now this has no effect as fixed-ram cannot yet be enabled with multifd. Signed-off-by: Fabiano Rosas --- - moved more of the packet code under use_packets --- migration/multifd.c | 138 +++++++++++++++++++++++++++----------------- migration/options.c | 5 ++ migration/options.h | 1 + 3 files changed, 91 insertions(+), 53 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index ec58c58082..9625640d61 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -654,18 +654,22 @@ static void *multifd_send_thread(void *opaque) Error *local_err =3D NULL; int ret =3D 0; bool use_zero_copy_send =3D migrate_zero_copy_send(); + bool use_packets =3D migrate_multifd_packets(); =20 thread =3D migration_threads_add(p->name, qemu_get_thread_id()); =20 trace_multifd_send_thread_start(p->id); rcu_register_thread(); =20 - if (multifd_send_initial_packet(p, &local_err) < 0) { - ret =3D -1; - goto out; + if (use_packets) { + if (multifd_send_initial_packet(p, &local_err) < 0) { + ret =3D -1; + goto out; + } + + /* initial packet */ + p->num_packets =3D 1; } - /* initial packet */ - p->num_packets =3D 1; =20 while (true) { qemu_sem_post(&multifd_send_state->channels_ready); @@ -677,11 +681,10 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(&p->mutex); =20 if (p->pending_job) { - uint64_t packet_num =3D p->packet_num; uint32_t flags; p->normal_num =3D 0; =20 - if (use_zero_copy_send) { + if (!use_packets || use_zero_copy_send) { p->iovs_num =3D 0; } else { p->iovs_num =3D 1; @@ -699,16 +702,20 @@ static void *multifd_send_thread(void *opaque) break; } } - multifd_send_fill_packet(p); + + if (use_packets) { + multifd_send_fill_packet(p); + p->num_packets++; + } + flags =3D p->flags; p->flags =3D 0; - p->num_packets++; p->total_normal_pages +=3D p->normal_num; p->pages->num =3D 0; p->pages->block =3D NULL; qemu_mutex_unlock(&p->mutex); =20 - trace_multifd_send(p->id, packet_num, p->normal_num, flags, + trace_multifd_send(p->id, p->packet_num, p->normal_num, flags, p->next_packet_size); =20 if (use_zero_copy_send) { @@ -718,7 +725,7 @@ static void *multifd_send_thread(void *opaque) if (ret !=3D 0) { break; } - } else { + } else if (use_packets) { /* Send header using the same writev call */ p->iov[0].iov_len =3D p->packet_len; p->iov[0].iov_base =3D p->packet; @@ -904,6 +911,7 @@ int multifd_save_setup(Error **errp) { int thread_count; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + bool use_packets =3D migrate_multifd_packets(); uint8_t i; =20 if (!migrate_multifd()) { @@ -928,14 +936,20 @@ int multifd_save_setup(Error **errp) p->pending_job =3D 0; p->id =3D i; p->pages =3D multifd_pages_init(page_count); - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); - p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); + + if (use_packets) { + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + p->packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); + p->packet->version =3D cpu_to_be32(MULTIFD_VERSION); + + /* We need one extra place for the packet header */ + p->iov =3D g_new0(struct iovec, page_count + 1); + } else { + p->iov =3D g_new0(struct iovec, page_count); + } p->name =3D g_strdup_printf("multifdsend_%d", i); - /* We need one extra place for the packet header */ - p->iov =3D g_new0(struct iovec, page_count + 1); p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); p->page_count =3D page_count; @@ -1067,7 +1081,7 @@ void multifd_recv_sync_main(void) { int i; =20 - if (!migrate_multifd()) { + if (!migrate_multifd() || !migrate_multifd_packets()) { return; } for (i =3D 0; i < migrate_multifd_channels(); i++) { @@ -1094,38 +1108,44 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; Error *local_err =3D NULL; + bool use_packets =3D migrate_multifd_packets(); int ret; =20 trace_multifd_recv_thread_start(p->id); rcu_register_thread(); =20 while (true) { - uint32_t flags; + uint32_t flags =3D 0; + p->normal_num =3D 0; =20 if (p->quit) { break; } =20 - ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ - break; - } + if (use_packets) { + ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ + break; + } + + qemu_mutex_lock(&p->mutex); + ret =3D multifd_recv_unfill_packet(p, &local_err); + if (ret) { + qemu_mutex_unlock(&p->mutex); + break; + } + p->num_packets++; + + flags =3D p->flags; + /* recv methods don't know how to handle the SYNC flag */ + p->flags &=3D ~MULTIFD_FLAG_SYNC; + trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, + p->next_packet_size); =20 - qemu_mutex_lock(&p->mutex); - ret =3D multifd_recv_unfill_packet(p, &local_err); - if (ret) { - qemu_mutex_unlock(&p->mutex); - break; + p->total_normal_pages +=3D p->normal_num; } =20 - flags =3D p->flags; - /* recv methods don't know how to handle the SYNC flag */ - p->flags &=3D ~MULTIFD_FLAG_SYNC; - trace_multifd_recv(p->id, p->packet_num, p->normal_num, flags, - p->next_packet_size); - p->num_packets++; - p->total_normal_pages +=3D p->normal_num; qemu_mutex_unlock(&p->mutex); =20 if (p->normal_num) { @@ -1135,7 +1155,7 @@ static void *multifd_recv_thread(void *opaque) } } =20 - if (flags & MULTIFD_FLAG_SYNC) { + if (use_packets && (flags & MULTIFD_FLAG_SYNC)) { qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); } @@ -1159,6 +1179,7 @@ int multifd_load_setup(Error **errp) { int thread_count; uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); + bool use_packets =3D migrate_multifd_packets(); uint8_t i; =20 /* @@ -1183,9 +1204,12 @@ int multifd_load_setup(Error **errp) qemu_sem_init(&p->sem_sync, 0); p->quit =3D false; p->id =3D i; - p->packet_len =3D sizeof(MultiFDPacket_t) - + sizeof(uint64_t) * page_count; - p->packet =3D g_malloc0(p->packet_len); + + if (use_packets) { + p->packet_len =3D sizeof(MultiFDPacket_t) + + sizeof(uint64_t) * page_count; + p->packet =3D g_malloc0(p->packet_len); + } p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); @@ -1231,18 +1255,27 @@ void multifd_recv_new_channel(QIOChannel *ioc, Erro= r **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; - int id; + bool use_packets =3D migrate_multifd_packets(); + int id, num_packets =3D 0; =20 - id =3D multifd_recv_initial_packet(ioc, &local_err); - if (id < 0) { - multifd_recv_terminate_threads(local_err); - error_propagate_prepend(errp, local_err, - "failed to receive packet" - " via multifd channel %d: ", - qatomic_read(&multifd_recv_state->count)); - return; + if (use_packets) { + id =3D multifd_recv_initial_packet(ioc, &local_err); + if (id < 0) { + multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + qatomic_read(&multifd_recv_state->coun= t)); + return; + } + trace_multifd_recv_new_channel(id); + + /* initial packet */ + num_packets =3D 1; + } else { + /* next patch gives this a meaningful value */ + id =3D 0; } - trace_multifd_recv_new_channel(id); =20 p =3D &multifd_recv_state->params[id]; if (p->c !=3D NULL) { @@ -1253,9 +1286,8 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) return; } p->c =3D ioc; + p->num_packets =3D num_packets; object_ref(OBJECT(ioc)); - /* initial packet */ - p->num_packets =3D 1; =20 p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, diff --git a/migration/options.c b/migration/options.c index 775428a8a5..10730b13ba 100644 --- a/migration/options.c +++ b/migration/options.c @@ -385,6 +385,11 @@ bool migrate_multifd_flush_after_each_section(void) return s->multifd_flush_after_each_section; } =20 +bool migrate_multifd_packets(void) +{ + return !migrate_fixed_ram(); +} + bool migrate_postcopy(void) { return migrate_postcopy_ram() || migrate_dirty_bitmaps(); diff --git a/migration/options.h b/migration/options.h index 8680a10b79..8a19d6939c 100644 --- a/migration/options.h +++ b/migration/options.h @@ -56,6 +56,7 @@ bool migrate_zero_copy_send(void); */ =20 bool migrate_multifd_flush_after_each_section(void); +bool migrate_multifd_packets(void); bool migrate_postcopy(void); bool migrate_rdma(void); bool migrate_tls(void); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111708263957.63432609905249; Mon, 27 Nov 2023 12:31:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC1-0002df-Ul; Mon, 27 Nov 2023 15:26:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iBy-0002ar-3u for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:56 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBw-0002mL-FN for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:53 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BA1891FB79; Mon, 27 Nov 2023 20:26:50 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A76711379A; Mon, 27 Nov 2023 20:26:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id GMdLG4j7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:48 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 12/30] migration/multifd: Allow QIOTask error reporting without an object Date: Mon, 27 Nov 2023 17:25:54 -0300 Message-Id: <20231127202612.23012-13-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [9.19 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.985]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-1.61)[92.53%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 9.19 X-Rspamd-Queue-Id: BA1891FB79 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117082828000007 Content-Type: text/plain; charset="utf-8" The only way for the channel backend to report an error to the multifd core during creation is by setting the QIOTask error. We must allow the channel backend to set the error even if the QIOChannel has failed to be created, which means the QIOTask source object would be NULL. At multifd_new_send_channel_async() move the QOM casting of the channel until after we have checked for the QIOTask error. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- context: When doing multifd + file, it's possible that we fail to open the file. I'll use the empty QIOTask to report the error back to multifd. --- migration/multifd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 9625640d61..123ff0dec0 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -865,8 +865,7 @@ static bool multifd_channel_connect(MultiFDSendParams *= p, return true; } =20 -static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, - QIOChannel *ioc, Error *err) +static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, Error *= err) { migrate_set_error(migrate_get_current(), err); /* Error happen, we need to tell who pay attention to me */ @@ -878,20 +877,20 @@ static void multifd_new_send_channel_cleanup(MultiFDS= endParams *p, * its status. */ p->quit =3D true; - object_unref(OBJECT(ioc)); error_free(err); } =20 static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) { MultiFDSendParams *p =3D opaque; - QIOChannel *ioc =3D QIO_CHANNEL(qio_task_get_source(task)); + Object *obj =3D qio_task_get_source(task); Error *local_err =3D NULL; =20 trace_multifd_new_send_channel_async(p->id); if (!qio_task_propagate_error(task, &local_err)) { - p->c =3D ioc; - qio_channel_set_delay(p->c, false); + QIOChannel *ioc =3D QIO_CHANNEL(obj); + + qio_channel_set_delay(ioc, false); p->running =3D true; if (multifd_channel_connect(p, ioc, &local_err)) { return; @@ -899,7 +898,8 @@ static void multifd_new_send_channel_async(QIOTask *tas= k, gpointer opaque) } =20 trace_multifd_new_send_channel_async_error(p->id, local_err); - multifd_new_send_channel_cleanup(p, ioc, local_err); + multifd_new_send_channel_cleanup(p, local_err); + object_unref(obj); } =20 static void multifd_new_send_channel_create(gpointer opaque) --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116905; cv=none; d=zohomail.com; s=zohoarc; b=H7FOwottMr+vGyA7U5ydZTAEZAXs2Je+MFjW5G7wlLFASrxUiaQO1OzduDvDWndJglZFAIVowK5eC3ZAghnlfXR/dMfmZQGSCJhtKEx92XClYxv3Q6ZTkSvRJkVowFBPuVARU/N/ZbC8jcDYw5y6L72I91QaPhyVK3osz/qBBPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116905; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ySHJGr28eNmdndGPA24e3H+ebuE7zi2Ok5x+3aj7lC8=; b=f9k/Ynw3QZZf4o3VSYP2hoxybXQVaXsUZYUu0j4IhcCtnyWIv3/gutqwJ9xAgHkfv623IQisjQCVrF6hGYxp6AyfPs/qqEVDf22NbqKrrAqjC5TBeSgSUSxlmFhlakS9GAMm6csL7a5abJz7O1G/qbdPEUiHTix/+Um6FWPVnRk= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116905569953.041084329258; Mon, 27 Nov 2023 12:28:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC2-0002dm-O7; Mon, 27 Nov 2023 15:26:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iC0-0002cP-FX for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:56 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iBy-0002mu-Gp for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:56 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 516E121B32; Mon, 27 Nov 2023 20:26:53 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3EDCE1379A; Mon, 27 Nov 2023 20:26:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id YGPMAYv7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116813; 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=ySHJGr28eNmdndGPA24e3H+ebuE7zi2Ok5x+3aj7lC8=; b=IudeiSeNKoKId1dotlW0Jfxj3ipFeSBMuEFVaWslPzNYnqkfN92YP3qpdOMpztpHvUmSuk FuMNVGYnxsEs89E4FcQFl67fSsowqqphWce3UnS0WxSTUMpybHqOUXCa7lUabSPuiRXydt yDFkSeLeFoVaWcyWjqXZCC747o0fVwg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116813; 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=ySHJGr28eNmdndGPA24e3H+ebuE7zi2Ok5x+3aj7lC8=; b=dukanSq4HybK3/tQeSiRFeEbYD9yLRPtx8PzPTeRm3QNdb67qTo5uuUA4u8QLeAq0BNcJ+ 5/LqhY7zplJET2CQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 13/30] migration/multifd: Add outgoing QIOChannelFile support Date: Mon, 27 Nov 2023 17:25:55 -0300 Message-Id: <20231127202612.23012-14-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116907070000003 Content-Type: text/plain; charset="utf-8" Allow multifd to open file-backed channels. This will be used when enabling the fixed-ram migration stream format which expects a seekable transport. The QIOChannel read and write methods will use the preadv/pwritev versions which don't update the file offset at each call so we can reuse the fd without re-opening for every channel. Note that this is just setup code and multifd cannot yet make use of the file channels. Signed-off-by: Fabiano Rosas --- - open multifd channels with O_WRONLY and no mode - stop cancelling migration and propagate error via qio_task --- migration/file.c | 47 +++++++++++++++++++++++++++++++++++++++++-- migration/file.h | 5 +++++ migration/multifd.c | 14 +++++++++++-- migration/options.c | 7 +++++++ migration/options.h | 1 + migration/qemu-file.h | 1 - 6 files changed, 70 insertions(+), 5 deletions(-) diff --git a/migration/file.c b/migration/file.c index 5d4975f43e..67d6f42da7 100644 --- a/migration/file.c +++ b/migration/file.c @@ -17,6 +17,10 @@ =20 #define OFFSET_OPTION ",offset=3D" =20 +static struct FileOutgoingArgs { + char *fname; +} outgoing_args; + /* Remove the offset option from @filespec and return it in @offsetp. */ =20 int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp) @@ -36,6 +40,42 @@ int file_parse_offset(char *filespec, uint64_t *offsetp,= Error **errp) return 0; } =20 +static void qio_channel_file_connect_worker(QIOTask *task, gpointer opaque) +{ + /* noop */ +} + +int file_send_channel_destroy(QIOChannel *ioc) +{ + if (ioc) { + qio_channel_close(ioc, NULL); + object_unref(OBJECT(ioc)); + } + g_free(outgoing_args.fname); + outgoing_args.fname =3D NULL; + + return 0; +} + +void file_send_channel_create(QIOTaskFunc f, void *data) +{ + QIOChannelFile *ioc; + QIOTask *task; + Error *err =3D NULL; + int flags =3D O_WRONLY; + + ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, &err); + + task =3D qio_task_new(OBJECT(ioc), f, (gpointer)data, NULL); + if (!ioc) { + qio_task_set_error(task, err); + return; + } + + qio_task_run_in_thread(task, qio_channel_file_connect_worker, + (gpointer)data, NULL, NULL); +} + void file_start_outgoing_migration(MigrationState *s, FileMigrationArgs *file_args, Error **e= rrp) { @@ -43,15 +83,18 @@ void file_start_outgoing_migration(MigrationState *s, g_autofree char *filename =3D g_strdup(file_args->filename); uint64_t offset =3D file_args->offset; QIOChannel *ioc; + int flags =3D O_CREAT | O_TRUNC | O_WRONLY; + mode_t mode =3D 0660; =20 trace_migration_file_outgoing(filename); =20 - fioc =3D qio_channel_file_new_path(filename, O_CREAT | O_WRONLY | O_TR= UNC, - 0600, errp); + fioc =3D qio_channel_file_new_path(filename, flags, mode, errp); if (!fioc) { return; } =20 + outgoing_args.fname =3D g_strdup(filename); + ioc =3D QIO_CHANNEL(fioc); if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) { return; diff --git a/migration/file.h b/migration/file.h index 37d6a08bfc..511019b319 100644 --- a/migration/file.h +++ b/migration/file.h @@ -9,10 +9,15 @@ #define QEMU_MIGRATION_FILE_H =20 #include "qapi/qapi-types-migration.h" +#include "io/task.h" +#include "channel.h" =20 void file_start_incoming_migration(FileMigrationArgs *file_args, Error **e= rrp); =20 void file_start_outgoing_migration(MigrationState *s, FileMigrationArgs *file_args, Error **e= rrp); int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); + +void file_send_channel_create(QIOTaskFunc f, void *data); +int file_send_channel_destroy(QIOChannel *ioc); #endif diff --git a/migration/multifd.c b/migration/multifd.c index 123ff0dec0..427740aab6 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -17,6 +17,7 @@ #include "exec/ramblock.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "file.h" #include "ram.h" #include "migration.h" #include "migration-stats.h" @@ -28,6 +29,7 @@ #include "threadinfo.h" #include "options.h" #include "qemu/yank.h" +#include "io/channel-file.h" #include "io/channel-socket.h" #include "yank_functions.h" =20 @@ -511,7 +513,11 @@ static void multifd_send_terminate_threads(Error *err) =20 static int multifd_send_channel_destroy(QIOChannel *send) { - return socket_send_channel_destroy(send); + if (migrate_to_file()) { + return file_send_channel_destroy(send); + } else { + return socket_send_channel_destroy(send); + } } =20 void multifd_save_cleanup(void) @@ -904,7 +910,11 @@ static void multifd_new_send_channel_async(QIOTask *ta= sk, gpointer opaque) =20 static void multifd_new_send_channel_create(gpointer opaque) { - socket_send_channel_create(multifd_new_send_channel_async, opaque); + if (migrate_to_file()) { + file_send_channel_create(multifd_new_send_channel_async, opaque); + } else { + socket_send_channel_create(multifd_new_send_channel_async, opaque); + } } =20 int multifd_save_setup(Error **errp) diff --git a/migration/options.c b/migration/options.c index 10730b13ba..f671e24758 100644 --- a/migration/options.c +++ b/migration/options.c @@ -409,6 +409,13 @@ bool migrate_tls(void) return s->parameters.tls_creds && *s->parameters.tls_creds; } =20 +bool migrate_to_file(void) +{ + MigrationState *s =3D migrate_get_current(); + + return qemu_file_is_seekable(s->to_dst_file); +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN =3D 0, WT_SUPPORT_ABSENT, diff --git a/migration/options.h b/migration/options.h index 8a19d6939c..84628a76e8 100644 --- a/migration/options.h +++ b/migration/options.h @@ -60,6 +60,7 @@ bool migrate_multifd_packets(void); bool migrate_postcopy(void); bool migrate_rdma(void); bool migrate_tls(void); +bool migrate_to_file(void); =20 /* capabilities helpers */ =20 diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 32fd4a34fd..78ea21ab98 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -83,5 +83,4 @@ size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf= , size_t buflen, off_t pos); =20 QIOChannel *qemu_file_get_ioc(QEMUFile *file); - #endif --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117079046547.7113010349656; Mon, 27 Nov 2023 12:31:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC5-0002hm-BF; Mon, 27 Nov 2023 15:27:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iC2-0002dv-V9 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:58 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iC1-0002ng-1Z for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:26:58 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D9EBB1FB54; Mon, 27 Nov 2023 20:26:55 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C885B1379A; Mon, 27 Nov 2023 20:26:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id YHZlI437ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:53 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 14/30] migration/multifd: Add incoming QIOChannelFile support Date: Mon, 27 Nov 2023 17:25:56 -0300 Message-Id: <20231127202612.23012-15-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.987]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: D9EBB1FB54 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117080703000003 Content-Type: text/plain; charset="utf-8" On the receiving side we don't need to differentiate between main channel and threads, so whichever channel is defined first gets to be the main one. And since there are no packets, use the atomic channel count to index into the params array. Signed-off-by: Fabiano Rosas --- - stop setting offset in secondary channels - check for packets when peeking --- migration/file.c | 36 ++++++++++++++++++++++++++++-------- migration/migration.c | 3 ++- migration/multifd.c | 3 +-- migration/multifd.h | 1 + 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/migration/file.c b/migration/file.c index 67d6f42da7..62ba994109 100644 --- a/migration/file.c +++ b/migration/file.c @@ -7,12 +7,14 @@ =20 #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qemu/error-report.h" #include "qapi/error.h" #include "channel.h" #include "file.h" #include "migration.h" #include "io/channel-file.h" #include "io/channel-util.h" +#include "options.h" #include "trace.h" =20 #define OFFSET_OPTION ",offset=3D" @@ -117,22 +119,40 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) g_autofree char *filename =3D g_strdup(file_args->filename); QIOChannelFile *fioc =3D NULL; uint64_t offset =3D file_args->offset; - QIOChannel *ioc; + int channels =3D 1; + int i =3D 0, fd; =20 trace_migration_file_incoming(filename); =20 fioc =3D qio_channel_file_new_path(filename, O_RDONLY, 0, errp); if (!fioc) { + goto out; + } + + if (offset && + qio_channel_io_seek(QIO_CHANNEL(fioc), offset, SEEK_SET, errp) < 0= ) { return; } =20 - ioc =3D QIO_CHANNEL(fioc); - if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) { + if (migrate_multifd()) { + channels +=3D migrate_multifd_channels(); + } + + fd =3D fioc->fd; + + do { + QIOChannel *ioc =3D QIO_CHANNEL(fioc); + + qio_channel_set_name(ioc, "migration-file-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + file_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); + } while (++i < channels && (fioc =3D qio_channel_file_new_fd(fd))); + +out: + if (!fioc) { + error_setg(errp, "Error creating migration incoming channel"); return; } - qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - file_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); } diff --git a/migration/migration.c b/migration/migration.c index 897ed1db67..16689171ab 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -838,7 +838,8 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) uint32_t channel_magic =3D 0; int ret =3D 0; =20 - if (migrate_multifd() && !migrate_postcopy_ram() && + if (migrate_multifd() && migrate_multifd_packets() && + !migrate_postcopy_ram() && qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { /* * With multiple channels, it is possible that we receive channels diff --git a/migration/multifd.c b/migration/multifd.c index 427740aab6..3476fac49f 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1283,8 +1283,7 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) /* initial packet */ num_packets =3D 1; } else { - /* next patch gives this a meaningful value */ - id =3D 0; + id =3D qatomic_read(&multifd_recv_state->count); } =20 p =3D &multifd_recv_state->params[id]; diff --git a/migration/multifd.h b/migration/multifd.h index a835643b48..a112ec7ac6 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -18,6 +18,7 @@ void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); void multifd_load_cleanup(void); void multifd_load_shutdown(void); +bool multifd_recv_first_channel(void); bool multifd_recv_all_channels_created(void); void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); void multifd_recv_sync_main(void); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117084; cv=none; d=zohomail.com; s=zohoarc; b=WqZGDSgJ8Ek8+hz/BQtz9gtYT2hX8UI73IByEKZnZ6i4yYzUrrRT8Ru3BCeEXUx9OInLf62sw6blnF7GgzSo0iJ3oMTAwAT7rz5DZOl+q2vjWUbloY/FVvHfEokHbOdXGsDSgBH0gTGBv2hKBXoRa7WUZHX32FptMMSd9ROmKVU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117084; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/195pm8KQkPAf9kNkJxFoF+O8UtxYL5GHt4E5CxVLQc=; b=hGevyKy4Ou4Bg3N8+Erm3swxtE+F9rl41GZwhw24tGF+r3iVE/ZfpuVddO/Swma2Y+fwqmfVq/DhuUdVl4r7opRBpr7c/61h3jOPPlcQX570aqa6+GU7PGdzrQliUVbgK3dOoiw0mou7gSHlKQIF/nQKQPZe6CJL6TRdUOrRP5c= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117084975889.5188168032432; Mon, 27 Nov 2023 12:31:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC8-0002jt-7O; Mon, 27 Nov 2023 15:27:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iC5-0002hv-M6 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:01 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iC3-0002oG-UW for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:01 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6D54221B32; Mon, 27 Nov 2023 20:26:58 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 5B48F1379A; Mon, 27 Nov 2023 20:26:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id yP6oCJD7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116818; 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=/195pm8KQkPAf9kNkJxFoF+O8UtxYL5GHt4E5CxVLQc=; b=Ay2OKCv0GHxhRKCV2ShZGY1Syhsc7V4PN9qt5QpRUqN9/CsmuzVJBs92pxTfwJ9F9D5G2n bM1qg2tlC/3MArFtwf6jYVXb0UzwljCVw0sSzCzrz6raBK08L25AfDeIQy1BDHqT6Fdu3X gRyTFaMK+J1rnvp0k05rsa7Pbo+a0xU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116818; 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=/195pm8KQkPAf9kNkJxFoF+O8UtxYL5GHt4E5CxVLQc=; b=IWQ6YkiKdCNrpJzEZwALTwDMN6jX86dUxdzKJ0oqMgn49WZjK0uvoDl3rPPd3bxoRmBOVF yrMD66DWUrAdyfAQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 15/30] io: Add a pwritev/preadv version that takes a discontiguous iovec Date: Mon, 27 Nov 2023 17:25:57 -0300 Message-Id: <20231127202612.23012-16-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117086915000018 Content-Type: text/plain; charset="utf-8" For the upcoming support to fixed-ram migration with multifd, we need to be able to accept an iovec array with non-contiguous data. Add a pwritev and preadv version that splits the array into contiguous segments before writing. With that we can have the ram code continue to add pages in any order and the multifd code continue to send large arrays for reading and writing. Signed-off-by: Fabiano Rosas --- - split the API that was merged into a single function - use uintptr_t for compatibility with 32-bit --- include/io/channel.h | 26 ++++++++++++++++ io/channel.c | 70 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/include/io/channel.h b/include/io/channel.h index 7986c49c71..25383db5aa 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -559,6 +559,19 @@ int qio_channel_close(QIOChannel *ioc, ssize_t qio_channel_pwritev(QIOChannel *ioc, const struct iovec *iov, size_t niov, off_t offset, Error **errp); =20 +/** + * qio_channel_pwritev_all: + * @ioc: the channel object + * @iov: the array of memory regions to write data from + * @niov: the length of the @iov array + * @offset: the iovec offset in the file where to write the data + * @errp: pointer to a NULL-initialized error object + * + * Returns: 0 if all bytes were written, or -1 on error + */ +int qio_channel_pwritev_all(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + /** * qio_channel_pwrite * @ioc: the channel object @@ -595,6 +608,19 @@ ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf,= size_t buflen, ssize_t qio_channel_preadv(QIOChannel *ioc, const struct iovec *iov, size_t niov, off_t offset, Error **errp); =20 +/** + * qio_channel_preadv_all: + * @ioc: the channel object + * @iov: the array of memory regions to read data to + * @niov: the length of the @iov array + * @offset: the iovec offset in the file from where to read the data + * @errp: pointer to a NULL-initialized error object + * + * Returns: 0 if all bytes were read, or -1 on error + */ +int qio_channel_preadv_all(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp); + /** * qio_channel_pread * @ioc: the channel object diff --git a/io/channel.c b/io/channel.c index a1f12f8e90..2f1745d052 100644 --- a/io/channel.c +++ b/io/channel.c @@ -472,6 +472,69 @@ ssize_t qio_channel_pwritev(QIOChannel *ioc, const str= uct iovec *iov, return klass->io_pwritev(ioc, iov, niov, offset, errp); } =20 +static int qio_channel_preadv_pwritev_contiguous(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, off_t offset, + bool is_write, Error **er= rp) +{ + ssize_t ret =3D -1; + int i, slice_idx, slice_num; + uintptr_t base, next, file_offset; + size_t len; + + slice_idx =3D 0; + slice_num =3D 1; + + /* + * If the iov array doesn't have contiguous elements, we need to + * split it in slices because we only have one (file) 'offset' for + * the whole iov. Do this here so callers don't need to break the + * iov array themselves. + */ + for (i =3D 0; i < niov; i++, slice_num++) { + base =3D (uintptr_t) iov[i].iov_base; + + if (i !=3D niov - 1) { + len =3D iov[i].iov_len; + next =3D (uintptr_t) iov[i + 1].iov_base; + + if (base + len =3D=3D next) { + continue; + } + } + + /* + * Use the offset of the first element of the segment that + * we're sending. + */ + file_offset =3D offset + (uintptr_t) iov[slice_idx].iov_base; + + if (is_write) { + ret =3D qio_channel_pwritev(ioc, &iov[slice_idx], slice_num, + file_offset, errp); + } else { + ret =3D qio_channel_preadv(ioc, &iov[slice_idx], slice_num, + file_offset, errp); + } + + if (ret < 0) { + break; + } + + slice_idx +=3D slice_num; + slice_num =3D 0; + } + + return (ret < 0) ? -1 : 0; +} + +int qio_channel_pwritev_all(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + return qio_channel_preadv_pwritev_contiguous(ioc, iov, niov, + offset, true, errp); +} + ssize_t qio_channel_pwrite(QIOChannel *ioc, char *buf, size_t buflen, off_t offset, Error **errp) { @@ -501,6 +564,13 @@ ssize_t qio_channel_preadv(QIOChannel *ioc, const stru= ct iovec *iov, return klass->io_preadv(ioc, iov, niov, offset, errp); } =20 +int qio_channel_preadv_all(QIOChannel *ioc, const struct iovec *iov, + size_t niov, off_t offset, Error **errp) +{ + return qio_channel_preadv_pwritev_contiguous(ioc, iov, niov, + offset, false, errp); +} + ssize_t qio_channel_pread(QIOChannel *ioc, char *buf, size_t buflen, off_t offset, Error **errp) { --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116867; cv=none; d=zohomail.com; s=zohoarc; b=hAHiAxfOYWlDWd6m8cgRabxupueGMCAJlCnkQCLTlPecHsHHmeRzEEH7eW+M4vE/QT6JaqVZpnJfP6meyrPS3er73H4EsC+i9kATbUQ1nAKUfnUC7C6AmIsPAKrZ2ETv9jkbxZtJ7Sweb67hXhBAjjKE3tRw7XBvJ1E/sj+jbBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116867; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rzjmm5ywc7HVTleLe9Pn0I3d48q28auF6LLuQc7e3mU=; b=BwirRb9gAUduFD4NqNWjvuc1eC19tdGHIVR++paOhZ5KU0+di6czUNbH9k/b+KksX80Va1oeR8qUNrxcgCEhNyhU/4/5uXmvUnt9No0DeHQ0TswGpgwr3nxUZpe4bdqgpHtDl62RQGE6BalOhvg51m/hkpPLVH7kebzicsX9r9A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111686728024.714191451643615; Mon, 27 Nov 2023 12:27:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iC9-0002lY-Ba; Mon, 27 Nov 2023 15:27:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iC8-0002jb-0o for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:04 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iC6-0002of-CM for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:03 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 048D71FB71; Mon, 27 Nov 2023 20:27:01 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E32201379A; Mon, 27 Nov 2023 20:26:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id MFLvKZL7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:26:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116821; 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=rzjmm5ywc7HVTleLe9Pn0I3d48q28auF6LLuQc7e3mU=; b=x2Wxz7+X41UVDBe+O5Ch6qar9SE1e7FYCnqJGNXcxPdoUr4hP0iNej7MOXToGdsk0sIe7s LFkQ60ucZSQ9CAyXDZ5C9lhTH2BKVscU0jjFGfATBGyMVFH+1EskGHR+A61US1hilolZzA YSr1S61g6p2TslCTnPR/YYrwh4BQvL4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116821; 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=rzjmm5ywc7HVTleLe9Pn0I3d48q28auF6LLuQc7e3mU=; b=zGxge5kl4HpKZx7jSt1dCPDG5hxT8QCEmV1GGD1x/KP8k2ims0sinm3IVWtcK4QCs3MCQu 93vRMEyxslRPS9DQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 16/30] multifd: Rename MultiFDSendParams::data to compress_data Date: Mon, 27 Nov 2023 17:25:58 -0300 Message-Id: <20231127202612.23012-17-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116867867000001 Content-Type: text/plain; charset="utf-8" Use a more specific name for the compression data so we can use the generic for the multifd core code. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd-zlib.c | 20 ++++++++++---------- migration/multifd-zstd.c | 20 ++++++++++---------- migration/multifd.h | 4 ++-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 37ce48621e..fd94e79dd9 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -69,7 +69,7 @@ static int zlib_send_setup(MultiFDSendParams *p, Error **= errp) err_msg =3D "out of memory for buf"; goto err_free_zbuff; } - p->data =3D z; + p->compress_data =3D z; return 0; =20 err_free_zbuff: @@ -92,15 +92,15 @@ err_free_z: */ static void zlib_send_cleanup(MultiFDSendParams *p, Error **errp) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; =20 deflateEnd(&z->zs); g_free(z->zbuff); z->zbuff =3D NULL; g_free(z->buf); z->buf =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -116,7 +116,7 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Err= or **errp) */ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; int ret; @@ -189,7 +189,7 @@ static int zlib_recv_setup(MultiFDRecvParams *p, Error = **errp) struct zlib_data *z =3D g_new0(struct zlib_data, 1); z_stream *zs =3D &z->zs; =20 - p->data =3D z; + p->compress_data =3D z; zs->zalloc =3D Z_NULL; zs->zfree =3D Z_NULL; zs->opaque =3D Z_NULL; @@ -219,13 +219,13 @@ static int zlib_recv_setup(MultiFDRecvParams *p, Erro= r **errp) */ static void zlib_recv_cleanup(MultiFDRecvParams *p) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; =20 inflateEnd(&z->zs); g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -241,7 +241,7 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) */ static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) { - struct zlib_data *z =3D p->data; + struct zlib_data *z =3D p->compress_data; z_stream *zs =3D &z->zs; uint32_t in_size =3D p->next_packet_size; /* we measure the change of total_out */ diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index b471daadcd..238eebbf4b 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -52,7 +52,7 @@ static int zstd_send_setup(MultiFDSendParams *p, Error **= errp) struct zstd_data *z =3D g_new0(struct zstd_data, 1); int res; =20 - p->data =3D z; + p->compress_data =3D z; z->zcs =3D ZSTD_createCStream(); if (!z->zcs) { g_free(z); @@ -90,14 +90,14 @@ static int zstd_send_setup(MultiFDSendParams *p, Error = **errp) */ static void zstd_send_cleanup(MultiFDSendParams *p, Error **errp) { - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; =20 ZSTD_freeCStream(z->zcs); z->zcs =3D NULL; g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -113,7 +113,7 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Err= or **errp) */ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; int ret; uint32_t i; =20 @@ -178,7 +178,7 @@ static int zstd_recv_setup(MultiFDRecvParams *p, Error = **errp) struct zstd_data *z =3D g_new0(struct zstd_data, 1); int ret; =20 - p->data =3D z; + p->compress_data =3D z; z->zds =3D ZSTD_createDStream(); if (!z->zds) { g_free(z); @@ -216,14 +216,14 @@ static int zstd_recv_setup(MultiFDRecvParams *p, Erro= r **errp) */ static void zstd_recv_cleanup(MultiFDRecvParams *p) { - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; =20 ZSTD_freeDStream(z->zds); z->zds =3D NULL; g_free(z->zbuff); z->zbuff =3D NULL; - g_free(p->data); - p->data =3D NULL; + g_free(p->compress_data); + p->compress_data =3D NULL; } =20 /** @@ -243,7 +243,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) uint32_t out_size =3D 0; uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - struct zstd_data *z =3D p->data; + struct zstd_data *z =3D p->compress_data; int ret; int i; =20 diff --git a/migration/multifd.h b/migration/multifd.h index a112ec7ac6..744b52762f 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -132,7 +132,7 @@ typedef struct { /* num of non zero pages */ uint32_t normal_num; /* used for compression methods */ - void *data; + void *compress_data; } MultiFDSendParams; =20 typedef struct { @@ -189,7 +189,7 @@ typedef struct { /* num of non zero pages */ uint32_t normal_num; /* used for de-compression methods */ - void *data; + void *compress_data; } MultiFDRecvParams; =20 typedef struct { --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117053; cv=none; d=zohomail.com; s=zohoarc; b=du7yMTHS9tjYYS27dLnHAlM6vMowe4QSp2duKIAn3QdHpLA4mC+j0hC+uhBgnGGSlf8Pr+/G5rKgsfpfBrWfsFM2XYM+UaAX1M5VSP/aDsBOfefuiCP6DMoloX/Ym4Fu2cm76modRjluwrJJOJeu3dCJHO02N7TgzPTrKFsofzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117053; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iG3ySoK+kjQLed5T1UGWfiBTuZNVuWrBdfLbg6Skwwk=; b=agm+RgyVPlAenest29L4PrPrKnCPzhU9Yua+YMo/fQcfKoUhJPbQXdzCSaSn72G6a6uFLwdpLKVGAhXZQ60UvkHS+gxM+pQS/3TxD9rXEqaxqC+fSZ3bCqX5lZqmBiEGQtrhxrj3VLDHcB8bGY9WCFibgmRwKjXTR6ovB9HwX8A= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117053880525.9442895026561; Mon, 27 Nov 2023 12:30:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCC-00031w-3V; Mon, 27 Nov 2023 15:27:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCA-0002vc-LD for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:06 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iC8-0002p1-Sk for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:06 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8D7B51FB79; Mon, 27 Nov 2023 20:27:03 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7C1921379A; Mon, 27 Nov 2023 20:27:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id MN7HEJX7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116823; 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=iG3ySoK+kjQLed5T1UGWfiBTuZNVuWrBdfLbg6Skwwk=; b=nrRJY+C1nYeZ/sGH++zrQvbRluH/4QOCKMWo3U79X3S50DuaA8shuxiRH7+LpNiNqzbi2k wsgz3fqBKUNRpsXAdp47HHjRpL/OyHA7ZKzTp74KfUMtoEWL+S6sCPdHHMhPXkdkkR+Cdg 8LSW8dVZ2SMPcrVYHrqS7EdvNqleaGk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116823; 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=iG3ySoK+kjQLed5T1UGWfiBTuZNVuWrBdfLbg6Skwwk=; b=G9Ml0aZ0tRW5YKNALiedceEDzWQiUux3XpeyK15dNi4nhykEq+eRhwIjoJHc2abmHYPLfx pIBGUoXa5csyEfBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 17/30] migration/multifd: Decouple recv method from pages Date: Mon, 27 Nov 2023 17:25:59 -0300 Message-Id: <20231127202612.23012-18-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117055955000003 Content-Type: text/plain; charset="utf-8" Next patch will abstract the type of data being received by the channels, so do some cleanup now to remove references to pages and dependency on 'normal_num'. Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu --- migration/multifd-zlib.c | 2 +- migration/multifd-zstd.c | 2 +- migration/multifd.c | 12 +++++++----- migration/multifd.h | 5 ++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index fd94e79dd9..e019d2d74e 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -314,7 +314,7 @@ static MultiFDMethods multifd_zlib_ops =3D { .send_prepare =3D zlib_send_prepare, .recv_setup =3D zlib_recv_setup, .recv_cleanup =3D zlib_recv_cleanup, - .recv_pages =3D zlib_recv_pages + .recv_data =3D zlib_recv_pages }; =20 static void multifd_zlib_register(void) diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index 238eebbf4b..0b8414df5b 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -305,7 +305,7 @@ static MultiFDMethods multifd_zstd_ops =3D { .send_prepare =3D zstd_send_prepare, .recv_setup =3D zstd_recv_setup, .recv_cleanup =3D zstd_recv_cleanup, - .recv_pages =3D zstd_recv_pages + .recv_data =3D zstd_recv_pages }; =20 static void multifd_zstd_register(void) diff --git a/migration/multifd.c b/migration/multifd.c index 3476fac49f..c1381bdc21 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -130,7 +130,7 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) } =20 /** - * nocomp_recv_pages: read the data from the channel into actual pages + * nocomp_recv_data: read the data from the channel * * For no compression we just need to read things into the correct place. * @@ -139,7 +139,7 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) * @p: Params for the channel that we are using * @errp: pointer to an error */ -static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) +static int nocomp_recv_data(MultiFDRecvParams *p, Error **errp) { uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; =20 @@ -161,7 +161,7 @@ static MultiFDMethods multifd_nocomp_ops =3D { .send_prepare =3D nocomp_send_prepare, .recv_setup =3D nocomp_recv_setup, .recv_cleanup =3D nocomp_recv_cleanup, - .recv_pages =3D nocomp_recv_pages + .recv_data =3D nocomp_recv_data }; =20 static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] =3D { @@ -1126,6 +1126,7 @@ static void *multifd_recv_thread(void *opaque) =20 while (true) { uint32_t flags =3D 0; + bool has_data =3D false; p->normal_num =3D 0; =20 if (p->quit) { @@ -1154,12 +1155,13 @@ static void *multifd_recv_thread(void *opaque) p->next_packet_size); =20 p->total_normal_pages +=3D p->normal_num; + has_data =3D !!p->normal_num; } =20 qemu_mutex_unlock(&p->mutex); =20 - if (p->normal_num) { - ret =3D multifd_recv_state->ops->recv_pages(p, &local_err); + if (has_data) { + ret =3D multifd_recv_state->ops->recv_data(p, &local_err); if (ret !=3D 0) { break; } diff --git a/migration/multifd.h b/migration/multifd.h index 744b52762f..406d42dbae 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -203,11 +203,10 @@ typedef struct { int (*recv_setup)(MultiFDRecvParams *p, Error **errp); /* Cleanup for receiving side */ void (*recv_cleanup)(MultiFDRecvParams *p); - /* Read all pages */ - int (*recv_pages)(MultiFDRecvParams *p, Error **errp); + /* Read all data */ + int (*recv_data)(MultiFDRecvParams *p, Error **errp); } MultiFDMethods; =20 void multifd_register_ops(int method, MultiFDMethods *ops); =20 #endif - --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116919; cv=none; d=zohomail.com; s=zohoarc; b=FFRJq0E9f0g508MHN/QouqZzKup1P2B/FhqVSeToYjMh2gWk3TtVyEU2oVkQxoOcJjMkTKzijlzSMzOhFsH2jAInqjsD9lam+R/tb38E2dXSzLZ9TIqcykrMLqXf1um83lqd48wkb4dOHl2XaXAPxC+fT7aO0/+A3Ilowguc5kc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116919; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G3lFVSaC2SFCUF6RJ0NZjaZayMP0TzCLKh4i0gsaGlA=; b=gVRkq0+UiNcb0Cf/pHpYDYr4nvGVGPB3jlufVXriK4Kl10uKfSZTSnhn5E8Fy6yd1vWOrz9Kw4o39XA0TQUnRuNP6Uw+36fBxfemCGeqQvJpU482dC0R5SLn/TEi+92GPeoQTfmTb4sinmCxcWPvU9Ts1vY/azBn+D94Bxa5dNY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116919905147.05579689909177; Mon, 27 Nov 2023 12:28:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCO-0003LN-FM; Mon, 27 Nov 2023 15:27:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCF-0003GJ-6b for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:12 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCB-0002pO-9Y for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:09 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1D6D71FB71; Mon, 27 Nov 2023 20:27:06 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0CCE91379A; Mon, 27 Nov 2023 20:27:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id EJk+MZf7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116826; 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=G3lFVSaC2SFCUF6RJ0NZjaZayMP0TzCLKh4i0gsaGlA=; b=R7qTSYoeh/lyv7uwhNraRG7SvxOzrbXB66pv9BCEKovlSyaGOv/t0+4OxOjRKYzcQ5wA2p G/w/2a7LaT2ugEaCmspQxIEX4bHJDZGRFyRdHVIVsdTxFcwC1uDuMY2dIcYUJ3BhPaKMbM eSmbooXWC+oLg7HvxNGwzalUhj1rLWM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116826; 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=G3lFVSaC2SFCUF6RJ0NZjaZayMP0TzCLKh4i0gsaGlA=; b=6glQq5X2VmGB/OeWkWaUp7H0oDErRJjXS77QpVkE7cV8wipyL6nNQqm5DUObD9bz1+wH5L OfgvDLj+XQPoJuBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 18/30] migration/multifd: Allow receiving pages without packets Date: Mon, 27 Nov 2023 17:26:00 -0300 Message-Id: <20231127202612.23012-19-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116921373000003 Content-Type: text/plain; charset="utf-8" Currently multifd does not need to have knowledge of pages on the receiving side because all the information needed is within the packets that come in the stream. We're about to add support to fixed-ram migration, which cannot use packets because it expects the ramblock section in the migration file to contain only the guest pages data. Add a data structure to transfer pages between the ram migration code and the multifd receiving threads. We don't want to reuse MultiFDPages_t for two reasons: a) multifd threads don't really need to know about the data they're receiving. b) the receiving side has to be stopped to load the pages, which means we can experiment with larger granularities than page size when transferring data. Signed-off-by: Fabiano Rosas --- - stopped using MultiFDPages_t and added a new structure which can take offset + size --- migration/multifd.c | 122 ++++++++++++++++++++++++++++++++++++++++++-- migration/multifd.h | 20 ++++++++ 2 files changed, 138 insertions(+), 4 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index c1381bdc21..7dfab2367a 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -142,17 +142,36 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) static int nocomp_recv_data(MultiFDRecvParams *p, Error **errp) { uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; + ERRP_GUARD(); =20 if (flags !=3D MULTIFD_FLAG_NOCOMP) { error_setg(errp, "multifd %u: flags received %x flags expected %x", p->id, flags, MULTIFD_FLAG_NOCOMP); return -1; } - for (int i =3D 0; i < p->normal_num; i++) { - p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D p->page_size; + + if (!migrate_multifd_packets()) { + MultiFDRecvData *data =3D p->data; + size_t ret; + + ret =3D qio_channel_pread(p->c, (char *) data->opaque, + data->size, data->file_offset, errp); + if (ret !=3D data->size) { + error_prepend(errp, + "multifd recv (%u): read 0x%zx, expected 0x%zx", + p->id, ret, data->size); + return -1; + } + + return 0; + } else { + for (int i =3D 0; i < p->normal_num; i++) { + p->iov[i].iov_base =3D p->host + p->normal[i]; + p->iov[i].iov_len =3D p->page_size; + } + + return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); } - return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); } =20 static MultiFDMethods multifd_nocomp_ops =3D { @@ -989,6 +1008,7 @@ int multifd_save_setup(Error **errp) =20 struct { MultiFDRecvParams *params; + MultiFDRecvData *data; /* number of created threads */ int count; /* syncs main thread and channels */ @@ -999,6 +1019,49 @@ struct { MultiFDMethods *ops; } *multifd_recv_state; =20 +int multifd_recv(void) +{ + int i; + static int next_recv_channel; + MultiFDRecvParams *p =3D NULL; + MultiFDRecvData *data =3D multifd_recv_state->data; + + /* + * next_channel can remain from a previous migration that was + * using more channels, so ensure it doesn't overflow if the + * limit is lower now. + */ + next_recv_channel %=3D migrate_multifd_channels(); + for (i =3D next_recv_channel;; i =3D (i + 1) % migrate_multifd_channel= s()) { + p =3D &multifd_recv_state->params[i]; + + qemu_mutex_lock(&p->mutex); + if (p->quit) { + error_report("%s: channel %d has already quit!", __func__, i); + qemu_mutex_unlock(&p->mutex); + return -1; + } + if (!p->pending_job) { + p->pending_job++; + next_recv_channel =3D (i + 1) % migrate_multifd_channels(); + break; + } + qemu_mutex_unlock(&p->mutex); + } + assert(p->data->size =3D=3D 0); + multifd_recv_state->data =3D p->data; + p->data =3D data; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); + + return 1; +} + +MultiFDRecvData *multifd_get_recv_data(void) +{ + return multifd_recv_state->data; +} + static void multifd_recv_terminate_threads(Error *err) { int i; @@ -1020,6 +1083,7 @@ static void multifd_recv_terminate_threads(Error *err) =20 qemu_mutex_lock(&p->mutex); p->quit =3D true; + qemu_sem_post(&p->sem); /* * We could arrive here for two reasons: * - normal quit, i.e. everything went fine, just finished @@ -1069,6 +1133,7 @@ void multifd_load_cleanup(void) p->c =3D NULL; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem_sync); + qemu_sem_destroy(&p->sem); g_free(p->name); p->name =3D NULL; p->packet_len =3D 0; @@ -1083,6 +1148,8 @@ void multifd_load_cleanup(void) qemu_sem_destroy(&multifd_recv_state->sem_sync); g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; + g_free(multifd_recv_state->data); + multifd_recv_state->data =3D NULL; g_free(multifd_recv_state); multifd_recv_state =3D NULL; } @@ -1094,6 +1161,21 @@ void multifd_recv_sync_main(void) if (!migrate_multifd() || !migrate_multifd_packets()) { return; } + + if (!migrate_multifd_packets()) { + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_sem_post(&p->sem); + qemu_sem_wait(&p->sem_sync); + + qemu_mutex_lock(&p->mutex); + assert(!p->pending_job || p->quit); + qemu_mutex_unlock(&p->mutex); + } + return; + } + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 @@ -1156,6 +1238,18 @@ static void *multifd_recv_thread(void *opaque) =20 p->total_normal_pages +=3D p->normal_num; has_data =3D !!p->normal_num; + } else { + /* + * No packets, so we need to wait for the vmstate code to + * give us work. + */ + qemu_sem_wait(&p->sem); + qemu_mutex_lock(&p->mutex); + if (!p->pending_job) { + qemu_mutex_unlock(&p->mutex); + break; + } + has_data =3D !!p->data->size; } =20 qemu_mutex_unlock(&p->mutex); @@ -1171,6 +1265,17 @@ static void *multifd_recv_thread(void *opaque) qemu_sem_post(&multifd_recv_state->sem_sync); qemu_sem_wait(&p->sem_sync); } + + if (!use_packets) { + qemu_mutex_lock(&p->mutex); + p->data->size =3D 0; + p->pending_job--; + qemu_mutex_unlock(&p->mutex); + } + } + + if (!use_packets) { + qemu_sem_post(&p->sem_sync); } =20 if (local_err) { @@ -1205,6 +1310,10 @@ int multifd_load_setup(Error **errp) thread_count =3D migrate_multifd_channels(); multifd_recv_state =3D g_malloc0(sizeof(*multifd_recv_state)); multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); + + multifd_recv_state->data =3D g_new0(MultiFDRecvData, 1); + multifd_recv_state->data->size =3D 0; + qatomic_set(&multifd_recv_state->count, 0); qemu_sem_init(&multifd_recv_state->sem_sync, 0); multifd_recv_state->ops =3D multifd_ops[migrate_multifd_compression()]; @@ -1214,9 +1323,14 @@ int multifd_load_setup(Error **errp) =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); + qemu_sem_init(&p->sem, 0); p->quit =3D false; + p->pending_job =3D 0; p->id =3D i; =20 + p->data =3D g_new0(MultiFDRecvData, 1); + p->data->size =3D 0; + if (use_packets) { p->packet_len =3D sizeof(MultiFDPacket_t) + sizeof(uint64_t) * page_count; diff --git a/migration/multifd.h b/migration/multifd.h index 406d42dbae..abaf16c3f2 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -13,6 +13,8 @@ #ifndef QEMU_MIGRATION_MULTIFD_H #define QEMU_MIGRATION_MULTIFD_H =20 +typedef struct MultiFDRecvData MultiFDRecvData; + int multifd_save_setup(Error **errp); void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); @@ -24,6 +26,8 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error **er= rp); void multifd_recv_sync_main(void); int multifd_send_sync_main(QEMUFile *f); int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); +int multifd_recv(void); +MultiFDRecvData *multifd_get_recv_data(void); =20 /* Multifd Compression flags */ #define MULTIFD_FLAG_SYNC (1 << 0) @@ -66,6 +70,13 @@ typedef struct { RAMBlock *block; } MultiFDPages_t; =20 +struct MultiFDRecvData { + void *opaque; + size_t size; + /* for preadv */ + off_t file_offset; +}; + typedef struct { /* Fields are only written at creating/deletion time */ /* No lock required for them, they are read only */ @@ -156,6 +167,8 @@ typedef struct { =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* sem where to wait for more work */ + QemuSemaphore sem; =20 /* this mutex protects the following parameters */ QemuMutex mutex; @@ -167,6 +180,13 @@ typedef struct { uint32_t flags; /* global number of generated multifd packets */ uint64_t packet_num; + int pending_job; + /* + * The owner of 'data' depends of 'pending_job' value: + * pending_job =3D=3D 0 -> migration_thread can use it. + * pending_job !=3D 0 -> multifd_channel can use it. + */ + MultiFDRecvData *data; =20 /* thread local variables. No locking required */ =20 --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116954; cv=none; d=zohomail.com; s=zohoarc; b=bU4XfmIrVWQei41VgaMS22fcjbapfxBB4GbJZw9F0+qUlJTTinKairUjpq4RaEmQsyL6Nbhj272DDfoINo+h1Uq6CLaK3x7MT8zLlcu0uZ8P/oaKnYIFpb8NLWQ/AjgkgI2q0Ndaw4ByLLfu7CeZ5Z+1skFuKSyGUttEiIA3x6M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116954; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f/O9z9Oa8tQPzYvTNemCX5g6I1I9k4l3WV4T6reynhQ=; b=J9LZx4DOwG27L52cmtrerh+OY86YiEPTv+9ivRhm4U3GbOr0fRxQUXvKNFjUlQCxxPwOgaaDABo+0WYclOtgoJ44+EnKTxqnctBYe+GTKMOIit1Wbphw06cEMnC1XVc2gbX/O7MIN3AullGo19GX0YNTIsGGrxgjOl8gbjh0YkM= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116954835322.5778804806007; Mon, 27 Nov 2023 12:29:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCR-0003So-HL; Mon, 27 Nov 2023 15:27:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCG-0003J0-Id for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:12 -0500 Received: from smtp-out1.suse.de ([195.135.223.130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCE-0002pl-Tw for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:12 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A053D21B32; Mon, 27 Nov 2023 20:27:08 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8F0391379A; Mon, 27 Nov 2023 20:27:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id WOdaFZr7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116828; 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=f/O9z9Oa8tQPzYvTNemCX5g6I1I9k4l3WV4T6reynhQ=; b=1JT63DT/31w0ZHhkho+ATn78qCBnQMWv/uP+XOuwBkEEvnFwKcKMFBz4S4gKKt4FfHgsoI /YQHgyVOG1If8KyR26kSgw5NAp6XnS+pDDn2Mj7XmB9OCKXcZwXkEKialMeMVHovOCOmlQ 1Dyz6bA9HWFtcjoyy+KZC+CFhqpbl+8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116828; 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=f/O9z9Oa8tQPzYvTNemCX5g6I1I9k4l3WV4T6reynhQ=; b=HAjy/4CzFpadodsMaFIWjo8U/BCIDyMzbSiBscMfCmqsem0EO+J5H1CHl8+DJjPlJ2nX9V 1NgURZJwAFPmysBA== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 19/30] migration/ram: Ignore multifd flush when doing fixed-ram migration Date: Mon, 27 Nov 2023 17:26:01 -0300 Message-Id: <20231127202612.23012-20-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 3.39 X-Spamd-Result: default: False [3.39 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.51)[80.04%] 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.223.130; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116955943000003 Content-Type: text/plain; charset="utf-8" Some functionalities of multifd are incompatible with the 'fixed-ram' migration format. The MULTIFD_FLUSH flag in particular is not used because in fixed-ram there is no sinchronicity between migration source and destination so there is not need for a sync packet. In fact, fixed-ram disables packets in multifd as a whole. However, we still need to sync the migration thread with the multifd channels at key moments: - between iterations, to avoid a slow channel being overrun by a fast channel in the subsequent iteration; - at ram_save_complete, to make sure all data has been transferred before finishing migration; Make sure RAM_SAVE_FLAG_MULTIFD_FLUSH is only emitted for fixed-ram at those key moments. Signed-off-by: Fabiano Rosas --- migration/ram.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 08604222f2..ad6abd1761 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1363,7 +1363,7 @@ static int find_dirty_block(RAMState *rs, PageSearchS= tatus *pss) pss->page =3D 0; pss->block =3D QLIST_NEXT_RCU(pss->block, next); if (!pss->block) { - if (migrate_multifd() && + if (migrate_multifd() && !migrate_fixed_ram() && !migrate_multifd_flush_after_each_section()) { QEMUFile *f =3D rs->pss[RAM_CHANNEL_PRECOPY].pss_channel; int ret =3D multifd_send_sync_main(f); @@ -3112,7 +3112,8 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return ret; } =20 - if (migrate_multifd() && !migrate_multifd_flush_after_each_section()) { + if (migrate_multifd() && !migrate_multifd_flush_after_each_section() + && !migrate_fixed_ram()) { qemu_put_be64(f, RAM_SAVE_FLAG_MULTIFD_FLUSH); } =20 @@ -3242,8 +3243,11 @@ static int ram_save_iterate(QEMUFile *f, void *opaqu= e) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - if (migrate_multifd() && migrate_multifd_flush_after_each_section(= )) { - ret =3D multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].ps= s_channel); + if (migrate_multifd() && + (migrate_multifd_flush_after_each_section() || + migrate_fixed_ram())) { + ret =3D multifd_send_sync_main( + rs->pss[RAM_CHANNEL_PRECOPY].pss_channel); if (ret < 0) { return ret; } --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17011171150521013.8832531810622; Mon, 27 Nov 2023 12:31:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCU-0003ZT-3Z; Mon, 27 Nov 2023 15:27:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCR-0003RN-6B for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:23 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCG-0002q7-Gb for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:14 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 39CA821B4C; Mon, 27 Nov 2023 20:27:11 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 264061379A; Mon, 27 Nov 2023 20:27:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id SDJ2N5z7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:08 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 20/30] migration/multifd: Support outgoing fixed-ram stream format Date: Mon, 27 Nov 2023 17:26:02 -0300 Message-Id: <20231127202612.23012-21-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.989]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: 39CA821B4C 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117115539000001 Content-Type: text/plain; charset="utf-8" The new fixed-ram stream format uses a file transport and puts ram pages in the migration file at their respective offsets and can be done in parallel by using the pwritev system call which takes iovecs and an offset. Add support to enabling the new format along with multifd to make use of the threading and page handling already in place. This requires multifd to stop sending headers and leaving the stream format to the fixed-ram code. When it comes time to write the data, we need to call a version of qio_channel_write that can take an offset. Usage on HMP is: (qemu) stop (qemu) migrate_set_capability multifd on (qemu) migrate_set_capability fixed-ram on (qemu) migrate_set_parameter max-bandwidth 0 (qemu) migrate_set_parameter multifd-channels 8 (qemu) migrate file:migfile Signed-off-by: Fabiano Rosas --- - altered to call a separate qio_channel function for fixed-ram --- include/qemu/bitops.h | 13 +++++++ migration/migration.c | 19 ++++++---- migration/multifd.c | 81 ++++++++++++++++++++++++++++++++++++------- migration/options.c | 6 ---- migration/ram.c | 17 +++++++-- migration/ram.h | 1 + 6 files changed, 110 insertions(+), 27 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index cb3526d1f4..2c0a2fe751 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -67,6 +67,19 @@ static inline void clear_bit(long nr, unsigned long *add= r) *p &=3D ~mask; } =20 +/** + * clear_bit_atomic - Clears a bit in memory atomically + * @nr: Bit to clear + * @addr: Address to start counting from + */ +static inline void clear_bit_atomic(long nr, unsigned long *addr) +{ + unsigned long mask =3D BIT_MASK(nr); + unsigned long *p =3D addr + BIT_WORD(nr); + + return qatomic_and(p, ~mask); +} + /** * change_bit - Toggle a bit in memory * @nr: Bit to change diff --git a/migration/migration.c b/migration/migration.c index 16689171ab..cc707b0223 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -128,11 +128,19 @@ static bool migration_needs_multiple_sockets(void) return migrate_multifd() || migrate_postcopy_preempt(); } =20 -static bool transport_supports_multi_channels(SocketAddress *saddr) +static bool transport_supports_multi_channels(MigrationAddress *addr) { - return saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET || - saddr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX || - saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK; + if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) { + SocketAddress *saddr =3D &addr->u.socket; + + return (saddr->type =3D=3D SOCKET_ADDRESS_TYPE_INET || + saddr->type =3D=3D SOCKET_ADDRESS_TYPE_UNIX || + saddr->type =3D=3D SOCKET_ADDRESS_TYPE_VSOCK); + } else if (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_FILE) { + return migrate_fixed_ram(); + } else { + return false; + } } =20 static bool migration_needs_seekable_channel(void) @@ -156,8 +164,7 @@ migration_channels_and_transport_compatible(MigrationAd= dress *addr, } =20 if (migration_needs_multiple_sockets() && - (addr->transport =3D=3D MIGRATION_ADDRESS_TYPE_SOCKET) && - !transport_supports_multi_channels(&addr->u.socket)) { + !transport_supports_multi_channels(addr)) { error_setg(errp, "Migration requires multi-channel URIs (e.g. tcp)= "); return false; } diff --git a/migration/multifd.c b/migration/multifd.c index 7dfab2367a..8eae7de4de 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -278,6 +278,17 @@ static void multifd_pages_clear(MultiFDPages_t *pages) g_free(pages); } =20 +static void multifd_set_file_bitmap(MultiFDSendParams *p) +{ + MultiFDPages_t *pages =3D p->pages; + + assert(pages->block); + + for (int i =3D 0; i < p->normal_num; i++) { + ramblock_set_shadow_bmap_atomic(pages->block, pages->offset[i]); + } +} + static void multifd_send_fill_packet(MultiFDSendParams *p) { MultiFDPacket_t *packet =3D p->packet; @@ -624,6 +635,34 @@ int multifd_send_sync_main(QEMUFile *f) } } =20 + if (!migrate_multifd_packets()) { + /* + * There's no sync packet to send. Just make sure the sending + * above has finished. + */ + for (i =3D 0; i < migrate_multifd_channels(); i++) { + qemu_sem_wait(&multifd_send_state->channels_ready); + } + + /* sanity check and release the channels */ + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDSendParams *p =3D &multifd_send_state->params[i]; + + qemu_mutex_lock(&p->mutex); + if (p->quit) { + error_report("%s: channel %d has already quit!", __func__,= i); + qemu_mutex_unlock(&p->mutex); + return -1; + } + assert(!p->pending_job); + qemu_mutex_unlock(&p->mutex); + + qemu_sem_post(&p->sem); + } + + return 0; + } + /* * When using zero-copy, it's necessary to flush the pages before any = of * the pages can be sent again, so we'll make sure the new version of = the @@ -707,6 +746,8 @@ static void *multifd_send_thread(void *opaque) =20 if (p->pending_job) { uint32_t flags; + uintptr_t write_base; + p->normal_num =3D 0; =20 if (!use_packets || use_zero_copy_send) { @@ -731,6 +772,15 @@ static void *multifd_send_thread(void *opaque) if (use_packets) { multifd_send_fill_packet(p); p->num_packets++; + } else { + multifd_set_file_bitmap(p); + + /* + * If we subtract the host page now, we don't need to + * pass it into qio_channel_pwritev_all() below. + */ + write_base =3D p->pages->block->pages_offset - + (uintptr_t)p->pages->block->host; } =20 flags =3D p->flags; @@ -743,21 +793,28 @@ static void *multifd_send_thread(void *opaque) trace_multifd_send(p->id, p->packet_num, p->normal_num, flags, p->next_packet_size); =20 - if (use_zero_copy_send) { - /* Send header first, without zerocopy */ - ret =3D qio_channel_write_all(p->c, (void *)p->packet, - p->packet_len, &local_err); - if (ret !=3D 0) { - break; + if (use_packets) { + if (use_zero_copy_send) { + /* Send header first, without zerocopy */ + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + break; + } + } else { + /* Send header using the same writev call */ + p->iov[0].iov_len =3D p->packet_len; + p->iov[0].iov_base =3D p->packet; } - } else if (use_packets) { - /* Send header using the same writev call */ - p->iov[0].iov_len =3D p->packet_len; - p->iov[0].iov_base =3D p->packet; + + ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_= num, + NULL, 0, p->write_flags, + &local_err); + } else { + ret =3D qio_channel_pwritev_all(p->c, p->iov, p->iovs_num, + write_base, &local_err); } =20 - ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, - 0, p->write_flags, &local_er= r); if (ret !=3D 0) { break; } diff --git a/migration/options.c b/migration/options.c index f671e24758..7f23881f51 100644 --- a/migration/options.c +++ b/migration/options.c @@ -666,12 +666,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps= , Error **errp) } =20 if (new_caps[MIGRATION_CAPABILITY_FIXED_RAM]) { - if (new_caps[MIGRATION_CAPABILITY_MULTIFD]) { - error_setg(errp, - "Fixed-ram migration is incompatible with multifd"); - return false; - } - if (new_caps[MIGRATION_CAPABILITY_XBZRLE]) { error_setg(errp, "Fixed-ram migration is incompatible with xbzrle"); diff --git a/migration/ram.c b/migration/ram.c index ad6abd1761..385fe431bf 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1149,7 +1149,7 @@ static int save_zero_page(RAMState *rs, PageSearchSta= tus *pss, =20 if (migrate_fixed_ram()) { /* zero pages are not transferred with fixed-ram */ - clear_bit(offset >> TARGET_PAGE_BITS, pss->block->shadow_bmap); + clear_bit_atomic(offset >> TARGET_PAGE_BITS, pss->block->shadow_bm= ap); return 1; } =20 @@ -2443,8 +2443,6 @@ 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(); @@ -3131,9 +3129,22 @@ static void ram_save_shadow_bmap(QEMUFile *f) qemu_put_buffer_at(f, (uint8_t *)block->shadow_bmap, bitmap_size, block->bitmap_offset); ram_transferred_add(bitmap_size); + + /* + * Free the bitmap here to catch any synchronization issues + * with multifd channels. No channels should be sending pages + * after we've written the bitmap to file. + */ + g_free(block->shadow_bmap); + block->shadow_bmap =3D NULL; } } =20 +void ramblock_set_shadow_bmap_atomic(RAMBlock *block, ram_addr_t offset) +{ + set_bit_atomic(offset >> TARGET_PAGE_BITS, block->shadow_bmap); +} + /** * ram_save_iterate: iterative stage for migration * diff --git a/migration/ram.h b/migration/ram.h index 9b937a446b..a65120de0d 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -75,6 +75,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock = *rb, Error **errp); bool ramblock_page_is_discarded(RAMBlock *rb, ram_addr_t start); void postcopy_preempt_shutdown_file(MigrationState *s); void *postcopy_preempt_thread(void *opaque); +void ramblock_set_shadow_bmap_atomic(RAMBlock *block, ram_addr_t offset); =20 /* ram cache */ int colo_init_ram_cache(void); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117074942376.59194703055914; Mon, 27 Nov 2023 12:31:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCT-0003Z1-U9; Mon, 27 Nov 2023 15:27:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCS-0003UM-Gv for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:24 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCQ-0002qc-Fl for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:24 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id BD6741FB54; Mon, 27 Nov 2023 20:27:13 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AD36B1379A; Mon, 27 Nov 2023 20:27:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id gLa7HJ/7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:11 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 21/30] migration/multifd: Support incoming fixed-ram stream format Date: Mon, 27 Nov 2023 17:26:03 -0300 Message-Id: <20231127202612.23012-22-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [10.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.987]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[41.93%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 10.80 X-Rspamd-Queue-Id: BD6741FB54 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117076606000003 Content-Type: text/plain; charset="utf-8" For the incoming fixed-ram migration we need to read the ramblock headers, get the pages bitmap and send the host address of each non-zero page to the multifd channel thread for writing. To read from the migration file we need a preadv function that can read into the iovs in segments of contiguous pages because (as in the writing case) the file offset applies to the entire iovec. Usage on HMP is: (qemu) migrate_set_capability multifd on (qemu) migrate_set_capability fixed-ram on (qemu) migrate_set_parameter max-bandwidth 0 (qemu) migrate_set_parameter multifd-channels 8 (qemu) migrate_incoming file:migfile (qemu) info status (qemu) c Signed-off-by: Fabiano Rosas --- migration/ram.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 385fe431bf..f5173755f0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -111,6 +111,7 @@ * pages region in the migration file at a time. */ #define FIXED_RAM_LOAD_BUF_SIZE 0x100000 +#define FIXED_RAM_MULTIFD_LOAD_BUF_SIZE 0x100000 =20 XBZRLECacheStats xbzrle_counters; =20 @@ -3942,13 +3943,36 @@ void colo_flush_ram_cache(void) trace_colo_flush_ram_cache_end(); } =20 +static size_t ram_load_multifd_pages(RAMBlock *block, ram_addr_t start_off= set, + size_t size) +{ + MultiFDRecvData *data =3D multifd_get_recv_data(); + + /* + * Pointing the opaque directly to the host buffer, no + * preprocessing needed. + */ + data->opaque =3D block->host + start_offset; + + data->file_offset =3D block->pages_offset + start_offset; + data->size =3D size; + + if (multifd_recv() < 0) { + return -1; + } + + return size; +} + static void read_ramblock_fixed_ram(QEMUFile *f, RAMBlock *block, long num_pages, unsigned long *bitmap) { unsigned long set_bit_idx, clear_bit_idx; ram_addr_t offset; void *host; - size_t read, unread, size, buf_size =3D FIXED_RAM_LOAD_BUF_SIZE; + size_t read, unread, size; + size_t buf_size =3D (migrate_multifd() ? FIXED_RAM_MULTIFD_LOAD_BUF_SI= ZE : + FIXED_RAM_LOAD_BUF_SIZE); =20 for (set_bit_idx =3D find_first_bit(bitmap, num_pages); set_bit_idx < num_pages; @@ -3963,8 +3987,12 @@ static void read_ramblock_fixed_ram(QEMUFile *f, RAM= Block *block, host =3D host_from_ram_block_offset(block, offset); size =3D MIN(unread, buf_size); =20 - read =3D qemu_get_buffer_at(f, host, size, - block->pages_offset + offset); + if (migrate_multifd()) { + read =3D ram_load_multifd_pages(block, offset, size); + } else { + read =3D qemu_get_buffer_at(f, host, size, + block->pages_offset + offset); + } offset +=3D read; unread -=3D read; } --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117117; cv=none; d=zohomail.com; s=zohoarc; b=isVpUpnuGhg9HAIvprnfZs5h9xeCqNQxQ0mKFrrW+XJt4sirIsJMFBfpcl+EnetmqhhNbwXe7rTo1hVP1BFu2utNDsVt5sKyll3BdeyTrNaY2kfxcAOjhVX6EH/+TSAvj6TxY6CG7kfb40XakapYo5F5W4yLWch2gjqmaD+X96k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117117; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NxltMMwNIlXzShEGEpkT9ZUVYe/wWZQMQtTvGw4nODY=; b=OaHL/psSYAQw0CDWDDXIasKZkD2IcX5u7WJQLW/uw9ABMU9uxEndiXo06i8DQg1cbs+g1WlA0hnxXoj/O3XSf20PAZ7EnpTslsx1q76EvhUUjHmWrXhrmi+ErOpVrncDxE8/wNomk2CwJDFkD1mLt5mGP5ot5shh0lLu+jjCPLY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117117243372.9828883806041; Mon, 27 Nov 2023 12:31:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCU-0003aG-I7; Mon, 27 Nov 2023 15:27:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCS-0003Ub-I2 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:24 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCQ-0002rB-Ts for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:24 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0074821B5D; Mon, 27 Nov 2023 20:27:17 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3B8941379A; Mon, 27 Nov 2023 20:27:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id OFD5AKL7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116837; 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=NxltMMwNIlXzShEGEpkT9ZUVYe/wWZQMQtTvGw4nODY=; b=MZrrZ8cDJNmiOMyt4UhNpGIyEywzaMv2kxXzCXOjtW+w9ZvL3x1K7fcv3dZO025hTSVtMR mWa7DWeT8V0hB2uwy52Oj2QE/2ypvWoUyp2NHwZZ7xUJVmVgRzquEk36gymaBE2bM6TJQ6 N1xY/Y6Rw7kbmGWWGyz211crMmkGBM4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116837; 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=NxltMMwNIlXzShEGEpkT9ZUVYe/wWZQMQtTvGw4nODY=; b=LafhpjSiCLvpa4FsiGz+rSs9XXbjE+nJBQLumnEJHdRYY0SPCWE0iUxk793Lf8gGOTO7zU Q2bQUcoAi0SA3cBQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [RFC PATCH v3 22/30] tests/qtest: Add a multifd + fixed-ram migration test Date: Mon, 27 Nov 2023 17:26:04 -0300 Message-Id: <20231127202612.23012-23-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-0.996]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 0.70 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117119622000011 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fabiano Rosas --- tests/qtest/migration-test.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 96a6217af0..5c5725687c 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2183,6 +2183,46 @@ static void test_precopy_file_fixed_ram(void) test_file_common(&args, true); } =20 +static void *migrate_multifd_fixed_ram_start(QTestState *from, QTestState = *to) +{ + migrate_fixed_ram_start(from, to); + + migrate_set_parameter_int(from, "multifd-channels", 4); + migrate_set_parameter_int(to, "multifd-channels", 4); + + migrate_set_capability(from, "multifd", true); + migrate_set_capability(to, "multifd", true); + + return NULL; +} + +static void test_multifd_file_fixed_ram_live(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_fixed_ram_start, + }; + + test_file_common(&args, false); +} + +static void test_multifd_file_fixed_ram(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_fixed_ram_start, + }; + + test_file_common(&args, true); +} + + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -3431,6 +3471,11 @@ int main(int argc, char **argv) qtest_add_func("/migration/precopy/file/fixed-ram/live", test_precopy_file_fixed_ram_live); =20 + qtest_add_func("/migration/multifd/file/fixed-ram", + test_multifd_file_fixed_ram); + qtest_add_func("/migration/multifd/file/fixed-ram/live", + test_multifd_file_fixed_ram_live); + #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117115; cv=none; d=zohomail.com; s=zohoarc; b=ClXO/2mmYyrk+L90qE9Mq4Wc99E9NhKXFLEZMD0+1tBCblycZe/Ardluyudw2LwH5z1I09AHmBggiby7cT0s5Yz1JJYrXWudPD4zhp9fMGQMVmfGX2qTQKJRf6oblWGQi1YcsBjeIBc4+qP3O3+5m8X8e/XNsuKkF6Hod5qQczQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117115; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YUKe/pyeE4WEZaYZLpMtb5IvIFiXBFWsJ/0+/7s6ibI=; b=lAnbTmG9Ujscn06TvjWRdIIdgW3dSvxmS64WLu9XupvRzFn3MaPeKm+D26JS9/tVsXVchR6U+Bh4LkM8uAghhmOfsqKSHsM61nz1HDSOeDZZG6y5kXSUAeydkkbtfrv+6OjulskMYQyxx4JoNHOngb4mQa2c5Xy7BVycSOwDJPI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117115423367.5135039660669; Mon, 27 Nov 2023 12:31:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCV-0003bZ-Oj; Mon, 27 Nov 2023 15:27:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCU-0003Zr-6J for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:26 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCQ-0002rR-V1 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:25 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C657121AF4; Mon, 27 Nov 2023 20:27:19 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7C7DB1379A; Mon, 27 Nov 2023 20:27:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id OL/FEKX7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116839; 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=YUKe/pyeE4WEZaYZLpMtb5IvIFiXBFWsJ/0+/7s6ibI=; b=dTCzZ43rzOjvD+AWMMVdK1l/Bz0lvz4yhFatGCwqy0uD1YT2/CJCr8OJNQW8iIaCTGORid VdtYIF1jAn9Mye8eERik2CsRtl96eRjmv2q9LGI6EXdvecB7OPfwb6loMM+yVLR/3xj0Yv qSNOyzfFQREouSum/gWOx6svKQzTlJ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116839; 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=YUKe/pyeE4WEZaYZLpMtb5IvIFiXBFWsJ/0+/7s6ibI=; b=b3n3RaDpmbVzlC37FgBa5TFnz4HaGr7dSf7x70TAN76Raj/9b8s4u7BAfmOjylaDuv8R4H gN0FRozufoTsH8DQ== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Eric Blake Subject: [RFC PATCH v3 23/30] migration: Add direct-io parameter Date: Mon, 27 Nov 2023 17:26:05 -0300 Message-Id: <20231127202612.23012-24-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out1.suse.de; none X-Spam-Score: 0.90 X-Spamd-Result: default: False [0.90 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_SEVEN(0.00)[8]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117117545000007 Content-Type: text/plain; charset="utf-8" Add the direct-io migration parameter that tells the migration code to use O_DIRECT when opening the migration stream file whenever possible. This is currently only used with fixed-ram migration for the multifd channels that transfer the RAM pages. Those channels only transfer the pages and are guaranteed to perform aligned writes. However the parameter could be made to affect other types of file-based migrations in the future. Signed-off-by: Fabiano Rosas --- - json formatting - added checks for O_DIRECT support --- include/qemu/osdep.h | 2 ++ migration/file.c | 22 ++++++++++++++++++++-- migration/migration-hmp-cmds.c | 11 +++++++++++ migration/options.c | 30 ++++++++++++++++++++++++++++++ migration/options.h | 1 + qapi/migration.json | 18 +++++++++++++++--- util/osdep.c | 9 +++++++++ 7 files changed, 88 insertions(+), 5 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 475a1c62ff..ea5d29ab9b 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -597,6 +597,8 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t le= n, bool exclusive); bool qemu_has_ofd_lock(void); #endif =20 +bool qemu_has_direct_io(void); + #if defined(__HAIKU__) && defined(__i386__) #define FMT_pid "%ld" #elif defined(WIN64) diff --git a/migration/file.c b/migration/file.c index 62ba994109..fc5c1a45f4 100644 --- a/migration/file.c +++ b/migration/file.c @@ -61,12 +61,30 @@ int file_send_channel_destroy(QIOChannel *ioc) =20 void file_send_channel_create(QIOTaskFunc f, void *data) { - QIOChannelFile *ioc; + QIOChannelFile *ioc =3D NULL; QIOTask *task; Error *err =3D NULL; int flags =3D O_WRONLY; =20 - ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, &err); + if (migrate_direct_io()) { +#ifdef O_DIRECT + /* + * Enable O_DIRECT for the secondary channels. These are used + * for sending ram pages and writes should be guaranteed to be + * aligned to at least page size. + */ + flags |=3D O_DIRECT; +#else + error_setg(&err, "System does not support O_DIRECT"); + error_append_hint(&err, + "Try disabling direct-io migration capability\n"= ); + /* errors are propagated through the qio_task below */ +#endif + } + + if (!err) { + ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, &= err); + } =20 task =3D qio_task_new(OBJECT(ioc), f, (gpointer)data, NULL); if (!ioc) { diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c index 86ae832176..5ad6b2788d 100644 --- a/migration/migration-hmp-cmds.c +++ b/migration/migration-hmp-cmds.c @@ -392,6 +392,13 @@ void hmp_info_migrate_parameters(Monitor *mon, const Q= Dict *qdict) monitor_printf(mon, "%s: %s\n", MigrationParameter_str(MIGRATION_PARAMETER_MODE), qapi_enum_lookup(&MigMode_lookup, params->mode)); + + if (params->has_direct_io) { + monitor_printf(mon, "%s: %s\n", + MigrationParameter_str( + MIGRATION_PARAMETER_DIRECT_IO), + params->direct_io ? "on" : "off"); + } } =20 qapi_free_MigrationParameters(params); @@ -679,6 +686,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDi= ct *qdict) p->has_mode =3D true; visit_type_MigMode(v, param, &p->mode, &err); break; + case MIGRATION_PARAMETER_DIRECT_IO: + p->has_direct_io =3D true; + visit_type_bool(v, param, &p->direct_io, &err); + break; default: assert(0); } diff --git a/migration/options.c b/migration/options.c index 7f23881f51..6c100dff7a 100644 --- a/migration/options.c +++ b/migration/options.c @@ -835,6 +835,22 @@ int migrate_decompress_threads(void) return s->parameters.decompress_threads; } =20 +bool migrate_direct_io(void) +{ + MigrationState *s =3D migrate_get_current(); + + /* For now O_DIRECT is only supported with fixed-ram */ + if (!s->capabilities[MIGRATION_CAPABILITY_FIXED_RAM]) { + return false; + } + + if (s->parameters.has_direct_io) { + return s->parameters.direct_io; + } + + return false; +} + uint64_t migrate_downtime_limit(void) { MigrationState *s =3D migrate_get_current(); @@ -1052,6 +1068,11 @@ MigrationParameters *qmp_query_migrate_parameters(Er= ror **errp) params->has_mode =3D true; params->mode =3D s->parameters.mode; =20 + if (s->parameters.has_direct_io) { + params->has_direct_io =3D true; + params->direct_io =3D s->parameters.direct_io; + } + return params; } =20 @@ -1087,6 +1108,7 @@ void migrate_params_init(MigrationParameters *params) params->has_x_vcpu_dirty_limit_period =3D true; params->has_vcpu_dirty_limit =3D true; params->has_mode =3D true; + params->has_direct_io =3D qemu_has_direct_io(); } =20 /* @@ -1388,6 +1410,10 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_mode) { dest->mode =3D params->mode; } + + if (params->has_direct_io) { + dest->direct_io =3D params->direct_io; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1532,6 +1558,10 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_mode) { s->parameters.mode =3D params->mode; } + + if (params->has_direct_io) { + s->parameters.direct_io =3D params->direct_io; + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) diff --git a/migration/options.h b/migration/options.h index 84628a76e8..9fbbf30168 100644 --- a/migration/options.h +++ b/migration/options.h @@ -81,6 +81,7 @@ uint8_t migrate_cpu_throttle_increment(void); uint8_t migrate_cpu_throttle_initial(void); bool migrate_cpu_throttle_tailslow(void); int migrate_decompress_threads(void); +bool migrate_direct_io(void); uint64_t migrate_downtime_limit(void); uint8_t migrate_max_cpu_throttle(void); uint64_t migrate_max_bandwidth(void); diff --git a/qapi/migration.json b/qapi/migration.json index 3b93e13743..1d38619842 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -878,6 +878,9 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @direct-io: Open migration files with O_DIRECT when possible. This +# requires that the 'fixed-ram' capability is enabled. (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -911,7 +914,8 @@ 'block-bitmap-mapping', { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable']= }, 'vcpu-dirty-limit', - 'mode'] } + 'mode', + 'direct-io'] } =20 ## # @MigrateSetParameters: @@ -1066,6 +1070,9 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @direct-io: Open migration files with O_DIRECT when possible. This +# requires that the 'fixed-ram' capability is enabled. (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -1119,7 +1126,8 @@ '*x-vcpu-dirty-limit-period': { 'type': 'uint64', 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', - '*mode': 'MigMode'} } + '*mode': 'MigMode', + '*direct-io': 'bool' } } =20 ## # @migrate-set-parameters: @@ -1294,6 +1302,9 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @direct-io: Open migration files with O_DIRECT when possible. This +# requires that the 'fixed-ram' capability is enabled. (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use @@ -1344,7 +1355,8 @@ '*x-vcpu-dirty-limit-period': { 'type': 'uint64', 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', - '*mode': 'MigMode'} } + '*mode': 'MigMode', + '*direct-io': 'bool' } } =20 ## # @query-migrate-parameters: diff --git a/util/osdep.c b/util/osdep.c index e996c4744a..d0227a60ab 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -277,6 +277,15 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t l= en, bool exclusive) } #endif =20 +bool qemu_has_direct_io(void) +{ +#ifdef O_DIRECT + return true; +#else + return false; +#endif +} + static int qemu_open_cloexec(const char *name, int flags, mode_t mode) { int ret; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117127641579.9294293982801; Mon, 27 Nov 2023 12:32:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCW-0003bm-BV; Mon, 27 Nov 2023 15:27:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCV-0003b9-2Z for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:27 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCS-0002tH-BJ for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:26 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1A4C221B4D; Mon, 27 Nov 2023 20:27:23 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 47DE11379A; Mon, 27 Nov 2023 20:27:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id GIXmA6j7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:20 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [RFC PATCH v3 24/30] tests/qtest: Add a test for migration with direct-io and multifd Date: Mon, 27 Nov 2023 17:26:06 -0300 Message-Id: <20231127202612.23012-25-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.988]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: 1A4C221B4D 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117127954000001 Content-Type: text/plain; charset="utf-8" The test is only allowed to run in systems that know and in filesystems which support O_DIRECT. Signed-off-by: Fabiano Rosas --- - added ifdefs for O_DIRECT and a probing function --- tests/qtest/migration-helpers.c | 39 +++++++++++++++++++++++++++++++++ tests/qtest/migration-helpers.h | 1 + tests/qtest/migration-test.c | 35 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 24fb7b3525..02b92f0cb6 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -292,3 +292,42 @@ char *resolve_machine_version(const char *alias, const= char *var1, =20 return find_common_machine_version(machine_name, var1, var2); } + +#ifdef O_DIRECT +/* + * Probe for O_DIRECT support on the filesystem. Since this is used + * for tests, be conservative, if anything fails, assume it's + * unsupported. + */ +bool probe_o_direct_support(const char *tmpfs) +{ + g_autofree char *filename =3D g_strdup_printf("%s/probe-o-direct", tmp= fs); + int fd, flags =3D O_CREAT | O_RDWR | O_DIRECT; + void *buf; + ssize_t ret, len; + uint64_t offset; + + fd =3D open(filename, flags, 0660); + if (fd < 0) { + unlink(filename); + return false; + } + + /* + * Assuming 4k should be enough to satisfy O_DIRECT alignment + * requirements. The migration code uses 1M to be conservative. + */ + len =3D 0x100000; + offset =3D 0x100000; + + buf =3D g_malloc0(len); + ret =3D pwrite(fd, buf, len, offset); + unlink(filename); + + if (ret < 0) { + return false; + } + + return true; +} +#endif diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index e31dc85cc7..15df009d35 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -47,4 +47,5 @@ char *find_common_machine_version(const char *mtype, cons= t char *var1, const char *var2); char *resolve_machine_version(const char *alias, const char *var1, const char *var2); +bool probe_o_direct_support(const char *tmpfs); #endif /* MIGRATION_HELPERS_H */ diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 5c5725687c..192b8ec993 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2222,6 +2222,36 @@ static void test_multifd_file_fixed_ram(void) test_file_common(&args, true); } =20 +#ifdef O_DIRECT +static void *migrate_multifd_fixed_ram_dio_start(QTestState *from, + QTestState *to) +{ + migrate_multifd_fixed_ram_start(from, to); + + migrate_set_parameter_bool(from, "direct-io", true); + migrate_set_parameter_bool(to, "direct-io", true); + + return NULL; +} + +static void test_multifd_file_fixed_ram_dio(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_fixed_ram_dio_start, + }; + + if (!probe_o_direct_support(tmpfs)) { + g_test_skip("Filesystem does not support O_DIRECT"); + return; + } + + test_file_common(&args, true); +} +#endif =20 static void test_precopy_tcp_plain(void) { @@ -3476,6 +3506,11 @@ int main(int argc, char **argv) qtest_add_func("/migration/multifd/file/fixed-ram/live", test_multifd_file_fixed_ram_live); =20 +#ifdef O_DIRECT + qtest_add_func("/migration/multifd/file/fixed-ram/dio", + test_multifd_file_fixed_ram_dio); +#endif + #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116967; cv=none; d=zohomail.com; s=zohoarc; b=BOjzyFtoj5pz9VYmcMYTLXEPBsm0a4S/qdNw1G5NJUafJwWH9QtrCYQJnjMLb/gheycaSWUI49CSz9VFpE0EcyPY3E7tU5AWOg4mlRDYQ2MvbsJIftruaJpCSutdXtYOQYipjnO7V00X/PfEmqz+ZbH2vnILwxPZYHniKOBAlOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116967; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/G6ThC3N+nnfX7FJ2t0KT5ydaj0Xe0MiFJ+bC9uw3Bk=; b=FaZwCcI81GQgRP3S56fdifKKVgDdkl6xRZMOUv9mQ1jURjfk772mgQLpnCFoT2dMTNietPkfZXSxkOsU3GrVb4HbygEpD5W1Q7Mqe6yM12YBykPhigXnXNxmaQPH0RJrsyVKH17ui69W7z7LrsaNREJDbz12FdHRHccz8vx9XQo= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116967676833.8736527621209; Mon, 27 Nov 2023 12:29:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCX-0003cJ-9Q; Mon, 27 Nov 2023 15:27:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCW-0003bs-Fn for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:28 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCU-0002tn-UD for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:28 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 906001FB54; Mon, 27 Nov 2023 20:27:25 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 813411379A; Mon, 27 Nov 2023 20:27:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id MF4AEqv7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116845; 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=/G6ThC3N+nnfX7FJ2t0KT5ydaj0Xe0MiFJ+bC9uw3Bk=; b=UiQYTim5poxfOZq/qvYk5lHCePtyIKBGOIJMK6dwi32447452mOt+HoBi4kb8SS+bBvKrJ OhBIm2R/yPYMzg4GYh3mdINd+27RtT1qYB8pwSi2OlfsYGWE1tlXAihchw9pehtCmytOYY NAmbC3nAqHAmNe8A/h4RsuRrtqnBl4s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116845; 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=/G6ThC3N+nnfX7FJ2t0KT5ydaj0Xe0MiFJ+bC9uw3Bk=; b=qfhrvUHEVuvoZWz0GfBrz/NdOgS+9tBOhwgpFfifauS0d8zYtqCLPpJkdCXPtJntxA3fu0 j9ZGtKTAaMlLexCw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 25/30] monitor: Honor QMP request for fd removal immediately Date: Mon, 27 Nov 2023 17:26:07 -0300 Message-Id: <20231127202612.23012-26-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.90 X-Spamd-Result: default: False [3.90 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCVD_COUNT_THREE(0.00)[3]; RCPT_COUNT_SEVEN(0.00)[7]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116968102000001 Content-Type: text/plain; charset="utf-8" We're currently only removing an fd from the fdset if the VM is running. This causes a QMP call to "remove-fd" to not actually remove the fd if the VM happens to be stopped. While the fd would eventually be removed when monitor_fdset_cleanup() is called again, the user request should be honored and the fd actually removed. Calling remove-fd + query-fdset shows a recently removed fd still present. The runstate_is_running() check was introduced by commit ebe52b592d ("monitor: Prevent removing fd from set during init"), which by the shortlog indicates that they were trying to avoid removing an yet-unduplicated fd too early. I don't see why an fd explicitly removed with qmp_remove_fd() should be under runstate_is_running(). I'm assuming this was a mistake when adding the parenthesis around the expression. Move the runstate_is_running() check to apply only to the QLIST_EMPTY(dup_fds) side of the expression and ignore it when mon_fdset_fd->removed has been explicitly set. Signed-off-by: Fabiano Rosas --- monitor/fds.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monitor/fds.c b/monitor/fds.c index d86c2c674c..4ec3b7eea9 100644 --- a/monitor/fds.c +++ b/monitor/fds.c @@ -173,9 +173,9 @@ static void monitor_fdset_cleanup(MonFdset *mon_fdset) MonFdsetFd *mon_fdset_fd_next; =20 QLIST_FOREACH_SAFE(mon_fdset_fd, &mon_fdset->fds, next, mon_fdset_fd_n= ext) { - if ((mon_fdset_fd->removed || - (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount =3D=3D 0= )) && - runstate_is_running()) { + if (mon_fdset_fd->removed || + (QLIST_EMPTY(&mon_fdset->dup_fds) && mon_refcount =3D=3D 0 && + runstate_is_running())) { close(mon_fdset_fd->fd); g_free(mon_fdset_fd->opaque); QLIST_REMOVE(mon_fdset_fd, next); --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701117088; cv=none; d=zohomail.com; s=zohoarc; b=a9/kORpsPwhXSXuASyFDDT8jdxNHvqzIEZW94I3ZL9n77t5fzp1IuZSCYig+gzQ3A/+5ffr9rde30i2LEikXEg8zBjY4wwBibLMkxDhWGa+N45s6RJ0DXQwy+Yjgs5V1LzGMXs811BlOHD4O91floPUoBw/ypW0eCclY/pV6A0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701117088; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=teigS40Z9XH923OGo7nijlRjRuL+JJjtabkdVm33NUY=; b=MS+Hj2wGUv7ARVtJhrngxhGKaoehlYLZkKqprEyX0hqrMgdp5a6w15tpxHDKiKZSHxrRQwDOCbMdEMW20HmmiUAYrds6H0kKTp3uxJ2GdKFkHZ36Cvhu4MTtJuItEIR/5X6HTTCZS82MSpkVgig18H0+x/HItVdMA+iaJi0Janw= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111708883020.681161932436453; Mon, 27 Nov 2023 12:31:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCa-0003mz-10; Mon, 27 Nov 2023 15:27:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCY-0003iW-Ng for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:30 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCX-0002uQ-5v for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:30 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1F6601FB71; Mon, 27 Nov 2023 20:27:28 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0F8571379A; Mon, 27 Nov 2023 20:27:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id qBrFMa37ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116848; 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=teigS40Z9XH923OGo7nijlRjRuL+JJjtabkdVm33NUY=; b=yoyytkLmp8oST3A6p5CwaOmBvq25PYRl7I7cFi24LIAzGg6eoW79RRxL9QswD9iFcpNFnM TXfpOKCKfEkMlx9n0JwKa2wtVYBa6rTxqZ896ye7Ss01nBJbbSYcut1VB+F6vebY3uPxUt UYDHMOscyRQBM4c3JVrQT5OcvZG8kLI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116848; 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=teigS40Z9XH923OGo7nijlRjRuL+JJjtabkdVm33NUY=; b=vSu0ytlyPKehTZeRtt9AR6o7BHF9uWpGutTZQOpGL7F5IPUurz/V3jCgf1DEM4nOSSlNMo LvEftrHAX/0x1FDg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 26/30] monitor: Extract fdset fd flags comparison into a function Date: Mon, 27 Nov 2023 17:26:08 -0300 Message-Id: <20231127202612.23012-27-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.90 X-Spamd-Result: default: False [3.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_RATELIMIT(0.00)[to_ip_from(RLjrdmmf3juheryardexw6jb95)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701117090963000003 Content-Type: text/plain; charset="utf-8" We're about to add one more condition to the flags comparison that requires an ifdef. Move the code into a separate function now to make it cleaner after the next patch. Signed-off-by: Fabiano Rosas --- monitor/fds.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/monitor/fds.c b/monitor/fds.c index 4ec3b7eea9..9a28e4b72b 100644 --- a/monitor/fds.c +++ b/monitor/fds.c @@ -406,6 +406,19 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset= _id, int64_t fdset_id, return fdinfo; } =20 +#ifndef _WIN32 +static bool monitor_fdset_flags_match(int flags, int fd_flags) +{ + bool match =3D false; + + if ((flags & O_ACCMODE) =3D=3D (fd_flags & O_ACCMODE)) { + match =3D true; + } + + return match; +} +#endif + int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags) { #ifdef _WIN32 @@ -431,7 +444,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flag= s) return -1; } =20 - if ((flags & O_ACCMODE) =3D=3D (mon_fd_flags & O_ACCMODE)) { + if (monitor_fdset_flags_match(flags, mon_fd_flags)) { fd =3D mon_fdset_fd->fd; break; } --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170111693344582.1692335707935; Mon, 27 Nov 2023 12:28:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCd-00045M-0n; Mon, 27 Nov 2023 15:27:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCb-0003wl-Cs for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:33 -0500 Received: from smtp-out1.suse.de ([2a07:de40:b251:101:10:150:64:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCZ-0002ug-P1 for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:33 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A290F21B4C; Mon, 27 Nov 2023 20:27:30 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 903811379A; Mon, 27 Nov 2023 20:27:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id YEiXFbD7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:28 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 27/30] monitor: fdset: Match against O_DIRECT Date: Mon, 27 Nov 2023 17:26:09 -0300 Message-Id: <20231127202612.23012-28-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ++++++++++ X-Spam-Score: 10.99 X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none) X-Rspamd-Queue-Id: A290F21B4C X-Spamd-Result: default: False [10.99 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.71)[-0.706]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.10)[-0.490]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[13.62%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] 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=2a07:de40:b251:101:10:150:64:1; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701116935494000003 Content-Type: text/plain; charset="utf-8" We're about to enable the use of O_DIRECT in the migration code and due to the alignment restrictions imposed by filesystems we need to make sure the flag is only used when doing aligned IO. The migration will do parallel IO to different regions of a file, so we need to use more than one file descriptor. Those cannot be obtained by duplicating (dup()) since duplicated file descriptors share the file status flags, including O_DIRECT. If one migration channel does unaligned IO while another sets O_DIRECT to do aligned IO, the filesystem would fail the unaligned operation. The add-fd QMP command along with the fdset code are specifically designed to allow the user to pass a set of file descriptors with different access flags into QEMU to be later fetched by code that needs to alternate between those flags when doing IO. Extend the fdset matching function to behave the same with the O_DIRECT flag. Signed-off-by: Fabiano Rosas --- monitor/fds.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monitor/fds.c b/monitor/fds.c index 9a28e4b72b..42bf3eb982 100644 --- a/monitor/fds.c +++ b/monitor/fds.c @@ -413,6 +413,12 @@ static bool monitor_fdset_flags_match(int flags, int f= d_flags) =20 if ((flags & O_ACCMODE) =3D=3D (fd_flags & O_ACCMODE)) { match =3D true; + +#ifdef O_DIRECT + if ((flags & O_DIRECT) !=3D (fd_flags & O_DIRECT)) { + match =3D false; + } +#endif } =20 return match; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 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=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1701116883; cv=none; d=zohomail.com; s=zohoarc; b=A+/t+5lU/4HGlcsP416YD6iL6JWzRm0SWrN6gnhmZm5FZYsyCNQrg1uje1rYe2dvwK6YQfGT64XFgRzSrGENHoSnpebt+6At9VlA6bdowTUQjK2lEK17Sx2xOS5D3CkD8D0WW/8spf6HqcUp21aFEYrf4b3c7et4EALUjqETsRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701116883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/8VJDEgdcZAIPeNmyCbW1EkvIyq9yJGkC8ExgSYhW4Y=; b=oAOWpHI534/IeOECUdZ2H8gmwxuk2AkoAxasktu7+r/eY1Ae9THikaRjWLsX2F/6R5mZ8L80eOPttErbJOivQD/50vibHo0UMmO3XCI8oKJchdX9wRUNZYkiDXkn99a5kkPlfaowI5myl1Vb5deWnc2vQFWB9HyzerKxBi6E2es= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701116883825312.0304834397525; Mon, 27 Nov 2023 12:28:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCm-0004pt-GS; Mon, 27 Nov 2023 15:27:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCk-0004Xz-DP for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:42 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCc-0002ux-9e for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:42 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3102A1FB54; Mon, 27 Nov 2023 20:27:33 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1FCA01379A; Mon, 27 Nov 2023 20:27:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id GH3fNbL7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1701116853; 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=/8VJDEgdcZAIPeNmyCbW1EkvIyq9yJGkC8ExgSYhW4Y=; b=lAKh0jkIz5de9nr4vkcKwhtJZW4xGWooDgOHv0u72RywHValLBumqsGiN/OzIgD5w25rqx Zst5/pYMbT5/VTroaZVbYHJJm63TCBwJn2UOxwjRJfy04zpWh8rIzAE61Kr1oDcMHzIjZs m+Y0jKhgJ412Aat/y7Hj4EWmbYOb9Tc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1701116853; 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=/8VJDEgdcZAIPeNmyCbW1EkvIyq9yJGkC8ExgSYhW4Y=; b=B4xUE4zRSae+72s8zcqgAJyA+d2qWDmQfE73S/y8uZ4TBBJ/Q6dkw5vHNVPrT6+wzDMDxK k83U/zDNYH6qgtBg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 28/30] docs/devel/migration.rst: Document the file transport Date: Mon, 27 Nov 2023 17:26:10 -0300 Message-Id: <20231127202612.23012-29-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 3.90 X-Spamd-Result: default: False [3.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_RATELIMIT(0.00)[to_ip_from(RLjrdmmf3juheryardexw6jb95)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-0.00)[17.13%] 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1701116884358000003 Content-Type: text/plain; charset="utf-8" When adding the support for file migration with the file: transport, we missed adding documentation for it. Signed-off-by: Fabiano Rosas --- docs/devel/migration.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index eeb4fec31f..1488e5b2f9 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -41,6 +41,10 @@ over any transport. - exec migration: do the migration using the stdin/stdout through a proces= s. - fd migration: do the migration using a file descriptor that is passed to QEMU. QEMU doesn't care how this file descriptor is opened. +- file migration: do the migration using a file that is passed to QEMU + by path. A file offset option is supported to allow a management + application to add its own metadata to the start of the file without + QEMU interference. =20 In addition, support is included for migration using RDMA, which transports the page data using ``RDMA``, where the hardware takes care of --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117140258319.5424785304069; Mon, 27 Nov 2023 12:32:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCn-0004uh-5S; Mon, 27 Nov 2023 15:27:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCk-0004dF-Us for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:42 -0500 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCi-0002vQ-Sw for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:42 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B2FA81FB74; Mon, 27 Nov 2023 20:27:35 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A36A71379A; Mon, 27 Nov 2023 20:27:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id OIVpGrX7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:33 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana Subject: [RFC PATCH v3 29/30] migration: Add support for fdset with multifd + file Date: Mon, 27 Nov 2023 17:26:11 -0300 Message-Id: <20231127202612.23012-30-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.987]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: B2FA81FB74 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=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117142077000003 Content-Type: text/plain; charset="utf-8" Allow multifd to use an fdset when migrating to a file. This is useful for the scenario where the management layer wants to have control over the migration file. By receiving the file descriptors directly, QEMU can delegate some high level operating system operations to the management layer (such as mandatory access control). The management layer might also want to add its own headers before the migration stream. Enable the "file:/dev/fdset/#" syntax for the multifd migration with fixed-ram. The requirements for the fdset mechanism are: On the migration source side: - the fdset must contain two fds that are not duplicates between themselves; - if direct-io is to be used, exactly one of the fds must have the O_DIRECT flag set; - the file must be opened with WRONLY both times. On the migration destination side: - the fdset must contain one fd; - the file must be opened with RDONLY. Signed-off-by: Fabiano Rosas --- docs/devel/migration.rst | 18 +++++++ migration/file.c | 100 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 6 deletions(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index 1488e5b2f9..096ef27ed7 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -46,6 +46,24 @@ over any transport. application to add its own metadata to the start of the file without QEMU interference. =20 + The file migration also supports using a file that has already been + opened. A set of file descriptors is passed to QEMU via an "fdset" + (see add-fd QMP command documentation). This method allows a + management application to have control over the migration file + opening operation. There are, however, strict requirements to this + interface: + + On the migration source side: + - the fdset must contain two file descriptors that are not + duplicates between themselves; + - if the direct-io capability is to be used, exactly one of the + file descriptors must have the O_DIRECT flag set; + - the file must be opened with WRONLY both times. + + On the migration destination side: + - the fdset must contain one file descriptor; + - the file must be opened with RDONLY. + In addition, support is included for migration using RDMA, which transports the page data using ``RDMA``, where the hardware takes care of transporting the pages, and the load on the CPU is much lower. While the diff --git a/migration/file.c b/migration/file.c index fc5c1a45f4..4b06335a8c 100644 --- a/migration/file.c +++ b/migration/file.c @@ -9,11 +9,13 @@ #include "qemu/cutils.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/qapi-commands-misc.h" #include "channel.h" #include "file.h" #include "migration.h" #include "io/channel-file.h" #include "io/channel-util.h" +#include "monitor/monitor.h" #include "options.h" #include "trace.h" =20 @@ -21,6 +23,7 @@ =20 static struct FileOutgoingArgs { char *fname; + int64_t fdset_id; } outgoing_args; =20 /* Remove the offset option from @filespec and return it in @offsetp. */ @@ -42,6 +45,84 @@ int file_parse_offset(char *filespec, uint64_t *offsetp,= Error **errp) return 0; } =20 +/* + * If the open flags and file status flags from the file descriptors + * in the fdset don't match what QEMU expects, errno gets set to + * EACCES. Let's provide a more user-friendly message. + */ +static void file_fdset_error(int flags, Error **errp) +{ + ERRP_GUARD(); + + if (errno =3D=3D EACCES) { + /* ditch the previous error */ + error_free(*errp); + *errp =3D NULL; + + error_setg(errp, "Fdset is missing a file descriptor with flags: 0= x%x", + flags); + } +} + +static void file_remove_fdset(void) +{ + if (outgoing_args.fdset_id !=3D -1) { + qmp_remove_fd(outgoing_args.fdset_id, false, -1, NULL); + outgoing_args.fdset_id =3D -1; + } +} + +/* + * Due to the behavior of the dup() system call, we need the fdset to + * have two non-duplicate fds so we can enable direct IO in the + * secondary channels without affecting the main channel. + */ +static bool file_parse_fdset(const char *filename, int64_t *fdset_id, + Error **errp) +{ + FdsetInfoList *fds_info; + FdsetFdInfoList *fd_info; + const char *fdset_id_str; + int nfds =3D 0; + + *fdset_id =3D -1; + + if (!strstart(filename, "/dev/fdset/", &fdset_id_str)) { + return true; + } + + if (!migrate_multifd()) { + error_setg(errp, "fdset is only supported with multifd"); + return false; + } + + *fdset_id =3D qemu_parse_fd(fdset_id_str); + + for (fds_info =3D qmp_query_fdsets(NULL); fds_info; + fds_info =3D fds_info->next) { + + if (*fdset_id !=3D fds_info->value->fdset_id) { + continue; + } + + for (fd_info =3D fds_info->value->fds; fd_info; fd_info =3D fd_inf= o->next) { + if (nfds++ > 2) { + break; + } + } + } + + if (nfds !=3D 2) { + error_setg(errp, "Outgoing migration needs two fds in the fdset, " + "got %d", nfds); + qmp_remove_fd(*fdset_id, false, -1, NULL); + *fdset_id =3D -1; + return false; + } + + return true; +} + static void qio_channel_file_connect_worker(QIOTask *task, gpointer opaque) { /* noop */ @@ -56,6 +137,7 @@ int file_send_channel_destroy(QIOChannel *ioc) g_free(outgoing_args.fname); outgoing_args.fname =3D NULL; =20 + file_remove_fdset(); return 0; } =20 @@ -88,6 +170,7 @@ void file_send_channel_create(QIOTaskFunc f, void *data) =20 task =3D qio_task_new(OBJECT(ioc), f, (gpointer)data, NULL); if (!ioc) { + file_fdset_error(flags, &err); qio_task_set_error(task, err); return; } @@ -108,13 +191,18 @@ void file_start_outgoing_migration(MigrationState *s, =20 trace_migration_file_outgoing(filename); =20 - fioc =3D qio_channel_file_new_path(filename, flags, mode, errp); - if (!fioc) { + if (!file_parse_fdset(filename, &outgoing_args.fdset_id, errp)) { return; } =20 outgoing_args.fname =3D g_strdup(filename); =20 + fioc =3D qio_channel_file_new_path(filename, flags, mode, errp); + if (!fioc) { + file_fdset_error(flags, errp); + return; + } + ioc =3D QIO_CHANNEL(fioc); if (offset && qio_channel_io_seek(ioc, offset, SEEK_SET, errp) < 0) { return; @@ -138,13 +226,14 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) QIOChannelFile *fioc =3D NULL; uint64_t offset =3D file_args->offset; int channels =3D 1; - int i =3D 0, fd; + int i =3D 0, fd, flags =3D O_RDONLY; =20 trace_migration_file_incoming(filename); =20 - fioc =3D qio_channel_file_new_path(filename, O_RDONLY, 0, errp); + fioc =3D qio_channel_file_new_path(filename, flags, 0, errp); if (!fioc) { - goto out; + file_fdset_error(flags, errp); + return; } =20 if (offset && @@ -168,7 +257,6 @@ void file_start_incoming_migration(FileMigrationArgs *f= ile_args, Error **errp) g_main_context_get_thread_default()); } while (++i < channels && (fioc =3D qio_channel_file_new_fd(fd))); =20 -out: if (!fioc) { error_setg(errp, "Error creating migration incoming channel"); return; --=20 2.35.3 From nobody Wed Nov 27 02:19:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701117081942785.8429472835672; Mon, 27 Nov 2023 12:31:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r7iCn-0004yU-Te; Mon, 27 Nov 2023 15:27:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r7iCl-0004mu-VW for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:43 -0500 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r7iCi-0002vk-TF for qemu-devel@nongnu.org; Mon, 27 Nov 2023 15:27:43 -0500 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F03171FB7A; Mon, 27 Nov 2023 20:27:38 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 362411379A; Mon, 27 Nov 2023 20:27:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 0FJHO7f7ZGVfIQAAD6G6ig (envelope-from ); Mon, 27 Nov 2023 20:27:35 +0000 From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: berrange@redhat.com, armbru@redhat.com, Juan Quintela , Peter Xu , Leonardo Bras , Claudio Fontana , Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [RFC PATCH v3 30/30] tests/qtest: Add a test for fixed-ram with passing of fds Date: Mon, 27 Nov 2023 17:26:12 -0300 Message-Id: <20231127202612.23012-31-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231127202612.23012-1-farosas@suse.de> References: <20231127202612.23012-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: +++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:97 is neither permitted nor denied by domain of farosas@suse.de) smtp.mailfrom=farosas@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [7.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; NEURAL_HAM_LONG(-0.99)[-0.988]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[10]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 7.80 X-Rspamd-Queue-Id: F03171FB7A 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.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701117082799000005 Content-Type: text/plain; charset="utf-8" Add a multifd test for fixed-ram with passing of fds into QEMU. This is how libvirt will consume the feature. There are a couple of details to the fdset mechanism: - multifd needs two distinct file descriptors (not duplicated with dup()) on the outgoing side so it can enable O_DIRECT only on the channels that write with alignment. The dup() system call creates file descriptors that share status flags, of which O_DIRECT is one. the incoming side doesn't set O_DIRECT, so it can dup() fds and therefore can receive only one in the fdset. - the open() access mode flags used for the fds passed into QEMU need to match the flags QEMU uses to open the file. Currently O_WRONLY for src and O_RDONLY for dst. O_DIRECT is not supported on all systems/filesystems, so run the fdset test without O_DIRECT if that's the case. The migration code should still work in that scenario. Signed-off-by: Fabiano Rosas --- tests/qtest/migration-helpers.c | 7 ++- tests/qtest/migration-test.c | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 02b92f0cb6..3013094800 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -302,7 +302,7 @@ char *resolve_machine_version(const char *alias, const = char *var1, bool probe_o_direct_support(const char *tmpfs) { g_autofree char *filename =3D g_strdup_printf("%s/probe-o-direct", tmp= fs); - int fd, flags =3D O_CREAT | O_RDWR | O_DIRECT; + int fd, flags =3D O_CREAT | O_RDWR | O_TRUNC | O_DIRECT; void *buf; ssize_t ret, len; uint64_t offset; @@ -320,9 +320,12 @@ bool probe_o_direct_support(const char *tmpfs) len =3D 0x100000; offset =3D 0x100000; =20 - buf =3D g_malloc0(len); + buf =3D aligned_alloc(len, len); + g_assert(buf); + ret =3D pwrite(fd, buf, len, offset); unlink(filename); + g_free(buf); =20 if (ret < 0) { return false; diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 192b8ec993..bb2dd805fc 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2251,8 +2251,90 @@ static void test_multifd_file_fixed_ram_dio(void) =20 test_file_common(&args, true); } + +static void migrate_multifd_fixed_ram_fdset_dio_end(QTestState *from, + QTestState *to, + void *opaque) +{ + QDict *resp; + QList *fdsets; + + /* + * Check that we removed the fdsets after migration, otherwise a + * second migration would fail due to too many fdsets. + */ + + resp =3D qtest_qmp(from, "{'execute': 'query-fdsets', " + "'arguments': {}}"); + g_assert(qdict_haskey(resp, "return")); + fdsets =3D qdict_get_qlist(resp, "return"); + g_assert(fdsets && qlist_empty(fdsets)); +} +#endif /* O_DIRECT */ + +#ifndef _WIN32 +static void *migrate_multifd_fixed_ram_fdset(QTestState *from, QTestState = *to) +{ + g_autofree char *file =3D g_strdup_printf("%s/%s", tmpfs, FILE_TEST_FI= LENAME); + int fds[3]; + int src_flags =3D O_CREAT | O_WRONLY; + int dst_flags =3D O_CREAT | O_RDONLY; + + /* main outgoing channel: no O_DIRECT */ + fds[0] =3D open(file, src_flags, 0660); + assert(fds[0] !=3D -1); + +#ifdef O_DIRECT + src_flags |=3D O_DIRECT; #endif =20 + /* secondary outgoing channels */ + fds[1] =3D open(file, src_flags, 0660); + assert(fds[1] !=3D -1); + + qtest_qmp_fds_assert_success(from, &fds[0], 1, "{'execute': 'add-fd', " + "'arguments': {'fdset-id': 1}}"); + + qtest_qmp_fds_assert_success(from, &fds[1], 1, "{'execute': 'add-fd', " + "'arguments': {'fdset-id': 1}}"); + + /* incoming channel */ + fds[2] =3D open(file, dst_flags, 0660); + assert(fds[2] !=3D -1); + + qtest_qmp_fds_assert_success(to, &fds[2], 1, "{'execute': 'add-fd', " + "'arguments': {'fdset-id': 1}}"); + +#ifdef O_DIRECT + migrate_multifd_fixed_ram_dio_start(from, to); +#else + migrate_multifd_fixed_ram_start(from, to); +#endif + + return NULL; +} + +static void test_multifd_file_fixed_ram_fdset(void) +{ + g_autofree char *uri =3D g_strdup_printf("file:/dev/fdset/1,offset=3D0= x100"); + MigrateCommon args =3D { + .connect_uri =3D uri, + .listen_uri =3D "defer", + .start_hook =3D migrate_multifd_fixed_ram_fdset, +#ifdef O_DIRECT + .finish_hook =3D migrate_multifd_fixed_ram_fdset_dio_end, +#endif + }; + + if (!probe_o_direct_support(tmpfs)) { + g_test_skip("Filesystem does not support O_DIRECT"); + return; + } + + test_file_common(&args, true); +} +#endif /* _WIN32 */ + static void test_precopy_tcp_plain(void) { MigrateCommon args =3D { @@ -3511,6 +3593,11 @@ int main(int argc, char **argv) test_multifd_file_fixed_ram_dio); #endif =20 +#ifndef _WIN32 + qtest_add_func("/migration/multifd/file/fixed-ram/fdset", + test_multifd_file_fixed_ram_fdset); +#endif + #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); --=20 2.35.3