From nobody Sat May 4 09:50:50 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; arc=pass (i=1 dmarc=pass fromdomain=nutanix.com); dmarc=pass(p=none dis=none) header.from=nutanix.com ARC-Seal: i=2; a=rsa-sha256; t=1667840018; cv=pass; d=zohomail.com; s=zohoarc; b=NxM5Y/CSGj87urzJZamqkMDJWBlW6+gye1c+tNHFIp8YeEpXqzktHZK8cDVmRDSv6a36qXpjo1So1uwLwX+eqSjO5arKEC4auE6AAuX5xcl6WaBW1UEAEL/7FZQdjeAYmVacR7IGf+1qTdD3ZSBcz7rYQ1kgeayJlq8pYBEhJpU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667840018; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=eSU6P+ltkfRaa1HIV6c5ZbHBsF7pcYPehHugtz/MSeM=; b=boGHFm7nxJCoyTPd7GMo+vNngKK+YBDkXABD6AulHt+tBSh31vHzHgiwPuvI8pc7FnFEfwLZ/XEmkCJTexmEmNMNpW9Oa7/AbkWkEaGdcTIs5WXGHeUzRMnnzFK9vazCYvoYCmtXkvE/dQdIN7KYW73H9Y7mF0t0ya3sVmFCoqk= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=nutanix.com); 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 1667840018308625.797533587747; Mon, 7 Nov 2022 08:53:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1os5Mn-0003ak-35; Mon, 07 Nov 2022 11:52: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 1os5Ml-0003aZ-GU for qemu-devel@nongnu.org; Mon, 07 Nov 2022 11:52:55 -0500 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1os5Mc-0005mU-TC for qemu-devel@nongnu.org; Mon, 07 Nov 2022 11:52:55 -0500 Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2A7AF3cT027173; Mon, 7 Nov 2022 08:52:39 -0800 Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3kpebntu22-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 07 Nov 2022 08:52:39 -0800 Received: from PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) by CY8PR02MB9154.namprd02.prod.outlook.com (2603:10b6:930:96::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.25; Mon, 7 Nov 2022 16:52:35 +0000 Received: from PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::6900:90d6:f4c2:8509]) by PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::6900:90d6:f4c2:8509%6]) with mapi id 15.20.5791.026; Mon, 7 Nov 2022 16:52:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=eSU6P+ltkfRaa1HIV6c5ZbHBsF7pcYPehHugtz/MSeM=; b=rQZT1KxDf5OPmZ21J2iBaeEwdI1tESBTeAoEO/766aGznqyvmRkcgPVFbx7rfibI7Nrz u1KppLm01i9TjTujBG8TiO2Ke+7FE/JPz8UL999fxKX/+tKj9h/nVy6oMc1AOArEiLAI kKDBQ/VLG8piHEtVwAa/J2ZXsmRaNGvKasbAcDyCK+Ti1CNT80IsC6Sb8wBjBbVbGv9y KdrK/xuihsrwOlM6IKU27HrraHULKEJF8xxL+9JLzVBsC8O2xQXxqtSiFmsozJb7ULIe EH310zMKnIVJIAnWlQlxWAbRwOUd1p0oC4OYM94kr4gK/Q9Eu6L/pkbn0zeri03I4A0S ng== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6lEa9EZFb4B8PJzpCrrx5gEPO/OXxq9geBasQ+lr4hg5fNHLMxnkRq8uVlW9uQ5Yg1aiBFX4NYEJeFutgzK37I2C6+NEBdOo+WloGPdbmOi2Fc8xYBqVyz3oBILfiG9SsCE7mRABIQ3gPaita089k8xbErdNfVSu4C734WbsfZLGWc0zIh/1KXtzeYDqY3wy3V14Bj57cCH0weGnC2or3AMPWelkOxe+tyhbWNigcnUXaR/ViKsF06yQSkt+mAEIDqbBa9WmOEPERpfF59O+SDdtZSFN70sV5tu6rj+odGHoOiVvVnnVLqdeUIcuVBaHKoGlEBBk68auMvszONt6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eSU6P+ltkfRaa1HIV6c5ZbHBsF7pcYPehHugtz/MSeM=; b=DCam8Sc6NAU5xHgaCTUEgjAwgfW8/uGl1K5tgYfyaJ47lI6P/YACivY5ZBAzAZRNUcmkSSN0NCe1fAjYv41IMUeXiqnnE/widvbtSgcXG7YTjdKAXv6MN39zFc+/rdv6NpEDb/0OZH6V29rMZnTbsEYT61YT2MT4DrTh7grlsXvF9wqu9FgzfKpkQKBKjdb8bdfMR9vXP5xB7GggrQPMA5wKyLrh7HJRamm7HdhpgmR8C9lituO+dWLZG6I9yKO7S1NCob85xhd4PE15R98vgsz/UelhWEHJYwnlrw0jdILnp5QJBm5/kisQ+qDvR81cDsr9kPoCF68j1rVy7PRxlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eSU6P+ltkfRaa1HIV6c5ZbHBsF7pcYPehHugtz/MSeM=; b=FasdTLEwtUZBwuWeaDk9505r52OZDT+ple/tQKYoOcRxVHiG2DV2IAO6RxohkcT1sf7YN+z33cl7jKBLyzYLFVa8rEUhbdQa6m7nMUPg3pLNZFhoyEhglpsPuLFnyzETKGMekp+7B0IXukOu6k87nJxDNxLlmM4VsmNRuQPrK5588X88ae4Bp9CswpwdBTBl/3sXj3dL+uhhbjzu+cw7aZAw1TYE6ToDjUTVi6evtPt649SeqbXrFuCI6kT6o3MJTmzLQJy2U1Z0F/bar6UOHQUGpIBqpslVoHLW78sxTqM9A0OyJYXvYWFJcLUdG8I5A+gIZXOEk9a6Q74D38Oycw== From: "manish.mishra" To: qemu-devel@nongnu.org Cc: berrange@redhat.com, peterx@redhat.com, prerna.saxena@nutanix.com, quintela@redhat.com, "manish.mishra" Subject: [PATCH v2] migration: check magic value for deciding the mapping of channels Date: Mon, 7 Nov 2022 16:51:59 +0000 Message-Id: <20221107165159.49534-1-manish.mishra@nutanix.com> X-Mailer: git-send-email 2.22.3 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0P220CA0012.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::24) To PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR02MB7384:EE_|CY8PR02MB9154:EE_ X-MS-Office365-Filtering-Correlation-Id: f3dfca5d-9d2b-4be1-1c5b-08dac0e078a8 x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IFK6LgnPbws9FRtH8R3yek7fmz/HxA/+DP2FsTE7yMzGAWtV85DuKd/D7bea3ntY5WvZLrgqdkQmmw7Db/uOw0NySbGMqIzw+zGzwyn7pBf5evj9kSN79GLivsG9Bbh5Fc60bv4IE+CY11xj/OF1b0f+Puh1TAf3IJgdFOUBDgiJ0/q+kFgpQ6gnAzYWPfU+GzEB3RyeonjuobV1z6MRcpMW/gtud5n54Q4mEqW81B4LIyy01YiVzwrrBQjlyXS0XNoLHCSjE5Aua9YBZG/hYsqfbW2/URJKMpuaonEmRTgRxK7WyfQVOSLrkF2cl15FbP78sdKhwlAmz8gh07+WR4u6HkwZKZaWhD0jzDRNaIK+g6UhCfRZFNrbYruQULYcBMs46ea1LOpnKgEVDsT9qfX2R6rLlqzaXgNZqtSqmrn4rQIV00whu/AnRBhgddJhEI9Hrli1XNPs6nDFtHueLZ7D0lrCpLNaCCP/CnHcF9y0gmF3jPlRrxd+MU81vXTkyTkkYkLqMz2xdVVS4TM4zBegk/cXPOXsGQCDS3dmzKoUjzxOI4/+B57Lz+AEnjQ2CVQyD0uaCt2Zpu3thFyMEq/5jJRcPRhHXmbI35BSnextQCRqZblTO2NUuWYbJylZQNk14rR51xN2BSg+OXhjm5fBt+ZSB4GUt38aNYAIxoiPxzazNouys326x9nEo3qt2A0IAw+EtIZb/Ts961n3XoNi41W99jPyXWvhLXGynnatYG7fIQujvngjZpwkSeQPlWD957/9t8uIX1Vxxtnp9Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR02MB7384.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(346002)(376002)(396003)(136003)(366004)(39860400002)(451199015)(186003)(1076003)(83380400001)(52116002)(2616005)(107886003)(6512007)(6506007)(6666004)(26005)(30864003)(2906002)(5660300002)(478600001)(41300700001)(8676002)(6486002)(8936002)(66476007)(4326008)(66556008)(66946007)(316002)(6916009)(36756003)(38350700002)(38100700002)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MnpkcERJWlZpbG1XbER5MmFXV1NWdVNNaUI1UWFMVEYreDVlUWoyS1FOY0JS?= =?utf-8?B?eDZvV1dlYkVFRDl0SHZKWlR6Vm5zckR2R2UxMmlhT05wNFZ4ZjZ2Q1ZLNURp?= =?utf-8?B?Q3BnQ1FpSlNmQWkxRmZUSWhoNm16a25yamRJK0Y2bS83SDRjcHN3VGxXbEVR?= =?utf-8?B?UlJLd09ZNWgxWERNdmQ0YUFEcW5ObFJnNk5EUGpxTGlzdHU5Zi9qenYvK0tQ?= =?utf-8?B?N3JNQUhLdGhsaHFZb00xemo5MHY1KyttUExiaU1WSEZEa2dYc1doU0dmYjdS?= =?utf-8?B?WUh3djZRWGowV3BKcFQxN0hpeElOL0NiRm9xcXdzSGRXanFKczR5eVRUOFpi?= =?utf-8?B?eDRhUmxDMUQwSXNEN1R3ZU1CVCtuSkNyRzI4L3d6ci9seFF5MDRrR2kvNW9j?= =?utf-8?B?N1VZZ21ROU84c2xpU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-Id: f3dfca5d-9d2b-4be1-1c5b-08dac0e078a8 X-MS-Exchange-CrossTenant-AuthSource: PH0PR02MB7384.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2022 16:52:35.7711 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SnXYU110ZHE032E+XkeBT3JUDGgcCumHZNgFpjzwuchey+fp4xX6MVLPAeT9Uv89MFvzUApji2tecIZQHFrZC1TanV2iHyhgByn92uOWqPk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR02MB9154 X-Proofpoint-ORIG-GUID: C2XxNl99nwQuy4OK36zbZmpUoQkqqYkC X-Proofpoint-GUID: C2XxNl99nwQuy4OK36zbZmpUoQkqqYkC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-07_08,2022-11-07_02,2022-06-22_01 X-Proofpoint-Spam-Reason: safe 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=148.163.151.68; envelope-from=manish.mishra@nutanix.com; helo=mx0a-002c1b01.pphosted.com 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, DKIMWL_WL_HIGH=-0.001, 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 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 @nutanix.com) X-ZM-MESSAGEID: 1667840020124100001 Current logic assumes that channel connections on the destination side are always established in the same order as the source and the first one will always be the main channel followed by the multifid or post-copy preemption channel. This may not be always true, as even if a channel has a connection established on the source side it can be in the pending state on the destination side and a newer connection can be established first. Basically causing out of order mapping of channels on the destination side. Currently, all channels except post-copy preempt send a magic number, this patch uses that magic number to decide the type of channel. This logic is applicable only for precopy(multifd) live migration, as mentioned, the post-copy preempt channel does not send any magic number. Also, tls live migrations already does tls handshake before creating other channels, so this issue is not possible with tls, hence this logic is avoided for tls live migrations. This patch uses MSG_PEEK to check the magic number of channels so that current data/control stream management remains un-effected. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: manish.mishra v2: TLS does not support MSG_PEEK, so V1 was broken for tls live migrations. For tls live migration, while initializing main channel tls handshake is done before we can create other channels, so this issue is not possible for tls live migrations. In V2 added a check to avoid checking magic number for tls live migration and fallback to older method to decide mapping of channels on destination side. --- include/io/channel.h | 25 +++++++++++++++++++++++ io/channel-socket.c | 27 ++++++++++++++++++++++++ io/channel.c | 39 +++++++++++++++++++++++++++++++++++ migration/migration.c | 44 +++++++++++++++++++++++++++++----------- migration/multifd.c | 12 ++++------- migration/multifd.h | 2 +- migration/postcopy-ram.c | 5 +---- migration/postcopy-ram.h | 2 +- 8 files changed, 130 insertions(+), 26 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index c680ee7480..74177aeeea 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -115,6 +115,10 @@ struct QIOChannelClass { int **fds, size_t *nfds, Error **errp); + ssize_t (*io_read_peek)(QIOChannel *ioc, + void *buf, + size_t nbytes, + Error **errp); int (*io_close)(QIOChannel *ioc, Error **errp); GSource * (*io_create_watch)(QIOChannel *ioc, @@ -475,6 +479,27 @@ int qio_channel_write_all(QIOChannel *ioc, size_t buflen, Error **errp); =20 +/** + * qio_channel_read_peek_all: + * @ioc: the channel object + * @buf: the memory region to read in data + * @nbytes: the number of bytes to read + * @errp: pointer to a NULL-initialized error object + * + * Read given @nbytes data from peek of channel into + * memory region @buf. + * + * The function will be blocked until read size is + * equal to requested size. + * + * Returns: 1 if all bytes were read, 0 if end-of-file + * occurs without data, or -1 on error + */ +int qio_channel_read_peek_all(QIOChannel *ioc, + void* buf, + size_t nbytes, + Error **errp); + /** * qio_channel_set_blocking: * @ioc: the channel object diff --git a/io/channel-socket.c b/io/channel-socket.c index b76dca9cc1..b99f5dfda6 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -705,6 +705,32 @@ static ssize_t qio_channel_socket_writev(QIOChannel *i= oc, } #endif /* WIN32 */ =20 +static ssize_t qio_channel_socket_read_peek(QIOChannel *ioc, + void *buf, + size_t nbytes, + Error **errp) +{ + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); + ssize_t bytes =3D 0; + +retry: + bytes =3D recv(sioc->fd, buf, nbytes, MSG_PEEK); + + if (bytes < 0) { + if (errno =3D=3D EINTR) { + goto retry; + } + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + + error_setg_errno(errp, errno, + "Unable to read from peek of socket"); + return -1; + } + + return bytes; +} =20 #ifdef QEMU_MSG_ZEROCOPY static int qio_channel_socket_flush(QIOChannel *ioc, @@ -902,6 +928,7 @@ static void qio_channel_socket_class_init(ObjectClass *= klass, =20 ioc_klass->io_writev =3D qio_channel_socket_writev; ioc_klass->io_readv =3D qio_channel_socket_readv; + ioc_klass->io_read_peek =3D qio_channel_socket_read_peek; ioc_klass->io_set_blocking =3D qio_channel_socket_set_blocking; ioc_klass->io_close =3D qio_channel_socket_close; ioc_klass->io_shutdown =3D qio_channel_socket_shutdown; diff --git a/io/channel.c b/io/channel.c index 0640941ac5..a2d9b96f3f 100644 --- a/io/channel.c +++ b/io/channel.c @@ -346,6 +346,45 @@ int qio_channel_write_all(QIOChannel *ioc, return qio_channel_writev_all(ioc, &iov, 1, errp); } =20 +int qio_channel_read_peek_all(QIOChannel *ioc, + void* buf, + size_t nbytes, + Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + ssize_t bytes =3D 0; + + if (!klass->io_read_peek) { + error_setg(errp, "Channel does not support read peek"); + return -1; + } + + while (bytes < nbytes) { + bytes =3D klass->io_read_peek(ioc, + buf, + nbytes, + errp); + + if (bytes =3D=3D QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_OUT); + } else { + qio_channel_wait(ioc, G_IO_OUT); + } + continue; + } + if (bytes =3D=3D 0) { + error_setg(errp, + "Unexpected end-of-file on channel"); + return 0; + } + if (bytes < 0) { + return -1; + } + } + + return 1; +} =20 int qio_channel_set_blocking(QIOChannel *ioc, bool enabled, diff --git a/migration/migration.c b/migration/migration.c index 739bb683f3..406a9e2f72 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -733,31 +733,51 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; - bool start_migration; QEMUFile *f; + bool default_channel =3D true; + uint32_t channel_magic =3D 0; + int ret =3D 0; =20 - if (!mis->from_src_file) { - /* The first connection (multifd may have multiple) */ + if (migrate_use_multifd() && !migration_in_postcopy() && + !migrate_use_tls()) { + /* + * With multiple channels, it is possible that we receive channels + * out of order on destination side, causing incorrect mapping of + * source channels on destination side. Check channel MAGIC to + * decide type of channel. Please note this is best effort, postco= py + * preempt channel does not send any magic number so avoid it for + * postcopy live migration. Also tls live migration already does + * tls handshake while initializing main channel so with tls this + * issue is not possible. + */ + ret =3D qio_channel_read_peek_all(ioc, (void *)&channel_magic, + sizeof(channel_magic), &local_err); + + if (ret !=3D 1) { + error_propagate(errp, local_err); + return; + } + + default_channel =3D (channel_magic =3D=3D cpu_to_be32(QEMU_VM_FILE= _MAGIC)); + } else { + default_channel =3D !mis->from_src_file; + } + + if (default_channel) { f =3D qemu_file_new_input(ioc); =20 if (!migration_incoming_setup(f, errp)) { return; } - - /* - * Common migration only needs one channel, so we can start - * right now. Some features need more than one channel, we wait. - */ - start_migration =3D !migration_needs_multiple_sockets(); } else { /* Multiple connections */ assert(migration_needs_multiple_sockets()); if (migrate_use_multifd()) { - start_migration =3D multifd_recv_new_channel(ioc, &local_err); + multifd_recv_new_channel(ioc, &local_err); } else { assert(migrate_postcopy_preempt()); f =3D qemu_file_new_input(ioc); - start_migration =3D postcopy_preempt_new_channel(mis, f); + postcopy_preempt_new_channel(mis, f); } if (local_err) { error_propagate(errp, local_err); @@ -765,7 +785,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) } } =20 - if (start_migration) { + if (migration_has_all_channels()) { /* If it's a recovery, we're done */ if (postcopy_try_recover()) { return; diff --git a/migration/multifd.c b/migration/multifd.c index 586ddc9d65..be86a4d07f 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1220,11 +1220,9 @@ bool multifd_recv_all_channels_created(void) =20 /* * Try to receive all multifd channels to get ready for the migration. - * - Return true and do not set @errp when correctly receiving all channel= s; - * - Return false and do not set @errp when correctly receiving the curren= t one; - * - Return false and set @errp when failing to receive the current channe= l. + * Sets @errp when failing to receive the current channel. */ -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) +void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; @@ -1237,7 +1235,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) "failed to receive packet" " via multifd channel %d: ", qatomic_read(&multifd_recv_state->count)); - return false; + return; } trace_multifd_recv_new_channel(id); =20 @@ -1247,7 +1245,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) id); multifd_recv_terminate_threads(local_err); error_propagate(errp, local_err); - return false; + return; } p->c =3D ioc; object_ref(OBJECT(ioc)); @@ -1258,6 +1256,4 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); qatomic_inc(&multifd_recv_state->count); - return qatomic_read(&multifd_recv_state->count) =3D=3D - migrate_multifd_channels(); } diff --git a/migration/multifd.h b/migration/multifd.h index 519f498643..913e4ba274 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -18,7 +18,7 @@ void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); int multifd_load_cleanup(Error **errp); bool multifd_recv_all_channels_created(void); -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); +void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); 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); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index b9a37ef255..f84f783ab4 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1539,7 +1539,7 @@ void postcopy_unregister_shared_ufd(struct PostCopyFD= *pcfd) } } =20 -bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) +void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) { /* * The new loading channel has its own threads, so it needs to be @@ -1548,9 +1548,6 @@ bool postcopy_preempt_new_channel(MigrationIncomingSt= ate *mis, QEMUFile *file) qemu_file_set_blocking(file, true); mis->postcopy_qemufile_dst =3D file; trace_postcopy_preempt_new_channel(); - - /* Start the migration immediately */ - return true; } =20 /* diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 6147bf7d1d..25881c4127 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -190,7 +190,7 @@ enum PostcopyChannels { RAM_CHANNEL_MAX, }; =20 -bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); +void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); int postcopy_preempt_setup(MigrationState *s, Error **errp); int postcopy_preempt_wait_channel(MigrationState *s); =20 --=20 2.22.3