From nobody Thu May 16 05:12:33 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=1671562192; cv=pass; d=zohomail.com; s=zohoarc; b=d1vLBUcVijFGcQ5R/Z4Hv0EjeJzvIrcAWG8wySGFb1S5iYbdC61bKpJJxAVNwJb6KaT7V6YzCeEiiLPSuuoL+x96Yz6ZmC8o3+w0mYvFhPVwVByPhCvwCKmQKOLV8xWRQX8uVAoRvHAcKOrpiyIk9hne8QaDlzb41JFWPT7tE5Q= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671562192; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=T+UQS1alBNd/DgGaRheG1P/jnPqIy7UMgCH9EEOF3aM=; b=i4ut9gVS6o1Y0TVQ9tA4Zto9F0rnZqLC0d85r+70b+pmqR4gtsRwMA/9dnS+ENq2M2n7oDdmk0vNs1GysL9eBG97b44LMNvBVKUySNgfJZXrzX7WceZYYtspk6zMucw6dz7P3ON58J4eK+H1hostQaXlMvZixfdKl6oYbvDPtBU= 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 1671562192248602.2960529942153; Tue, 20 Dec 2022 10:49:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7hbr-0004Bw-OJ; Tue, 20 Dec 2022 13:45:03 -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 1p7hbg-00046f-Hd for qemu-devel@nongnu.org; Tue, 20 Dec 2022 13:44: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 1p7hbY-0002Yh-6N for qemu-devel@nongnu.org; Tue, 20 Dec 2022 13:44:48 -0500 Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BKFVdSH011031; Tue, 20 Dec 2022 10:44:42 -0800 Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3mhe748at9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 10:44:41 -0800 Received: from PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) by CO6PR02MB7763.namprd02.prod.outlook.com (2603:10b6:303:a2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Tue, 20 Dec 2022 18:44:40 +0000 Received: from PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::dff2:2d3c:e182:fb66]) by PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::dff2:2d3c:e182:fb66%3]) with mapi id 15.20.5924.016; Tue, 20 Dec 2022 18:44:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=T+UQS1alBNd/DgGaRheG1P/jnPqIy7UMgCH9EEOF3aM=; b=QzS5MF+16AnxNIWBAOXfeKfUI0YD9gqqMQyk7xWk+gYwfl7pX7rlcRJXpgwFvktXmm0+ vX1+zSz+pKJ/h5e5NPsuiaNR2zDwX7+pkcnazRfytayZ9iQn3SfAFwrs8SWsOfxrGaVn 1SWFMtAXygrSHNH3T7R/iuhFfhvNDKfi4w/j45TssecDHsmCiuTz+7Z3VgQ+TSTGlMoe YGYFHfvcFjaCKugMlz3lx04z2Ym+uyR82xhoA5GgaH6/xL1LoYFp8tvShD4PnQzkw+jH BQx/stkaD6fhiaxqgT6pMAOGSU4ij6vA7EJrbgwtYwJ8VYJxdklXBgut+xo0sa//vX89 MQ== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hA+C0U7MSCALCgbV7bkYvGNz7159z401FpV20sLp4JeDVpS1qBNYk7mpI/RiStuMuB33FZh+U34Fk8t9z/yXOhCyTi3CKmyluFZB8Bh5Ko2YEnqoTOvzgB4oyPBHkPjVvUZslTP9mqxkbyajjRZHzAwALULHxDtfJz1a90wR4QYzl9bpG5BFJjj7ZQt6RFePEOtYGtPCx5qIvos8HVyDalSIVD7RPdu2+gJV6xDLkeZX7ZzYKOfe834d9wIPbfyrEqKTEFvWbiRittUJSLYomB/S4DCaFr3ssh3E6CctL0hlq9xjr1oYearlBNOLeheJFpePmqBlIDyV/et/xty/ag== 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=T+UQS1alBNd/DgGaRheG1P/jnPqIy7UMgCH9EEOF3aM=; b=Tt4cCfo7yILqtEmlxBaWD6cjTLqo8dmOYaU4IaYXG9ZQRbFsQWq7ZYqu9k1ew3jPoREYzZe1Y+QEKSWjLxZtEOppIe9ps3ytIL8J7LRcD9kCX5wVwfpETO3HZpFAW9tzeWSpIkaS01YHf7Mq7qEQxFYWbv4MRCqUcdBWVAlukfSrv7PF9Yj3SiNBcIPq0MJA9rsEJHppkIGgNZeVECssR8zHn3lbBQXfLSkYzUNR0KJ+zqSTuZrI3gUSsw2T5LrGWLB5FEgKpPfe2CkNUOkrEJo8wTxW2hf1sOt3xn1xT0u82QcctKc+JSY5yrbF8iVnsMUTaYSRov589QW458PRbQ== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=T+UQS1alBNd/DgGaRheG1P/jnPqIy7UMgCH9EEOF3aM=; b=VGQAvmvzBvH9SPbvTbs9NeAB4NSu6TNMlVnMVx+AVkI+7168IXAp+s9W3rL7wVR6kbUFcBXUlYJcq/QNhy4ZgJ9f/fxRDnsetZOOkRe9JJWzI4aAyHLXO3NZ5J1i/ypAjt1BhY7PSKh1mktE3WeI1+IwK0AfIzVMythmLVyQVCPnHShGNh4MSvDTdB6NqEKZI2YX3TR4ztXIr0vSfW4SZpUvVHvaDzIttxK5dHc+3oLmlD9oVeRWFL04gHhC8Nqjy3G1/ornwiJdBkEzYiT2Myk141fwY6yPinuq2qXu01bhcmjFK6W+MhVw1+i++dxmzZTGdVTcjvNw57P2+AHNBg== From: "manish.mishra" To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, lsoaresp@redhat.com, "manish.mishra" , Peter Xu , "Daniel P . Berrange" Subject: [PATCH v6 1/2] io: Add support for MSG_PEEK for socket channel Date: Tue, 20 Dec 2022 18:44:17 +0000 Message-Id: <20221220184418.228834-2-manish.mishra@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20221220184418.228834-1-manish.mishra@nutanix.com> References: <20221220184418.228834-1-manish.mishra@nutanix.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR13CA0179.namprd13.prod.outlook.com (2603:10b6:a03:2c7::34) To PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR02MB7384:EE_|CO6PR02MB7763:EE_ X-MS-Office365-Filtering-Correlation-Id: ad8054ec-e8c2-4f84-6ecb-08dae2ba4091 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: scE3001lByiZGiiSakBSKbAZ0hWYKXDHLRhmJvpvL2Pq+QelzR8rb11ugDIO0TR/7wOEUfqANOTOfPFakEn7BfnJ7ekFzvFUl1xrS9lsaztUgkZqVsH5zF6KDWQL8VPYlycUauAJleBw3RJeac8+yFMm/qreSj86WTETPbaksugwpM+/24XrDZQH3L6GADnlO4585QvZUzBreQy2EdvYudNY0hc3VXu2vCEtMhvmQNirQZT0CdVdNbrGFkBWTcR5xLlNIGM7uDcscz+H33hVS/1BRwsKzrk3dJ2N7JkaIqvs5DP1WqgztztIdqJP2XGGYlhYbh1nKEB3y1j0mqnsargfDIpuauW3sJgKxohaQs1kv8JRUkVE4mMntje8E3aVZx9pAW99G+j0unDJpyXCQTVnmPaMa+65ZUYXX+N19vx6pi7R+arw0q/vHA0K4SUpHL+82jH5kNt0x6fUdkMvaku4iz8RTk8H4SX2mXJ93ffe11fsn17SoCvGW6taqo6ScmeJ2TJtAbPAm4pTuO92pVX5NPN2M7e7ydUJf9KdJhKKSRy3q13/tyvkAd2pl7mIAoZQJJd9s484VnuhvRQXdPYCofmnP5DY4lyXfaJ5Jvvw5ZraMuAiVHIjNNWtMZY9Edw+7OCG09BDuT1t/EBbqhhPrDIAjfvYqN8JCGDGCT2NRnO24+WRYW9YT31/YYsWNzhZSttlgDy1somDB5C4XA== 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)(39860400002)(366004)(346002)(396003)(136003)(376002)(451199015)(38350700002)(38100700002)(83380400001)(86362001)(4326008)(5660300002)(66556008)(30864003)(8676002)(2906002)(66476007)(66946007)(41300700001)(26005)(52116002)(6506007)(6512007)(1076003)(186003)(6666004)(54906003)(316002)(478600001)(6486002)(6916009)(2616005)(8936002)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CJZ2Vg7ZRch4EAgePFE2opi+19eOUQCffl+S0O0weduxPhlK4J+JQ5Jl1dE9?= =?us-ascii?Q?iUv/9k6QP8XcVPy+r2+CwyAs5E+89rCZmKOEkClCNkT/AVEelyysz1qKeFA7?= =?us-ascii?Q?LQKqIG2rynxLIN6IWEI7+Hf28p4MINb7HbDhjUYQCGvLIosdRYZmbPSZ9grD?= =?us-ascii?Q?PsxvV1bxRVPcbYHkkhIyl4TQr5jjGMD4kqRtzAJxFQ9EONu+2zCftOAFWdbc?= =?us-ascii?Q?2Wjvo6ejG652nIahjunfoR04D4j+Vo/Bwfnoqh312giDxOjIpduYe+exx6vU?= =?us-ascii?Q?KjC/PdvlW5+wogNjXfH4IMsso+m1SuPiAaCD1dhuy4xw+vLZJg3QVSp1I00Q?= =?us-ascii?Q?T5nlD+etdUKdbwws88DDRKNOdMkDSwqSsDOb7G+wzdWKRFhTy4CNPbCA2RZs?= =?us-ascii?Q?Rehkpo8AJ1QSV2owNg79rM8Our7f5X61y0864KvwqN6VxNkVoAxOOlBiQTd1?= =?us-ascii?Q?QEtdQVH7X4hZeyK72tmDb9QfT2ylKsFPMDcIBa/lh2FA1S+FCbU6rg+08F4N?= =?us-ascii?Q?Hzy5IITQ6WV9vkM+JxDw8MiL60unF19GvlQOh19LtT85mkapC7G4f/At4ZGI?= =?us-ascii?Q?mzYsQ0F5RCnFY2FKRGSxwHvtHlbt59Q7GYmbxn3IJSrtWBBsK1AwT8MQFx0p?= =?us-ascii?Q?jm8BDpAJJhKMFRDd5DTaQqDPxWtCJkfVA+ne19/UAQht/5pMVviLbf7dUKzL?= =?us-ascii?Q?a8ZXMy3heHvdmbBTO5rOJnKhXCZYGJCgB2kv91KG4uC8gu3oA3yyXFWRo6dn?= =?us-ascii?Q?MKWkoUL4IMb1Q4H5yA5w1Mub1NWGHeJKrb7hu98DQpzhB/aLXew47DAULwj+?= =?us-ascii?Q?wFHGwq+Fzb9N95NBQeAjwWizxGCrAYFJM+enPXr01a8bc02yXsie43fI6fKP?= =?us-ascii?Q?Ix6x+/uN52q94GSUzrvELPB4Smmn6TC3uQ3Mh/UdaR2F030gBA7v75lGgCA/?= =?us-ascii?Q?fA6zEW95GFjEM+3RcKCL2dGPXcYxnq4zH9dwEzR4lpjcJaao9QC6TNImhkih?= =?us-ascii?Q?RHTuRkrn2EUP+7OY767j5nEIbeixhM4DaEVR9hn412n3/Ee28T2PEA0XCQmL?= =?us-ascii?Q?RaMuIuX7/Ub9etE3RfvBJCBOYVlRbP2EzaDFBgvn6XaHlJnKAH04JSkLFH1w?= =?us-ascii?Q?VwctdyG387WO0LhdRC15ztPIKCkb8is60V6L4x/yPsC1Ycdt93VfG+zgg5FJ?= =?us-ascii?Q?N5Ha36Bz/utxa6JqPjDiYRNEQXRA7JTSgCmb/hmnjSru9sh32E17a+o9I0BY?= =?us-ascii?Q?7oLNwNiSU5e6nq+xyPUynLBMv7U24DFg+ytL790cww50zWMJ9ReH7igbaYqv?= =?us-ascii?Q?Eh49yLhfmUSpTbyDh1Z8bfic+JWV0T74GiH1CYgfvDKTfQrnWQ4v5XroOZ7J?= =?us-ascii?Q?ry5y+ylWA0sZKY59isU/9lFDp1TvghDvKjj0QGoPCqxOJuQEQGPoLD5J8tja?= =?us-ascii?Q?DzqoBYni6F9RBo6KItbEMdMvySDgybIjukbISVUf/I7EtBSsLmHC/pEQEuE0?= =?us-ascii?Q?IgRMDQVz6r2Gc8D2zySVD5qfIZopiPZDJGuXkFKhRP77bdfNiD0nIQrfDFg5?= =?us-ascii?Q?V66K1161YonEv+78dtWIjg/k8RIcmiV3KXhJUW+GpMyxMob2Fm0h4K0bMhdY?= =?us-ascii?Q?Gg=3D=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad8054ec-e8c2-4f84-6ecb-08dae2ba4091 X-MS-Exchange-CrossTenant-AuthSource: PH0PR02MB7384.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2022 18:44:40.2976 (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: SARCdzvQMo89BBpcY5xiiENwN1BSZ/ZzXtU7AENw1HDFkyslPgjgjARcG31CjJkSRRjygKnmwVnZUd4lDAyfZrKv4QXnBG990WtiXpl18vg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR02MB7763 X-Proofpoint-ORIG-GUID: KpXkx7La0KHFdfiDR8PKrA0M4SbeM9aL X-Proofpoint-GUID: KpXkx7La0KHFdfiDR8PKrA0M4SbeM9aL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-20_06,2022-12-20_01,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: 1671562193179100003 Content-Type: text/plain; charset="utf-8" MSG_PEEK peeks at the channel, The data is treated as unread and the next read shall still return this data. This support is currently added only for socket class. Extra parameter 'flags' is added to io_readv calls to pass extra read flags like MSG_PEEK. Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrange Suggested-by: Daniel P. Berrange Signed-off-by: manish.mishra Reviewed-by: Juan Quintela --- chardev/char-socket.c | 4 ++-- include/io/channel.h | 6 ++++++ io/channel-buffer.c | 1 + io/channel-command.c | 1 + io/channel-file.c | 1 + io/channel-null.c | 1 + io/channel-socket.c | 17 ++++++++++++++++- io/channel-tls.c | 1 + io/channel-websock.c | 1 + io/channel.c | 16 ++++++++++++---- migration/channel-block.c | 1 + scsi/qemu-pr-helper.c | 2 +- tests/qtest/tpm-emu.c | 2 +- tests/unit/test-io-channel-socket.c | 1 + util/vhost-user-server.c | 2 +- 15 files changed, 47 insertions(+), 10 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 29ffe5075e..c2265436ac 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -283,11 +283,11 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, = size_t len) if (qio_channel_has_feature(s->ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { ret =3D qio_channel_readv_full(s->ioc, &iov, 1, &msgfds, &msgfds_num, - NULL); + 0, NULL); } else { ret =3D qio_channel_readv_full(s->ioc, &iov, 1, NULL, NULL, - NULL); + 0, NULL); } =20 if (msgfds_num) { diff --git a/include/io/channel.h b/include/io/channel.h index f1b7e05f81..5b41d02b2b 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -34,6 +34,8 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass, =20 #define QIO_CHANNEL_WRITE_FLAG_ZERO_COPY 0x1 =20 +#define QIO_CHANNEL_READ_FLAG_MSG_PEEK 0x1 + typedef enum QIOChannelFeature QIOChannelFeature; =20 enum QIOChannelFeature { @@ -41,6 +43,7 @@ enum QIOChannelFeature { QIO_CHANNEL_FEATURE_SHUTDOWN, QIO_CHANNEL_FEATURE_LISTEN, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, + QIO_CHANNEL_FEATURE_READ_MSG_PEEK, }; =20 =20 @@ -114,6 +117,7 @@ struct QIOChannelClass { size_t niov, int **fds, size_t *nfds, + int flags, Error **errp); int (*io_close)(QIOChannel *ioc, Error **errp); @@ -188,6 +192,7 @@ void qio_channel_set_name(QIOChannel *ioc, * @niov: the length of the @iov array * @fds: pointer to an array that will received file handles * @nfds: pointer filled with number of elements in @fds on return + * @flags: read flags (QIO_CHANNEL_READ_FLAG_*) * @errp: pointer to a NULL-initialized error object * * Read data from the IO channel, storing it in the @@ -224,6 +229,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp); =20 =20 diff --git a/io/channel-buffer.c b/io/channel-buffer.c index bf52011be2..8096180f85 100644 --- a/io/channel-buffer.c +++ b/io/channel-buffer.c @@ -54,6 +54,7 @@ static ssize_t qio_channel_buffer_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelBuffer *bioc =3D QIO_CHANNEL_BUFFER(ioc); diff --git a/io/channel-command.c b/io/channel-command.c index 74516252ba..e7edd091af 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -203,6 +203,7 @@ static ssize_t qio_channel_command_readv(QIOChannel *io= c, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); diff --git a/io/channel-file.c b/io/channel-file.c index b67687c2aa..d76663e6ae 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -86,6 +86,7 @@ static ssize_t qio_channel_file_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); diff --git a/io/channel-null.c b/io/channel-null.c index 75e3781507..4fafdb770d 100644 --- a/io/channel-null.c +++ b/io/channel-null.c @@ -60,6 +60,7 @@ qio_channel_null_readv(QIOChannel *ioc, size_t niov, int **fds G_GNUC_UNUSED, size_t *nfds G_GNUC_UNUSED, + int flags, Error **errp) { QIOChannelNull *nioc =3D QIO_CHANNEL_NULL(ioc); diff --git a/io/channel-socket.c b/io/channel-socket.c index b76dca9cc1..dfb8cb6c40 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -173,6 +173,8 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *i= oc, } #endif =20 + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_READ_MSG= _PEEK); + return 0; } =20 @@ -406,6 +408,8 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, } #endif /* WIN32 */ =20 + qio_channel_set_feature(QIO_CHANNEL(cioc), QIO_CHANNEL_FEATURE_READ_MS= G_PEEK); + trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd); return cioc; =20 @@ -496,6 +500,7 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); @@ -517,6 +522,10 @@ static ssize_t qio_channel_socket_readv(QIOChannel *io= c, =20 } =20 + if (flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) { + sflags |=3D MSG_PEEK; + } + retry: ret =3D recvmsg(sioc->fd, &msg, sflags); if (ret < 0) { @@ -624,11 +633,17 @@ static ssize_t qio_channel_socket_readv(QIOChannel *i= oc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); ssize_t done =3D 0; ssize_t i; + int sflags =3D 0; + + if (flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) { + sflags |=3D MSG_PEEK; + } =20 for (i =3D 0; i < niov; i++) { ssize_t ret; @@ -636,7 +651,7 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, ret =3D recv(sioc->fd, iov[i].iov_base, iov[i].iov_len, - 0); + sflags); if (ret < 0) { if (errno =3D=3D EAGAIN) { if (done) { diff --git a/io/channel-tls.c b/io/channel-tls.c index 4ce890a538..c730cb8ec5 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -260,6 +260,7 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); diff --git a/io/channel-websock.c b/io/channel-websock.c index fb4932ade7..a12acc27cf 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -1081,6 +1081,7 @@ static ssize_t qio_channel_websock_readv(QIOChannel *= ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK(ioc); diff --git a/io/channel.c b/io/channel.c index 0640941ac5..a8c7f11649 100644 --- a/io/channel.c +++ b/io/channel.c @@ -52,6 +52,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); @@ -63,7 +64,14 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, return -1; } =20 - return klass->io_readv(ioc, iov, niov, fds, nfds, errp); + if ((flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) && + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { + error_setg_errno(errp, EINVAL, + "Channel does not support peek read"); + return -1; + } + + return klass->io_readv(ioc, iov, niov, fds, nfds, flags, errp); } =20 =20 @@ -146,7 +154,7 @@ int qio_channel_readv_full_all_eof(QIOChannel *ioc, while ((nlocal_iov > 0) || local_fds) { ssize_t len; len =3D qio_channel_readv_full(ioc, local_iov, nlocal_iov, local_f= ds, - local_nfds, errp); + local_nfds, 0, errp); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_IN); @@ -284,7 +292,7 @@ ssize_t qio_channel_readv(QIOChannel *ioc, size_t niov, Error **errp) { - return qio_channel_readv_full(ioc, iov, niov, NULL, NULL, errp); + return qio_channel_readv_full(ioc, iov, niov, NULL, NULL, 0, errp); } =20 =20 @@ -303,7 +311,7 @@ ssize_t qio_channel_read(QIOChannel *ioc, Error **errp) { struct iovec iov =3D { .iov_base =3D buf, .iov_len =3D buflen }; - return qio_channel_readv_full(ioc, &iov, 1, NULL, NULL, errp); + return qio_channel_readv_full(ioc, &iov, 1, NULL, NULL, 0, errp); } =20 =20 diff --git a/migration/channel-block.c b/migration/channel-block.c index f4ab53acdb..b7374363c3 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -53,6 +53,7 @@ qio_channel_block_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 196b78c00d..199227a556 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -614,7 +614,7 @@ static int coroutine_fn prh_read(PRHelperClient *client= , void *buf, int sz, iov.iov_base =3D buf; iov.iov_len =3D sz; n_read =3D qio_channel_readv_full(QIO_CHANNEL(client->ioc), &iov, = 1, - &fds, &nfds, errp); + &fds, &nfds, 0, errp); =20 if (n_read =3D=3D QIO_CHANNEL_ERR_BLOCK) { qio_channel_yield(QIO_CHANNEL(client->ioc), G_IO_IN); diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c index 2994d1cf42..3cf1acaf7d 100644 --- a/tests/qtest/tpm-emu.c +++ b/tests/qtest/tpm-emu.c @@ -106,7 +106,7 @@ void *tpm_emu_ctrl_thread(void *data) int *pfd =3D NULL; size_t nfd =3D 0; =20 - qio_channel_readv_full(ioc, &iov, 1, &pfd, &nfd, &error_abort); + qio_channel_readv_full(ioc, &iov, 1, &pfd, &nfd, 0, &error_abort); cmd =3D be32_to_cpu(cmd); g_assert_cmpint(cmd, =3D=3D, CMD_SET_DATAFD); g_assert_cmpint(nfd, =3D=3D, 1); diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-chann= el-socket.c index b36a5d972a..b964bb202d 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -460,6 +460,7 @@ static void test_io_channel_unix_fd_pass(void) G_N_ELEMENTS(iorecv), &fdrecv, &nfdrecv, + 0, &error_abort); =20 g_assert(nfdrecv =3D=3D G_N_ELEMENTS(fdsend)); diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 232984ace6..145eb17c08 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -116,7 +116,7 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMs= g *vmsg) * qio_channel_readv_full may have short reads, keeping calling it * until getting VHOST_USER_HDR_SIZE or 0 bytes in total */ - rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, &local_er= r); + rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, 0, &local= _err); if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { assert(local_err =3D=3D NULL); --=20 2.22.3 From nobody Thu May 16 05:12:33 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=1671561985; cv=pass; d=zohomail.com; s=zohoarc; b=GY18NBhriVdVm0/lJ7ZLheh+cssR82zy/uOlspyPITiJi1CsO3yvTHwOP05ccXvHIrwDsIfPHsCIAACZKMmKdQZDC4GvHitardY+y5pnjXseU48NTu5J1sDCkYBarhIfYG1CfRUZ1l9jUXYyke3tA45WOVB7s4ucjbWTC0dGjpM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671561985; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8LQGzVrJyAMNA1bUU6nW4oA0kAwtmAykqN2VCfk2JG8=; b=hQbZAm57TxwQ3goNQIki273lqaopRnSFJwpZf/pMWL9v6l7l/lJdeG1DlX1Mo+CX0HYvS9m2eK0E6c2HwK41XLyqczYvB4TVLFlVzqhfphW/Na8okvb37AXwK9abGk/2dajyggsp9IbvxIwPAEBxySEgV1Uw9q87yG9SMtbO0zU= 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 167156198531498.99741152995375; Tue, 20 Dec 2022 10:46:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p7hbt-0004HD-3y; Tue, 20 Dec 2022 13:45: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 1p7hbl-00048D-3G for qemu-devel@nongnu.org; Tue, 20 Dec 2022 13:44:57 -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 1p7hbf-0002Z6-4l for qemu-devel@nongnu.org; Tue, 20 Dec 2022 13:44:54 -0500 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BKEcG7I006602; Tue, 20 Dec 2022 10:44:47 -0800 Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3mhajdgq2h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Dec 2022 10:44:47 -0800 Received: from PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) by CO6PR02MB7763.namprd02.prod.outlook.com (2603:10b6:303:a2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Tue, 20 Dec 2022 18:44:46 +0000 Received: from PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::dff2:2d3c:e182:fb66]) by PH0PR02MB7384.namprd02.prod.outlook.com ([fe80::dff2:2d3c:e182:fb66%3]) with mapi id 15.20.5924.016; Tue, 20 Dec 2022 18:44:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nutanix.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=proofpoint20171006; bh=8LQGzVrJyAMNA1bUU6nW4oA0kAwtmAykqN2VCfk2JG8=; b=cnnXTB+Weao1F/+nPSOloqNeWXas3tXlFuegS4VY2MlSbq1TrmLi8fhL+q+UnhBB3PgH nNm7yfRzZeMM+Ceb43mztNTnk8XF8aOXfnpI9z7AFpEyOVPrMvKo3re/rxjLma7BnIYK +KfLMtCYbggEM24TAQuZKDLPxbTvRsJ2YM31tosxWzvvHWTaTtCh+soN4w0QToT8r5+X Wc3io3yK8P2eAz1x7zmlJsFmoLCisVgv36YKzOVgjCgrvaERnQToV+JJ65Vtu6/vosXm rVdD8IkKVnQESoLFOkCORJfbzjxEmhN8BkRd/JRKR1cLvY9DSLRsY38chk9GtBDyy4dD Vg== ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxyHJMMs/zwV1nngENzyzXiTB1KXLobpD8E1Karqz39o/4HUc0jGUeW2EJj4Zezp7vEv8RyrAV87eaYe0uSC/1DghHvT63SNLOM1jlSQiyDWLoR4zg8mwl+VSn+H3TxzHsBzV4GCx7UC9mztiJQypWpV4+29BhC1RNuEWwdRGruWSvqjV00F11iFXgzDvXScgn6RXhjwguGWX8SgrvylfhKj8xGn0oDz4UvJA1WFRdafUl07oRtHn8KDDKTAGVTfuEJG5FLC4Kd1wDfO9k4yokPo3lGzMD7AjZGkI8Sds4Rjcwc4kjhPi+VNrTCLNOlEhT+tYBpZxGg8bYvQo+0Fig== 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=8LQGzVrJyAMNA1bUU6nW4oA0kAwtmAykqN2VCfk2JG8=; b=gdjIcDk9Vd1uE973blVZiTKRfgWciXBwIhIJJa9bUjH/PimEaDmqM2AMPmNsQjfE61n2AxlhVWWvJ23jJanZRBJGJE0nsKbQdLyAlkGqTC1pSBCzFNCrC0ggrbHhJpegcKbd++qqEApzACicdVQAQlwjDG4nuU2iliddt7G8JR9+Z9I1I2ULzxhouRbf/LIReFtWbMHp9I9cyyPjbmEEpHowpztqscJ5rvGo3U6xZbR+GpyWnftizsJ1/eQt0R9qJTupTPOQDWe9kOsRChQeh0RR0l9FtbOqdVjCUDpE3WWiLpqnuu8s/f/QqHKMBjI/ZDKQbTxZXMZ+h3PYh48ehQ== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8LQGzVrJyAMNA1bUU6nW4oA0kAwtmAykqN2VCfk2JG8=; b=mFIlEcT2i6YfRxYQJfqSFuJ6X516InYsqkmRfFLimK7iISmCG54HhXT4q1TJkzNkQx3x4jmyvAXNKpclpd5EIXPPSVzePiclDjlIB+DlJpHnJGS0tyfwqyBdtFQnNRDZ3djxMjpMUXOWdMAFPm0kpCVSHat8BjxYKqKaPnNTGNvLNNjUoc821h0uCZEk/1la406wygTwu8h0FO3jHQ0dmuGfDxQs6wcCmDB2vjtOJviSYRmPMWov0O64VqrOzgfcq2bpVZPBin/k40i/bB2novT2wCfyMSLz1/WgfNUqbaDl+Jp58cZu0ZfzW26+8RSxnvkRIWRMu1g2R7mZnch2/g== From: "manish.mishra" To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, lsoaresp@redhat.com, "manish.mishra" , Peter Xu , "Daniel P . Berrange" Subject: [PATCH v6 2/2] migration: check magic value for deciding the mapping of channels Date: Tue, 20 Dec 2022 18:44:18 +0000 Message-Id: <20221220184418.228834-3-manish.mishra@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20221220184418.228834-1-manish.mishra@nutanix.com> References: <20221220184418.228834-1-manish.mishra@nutanix.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SJ0PR13CA0179.namprd13.prod.outlook.com (2603:10b6:a03:2c7::34) To PH0PR02MB7384.namprd02.prod.outlook.com (2603:10b6:510:12::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR02MB7384:EE_|CO6PR02MB7763:EE_ X-MS-Office365-Filtering-Correlation-Id: ed102759-9bf8-49c0-6039-08dae2ba43f5 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: fMA37FK1v5AoZuKAQFuUYRSzPktuP6IiHp+zeEaVtjgizG7Erv/3x5Bz4Af7zvUdVBZ4lb6qTASY2NShR49O9bLmFLshLhGVp0KzDCzQdvvFOEluBNTpa+O4Jq0Wgc0iRrfUepKsZlxboOPESQXHS2iAn2glBFsq+6nmIWhOuyv8PYoKmqilHjOCTLwCdGvgmRiT8UVAJ5WxDWxQhOeb42UStTfirRPV5fkycqIkBuoQ9t1bvzaJJKEFvm+6rqWYjiP3h0qxW+XV98heXcLXNChqF8ucI0LXhQhZJ/K0rMWuozYHh5Kav14+e8NhjCKy3AjTODYdeEa45zX77tEHTevzlSXr0xZe6tmXvhnFjeqkgldwMjI8TLJbnm+UjUUfInzAhFYiiS4QqvnK8CT/15ak+JLZ8cDUDN7oZCsMt9EVEvpPoBUbvnK63uufFKjCpH2l3tQag06PJs3afXidRiDCiT1qGS4+aLM80fUhq4rY5uOY1RjuOy6cCIlOjwSDK6wSkmkRMu8FyRrJc+iHwWJ1mwz+soFxZOvXtAY1KiWhu5cHWKnQzRMdtcd/LzHTkrHLjU8jmVSEzKRoTNZW4br3itADkd22R+UFCvLnKbzafQGgo/zFeEciph345UEFgvzS4J7OiSll3q0SQTKZLB0IMFQF/QdGx4mPLXmd4R2coEN46icWtxnzaF2XgpYKz5LaC55JaV/gSEv5Sxo+ug== 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)(39860400002)(366004)(346002)(396003)(136003)(376002)(451199015)(38350700002)(38100700002)(83380400001)(86362001)(4326008)(5660300002)(66556008)(30864003)(8676002)(2906002)(66476007)(66946007)(41300700001)(26005)(52116002)(6506007)(6512007)(1076003)(186003)(6666004)(54906003)(316002)(478600001)(6486002)(6916009)(2616005)(8936002)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ip8c+jSlLuecsGwauGyAb/q1ewZbWGatje4kEy1YaPmc4l3Evo2X9tqOA6ON?= =?us-ascii?Q?XqH8bkZkc7+ZQQbPH0j12B7Y5n7EMhTbI1TtOi4gqaUaoASeY2cR34cb4zUP?= =?us-ascii?Q?+rbhHUWNj3h5zLq17SnyqrB5KsR9M7LMjn92CzgwMqfux7E3sj5LFPJzzwJz?= =?us-ascii?Q?t4aTkEgYCKJW3A76YpLWRbC1LFFHiBkk4vmH8IK6DN5uLPZht0e751Iae5EW?= =?us-ascii?Q?Q3RWBSg+jQOX2PPC9VBxDAB/cwR1q47LQii7C3mdDrTnMsWM8ypwVifrPIe2?= =?us-ascii?Q?3pNvtZXCmkeyK4C/1TLeN90/Nu/oa3PlazdZbqvyunGExxhS71X77LeL21bH?= =?us-ascii?Q?k0CxpBvghU07ikdOgFsMntT9ZOyp0cySGmVYE+8dcLr92dYZ96zllyCR+hie?= =?us-ascii?Q?ZN1XgcRNVJYXcF8OQw7BJAmQ+Jvb9VuQwrhd7nqpZePOpN11C9WaayFLmgPO?= =?us-ascii?Q?5ZC8i7vqqFuWYyIJtP4Zn7WlqhONPDMdAMx86tyVLrHwl3k+Iv2hvCAdfwYq?= =?us-ascii?Q?rna834U7r8oDbd5piIOqYQdR6Rv1dmTNd1wT5exc0Cg9iZ3GrytrGhhj3set?= =?us-ascii?Q?Hkzrs/TaxphRvPfm1nu3H0u1LyEVxpwgv84IFpYuFxSu0TT/okP4SwOtGjJr?= =?us-ascii?Q?ODh7cfZOfEhUy1ENnd8soLnD/8C2RrvYfgssSGy4UtV6GYXfM9k98NZ012E/?= =?us-ascii?Q?A2+ZcxnGEiE2YWLJjCwBzT7IO1uURvZeL0g6A0lTp7T7/DSrxKb1nq91L/y2?= =?us-ascii?Q?ME+Hbcpdp41apXFofv2u2kcWrR7ibtIEtHlNFS/JegWsxOt3RBppdT7WBnPY?= =?us-ascii?Q?5LeHu8+jo6zXB8cOBK7DOda7NZTgnNC1K6U4Xff/ulf/Q+HprIGb3JGmu7Pf?= =?us-ascii?Q?5K7ggH4n1Bd5V6ytgNCO2JgL4EyvyPL9k+cTD0FITLWZrD+n5rqdpb9erMvz?= =?us-ascii?Q?Vbg5MVWvs1pB2gGECMhsaol99fgAGYo6vsHU80qox07MqEPnReTMR025s/h3?= =?us-ascii?Q?6sQpAMy/9Yjrin7p031EhBJaqArF/jFp5m3kxgbTr3pEIqQ4wIN1+zOhLq85?= =?us-ascii?Q?y3iHgydbMqhZwRDPEmHowx3M/ZkU+LcS13erE7eLnGkErpYTAnwcsVDJQuat?= =?us-ascii?Q?zVlz/bnAizxde9q5RnTAmZQHmR7OAVrgNG3b3aRML9CcJ9DuRU5CYM1VsSMH?= =?us-ascii?Q?5TFHXLm8MhbzyzEOzHqrc4Faky2+TAz/JqBqbbazfJRa2UEp5LGBk74i64uV?= =?us-ascii?Q?MOhB/wF8RZt9fIuANLRkpHOxYIFRys4VaegOJIS6LXI3YnIAV690I0DtoPaf?= =?us-ascii?Q?gYr1nM/cKl3vP54Sv8DTw4TVNYCsXN6+XQgRC0yCAgGEpSVigFMmXClKwW8s?= =?us-ascii?Q?g4GHgKn6niqkS41ssz0Bht0U0LQk7ZWlRaK77Vk24vZB3bqAR7q4W/9uzGRH?= =?us-ascii?Q?wdmSDztIWqLsoYXXSD+zMtVrAAfLi/NsE8unLv+GSUw5ZhQ5lBVvZAwsnfON?= =?us-ascii?Q?+s6m1h0h4SdLI68b1dJzjFNoGk8BTAS6RP1JiFwJ2Fs4aOznxzXC+NL6co9H?= =?us-ascii?Q?gRMmq+9XHUwsuSLo53uY54Hwb3pwtiXybr9XBmj4Mn5OiEPdWK6XMj/nzjpt?= =?us-ascii?Q?Kg=3D=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed102759-9bf8-49c0-6039-08dae2ba43f5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR02MB7384.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2022 18:44:46.0013 (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: Fyu269BNYAe3Nv25my74VOhqu1thdupQ0+JQr4kBK6rFBDYGDrNaqGf5db9Jn80i+2k9+uZqmUuVcncCEOJw+F9a5ei5J4w/nFRWo3VsYrA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR02MB7763 X-Proofpoint-GUID: cDpXIRprMI1HbMsX33Z9WTddcD643Lhe X-Proofpoint-ORIG-GUID: cDpXIRprMI1HbMsX33Z9WTddcD643Lhe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-20_06,2022-12-20_01,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: 1671561987084100003 Content-Type: text/plain; charset="utf-8" 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 read peek to check the magic number of channels so that current data/control stream management remains un-effected. Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrange Suggested-by: Daniel P. Berrange Signed-off-by: manish.mishra Reviewed-by: Juan Quintela --- migration/channel.c | 45 +++++++++++++++++++++++++++++++++ migration/channel.h | 5 ++++ migration/migration.c | 54 ++++++++++++++++++++++++++++------------ migration/multifd.c | 19 +++++++------- migration/multifd.h | 2 +- migration/postcopy-ram.c | 5 +--- migration/postcopy-ram.h | 2 +- 7 files changed, 101 insertions(+), 31 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 1b0815039f..fc0228a198 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -92,3 +92,48 @@ void migration_channel_connect(MigrationState *s, migrate_fd_connect(s, error); error_free(error); } + + +/** + * @migration_channel_read_peek - Peek at migration channel, without + * actually removing it from channel buffer. + * + * @ioc: the channel object + * @buf: the memory region to read data into + * @buflen: the number of bytes to read in @buf + * @errp: pointer to a NULL-initialized error object + * + * Returns 0 if successful, returns -1 and sets @errp if fails. + */ +int migration_channel_read_peek(QIOChannel *ioc, + const char *buf, + const size_t buflen, + Error **errp) +{ + ssize_t len =3D 0; + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buflen = }; + + while (true) { + len =3D qio_channel_readv_full(ioc, &iov, 1, NULL, + NULL, QIO_CHANNEL_READ_FLAG_MSG_PEEK,= errp); + + if (len <=3D 0 && len !=3D QIO_CHANNEL_ERR_BLOCK) { + error_setg(errp, + "Failed to peek at channel"); + return -1; + } + + if (len =3D=3D buflen) { + break; + } + + /* 1ms sleep. */ + if (qemu_in_coroutine()) { + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000); + } else { + g_usleep(1000); + } + } + + return 0; +} diff --git a/migration/channel.h b/migration/channel.h index 67a461c28a..5bdb8208a7 100644 --- a/migration/channel.h +++ b/migration/channel.h @@ -24,4 +24,9 @@ void migration_channel_connect(MigrationState *s, QIOChannel *ioc, const char *hostname, Error *error_in); + +int migration_channel_read_peek(QIOChannel *ioc, + const char *buf, + const size_t buflen, + Error **errp); #endif diff --git a/migration/migration.c b/migration/migration.c index 52b5d39244..bbc9ce3ca6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -31,6 +31,7 @@ #include "migration.h" #include "savevm.h" #include "qemu-file.h" +#include "channel.h" #include "migration/vmstate.h" #include "block/block.h" #include "qapi/error.h" @@ -663,10 +664,6 @@ static bool migration_incoming_setup(QEMUFile *f, Erro= r **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (multifd_load_setup(errp) !=3D 0) { - return false; - } - if (!mis->from_src_file) { mis->from_src_file =3D f; } @@ -733,31 +730,56 @@ 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() && !migrate_postcopy_ram() && + qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { + /* + * 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 migration_channel_read_peek(ioc, (void *)&channel_magic, + sizeof(channel_magic), &local_er= r); + + if (ret !=3D 0) { + 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 (multifd_load_setup(errp) !=3D 0) { + error_setg(errp, "Failed to setup multifd channels"); + return; + } + + 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 +787,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 000ca4d4ec..eeb4fb87ee 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1164,9 +1164,14 @@ int multifd_load_setup(Error **errp) uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); uint8_t i; =20 - if (!migrate_use_multifd()) { + /* + * Return successfully if multiFD recv state is already initialised + * or multiFD is not enabled. + */ + if (multifd_recv_state || !migrate_use_multifd()) { return 0; } + if (!migrate_multi_channels_is_allowed()) { error_setg(errp, "multifd is not supported by current protocol"); return -1; @@ -1227,11 +1232,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; @@ -1244,7 +1247,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 @@ -1254,7 +1257,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)); @@ -1265,6 +1268,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 e2802a9ce2..ff3aa2e2e9 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