From patchwork Thu Jun 9 07:33:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Het Gala X-Patchwork-Id: 12875611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD92EC43334 for ; Thu, 9 Jun 2022 14:03:48 +0000 (UTC) Received: from localhost ([::1]:50826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzIlH-0002cw-VY for qemu-devel@archiver.kernel.org; Thu, 09 Jun 2022 10:03:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfU-00029E-8f for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:24 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:57086) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfQ-0007u8-Dh for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:23 -0400 Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25964PeN022399; Thu, 9 Jun 2022 00:33:15 -0700 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-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=dKLyhRXmd9foly6WSGrPHdyLCHn1LmBo+8gCkrBjBSk=; b=e7Jm1FrY+3YKHgIxs3PdT1iswbrn6lCBpblOYW8KPsu0CWguSkTeotx1gsbV2WIl/QpT /b0CiYlr9vsmLqR1JDigix20776Ben3MUuGFP0KhRUy7kF78fkS1O1P3XqKknf11+630 F0yfHtJcAp/ggtDa2CaUbOMv+ex/1RaXJ+dcH2SPfnisPryW/CeXhETb9j0cmBo7JvOl pLbBn+SCDbWn30+NbIjIdgnewD4c2eBowIFBPM8y9W4VZ/sCNUAn0Z3E5MfOw+4/hf7U w4+9xzSKAYsnyPhy0h9hSsTYrrprBPidsPZksajAA26Wb1+GPwqZ4+mGsA01iultFFxS Hw== Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2174.outbound.protection.outlook.com [104.47.73.174]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3gg6y0a3qy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jun 2022 00:33:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fpAzvoKJMyU9L2E4V3oek0/atjdH48dND6r72hof31MicsIQlnfy8nL34jr/PtJmlijuF5sZO3pIn/Zwb5tJiek4ozivD2o6ePnddjvpVpNRlqEKmpdbRpkTFc1F6O83CwBPwZ4+uumF7IB80mTpCsb7xU+urWJHjIvL4GiypitU0PXb2TORuoFMEIlpQvGMSQhoKwRaMPyNwoc9Mhw6WMzLkFt0yBbITmyPnR9jrqDrf1qlGZ8w0HGYdRaPaDmzc1thykUaJZai/Sq8Ak1rig/i2DR3fMIEPnaYkZ3tHqW8+vkAf4FUQE5kbShYFm6SYKn+8zFr71mMSIAgjFbLIQ== 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=dKLyhRXmd9foly6WSGrPHdyLCHn1LmBo+8gCkrBjBSk=; b=RMfq9sErGaeg45b4+mps7aHp4T8tg9JJ2ilOAHOrpswzDFTmbsAwfE7p/bDPjwCaVaPLIIpuQkrb2IFbI0hKsDkg8F/hC1RQVaIO+TwB4tSWlDU3jps6ISYMBuOOgS31fQeEVJF8jroG2EKFFZa/NKICVMXYqoMIMporvSDsm0bkZRBDHWGy+hcOQ0PGl1wb1TRgeF+jlh9VPbwuJJVe0pvHEWG6yS5zgwpUseaxq6aFmd6KYYMDbeElYSLcS05/04K7GO3AYUHavaWVYWW1Zr7F4GZZ2CR56BHE6+KcjLHQCxfsllmtrZEN31ado2TF44ESDg6Vh2UFD4gnBgSbSw== 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 Received: from BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) by SA1PR02MB8639.namprd02.prod.outlook.com (2603:10b6:806:1fe::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 9 Jun 2022 07:33:13 +0000 Received: from BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f]) by BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f%5]) with mapi id 15.20.5314.019; Thu, 9 Jun 2022 07:33:13 +0000 From: Het Gala To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, eblake@redhat.com, Het Gala , Manish Mishra Subject: [PATCH 1/4] =?utf-8?q?Modifying_=E2=80=98migrate=E2=80=99_qmp_comma?= =?utf-8?q?nd_to_add_multi-FD_socket_on_particular_source_and_destination_pa?= =?utf-8?q?ir?= Date: Thu, 9 Jun 2022 07:33:02 +0000 Message-Id: <20220609073305.142515-2-het.gala@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220609073305.142515-1-het.gala@nutanix.com> References: <20220609073305.142515-1-het.gala@nutanix.com> X-ClientProxiedBy: BY5PR04CA0002.namprd04.prod.outlook.com (2603:10b6:a03:1d0::12) To BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14b39540-bfb1-40e9-d0ac-08da49ea4f51 X-MS-TrafficTypeDiagnostic: SA1PR02MB8639:EE_ X-Microsoft-Antispam-PRVS: 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: 1oB9NpCUv8bKZ7kBcYlM/X7KKcgltBK617ZKBTbQB8ElLfJMREzwrr3yA6f+r24koWoEHLEbmTh8IR1t6zdqofJEJfRIvJo+D5kWPhlEbItlvqkxVf+DjP8jQthQrQV2HdmhcgsNYc+FTG50hrNZTi2LuCAY41viutgq/8Otn/FteAfCJVV88U7YPpWO2buVsxy3zOBepylYP68O49Cubzm5+gQgmSLTgqFBi+6g4rip4TnwuCHMFfIrFvwr67vLJjfPXXAkTlXa1Y+aT7GVc1ik4olH+jmG7zafxkiWQh0oIlv6zm2wqLL0YKZdk2c4Gii/QoWddo3fYkzEe/DM6Lh49Or4bTA+pPqMFWeBwO42FoWIAtuOt4KYBBi2Pf5qW19LRcnBgc/CKWgdJhllMfsR85uMyJOV5e7hXKrFbrRtUhyOucqgjOEm7HXk0RZL/jaN9WxzkaHkbHkCcojIYhxemILHqYB5I3SElREW+CNb0vPzaJSIw37+20IkXU94d1EWyRYG/T0IM2eUgk5b3f27Oy4yOe+WPCk24AHomK1QNHQq/OFQh8aZwbp6VLUvf9NJFbZXxOSHXn+YDw+LXzos7l+fTBLnMMsmA1s39ZLbjzzV4fCZ7e/XAgEm1qhtVDUUvpXbYfh1+azJT7XLcNKjdgTUAIhOY/ZUv1hWLVGbxW+IVWn4Jeh2pFhqKz+mrdP83LU4LJ0gQtPxDs/hWxg5Q3Sv8W8/igIPjt7husc= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR02MB4343.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(107886003)(6666004)(1076003)(2906002)(8936002)(52116002)(54906003)(86362001)(6506007)(186003)(5660300002)(30864003)(83380400001)(6486002)(44832011)(38350700002)(26005)(38100700002)(36756003)(6512007)(2616005)(316002)(66556008)(66946007)(4326008)(6916009)(66476007)(309714004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Sn8SQTb27AgG0VcFJJ5LN9PWRJse?= =?utf-8?q?6DB58DIeajfuDVunTDtMfHIs0giOzg2P/HDT7ZTBZxJjWh7wv84nNsoyGykiZotHc?= =?utf-8?q?xzzr27Qaj6i/iwn9e7b1z/GbacoqzocSsY10KV8Ks8DPd6d44YeahyEDzdFhJcE0R?= =?utf-8?q?lUCgweWwwy77zGyP4ZnzJ8X7Td7YJZ+pVCOM93bLWlAlLI3Ile1NNBwaIyu7bfRX0?= =?utf-8?q?K+PZ4wxhUy09vb63eD1oq6/O7aLLYPKsRkF5AaON9GZNsemJpvBQMMmzofg8swaq3?= =?utf-8?q?cDd0EU7lGWEetbw3dwPqTwxzzLNAQ/IWrvgrP8Ht9u5JlXAzjpFTq3sHjQGDmtCNp?= =?utf-8?q?qXw8YAtYdF7iTnrjtzveR3uiRMfdhYAPNN4Svx4V+pDdIJ/SjRvQn048q96boL46P?= =?utf-8?q?lp9EzjDGoxDbGrynKdScik5VEFF0SZKq1EuLZozdJU+s5DVdJGBLsVdRNojYtwrBU?= =?utf-8?q?FFJ/Zcgd+/HmFJfSgm8+M0gUIOWo4HFP4Kkv8fclG1/5BiFj6XNpleuHkxCJQNAqI?= =?utf-8?q?4zjB+zhUQjuMBo573U0W2yUMGb1a4t58LCxrR1bxG9F8uGoM8AQOx61Z7qhUezfPk?= =?utf-8?q?meZMd6tPQN1dtcjLo23ElhVJD2DHQ0mHOteWAyQMtEnespRwd+h7YdE+L28BuBaur?= =?utf-8?q?7TmyuXetLoip1Tz10C+VBeLZZIOBfw4Z21oaDBP3bTbJfdaP8gi7LJroqQttl8aPe?= =?utf-8?q?UuS/B3dDmAdn+2sXOsTSyNZuriqi6YxDUQL0V/OPvjmflu3bVYDjRwsQHWwmE2SZb?= =?utf-8?q?ex7ZTCm8f2R3dPZn1J9+46mdOO0lvbq5Zp02XVi3B7OuegC52uVh2Do/1brZKvJMx?= =?utf-8?q?Z2Ebr+CFzuaQTgi3pi2IT1AVwuHnIlF/1OUy9NSWWiaTX59+Mn84/HHcoJ60r2IAI?= =?utf-8?q?x+2AUGC1dfMlJ8VVpRGpRIo2g2voOsq6hW7n/0Xf+pVQ6XbGGl3KM8s9p+1baYe88?= =?utf-8?q?Fb+W58mAxrMqcQK5O7F1VU+phIVoTiv7IbzxGESbm2EEge5kFbfwMMPlKeLY8n/Tx?= =?utf-8?q?qCCRaBFTvHceDGFFgGAtYwrPisWJ3hRKXAF37uGe33Ay2OrxtdB1mJhqo9Z7YXPdZ?= =?utf-8?q?fBkb00y2UgcTWeBK4K/qxAWuMluDQF5BcpeSywOWwp4MXOeuLFo9UWVrgcR1u2n+7?= =?utf-8?q?OAq/Szn08t0sDvaBltWf3OHdLS0bEaJiZXa61ndBuj92CkbF/d/trhIUnCx7eoUkN?= =?utf-8?q?lHxNxXeatmcnO8L0mjGgdnGzu0jaRjDttWUAfxcRfg+WOOC4aGFJ2gotl5yBE0fwl?= =?utf-8?q?7wGA2Vr4tNcJbdoEdJBLUk9tq65mJvYSI7U5R0Lifd1VR6B0IOgOjrVaYGogu3/1B?= =?utf-8?q?D4PC37mOEFELDPxaI2R1SlHqdXuq+W1pOMl5NG3v72MBgMSCQiyflJCaTKDwc+U09?= =?utf-8?q?JCiG3/7vIJvGYEndN0lLQsqosQRRZ0cpFyRB0fkLh3XZXlDyV1HJqpL07Wbr95Xdo?= =?utf-8?q?TH52uvTWClYFrL5VPRwLcHnTOtcdcRwgEwhp5z6pYAOy+nkBpcXYafFbBUrhBHWP0?= =?utf-8?q?rQwWA6HONiyn9lM9lprmPLR3epT7gxeISP5bBzdfinqdDVV6l1ZaBSD0PlEZp9ymq?= =?utf-8?q?XivUr8M0gymt+uakFSfXlSQaTdDtzc7SpsYPKiTRd3YUGDHmD97NvENHwygvxhilm?= =?utf-8?q?h9zWmUObh7lTK66KPOuSdWVy7wt03q4D7GNW0oQt1So5iIeYeGGBg=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14b39540-bfb1-40e9-d0ac-08da49ea4f51 X-MS-Exchange-CrossTenant-AuthSource: BYAPR02MB4343.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 07:33:12.9220 (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: UOPxecwBrJCK5kZ2MbEfX7BqdiA6zye37UZiXSM57p02eYESIvy7pKzKyzGXXXGBOtDZweVNz7yllF4v9wPn9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB8639 X-Proofpoint-GUID: EuC86nl0_eFHzIdfIumiQdCm512sIRog X-Proofpoint-ORIG-GUID: EuC86nl0_eFHzIdfIumiQdCm512sIRog X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-09_07,2022-06-07_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=het.gala@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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-Mailman-Approved-At: Thu, 09 Jun 2022 09:30:26 -0400 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" i) Modified the format of the qemu monitor command : 'migrate' by adding a list, each element in the list consists of multi-FD connection parameters: source and destination uris and of the number of multi-fd channels between each pair. ii) Information of all multi-FD connection parameters’ list, length of the list and total number of multi-fd channels for all the connections together is stored in ‘OutgoingArgs’ struct. Suggested-by: Manish Mishra Signed-off-by: Het Gala --- include/qapi/util.h | 9 ++++++++ migration/migration.c | 47 ++++++++++++++++++++++++++++++-------- migration/socket.c | 53 ++++++++++++++++++++++++++++++++++++++++--- migration/socket.h | 17 +++++++++++++- monitor/hmp-cmds.c | 22 ++++++++++++++++-- qapi/migration.json | 43 +++++++++++++++++++++++++++++++---- 6 files changed, 170 insertions(+), 21 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index 81a2b13a33..3041feb3d9 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -56,4 +56,13 @@ int parse_qapi_name(const char *name, bool complete); (tail) = &(*(tail))->next; \ } while (0) +#define QAPI_LIST_LENGTH(list) ({ \ + int _len = 0; \ + typeof(list) _elem; \ + for (_elem = list; _elem != NULL; _elem = _elem->next) { \ + _len++; \ + } \ + _len; \ +}) + #endif diff --git a/migration/migration.c b/migration/migration.c index 31739b2af9..c408175aeb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2328,13 +2328,14 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, return true; } -void qmp_migrate(const char *uri, bool has_blk, bool blk, +void qmp_migrate(const char *uri, bool has_multi_fd_uri_list, + MigrateUriParameterList *cap, bool has_blk, bool blk, bool has_inc, bool inc, bool has_detach, bool detach, bool has_resume, bool resume, Error **errp) { Error *local_err = NULL; MigrationState *s = migrate_get_current(); - const char *p = NULL; + const char *dst_ptr = NULL; if (!migrate_prepare(s, has_blk && blk, has_inc && inc, has_resume && resume, errp)) { @@ -2348,20 +2349,46 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, } } + /* + * In case of Multi-FD migration parameters, if uri is provided, + * supports only tcp network protocol. + */ + if (has_multi_fd_uri_list) { + int length = QAPI_LIST_LENGTH(cap); + init_multifd_array(length); + for (int i = 0; i < length; i++) { + const char *p1 = NULL, *p2 = NULL; + const char *multifd_dst_uri = cap->value->destination_uri; + const char *multifd_src_uri = cap->value->source_uri; + uint8_t multifd_channels = cap->value->multifd_channels; + if (!strstart(multifd_dst_uri, "tcp:", &p1) || + !strstart(multifd_src_uri, "tcp:", &p2)) { + error_setg(errp, "multi-fd destination and multi-fd source " + "uri, both should be present and follows tcp protocol only"); + break; + } else { + store_multifd_migration_params(p1 ? p1 : multifd_dst_uri, + p2 ? p2 : multifd_src_uri, + multifd_channels, i, &local_err); + } + cap = cap->next; + } + } + migrate_protocol_allow_multi_channels(false); - if (strstart(uri, "tcp:", &p) || + if (strstart(uri, "tcp:", &dst_ptr) || strstart(uri, "unix:", NULL) || strstart(uri, "vsock:", NULL)) { migrate_protocol_allow_multi_channels(true); - socket_start_outgoing_migration(s, p ? p : uri, &local_err); + socket_start_outgoing_migration(s, dst_ptr ? dst_ptr : uri, &local_err); #ifdef CONFIG_RDMA - } else if (strstart(uri, "rdma:", &p)) { - rdma_start_outgoing_migration(s, p, &local_err); + } else if (strstart(uri, "rdma:", &dst_ptr)) { + rdma_start_outgoing_migration(s, dst_ptr, &local_err); #endif - } else if (strstart(uri, "exec:", &p)) { - exec_start_outgoing_migration(s, p, &local_err); - } else if (strstart(uri, "fd:", &p)) { - fd_start_outgoing_migration(s, p, &local_err); + } else if (strstart(uri, "exec:", &dst_ptr)) { + exec_start_outgoing_migration(s, dst_ptr, &local_err); + } else if (strstart(uri, "fd:", &dst_ptr)) { + fd_start_outgoing_migration(s, dst_ptr, &local_err); } else { if (!(has_resume && resume)) { yank_unregister_instance(MIGRATION_YANK_INSTANCE); diff --git a/migration/socket.c b/migration/socket.c index 4fd5e85f50..7ca6af8cca 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -32,6 +32,17 @@ struct SocketOutgoingArgs { SocketAddress *saddr; } outgoing_args; +struct SocketArgs { + struct SrcDestAddr data; + uint8_t multifd_channels; +}; + +struct OutgoingMigrateParams { + struct SocketArgs *socket_args; + size_t length; + uint64_t total_multifd_channel; +} outgoing_migrate_params; + void socket_send_channel_create(QIOTaskFunc f, void *data) { QIOChannelSocket *sioc = qio_channel_socket_new(); @@ -47,6 +58,14 @@ int socket_send_channel_destroy(QIOChannel *send) qapi_free_SocketAddress(outgoing_args.saddr); outgoing_args.saddr = NULL; } + + if (outgoing_migrate_params.socket_args != NULL) { + g_free(outgoing_migrate_params.socket_args); + outgoing_migrate_params.socket_args = NULL; + } + if (outgoing_migrate_params.length) { + outgoing_migrate_params.length = 0; + } return 0; } @@ -117,13 +136,41 @@ socket_start_outgoing_migration_internal(MigrationState *s, } void socket_start_outgoing_migration(MigrationState *s, - const char *str, + const char *dst_str, Error **errp) { Error *err = NULL; - SocketAddress *saddr = socket_parse(str, &err); + SocketAddress *dst_saddr = socket_parse(dst_str, &err); + if (!err) { + socket_start_outgoing_migration_internal(s, dst_saddr, &err); + } + error_propagate(errp, err); +} + +void init_multifd_array(int length) +{ + outgoing_migrate_params.socket_args = g_new0(struct SocketArgs, length); + outgoing_migrate_params.length = length; + outgoing_migrate_params.total_multifd_channel = 0; +} + +void store_multifd_migration_params(const char *dst_uri, + const char *src_uri, + uint8_t multifd_channels, + int idx, Error **errp) +{ + Error *err = NULL; + SocketAddress *src_addr = NULL; + SocketAddress *dst_addr = socket_parse(dst_uri, &err); + if (src_uri) { + src_addr = socket_parse(src_uri, &err); + } if (!err) { - socket_start_outgoing_migration_internal(s, saddr, &err); + outgoing_migrate_params.socket_args[idx].data.dst_addr = dst_addr; + outgoing_migrate_params.socket_args[idx].data.src_addr = src_addr; + outgoing_migrate_params.socket_args[idx].multifd_channels + = multifd_channels; + outgoing_migrate_params.total_multifd_channel += multifd_channels; } error_propagate(errp, err); } diff --git a/migration/socket.h b/migration/socket.h index 891dbccceb..bba7f177fe 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -19,12 +19,27 @@ #include "io/channel.h" #include "io/task.h" +#include "migration.h" + +/* info regarding destination and source uri */ +struct SrcDestAddr { + SocketAddress *dst_addr; + SocketAddress *src_addr; +}; void socket_send_channel_create(QIOTaskFunc f, void *data); int socket_send_channel_destroy(QIOChannel *send); void socket_start_incoming_migration(const char *str, Error **errp); -void socket_start_outgoing_migration(MigrationState *s, const char *str, +void socket_start_outgoing_migration(MigrationState *s, const char *dst_str, Error **errp); + +int multifd_list_length(MigrateUriParameterList *list); + +void init_multifd_array(int length); + +void store_multifd_migration_params(const char *dst_uri, const char *src_uri, + uint8_t multifd_channels, int idx, + Error **erp); #endif diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 622c783c32..2db539016a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -56,6 +56,9 @@ #include "migration/snapshot.h" #include "migration/misc.h" +/* Default number of multi-fd channels */ +#define DEFAULT_MIGRATE_MULTIFD_CHANNELS 2 + #ifdef CONFIG_SPICE #include #endif @@ -1574,10 +1577,25 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) bool inc = qdict_get_try_bool(qdict, "inc", false); bool resume = qdict_get_try_bool(qdict, "resume", false); const char *uri = qdict_get_str(qdict, "uri"); + + const char *src_uri = qdict_get_str(qdict, "source-uri"); + const char *dst_uri = qdict_get_str(qdict, "destination-uri"); + uint8_t multifd_channels = qdict_get_try_int(qdict, "multifd-channels", + DEFAULT_MIGRATE_MULTIFD_CHANNELS); Error *err = NULL; + MigrateUriParameterList *caps = NULL; + MigrateUriParameter *value; + + value = g_malloc0(sizeof(*value)); + value->source_uri = (char *)src_uri; + value->destination_uri = (char *)dst_uri; + value->multifd_channels = multifd_channels; + QAPI_LIST_PREPEND(caps, value); + + qmp_migrate(uri, !!caps, caps, !!blk, blk, !!inc, + inc, false, false, true, resume, &err); + qapi_free_MigrateUriParameterList(caps); - qmp_migrate(uri, !!blk, blk, !!inc, inc, - false, false, true, resume, &err); if (hmp_handle_error(mon, err)) { return; } diff --git a/qapi/migration.json b/qapi/migration.json index 6130cd9fae..fb259d626b 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1454,12 +1454,38 @@ ## { 'command': 'migrate-continue', 'data': {'state': 'MigrationStatus'} } +## +# @MigrateUriParameter: +# +# Information regarding which source interface is connected to which +# destination interface and number of multifd channels over each interface. +# +# @source-uri: the Uniform Resource Identifier of the source VM. +# Default port number is 0. +# +# @destination-uri: the Uniform Resource Identifier of the destination VM +# +# @multifd-channels: number of parallel multifd channels used to migrate data +# for specific source-uri and destination-uri. Default value +# in this case is 2 (Since 4.0) +# +## +{ 'struct' : 'MigrateUriParameter', + 'data' : { 'source-uri' : 'str', + 'destination-uri' : 'str', + '*multifd-channels' : 'uint8'} } + ## # @migrate: # # Migrates the current running guest to another Virtual Machine. # # @uri: the Uniform Resource Identifier of the destination VM +# for migration thread +# +# @multi-fd-uri-list: list of pair of source and destination VM Uniform +# Resource Identifiers with number of multifd-channels +# for each pair # # @blk: do block migration (full disk copy) # @@ -1479,20 +1505,27 @@ # 1. The 'query-migrate' command should be used to check migration's progress # and final result (this information is provided by the 'status' member) # -# 2. All boolean arguments default to false +# 2. The uri argument should have the Uniform Resource Identifier of default +# destination VM. This connection will be bound to default network +# +# 3. All boolean arguments default to false # -# 3. The user Monitor's "detach" argument is invalid in QMP and should not +# 4. The user Monitor's "detach" argument is invalid in QMP and should not # be used # # Example: # -# -> { "execute": "migrate", "arguments": { "uri": "tcp:0:4446" } } +# -> { "execute": "migrate", +# "arguments": { "uri": "tcp:0:4446", "multi-fd-uri-list": [ { +# "source-uri": "tcp::6900", "destination-uri": "tcp:0:4480", +# "multifd-channels": 4}, { "source-uri": "tcp:10.0.0.0: ", +# "destination-uri": "tcp:11.0.0.0:7789", "multifd-channels": 5} ] } } # <- { "return": {} } # ## { 'command': 'migrate', - 'data': {'uri': 'str', '*blk': 'bool', '*inc': 'bool', - '*detach': 'bool', '*resume': 'bool' } } + 'data': {'uri': 'str', '*multi-fd-uri-list': ['MigrateUriParameter'], '*blk': 'bool', + '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } } ## # @migrate-incoming: From patchwork Thu Jun 9 07:33:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Het Gala X-Patchwork-Id: 12875619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55D65C433EF for ; Thu, 9 Jun 2022 14:20:38 +0000 (UTC) Received: from localhost ([::1]:58920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzJ1Z-0004jS-5K for qemu-devel@archiver.kernel.org; Thu, 09 Jun 2022 10:20:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfW-0002B3-Jl for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:29 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:46408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfQ-0007uI-Pm for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:26 -0400 Received: from pps.filterd (m0127838.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25964PeO022399; Thu, 9 Jun 2022 00:33:17 -0700 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-type : content-transfer-encoding : mime-version; s=proofpoint20171006; bh=fVlopdvxuJj6Cz63nf3fC0gf0KuCacUk6nP1g4zXZXg=; b=JzWOYzA5pBry4s6Gtt9pbvMg44/9p1Hmuz7UmF86SfTP67mxjEGLV0q6gTi4Nw7prZRm wOi7Hxjt7RAKkYFT3YO+WKfi4JudZ1bj8Nr0f8wt3a4I9ShCXAg1HPiD0+3DF3SI5zr1 3tesp6NGgyN3kaEhSfUg7Rjbctv2Ej8oxr8AxC8+LFLzOgvDvSvWthVpfIoU7wLi2K9/ MfAC8qCzWpJdx0QJJYsilpQH6il8IF97KOA8YKCuWjI0ujwmRsrklVJDZRpaOL4IzVe4 SPEUtQWtSEBvQ06mmflhR1JNFwBhMi3Nm4vSr4oJmQvjnFwIvqqiRov22S99Ncaisl2q aQ== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3gg6y0a3r2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jun 2022 00:33:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a06eldtezXhlUyrTH20DfjROPS2UBMs3uNZXV+UoTiSefGiFCmpn1LfNZOjocSE2YyqXk5ZUB3IDGsbLhn1dMuLDYAgL9nnNdZB/9gaM0PxwycsRIhWBPtUlW8hke4dcC04d4xKl3PB1bG94Db9Mkb6sqBJCVbEfW07XpsBrFxgm4bAfEuyCF4vRitqtpSd6BE/QG1pnzfmkOOYh9j0ffati5XtxdMVAS3OnXNHS4mDjN2uY/uQ6wYvuGmFN5ks8aWVSBawL4aRVWNun91sMt2zxZ2g1h1UbY1BQueC79YkBT0OVKgcI5DBLqEgw3N/6VzeaTBnhXdC4SHv8z4jX3Q== 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=fVlopdvxuJj6Cz63nf3fC0gf0KuCacUk6nP1g4zXZXg=; b=M6AqpzVBAvsN0HKwmPGHIzzUrpcLdNNHPRScanHXcbRJFLzdX3pw/w6Q9EENLyqMu0B77AiJ4qS3mzed2xQzF7oR7i49YfLP+uqgQjt/PQZsnJNQ/wZGvA4TQJlHTYpaqUct45wp7sqDG0T480Qo1+UbUPCF7O6ns0rf2wLOmUxHcg3eimQxNivr6Q2jbOcuO6HbrRXHBAEqES2nxCzDNr1QBE8+zA0Q1BqlrOdKwsRsxRvdJltX6M8buoBbvr07oGGQ3l8/YzfvIevSKFdG0JPzby641fAUOTjF31SSyfz9pZY9694ynuiNscoifH6OBZrVDBuIS4yxjoIKigX/zg== 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 Received: from BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) by SA1PR02MB8639.namprd02.prod.outlook.com (2603:10b6:806:1fe::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 9 Jun 2022 07:33:14 +0000 Received: from BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f]) by BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f%5]) with mapi id 15.20.5314.019; Thu, 9 Jun 2022 07:33:14 +0000 From: Het Gala To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, eblake@redhat.com, Het Gala , Manish Mishra Subject: [PATCH 2/4] Adding multi-interface support for multi-FD on destination side Date: Thu, 9 Jun 2022 07:33:03 +0000 Message-Id: <20220609073305.142515-3-het.gala@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220609073305.142515-1-het.gala@nutanix.com> References: <20220609073305.142515-1-het.gala@nutanix.com> X-ClientProxiedBy: BY5PR04CA0002.namprd04.prod.outlook.com (2603:10b6:a03:1d0::12) To BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdc8117f-8c16-4444-832f-08da49ea506d X-MS-TrafficTypeDiagnostic: SA1PR02MB8639:EE_ X-Microsoft-Antispam-PRVS: 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: EXKnHtJQxpJZkOcKncpoxIrqZwkwLDvpe8WCHf3U7tGQqEtqfL6twlWw6CVfrlX0XfgwZSUTIwwsJn2yQ/AvnbCmZUQyIG5as+RAQzlOAZ5RTDMF7Vdwvd002hCkOgYDz9d/a/7v+vWj1hDhz7GTtp5O+LnmuUbX7ZBXrcLHjPbgRd4/0PstcVL+iPJPN34f5LvqnyUIADe/d/C09B+sVQC64R4RIAznDXtieNllLYQszGqxwclGaQyAr1g/XAm9AHpiSg/GChGhOXkTAd1tfmciLOh4Ox0TNdk72B69arlCwvBNFoSej8jpXmCXAJlYYc3ncih1ybSuNnFrLrG+Jh/yzPs534Rx72ulda0MSBs6MWjW9s4vVL6YcZbcntlWyqspSPlpptoMAhrRkkJ9M3D82p9KbIMitEruC2CcvKweZ82ONEe3DC3R1Ixplvm7yA6pkzBkj/xZjCAVnmO16ieiAn/IJUDxhGR89ruzUekGJRGzIzg3Wl1VfmBrBne2lk+1DwFwbU34VwcnYEwJxgoRMsZ5O9PbGkUVegvSKAXx5BaR8D3g1rJUtIzF3NZLrRn7xQFu0NXsKgdMHziHzSlibsKecXbyb5EOW619X3KkuYP4wLb6gM1jTVtRh+ZiG5FpCxDGgcBMtTciun/ZAMkMwzOUfleuT+8CLx5HaOO8TmZVWUCYSZKcL2L6LflMFK+6Z+nQJeIt1Cu82QPygxEIeZGZwvr3KjQIi0qg0Ho= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR02MB4343.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(107886003)(6666004)(1076003)(2906002)(8936002)(52116002)(54906003)(86362001)(6506007)(186003)(5660300002)(30864003)(83380400001)(6486002)(44832011)(38350700002)(26005)(38100700002)(36756003)(6512007)(2616005)(316002)(66556008)(66946007)(4326008)(6916009)(8676002)(66476007)(309714004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?z0HJlFMKM4eI4S8I67IIrdrHnXaQ?= =?utf-8?q?Re8UP3fg3vMsHMQQl/4qx9Gg/orYNTHkG1gyBhwPt4l4xrmmTMuuURXaYPzpFAb1Q?= =?utf-8?q?IfuQZ4dMqHS3lzltuJfLOF2h7uBhYRq/1eg1CSq+tPn24dZI3VQA74FpSX8IG2aWI?= =?utf-8?q?dYRSXIplKErjApW520bnG21SeBMx0b/2Ae9rAcHFJ42aYN7+7UHhHPqQNtz2W6oeO?= =?utf-8?q?Um3PzDn0NiPejF1nlBUO/k4iqptK2zQAT20XxWMVTER5cXWsTbJeiCa46L35UKngP?= =?utf-8?q?2xFY+03OHp0+zTEiyMxn071Cn7D2ON1yxZ+TU3jj4kiaFL/8VV5tASvEDtVG8nna6?= =?utf-8?q?OOBhK+6BQjOMVqpfvbKDyF0y6YHRlmwbDOGADBS0C0flUoMNAYw7WuJsxcoMSlF/N?= =?utf-8?q?/GsPq10GslsTZvDMfZ98Rhclb1ikpqXt8zUEJoIG7d7tATkLQQBIbNkcwpgMib/qB?= =?utf-8?q?YR0CZjf6lpwZHZcm7cL02J2Zp1DfqcAGziGXmdIHobcY09K02QvUadxWsoadWO+FC?= =?utf-8?q?MDPELDUOa3TZOg2GsgDrUJP/akQtLE+rEOpIujoblTKov4H7iqnv0wiSuAaWvA1rP?= =?utf-8?q?AOXzVUTHszYiSb23WF0yt03uUSvjqLZl0EE9TT2CQLoAaDDR3itKCqIYk5PfaDvbT?= =?utf-8?q?tjzazGmgOYxHUzzAInfvxDcLV0ljG8aDIsF+yQ/4lys/W3EQOgiZ6sZpDuo6dkGrf?= =?utf-8?q?479IF+rJv+OTMtZmwTdhPkZYK/zhkjJ4ml/tWWJJL2b6R4bkbd2/MzhTcbMrZFkxP?= =?utf-8?q?mUDKg85Wj4KJQrf8EE/IvmSX2rWblGFBkGmnW6mam4lIdUTxaxD+Z9QLi0mIkn7OW?= =?utf-8?q?rOiWeFLGdl4xYrfq876QvGX+VPe/79FZTZuydfLCZsMHX1lkQtZ754TrL9z+tcq/u?= =?utf-8?q?s7sizTIF1LvPXifSVxO8j5MFH76w6zHb/RdB6fM1bxCvzDAXmWIqWpDvVMdYXrLsk?= =?utf-8?q?Zxws3HKf/c/7Ve8ufUBxaiDa64hbr4lPzEkYrvWMMQ/ixfvEQmrV/lRH1L5I47otK?= =?utf-8?q?/AHAkzWO5yOJp9dAPRN63Hkwl54F0xHLNxw+25Z6K1DZQ7Vb7nQB99ripZQXuYSer?= =?utf-8?q?HyI7ZOi07EVMtUXDhd9JrhtnzoQBjjoUn5sAkSxmxW6BaF3lZF/UBVmesQDsX1ojl?= =?utf-8?q?rvvII06V4Z+TFAFC75BPBkC6MzSVEud9rnyifTun/DafDLf7Bq6/ZE348rIJ+ajHI?= =?utf-8?q?RMI5K90OdKNUgZvI5gzeD+LPx6TUl8wwnvWnE6leeL0XPlR5WIK5ucjujV9K560pj?= =?utf-8?q?wWnKJcVgsBcn7Z6nvgJyk2MPlvDvrIR0UvxMQ8cei3TbFtcTu1mR+kY4dlpTvaIlZ?= =?utf-8?q?wjIotJC30m1G2tqSVHyVS4mYSV5iRMo2DC2foPFBiHRfZcweXySpTj4E8i3LWuGQo?= =?utf-8?q?OpLR8zm/ChDq7hyM8K9CNOP6GNnohHiYamSVp+Cu/EuZltKgxHvDJR59gqFOv3DpJ?= =?utf-8?q?/i5FuDq7xRIV/wM1IXJ2+OjBo5+zIKSrVRG5/Zzomq7npFpCHmQoLHvKkI4XjPx03?= =?utf-8?q?edXVtsp3I7lyw+j/BX5EojNp/EmiF0ZAFOZ91LgMVXMROR+I5e163RjdH9fiZXoAI?= =?utf-8?q?A4UQ073sctFWTipyfixe7qWo3rxIhbuNnoDd8fbfSXZY3t5J2KX8wYHS/Xbynss6o?= =?utf-8?q?Ak07SbruZiAteXepakcUnKc9KiJV+uzJ81D8rKX741jAbvoIz8Cm4=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdc8117f-8c16-4444-832f-08da49ea506d X-MS-Exchange-CrossTenant-AuthSource: BYAPR02MB4343.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 07:33:14.7813 (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: V/Rl4oYGR0kkxeOfSoxvvzeyVjralrM3pH6G5RmazfnVxrYcU7YCVhzesNc0cmkow3sAZxfRuua/tuRUSQJpAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB8639 X-Proofpoint-GUID: N7GQt9PTXAnIpREplu6LCjWWbOrFCAX4 X-Proofpoint-ORIG-GUID: N7GQt9PTXAnIpREplu6LCjWWbOrFCAX4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-09_07,2022-06-07_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=het.gala@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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-Mailman-Approved-At: Thu, 09 Jun 2022 09:30:34 -0400 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" i) Modified the format of qemu monitor command: ‘migrate-incoming’ by adding a list, each element in the list is to open listeners with a given number of multiFD channels. ii) Qemu starts with -incoming flag defer and -multi-fd-incoming defer to allow the modified 'migrate-incoming' command to be used. iii) Format for -multi-fd-incoming flag as a comma separated string has been added with each substring containing listener socket address and number of sockets to open. Suggested-by: Manish Mishra Signed-off-by: Het Gala --- include/qapi/util.h | 1 + migration/migration.c | 149 ++++++++++++++++++++++++++++++++++++------ migration/migration.h | 2 + migration/socket.c | 11 ++-- migration/socket.h | 3 +- monitor/hmp-cmds.c | 42 ++++-------- qapi/migration.json | 43 ++++++++++-- qapi/qapi-util.c | 27 ++++++++ qemu-options.hx | 18 +++++ softmmu/vl.c | 30 ++++++++- 10 files changed, 265 insertions(+), 61 deletions(-) diff --git a/include/qapi/util.h b/include/qapi/util.h index 3041feb3d9..88fb2270db 100644 --- a/include/qapi/util.h +++ b/include/qapi/util.h @@ -29,6 +29,7 @@ bool qapi_bool_parse(const char *name, const char *value, bool *obj, Error **errp); int parse_qapi_name(const char *name, bool complete); +struct strList *strList_from_string(const char *in, char c); /* * For any GenericList @list, insert @element at the front. diff --git a/migration/migration.c b/migration/migration.c index c408175aeb..9b0ad732e7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -477,28 +477,39 @@ void migrate_add_address(SocketAddress *address) QAPI_CLONE(SocketAddress, address)); } -static void qemu_start_incoming_migration(const char *uri, Error **errp) +static void qemu_start_incoming_migration(const char *uri, uint8_t number, + int idx, Error **errp) { const char *p = NULL; - migrate_protocol_allow_multi_channels(false); /* reset it anyway */ - qapi_event_send_migration(MIGRATION_STATUS_SETUP); - if (strstart(uri, "tcp:", &p) || - strstart(uri, "unix:", NULL) || - strstart(uri, "vsock:", NULL)) { - migrate_protocol_allow_multi_channels(true); - socket_start_incoming_migration(p ? p : uri, errp); -#ifdef CONFIG_RDMA - } else if (strstart(uri, "rdma:", &p)) { - rdma_start_incoming_migration(p, errp); -#endif - } else if (strstart(uri, "exec:", &p)) { - exec_start_incoming_migration(p, errp); - } else if (strstart(uri, "fd:", &p)) { - fd_start_incoming_migration(p, errp); + if (number == 0) { + migrate_protocol_allow_multi_channels(false); /* reset it anyway */ + qapi_event_send_migration(MIGRATION_STATUS_SETUP); + if (strstart(uri, "tcp:", &p) || + strstart(uri, "unix:", NULL) || + strstart(uri, "vsock:", NULL)) { + migrate_protocol_allow_multi_channels(true); + #ifdef CONFIG_RDMA + } else if (strstart(uri, "rdma:", &p)) { + rdma_start_incoming_migration(p, errp); + #endif + } else if (strstart(uri, "exec:", &p)) { + exec_start_incoming_migration(p, errp); + } else if (strstart(uri, "fd:", &p)) { + fd_start_incoming_migration(p, errp); + } else { + error_setg(errp, "unknown migration protocol: %s", uri); + } } else { - error_setg(errp, "unknown migration protocol: %s", uri); + /* multi-FD parameters only support tcp network protocols */ + if (!strstart(uri, "tcp:", &p)) { + error_setg(errp, "multifd-destination uri supports " + "tcp protocol only"); + return; + } + store_multifd_migration_params(p ? p : uri, NULL, number, idx, errp); } + socket_start_incoming_migration(p ? p : uri, number, errp); } static void process_incoming_migration_bh(void *opaque) @@ -2140,7 +2151,17 @@ void migrate_del_blocker(Error *reason) migration_blockers = g_slist_remove(migration_blockers, reason); } -void qmp_migrate_incoming(const char *uri, Error **errp) +static inline int incoming_multi_fd_uri_parse(const char *str, char delim) +{ + int count = 0; + for (int i = 0; i < strlen(str); i++) { + count += (str[i] == delim); + } + return count; +} + +/* migrate_incoming comes from -incoming flag in qemu process */ +void migrate_incoming(const char *uri, Error **errp) { Error *local_err = NULL; static bool once = true; @@ -2154,11 +2175,99 @@ void qmp_migrate_incoming(const char *uri, Error **errp) return; } + qemu_start_incoming_migration(uri, 0, 0, &local_err); + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { return; } - qemu_start_incoming_migration(uri, &local_err); + if (local_err) { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); + error_propagate(errp, local_err); + return; + } + + once = false; +} + +/* multi_fd_migrate_incoming comes from -multi-fd-migrate-incoming flag in qemu process */ +void multi_fd_migrate_incoming(const char *uri, Error **errp) +{ + Error *local_err = NULL; + static bool once = true; + + if (!once) { + error_setg(errp, "The incoming migration has already been started"); + return; + } + if (!runstate_check(RUN_STATE_INMIGRATE)) { + error_setg(errp, "'-multi-fd-incoming' was not specified on the command line"); + return; + } + + strList *st = strList_from_string(uri, ','); + strList *r = st; + int length = QAPI_LIST_LENGTH(st); + init_multifd_array(length); + + for (int i = 0; i < length; i++) { + const char *uri = NULL, *ret = NULL; + const char *str = r->value; + uint8_t multifd_channels = DEFAULT_MIGRATE_MULTIFD_CHANNELS; + int parse_count = incoming_multi_fd_uri_parse(str, ':'); + if (parse_count < 2 || parse_count > 3) { + error_setg(errp, "Invalid format of string-id %d in " + "'-multi-fd-incoming' flag", i); + return; + } + if (parse_count == 3) { + ret = strrchr(str, ':'); + uri = g_strndup(str, strlen(str) - strlen(ret)); + multifd_channels = atoi(ret + 1); + } + qemu_start_incoming_migration(parse_count == 2 ? str : uri, + multifd_channels, i, &local_err); + r = r->next; + } + + if (local_err) { + yank_unregister_instance(MIGRATION_YANK_INSTANCE); + error_propagate(errp, local_err); + return; + } + + once = false; +} + +/* qmp_migrate_incoming comes from qemu qmp monitor command */ +void qmp_migrate_incoming(const char *uri, bool has_multi_fd_uri_list, + MigrateIncomingUriList *cap, Error **errp) +{ + Error *local_err = NULL; + static bool once = true; + + if (!once) { + error_setg(errp, "The incoming migration has already been started"); + return; + } + + if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) { + return; + } + + /* For migration thread */ + qemu_start_incoming_migration(uri, 0, 0, &local_err); + + /* For Multi-FD */ + int length = QAPI_LIST_LENGTH(cap); + init_multifd_array(length); + for (int i = 0; i < length; i++) { + const char *multifd_dst_uri = cap->value->destination_uri; + uint8_t multifd_channels = cap->value->multifd_channels; + qemu_start_incoming_migration(multifd_dst_uri, multifd_channels, + i, &local_err); + cap = cap->next; + } if (local_err) { yank_unregister_instance(MIGRATION_YANK_INSTANCE); @@ -2194,7 +2303,7 @@ void qmp_migrate_recover(const char *uri, Error **errp) * only re-setup the migration stream and poke existing migration * to continue using that newly established channel. */ - qemu_start_incoming_migration(uri, errp); + qemu_start_incoming_migration(uri, 0, 0, errp); } void qmp_migrate_pause(Error **errp) diff --git a/migration/migration.h b/migration/migration.h index 485d58b95f..fa8717ec9e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -353,6 +353,8 @@ bool migration_is_setup_or_active(int state); bool migration_is_running(int state); void migrate_init(MigrationState *s); +void migrate_incoming(const char *uri, Error **errp); +void multi_fd_migrate_incoming(const char *uri_str, Error **errp); bool migration_is_blocked(Error **errp); /* True if outgoing migration has entered postcopy phase */ bool migration_in_postcopy(void); diff --git a/migration/socket.c b/migration/socket.c index 7ca6af8cca..21e0983df2 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -202,17 +202,17 @@ socket_incoming_migration_end(void *opaque) static void socket_start_incoming_migration_internal(SocketAddress *saddr, - Error **errp) + uint8_t number, Error **errp) { QIONetListener *listener = qio_net_listener_new(); MigrationIncomingState *mis = migration_incoming_get_current(); size_t i; - int num = 1; + uint8_t num = 1; qio_net_listener_set_name(listener, "migration-socket-listener"); if (migrate_use_multifd()) { - num = migrate_multifd_channels(); + num = number; } if (qio_net_listener_open_sync(listener, saddr, num, errp) < 0) { @@ -239,12 +239,13 @@ socket_start_incoming_migration_internal(SocketAddress *saddr, } } -void socket_start_incoming_migration(const char *str, Error **errp) +void socket_start_incoming_migration(const char *str, + uint8_t number, Error **errp) { Error *err = NULL; SocketAddress *saddr = socket_parse(str, &err); if (!err) { - socket_start_incoming_migration_internal(saddr, &err); + socket_start_incoming_migration_internal(saddr, number, &err); } qapi_free_SocketAddress(saddr); error_propagate(errp, err); diff --git a/migration/socket.h b/migration/socket.h index bba7f177fe..b9e3699167 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -30,7 +30,8 @@ struct SrcDestAddr { void socket_send_channel_create(QIOTaskFunc f, void *data); int socket_send_channel_destroy(QIOChannel *send); -void socket_start_incoming_migration(const char *str, Error **errp); +void socket_start_incoming_migration(const char *str, uint8_t number, + Error **errp); void socket_start_outgoing_migration(MigrationState *s, const char *dst_str, Error **errp); diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 2db539016a..32a6b67d5f 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -42,6 +42,7 @@ #include "qapi/qapi-commands-run-state.h" #include "qapi/qapi-commands-tpm.h" #include "qapi/qapi-commands-ui.h" +#include "qapi/util.h" #include "qapi/qapi-visit-net.h" #include "qapi/qapi-visit-migration.h" #include "qapi/qmp/qdict.h" @@ -72,32 +73,6 @@ bool hmp_handle_error(Monitor *mon, Error *err) return false; } -/* - * Produce a strList from a comma separated list. - * A NULL or empty input string return NULL. - */ -static strList *strList_from_comma_list(const char *in) -{ - strList *res = NULL; - strList **tail = &res; - - while (in && in[0]) { - char *comma = strchr(in, ','); - char *value; - - if (comma) { - value = g_strndup(in, comma - in); - in = comma + 1; /* skip the , */ - } else { - value = g_strdup(in); - in = NULL; - } - QAPI_LIST_APPEND(tail, value); - } - - return res; -} - void hmp_info_name(Monitor *mon, const QDict *qdict) { NameInfo *info; @@ -1117,7 +1092,7 @@ void hmp_announce_self(Monitor *mon, const QDict *qdict) migrate_announce_params()); qapi_free_strList(params->interfaces); - params->interfaces = strList_from_comma_list(interfaces_str); + params->interfaces = strList_from_string(interfaces_str, ','); params->has_interfaces = params->interfaces != NULL; params->id = g_strdup(id); params->has_id = !!params->id; @@ -1147,8 +1122,19 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) { Error *err = NULL; const char *uri = qdict_get_str(qdict, "uri"); + const char *dst_uri = qdict_get_str(qdict, "destination-uri"); + uint8_t multifd_channels = qdict_get_try_int(qdict, "multifd-channels", + DEFAULT_MIGRATE_MULTIFD_CHANNELS); + MigrateIncomingUriList *caps = NULL; + MigrateIncomingUri *value; + + value = g_malloc0(sizeof(*value)); + value->destination_uri = (char *)dst_uri; + value->multifd_channels = multifd_channels; + QAPI_LIST_PREPEND(caps, value); - qmp_migrate_incoming(uri, &err); + qmp_migrate_incoming(uri, !!caps, caps, &err); + qapi_free_MigrateIncomingUriList(caps); hmp_handle_error(mon, err); } diff --git a/qapi/migration.json b/qapi/migration.json index fb259d626b..62a7b22d19 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1527,15 +1527,37 @@ 'data': {'uri': 'str', '*multi-fd-uri-list': ['MigrateUriParameter'], '*blk': 'bool', '*inc': 'bool', '*detach': 'bool', '*resume': 'bool' } } +## +# @MigrateIncomingUri: +# +# Information regarding which destination listening interface to be connected +# and number of multifd channels over that interface. +# +# @destination-uri: the Uniform Resource Identifier of the destination VM +# +# @multifd-channels: number of channels used to migrate data in parallel for +# for specific source-uri and destination-uri. +# Default value in this case is 2 (Since 4.0) +# +## +{ 'struct' : 'MigrateIncomingUri', + 'data' : { 'destination-uri' : 'str', + '*multifd-channels' : 'uint8'} } + ## # @migrate-incoming: # # Start an incoming migration, the qemu must have been started -# with -incoming defer +# with -incoming defer. qemu can also be started with optional +# -multi-fd-incoming defer for opening multifd listening sockets # # @uri: The Uniform Resource Identifier identifying the source or # address to listen on # +# @multi-fd-uri-list: list of pair of source and destination VM Uniform +# Resource Identifiers with number of multifd-channels +# for each pair +# # Returns: nothing on success # # Since: 2.3 @@ -1546,19 +1568,30 @@ # compatible with -incoming and the format of the uri is already exposed # above libvirt. # -# 2. QEMU must be started with -incoming defer to allow migrate-incoming to +# 2. multi-fd-uri-list will have list of destination uri as listening sockets +# and multi-fd number of channels on each listening socket. +# +# 3. QEMU must be started with -incoming defer to allow migrate-incoming to # be used. # -# 3. The uri format is the same as for -incoming +# 4. multi-fd-uri-list format is not the same as for -multi-fd-incoming flag. +# For -multi-fd-incoming flag, it is a comma separated list of listener +# sockets with multifd channels. +# Example: -multi-fd-incoming "tcp::6900:4,tcp:11.0.0.0:7789:5". # # Example: # # -> { "execute": "migrate-incoming", -# "arguments": { "uri": "tcp::4446" } } +# "arguments": {"uri": "tcp::6789", +# "multi-fd-uri-list" : [ {"destination-uri" : "tcp::6900", +# "multifd-channels": 4}, +# {"destination-uri" : "tcp:11.0.0.0:7789", +# "multifd-channels": 5} ] } } # <- { "return": {} } # ## -{ 'command': 'migrate-incoming', 'data': {'uri': 'str' } } +{ 'command': 'migrate-incoming', + 'data': {'uri': 'str', '*multi-fd-uri-list': ['MigrateIncomingUri'] } } ## # @xen-save-devices-state: diff --git a/qapi/qapi-util.c b/qapi/qapi-util.c index 63596e11c5..9cc43ebcd3 100644 --- a/qapi/qapi-util.c +++ b/qapi/qapi-util.c @@ -15,6 +15,7 @@ #include "qapi/error.h" #include "qemu/ctype.h" #include "qapi/qmp/qerror.h" +#include "qapi/qapi-builtin-types.h" CompatPolicy compat_policy; @@ -152,3 +153,29 @@ int parse_qapi_name(const char *str, bool complete) } return p - str; } + +/* + * Produce a strList from a delimiter separated list. + * A NULL or empty input string return NULL. + */ +strList *strList_from_string(const char *in, char c) +{ + strList *res = NULL; + strList **tail = &res; + + while (in && in[0]) { + char *ch = strchr(in, c); + char *value; + + if (ch) { + value = g_strndup(in, ch - in); + in = ch + 1; /* skip the , */ + } else { + value = g_strdup(in); + in = NULL; + } + QAPI_LIST_APPEND(tail, value); + } + + return res; +} diff --git a/qemu-options.hx b/qemu-options.hx index 60cf188da4..2e82e41dd5 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4480,6 +4480,24 @@ SRST to issuing the migrate\_incoming to allow the migration to begin. ERST +DEF("multi-fd-incoming", HAS_ARG, QEMU_OPTION_multi_fd_incoming, \ + "-multi-fd-incoming tcp:[host]:port[:channel][,to=maxport][,ipv4=on|off][,ipv6=on|off]\n" \ + "-multi-fd-incoming defer\n" \ + " wait for the URI to be specified via\n" \ + " multi_fd_migrate_incoming\n", + QEMU_ARCH_ALL) +SRST +``-multi-fd-incoming tcp:[host]:port[:channel][,to=maxport][,ipv4=on|off][,ipv6=on|off]`` + Prepare for multi-fd incoming migration, with multi-fd listening sockets + on that connection. Default number of multi-fd channels is 2. + +``-multi-fd-incoming defer`` + Wait for the URI to be specified via multi_fd_migrate\_incoming. The + monitor can be used to change settings (such as migration parameters) + prior to issuing the multi_fd_migrate\_incoming to allow the migration + to begin. +ERST + DEF("only-migratable", 0, QEMU_OPTION_only_migratable, \ "-only-migratable allow only migratable devices\n", QEMU_ARCH_ALL) SRST diff --git a/softmmu/vl.c b/softmmu/vl.c index 4c1e94b00e..2f5cf18eff 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -45,7 +45,7 @@ #include "sysemu/seccomp.h" #include "sysemu/tcg.h" #include "sysemu/xen.h" - +#include "migration/migration.h" #include "qemu/error-report.h" #include "qemu/sockets.h" #include "qemu/accel.h" @@ -167,6 +167,7 @@ typedef struct DeviceOption { static const char *cpu_option; static const char *mem_path; static const char *incoming; +static const char *multi_fd_incoming; static const char *loadvm; static const char *accelerators; static bool have_custom_ram_size; @@ -2349,6 +2350,11 @@ static void qemu_validate_options(const QDict *machine_opts) error_report("'preconfig' supports '-incoming defer' only"); exit(EXIT_FAILURE); } + if (multi_fd_incoming && preconfig_requested && + strcmp(multi_fd_incoming, "defer") != 0) { + error_report("'preconfig' supports '-multi-fd-incoming defer' only"); + exit(EXIT_FAILURE); + } #ifdef CONFIG_CURSES if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) { @@ -2621,7 +2627,7 @@ void qmp_x_exit_preconfig(Error **errp) if (incoming) { Error *local_err = NULL; if (strcmp(incoming, "defer") != 0) { - qmp_migrate_incoming(incoming, &local_err); + migrate_incoming(incoming, &local_err); if (local_err) { error_reportf_err(local_err, "-incoming %s: ", incoming); exit(1); @@ -2630,6 +2636,20 @@ void qmp_x_exit_preconfig(Error **errp) } else if (autostart) { qmp_cont(NULL); } + + if (multi_fd_incoming) { + Error *local_err = NULL; + if (strcmp(multi_fd_incoming, "defer") != 0) { + multi_fd_migrate_incoming(multi_fd_incoming, &local_err); + if (local_err) { + error_reportf_err(local_err, "-multi-fd-incoming %s: ", + multi_fd_incoming); + exit(1); + } + } + } else if (autostart) { + qmp_cont(NULL); + } } void qemu_init(int argc, char **argv, char **envp) @@ -3355,6 +3375,12 @@ void qemu_init(int argc, char **argv, char **envp) } incoming = optarg; break; + case QEMU_OPTION_multi_fd_incoming: + if (!multi_fd_incoming) { + runstate_set(RUN_STATE_INMIGRATE); + } + multi_fd_incoming = optarg; + break; case QEMU_OPTION_only_migratable: only_migratable = 1; break; From patchwork Thu Jun 9 07:33:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Het Gala X-Patchwork-Id: 12875730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E24E0C43334 for ; Thu, 9 Jun 2022 14:49:49 +0000 (UTC) Received: from localhost ([::1]:35876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzJTo-0007Us-PH for qemu-devel@archiver.kernel.org; Thu, 09 Jun 2022 10:49:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfW-0002B5-UE for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:29 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:1688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfR-0007uP-1L for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:26 -0400 Received: from pps.filterd (m0127837.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25964eWX027717; Thu, 9 Jun 2022 00:33:19 -0700 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=7+LOV4TNbMSsT83B7FiHwpFKsg7v6LYRFo9WTGpek9Q=; b=paowXkW4ALIv6J/uzuQG2R2vBYG0Y4CLyi+B2fA+FBkdyEuof7qDptjBSpRywjIgofO/ U1RBm+nlzcqNdZJZVpTGYL4hrtmvSxrNiWLAp1XiSwaltNa8FG5jZ30QgRNnOjXCEmn7 motD+P3cDFsOWWFp9TS/s16++Whb9ZVjDbX2sNE4JsOBJAfhG+QLr0AGmbC6Pgg3u9OB 2mxttXFzW2Riz6R2L3m8wW8DUS/rXP+k0TXvr5IGjCAc+DKRp3RSKtjTWfzCUxBHd/oQ 1qeOscZbxh6f2pQ6/HaIhQf6tJlKBWx3kd490cvysObVUvxIeRRahyD4gAfcMOLb6iAe 1A== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2175.outbound.protection.outlook.com [104.47.55.175]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3gg3aatafk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jun 2022 00:33:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=elAJyHOELTYrPwCtRDuFg4hhys4f2aCr51aCv1XIDVSb9atTpqpYuGe2oKW7/AJSX+ATDDjqL0eU97IkJE+GMlLo9ov8lImW9W5c8aEQh8vAgpOcb5XKbzZdaYfZHhaE3j+TjskucneGU9XzXiQfGBg/rhvpW+1dB5nCbuAVANz5kCeDtx6G/my5Qf1bLH2NZqRkahrs6zz4eyiy4ethl1BclWPPIhCOixq2R5z4hBYXNfYvirzMNDv2rZ7klQ22KO5xLO1Ol5ajDKNcTwSsj7+FdBEQIQi2umbvJ8Fviuo7aE4VzFMlBzhzO87NPEncyoL0n8KyYeuWWDwz3P0u2A== 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=7+LOV4TNbMSsT83B7FiHwpFKsg7v6LYRFo9WTGpek9Q=; b=hZ16i10EAYeOGgLZ0Pun16vPhkpb9bftO7zPnzxfJLrRcYMoCX4NFAEqwZKfFvDhqUILGXSFM3dQbKC343jyJQrk+jMad624IbTQ7Zs1ebFH5R0Ijw6a8b2HRMkVEX/vAL3HvbWYFm9xMXpP1gYCnooaNnVA+ADbPBcYY1iPXtggZN0Cpv9scLUmNysFRUKl1cLWa+VK4HWK03bAt3nYHpVncZLmIcQEoJ1c+Tj1QvPT2sJX+euZW1FQwQNaqWzARUsdFEiBiBZZ1j5Ce2wuXFd93+gT4mGTJC5bH8yiiBfgF8bFEToqFuv2RMV16D1eOvM8VjFJk4ORGFHddk17EA== 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 Received: from BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) by SA1PR02MB8639.namprd02.prod.outlook.com (2603:10b6:806:1fe::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 9 Jun 2022 07:33:17 +0000 Received: from BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f]) by BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f%5]) with mapi id 15.20.5314.019; Thu, 9 Jun 2022 07:33:17 +0000 From: Het Gala To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, eblake@redhat.com, Het Gala , Manish Mishra Subject: [PATCH 3/4] Establishing connection between any non-default source and destination pair Date: Thu, 9 Jun 2022 07:33:04 +0000 Message-Id: <20220609073305.142515-4-het.gala@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220609073305.142515-1-het.gala@nutanix.com> References: <20220609073305.142515-1-het.gala@nutanix.com> X-ClientProxiedBy: BY5PR04CA0002.namprd04.prod.outlook.com (2603:10b6:a03:1d0::12) To BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23c25bc8-a97a-4bb1-7f5b-08da49ea51d5 X-MS-TrafficTypeDiagnostic: SA1PR02MB8639:EE_ X-Microsoft-Antispam-PRVS: 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: z3zPjrVWAgypVcp97VylpyAVZfq8LlrvPwyYXo/CfSok9AhxHd6tuKvqQERJXMRxrvXCtTRzbNzxC5GTjVc2sI94oLVIJQ2q8JZGC7vVU4lc4NA8LyIrN3qhDdmOmGpCLJ7pzcPbfng4yiIna/GkQm6zvdmlLrESjx1wDCJLZY4zClX1D4mCF/a/HUMWnWnZSDgk+ok/5T0nKDMHi4+GFjsaCtRhLSYonKBeCAltUgFj9Ehw37w/HGx39XFI7jklqWlpGcDuFg5UVgO2OVncIRDafNjC8Kxd7eF7cSkeC6zzLBkdNdw1EUYTeR864lGBuTT0rQpIUujChsW4CNtNDhzsm4wn2PQmiZqtzO3t22SzzETgENL7ghw22DUeG9Nr5efVannrBm8vx1+pmAKRAckcZT7G6n5krcpoFalbWaq4dj3SgWrPSYd3qKiReD4AsTpPhcGKRYxdIqj5Ni4iMo/6T+nMw5Zxc3Uix1W4Vi/fqDcvOLMyXtnQg+W/gUjZ/8QG0oEQXIKNMX/zve3HsNgs4dQuXJIOHcEMCiM8nT7MSRM84/FcIMX/ZloPPm0pSWZnFBzRJ+oD0C6dpGrvaeiQJ3gXf63ZCIEx28F4N2drbSZ13iGhuysCG/e3Y93DTkV70jFr/inwaRZhUxbKQc8ylJPOfVE1gLkhlsWPqJUvKYtVgjI7whieXFVht4XnM1YSK0YU/wccYyLAgNt8Hg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR02MB4343.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(107886003)(6666004)(1076003)(2906002)(8936002)(52116002)(54906003)(86362001)(6506007)(186003)(5660300002)(30864003)(83380400001)(66574015)(6486002)(44832011)(38350700002)(26005)(38100700002)(36756003)(6512007)(2616005)(316002)(66556008)(66946007)(4326008)(6916009)(8676002)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lcj6Sw3ExuixowQ4EdM/YuUgmYqwG8oKw1elvcMhqWH5dhzoWN2z2UclmWI7NHEDaxuSMIJ9SORms4V01Gyo+TtmeZh3ufRffDT4wLHselOVCAMxVnBjmJL/DnvT9iD81Pn8hxW6oMHiL7gMQDoQ0pq+CbFfKI+KTnWy5MDaVzo0+1jc5GgY0eCNR0ye0Oi74sOBVSsj1A1DaN28sRNuybbnuXb++WiKrOWCkkyOw6EpKJQM7JfIV0ZMGFUbMcWz340sDiedwdqrznBbiwMhrNiy0rEeNVBKprJAEB7gLQHVfOJPJ+DbqVy+831SmvjVXt/DucTU5SwumhlACEauMl2wT4gKKfNBGtUBGQTTK98KU2UA2FiK5/0NSi5Jzy76gy4PpNjrbc+jbWu42yzhXPwRiEIAvzsIYqNVEvbEyHv75YMotaQPOSu58cfvvrk5ja3XV++IMsatRXu44IPN8WXvN4F0sv4xB3IZSTPijWqqxokb6S8IM5J9Dcg4H5J0DWHodB3/W1oFlN+cu26TXy016iiM9s5YG7JxvriDIfEfuve9sH+mY9vjmcE1fZ7xhPbqnQ4qPYyANS/aFpscScOKUSsWTrRdNRq3UnbSWkPLEE3MsXOpzRaQuDhuXm4rrGRw6kvBEHJfK2muqLZfSDPCgLl95Nc634zegFB5GSgSAe+zYwPE0tYUMW9tiS8WI8ncldUVqqECHjDOo3yrCT8LqymRL2MmvNcHy82oGJZudFGMSB1SrB6w8h0uH1RJ4q+BWQ10AJTtsY8irg+3D5JNuAQjMlRvXj8s3MPA/rRpGFLwmZSy2Q0DvXzz/GDnV17kozMH7bC80Yla0Lq0btbZiR94a4tn8o/Po7KiLySBcAYZVNDjLkuUb/V9GsrV36PmU/Q37Oop1VagxeFdLB7jsLgIRbiX/uvX9+dVwof891OJe8hsnhB0HgrOV8YAieRj8tFDr1QoifhwzDBIUldZhc+g9TTPJ3QeDcRoyXMQsTui27Xukdmppbzn9LkTnsT3nhPaDcYGewd6Xk8fy4bjFg8ue81Y3dLmVC5svXbvF9tQPePi8r8MRe5sRJgOXw/dHY7ge4erBX0k609GPQiYxc5t/0OtQJS3aw0MPxOEOCbUnAsa4D4pDRgq8FGVET5gKAwAwO9AudjQ2ja3KPGPUJfN4bv3zpz4mXH0osrjZKLzRMyE8Pmk6+X6O+DJPR3sAvK8kF39BSdTBEISA41ffecO3dKZaOsJsKs6m+sBNdvuPB2k58104qvfjBGRuDzjnNxVwo800pRghkLoKgTedYHgRaGRTZeNhGpWMLn9rmjc2/PdQF8j2imdnYb55szkgI1d0teYntVPAF9/hX+rzD8T3QjYj4V0k1DnVtv7n/ZlStD9wmVg8LHa+JIHdvdiMY2RjiRS6Ri0C1GQn9D0q+fda4MXF5y7OdHIklNSILn4WKJzfn/XEilDrfhrZ3+waYIatHzTEqj1MzXHSEf3BibSqOXjSwsSXVQaJ/ySg63GOAtMqSULaoCHbAwDNP2lxgsCJT4P3eJ7pN7Xm9VhdfWTxWe57rTjimi4J6NoK8dP7zAGDwZj6dqh5Nue6XpkPcq+1joO31kYoBb6AlLEzp9r4eapR9j5r5r1PPWk1zjYCZCZAnN+GNOmch0RMBsCVqu9rG5hpXSaiya8V1ipzPiE8hMENTLi988NiaedrLLKRB67mtGi/V09aKQHOyBoUQHWDyhYnidwMIuUvKrDSsmyjCgumvMBHHfgDlI= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23c25bc8-a97a-4bb1-7f5b-08da49ea51d5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR02MB4343.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 07:33:17.1561 (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: igLBSBi71NhsVNfDXhGpjEhLo8DnHHM03EtZxvwv0IMv7inuuVFx3nDI1cfwfP57KD31LdFUCrhEjhx37HDKIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB8639 X-Proofpoint-ORIG-GUID: K9vbwjo7tXBeykz6lizvtVKQz9qLKN04 X-Proofpoint-GUID: K9vbwjo7tXBeykz6lizvtVKQz9qLKN04 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-09_07,2022-06-07_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=het.gala@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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-Mailman-Approved-At: Thu, 09 Jun 2022 09:30:32 -0400 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" i) Binding of the socket to source ip address and port on the non-default interface has been implemented for multi-FD connection, which was not necessary earlier because the binding was on the default interface itself. ii) Created an end to end connection between all multi-FD source and destination pairs. Suggested-by: Manish Mishra Signed-off-by: Het Gala --- chardev/char-socket.c | 4 +- include/io/channel-socket.h | 26 ++++++----- include/qemu/sockets.h | 6 ++- io/channel-socket.c | 50 ++++++++++++++------ migration/socket.c | 15 +++--- nbd/client-connection.c | 2 +- qemu-nbd.c | 4 +- scsi/pr-manager-helper.c | 1 + tests/unit/test-char.c | 8 ++-- tests/unit/test-io-channel-socket.c | 4 +- tests/unit/test-util-sockets.c | 16 +++---- ui/input-barrier.c | 2 +- ui/vnc.c | 3 +- util/qemu-sockets.c | 71 ++++++++++++++++++++--------- 14 files changed, 135 insertions(+), 77 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index dc4e218eeb..f3725238c5 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -932,7 +932,7 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp) QIOChannelSocket *sioc = qio_channel_socket_new(); tcp_chr_change_state(s, TCP_CHARDEV_STATE_CONNECTING); tcp_chr_set_client_ioc_name(chr, sioc); - if (qio_channel_socket_connect_sync(sioc, s->addr, errp) < 0) { + if (qio_channel_socket_connect_sync(sioc, s->addr, NULL, errp) < 0) { tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED); object_unref(OBJECT(sioc)); return -1; @@ -1120,7 +1120,7 @@ static void tcp_chr_connect_client_task(QIOTask *task, SocketAddress *addr = opaque; Error *err = NULL; - qio_channel_socket_connect_sync(ioc, addr, &err); + qio_channel_socket_connect_sync(ioc, addr, NULL, &err); qio_task_set_error(task, err); } diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index 513c428fe4..59d5b1b349 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -83,41 +83,45 @@ qio_channel_socket_new_fd(int fd, /** * qio_channel_socket_connect_sync: * @ioc: the socket channel object - * @addr: the address to connect to + * @dst_addr: the destination address to connect to + * @src_addr: the source address to be connected * @errp: pointer to a NULL-initialized error object * - * Attempt to connect to the address @addr. This method - * will run in the foreground so the caller will not regain - * execution control until the connection is established or + * Attempt to connect to the address @dst_addr with @src_addr. + * This method will run in the foreground so the caller will not + * regain execution control until the connection is established or * an error occurs. */ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddress *dst_addr, + SocketAddress *src_addr, Error **errp); /** * qio_channel_socket_connect_async: * @ioc: the socket channel object - * @addr: the address to connect to + * @dst_addr: the destination address to connect to * @callback: the function to invoke on completion * @opaque: user data to pass to @callback * @destroy: the function to free @opaque * @context: the context to run the async task. If %NULL, the default * context will be used. + * @src_addr: the source address to be connected * - * Attempt to connect to the address @addr. This method - * will run in the background so the caller will regain + * Attempt to connect to the address @dst_addr with the @src_addr. + * This method will run in the background so the caller will regain * execution control immediately. The function @callback - * will be invoked on completion or failure. The @addr + * will be invoked on completion or failure. The @dst_addr * parameter will be copied, so may be freed as soon * as this function returns without waiting for completion. */ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddress *dst_addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy, - GMainContext *context); + GMainContext *context, + SocketAddress *src_addr); /** diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 038faa157f..dc863c3df8 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -33,7 +33,8 @@ int inet_ai_family_from_address(InetSocketAddress *addr, Error **errp); int inet_parse(InetSocketAddress *addr, const char *str, Error **errp); int inet_connect(const char *str, Error **errp); -int inet_connect_saddr(InetSocketAddress *saddr, Error **errp); +int inet_connect_saddr(InetSocketAddress *dst_addr, + InetSocketAddress *src_addr, Error **errp); NetworkAddressFamily inet_netfamily(int family); @@ -41,7 +42,8 @@ int unix_listen(const char *path, Error **errp); int unix_connect(const char *path, Error **errp); SocketAddress *socket_parse(const char *str, Error **errp); -int socket_connect(SocketAddress *addr, Error **errp); +int socket_connect(SocketAddress *dst_addr, SocketAddress *src_addr, + Error **errp); int socket_listen(SocketAddress *addr, int num, Error **errp); void socket_listen_cleanup(int fd, Error **errp); int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp); diff --git a/io/channel-socket.c b/io/channel-socket.c index dc9c165de1..f8746ad646 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -36,6 +36,12 @@ #define SOCKET_MAX_FDS 16 +struct SrcDestAddress { + SocketAddress *dst_addr; + SocketAddress *src_addr; +}; + + SocketAddress * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp) @@ -145,13 +151,14 @@ qio_channel_socket_new_fd(int fd, int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddress *dst_addr, + SocketAddress *src_addr, Error **errp) { int fd; - trace_qio_channel_socket_connect_sync(ioc, addr); - fd = socket_connect(addr, errp); + trace_qio_channel_socket_connect_sync(ioc, dst_addr); + fd = socket_connect(dst_addr, src_addr, errp); if (fd < 0) { trace_qio_channel_socket_connect_fail(ioc); return -1; @@ -177,39 +184,56 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, } +static void qio_channel_socket_worker_free(gpointer opaque) +{ + struct SrcDestAddress *data = opaque; + if (!data) { + return; + } + qapi_free_SocketAddress(data->dst_addr); + qapi_free_SocketAddress(data->src_addr); + g_free(data); +} + + static void qio_channel_socket_connect_worker(QIOTask *task, gpointer opaque) { QIOChannelSocket *ioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task)); - SocketAddress *addr = opaque; + struct SrcDestAddress *data = opaque; Error *err = NULL; - qio_channel_socket_connect_sync(ioc, addr, &err); + qio_channel_socket_connect_sync(ioc, data->dst_addr, data->src_addr, &err); qio_task_set_error(task, err); } void qio_channel_socket_connect_async(QIOChannelSocket *ioc, - SocketAddress *addr, + SocketAddress *dst_addr, QIOTaskFunc callback, gpointer opaque, GDestroyNotify destroy, - GMainContext *context) + GMainContext *context, + SocketAddress *src_addr) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); - SocketAddress *addrCopy; - - addrCopy = QAPI_CLONE(SocketAddress, addr); + struct SrcDestAddress *data = g_new0(struct SrcDestAddress, 1); + data->dst_addr = QAPI_CLONE(SocketAddress, dst_addr); + if (src_addr) { + data->src_addr = QAPI_CLONE(SocketAddress, src_addr); + } else { + data->src_addr = NULL; + } /* socket_connect() does a non-blocking connect(), but it * still blocks in DNS lookups, so we must use a thread */ - trace_qio_channel_socket_connect_async(ioc, addr); + trace_qio_channel_socket_connect_async(ioc, dst_addr); qio_task_run_in_thread(task, qio_channel_socket_connect_worker, - addrCopy, - (GDestroyNotify)qapi_free_SocketAddress, + data, + qio_channel_socket_worker_free, context); } diff --git a/migration/socket.c b/migration/socket.c index 21e0983df2..d0cb7cc6a6 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -47,7 +47,7 @@ void socket_send_channel_create(QIOTaskFunc f, void *data) { QIOChannelSocket *sioc = qio_channel_socket_new(); qio_channel_socket_connect_async(sioc, outgoing_args.saddr, - f, data, NULL, NULL); + f, data, NULL, NULL, NULL); } int socket_send_channel_destroy(QIOChannel *send) @@ -110,7 +110,7 @@ out: static void socket_start_outgoing_migration_internal(MigrationState *s, - SocketAddress *saddr, + SocketAddress *dst_addr, Error **errp) { QIOChannelSocket *sioc = qio_channel_socket_new(); @@ -118,20 +118,17 @@ socket_start_outgoing_migration_internal(MigrationState *s, data->s = s; - /* in case previous migration leaked it */ - qapi_free_SocketAddress(outgoing_args.saddr); - outgoing_args.saddr = saddr; - - if (saddr->type == SOCKET_ADDRESS_TYPE_INET) { - data->hostname = g_strdup(saddr->u.inet.host); + if (dst_addr->type == SOCKET_ADDRESS_TYPE_INET) { + data->hostname = g_strdup(dst_addr->u.inet.host); } qio_channel_set_name(QIO_CHANNEL(sioc), "migration-socket-outgoing"); qio_channel_socket_connect_async(sioc, - saddr, + dst_addr, socket_outgoing_migration, data, socket_connect_data_free, + NULL, NULL); } diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 2a632931c3..4bc505d26e 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -133,7 +133,7 @@ static int nbd_connect(QIOChannelSocket *sioc, SocketAddress *addr, *outioc = NULL; } - ret = qio_channel_socket_connect_sync(sioc, addr, errp); + ret = qio_channel_socket_connect_sync(sioc, addr, NULL, errp); if (ret < 0) { return ret; } diff --git a/qemu-nbd.c b/qemu-nbd.c index 0cd5aa6f02..fe178f271e 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -191,7 +191,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls, int i, j; sioc = qio_channel_socket_new(); - if (qio_channel_socket_connect_sync(sioc, saddr, &err) < 0) { + if (qio_channel_socket_connect_sync(sioc, saddr, NULL, &err) < 0) { error_report_err(err); goto out; } @@ -284,7 +284,7 @@ static void *nbd_client_thread(void *arg) sioc = qio_channel_socket_new(); if (qio_channel_socket_connect_sync(sioc, - saddr, + saddr, NULL, &local_error) < 0) { error_report_err(local_error); goto out; diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c index 3be52a98d5..6e3e00eadf 100644 --- a/scsi/pr-manager-helper.c +++ b/scsi/pr-manager-helper.c @@ -114,6 +114,7 @@ static int pr_manager_helper_initialize(PRManagerHelper *pr_mgr, qio_channel_set_name(QIO_CHANNEL(sioc), "pr-manager-helper"); qio_channel_socket_connect_sync(sioc, &saddr, + NULL, &local_err); g_free(path); if (local_err) { diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c index 5b3b48ebac..fd5f281777 100644 --- a/tests/unit/test-char.c +++ b/tests/unit/test-char.c @@ -691,7 +691,7 @@ char_socket_addr_to_opt_str(SocketAddress *addr, bool fd_pass, if (is_listen) { qio_channel_socket_listen_sync(ioc, addr, 1, &error_abort); } else { - qio_channel_socket_connect_sync(ioc, addr, &error_abort); + qio_channel_socket_connect_sync(ioc, addr, NULL, &error_abort); } fd = ioc->fd; ioc->fd = -1; @@ -748,7 +748,7 @@ char_socket_server_client_thread(gpointer data) SocketAddress *addr = data; QIOChannelSocket *ioc = qio_channel_socket_new(); - qio_channel_socket_connect_sync(ioc, addr, &error_abort); + qio_channel_socket_connect_sync(ioc, addr, NULL, &error_abort); char_socket_ping_pong(QIO_CHANNEL(ioc), &error_abort); @@ -1147,7 +1147,7 @@ static void char_socket_server_two_clients_test(gconstpointer opaque) &closed, NULL, true); ioc1 = qio_channel_socket_new(); - qio_channel_socket_connect_sync(ioc1, addr, &error_abort); + qio_channel_socket_connect_sync(ioc1, addr, NULL, &error_abort); qemu_chr_wait_connected(chr, &error_abort); /* switch the chardev to another context */ @@ -1161,7 +1161,7 @@ static void char_socket_server_two_clients_test(gconstpointer opaque) * succeed immediately. */ ioc2 = qio_channel_socket_new(); - qio_channel_socket_connect_sync(ioc2, addr, &error_abort); + qio_channel_socket_connect_sync(ioc2, addr, NULL, &error_abort); object_unref(OBJECT(ioc1)); /* The two connections should now be processed serially. */ diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-channel-socket.c index 6713886d02..bc33ce6956 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -72,7 +72,7 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr, *src = QIO_CHANNEL(qio_channel_socket_new()); qio_channel_socket_connect_sync( - QIO_CHANNEL_SOCKET(*src), connect_addr, &error_abort); + QIO_CHANNEL_SOCKET(*src), connect_addr, NULL, &error_abort); qio_channel_set_delay(*src, false); qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); @@ -136,7 +136,7 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, qio_channel_socket_connect_async( QIO_CHANNEL_SOCKET(*src), connect_addr, - test_io_channel_complete, &data, NULL, NULL); + test_io_channel_complete, &data, NULL, NULL, NULL); g_main_loop_run(data.loop); g_main_context_iteration(g_main_context_default(), FALSE); diff --git a/tests/unit/test-util-sockets.c b/tests/unit/test-util-sockets.c index 63909ccb2b..aa26630045 100644 --- a/tests/unit/test-util-sockets.c +++ b/tests/unit/test-util-sockets.c @@ -89,7 +89,7 @@ static void test_socket_fd_pass_name_good(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup(mon_fdname); - fd = socket_connect(&addr, &error_abort); + fd = socket_connect(&addr, NULL, &error_abort); g_assert_cmpint(fd, !=, -1); g_assert_cmpint(fd, !=, mon_fd); close(fd); @@ -121,7 +121,7 @@ static void test_socket_fd_pass_name_bad(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup(mon_fdname); - fd = socket_connect(&addr, &err); + fd = socket_connect(&addr, NULL, &err); g_assert_cmpint(fd, ==, -1); error_free_or_abort(&err); @@ -148,7 +148,7 @@ static void test_socket_fd_pass_name_nomon(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup("myfd"); - fd = socket_connect(&addr, &err); + fd = socket_connect(&addr, NULL, &err); g_assert_cmpint(fd, ==, -1); error_free_or_abort(&err); @@ -172,7 +172,7 @@ static void test_socket_fd_pass_num_good(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup_printf("%d", sfd); - fd = socket_connect(&addr, &error_abort); + fd = socket_connect(&addr, NULL, &error_abort); g_assert_cmpint(fd, ==, sfd); fd = socket_listen(&addr, 1, &error_abort); @@ -194,7 +194,7 @@ static void test_socket_fd_pass_num_bad(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup_printf("%d", sfd); - fd = socket_connect(&addr, &err); + fd = socket_connect(&addr, NULL, &err); g_assert_cmpint(fd, ==, -1); error_free_or_abort(&err); @@ -217,7 +217,7 @@ static void test_socket_fd_pass_num_nocli(void) addr.type = SOCKET_ADDRESS_TYPE_FD; addr.u.fd.str = g_strdup_printf("%d", STDOUT_FILENO); - fd = socket_connect(&addr, &err); + fd = socket_connect(&addr, NULL, &err); g_assert_cmpint(fd, ==, -1); error_free_or_abort(&err); @@ -246,10 +246,10 @@ static gpointer unix_client_thread_func(gpointer user_data) for (i = 0; i < ABSTRACT_SOCKET_VARIANTS; i++) { if (row->expect_connect[i]) { - fd = socket_connect(row->client[i], &error_abort); + fd = socket_connect(row->client[i], NULL, &error_abort); g_assert_cmpint(fd, >=, 0); } else { - fd = socket_connect(row->client[i], &err); + fd = socket_connect(row->client[i], NULL, &err); g_assert_cmpint(fd, ==, -1); error_free_or_abort(&err); } diff --git a/ui/input-barrier.c b/ui/input-barrier.c index 2d57ca7079..ee78654e3b 100644 --- a/ui/input-barrier.c +++ b/ui/input-barrier.c @@ -506,7 +506,7 @@ static void input_barrier_complete(UserCreatable *uc, Error **errp) ib->sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(ib->sioc), "barrier-client"); - qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, &local_err); + qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, NULL, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/ui/vnc.c b/ui/vnc.c index 6a05d06147..c3dd84026a 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3931,7 +3931,8 @@ static int vnc_display_connect(VncDisplay *vd, vd->is_unix = saddr_list->value->type == SOCKET_ADDRESS_TYPE_UNIX; sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(sioc), "vnc-reverse"); - if (qio_channel_socket_connect_sync(sioc, saddr_list->value, errp) < 0) { + if (qio_channel_socket_connect_sync(sioc, saddr_list->value, + NULL, errp) < 0) { object_unref(OBJECT(sioc)); return -1; } diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 13b5b197f9..bbe0dc0ee0 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -226,7 +226,7 @@ static int inet_listen_saddr(InetSocketAddress *saddr, return -1; } - memset(&ai,0, sizeof(ai)); + memset(&ai,0,sizeof(ai)); ai.ai_flags = AI_PASSIVE; if (saddr->has_numeric && saddr->numeric) { ai.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV; @@ -282,8 +282,8 @@ static int inet_listen_saddr(InetSocketAddress *saddr, e->ai_protocol = IPPROTO_MPTCP; } #endif - getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen, - uaddr,INET6_ADDRSTRLEN,uport,32, + getnameinfo((struct sockaddr *)e->ai_addr, e->ai_addrlen, + uaddr, INET6_ADDRSTRLEN, uport, 32, NI_NUMERICHOST | NI_NUMERICSERV); port_min = inet_getport(e); @@ -358,7 +358,8 @@ listen_ok: ((rc) == -EINPROGRESS) #endif -static int inet_connect_addr(const InetSocketAddress *saddr, +static int inet_connect_addr(const InetSocketAddress *dst_addr, + const InetSocketAddress *src_addr, struct addrinfo *addr, Error **errp) { int sock, rc; @@ -371,8 +372,28 @@ static int inet_connect_addr(const InetSocketAddress *saddr, } socket_set_fast_reuse(sock); + /* to bind the socket if src_addr is available */ + + if (src_addr) { + struct sockaddr_in servaddr; + + /* bind to a specific interface in the internet domain */ + /* to make sure the sin_zero filed is cleared */ + memset(&servaddr, 0, sizeof(servaddr)); + + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = inet_addr(src_addr->host); + servaddr.sin_port = 0; + + if (bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + error_setg_errno(errp, errno, "Failed to bind socket"); + return -1; + } + } + /* connect to peer */ do { + rc = 0; if (connect(sock, addr->ai_addr, addr->ai_addrlen) < 0) { rc = -errno; @@ -380,8 +401,14 @@ static int inet_connect_addr(const InetSocketAddress *saddr, } while (rc == -EINTR); if (rc < 0) { - error_setg_errno(errp, errno, "Failed to connect to '%s:%s'", - saddr->host, saddr->port); + if (src_addr) { + error_setg_errno(errp, errno, "Failed to connect '%s:%s' to " + "'%s:%s'", dst_addr->host, dst_addr->port, + src_addr->host, src_addr->port); + } else { + error_setg_errno(errp, errno, "Failed to connect '%s:%s'", + dst_addr->host, dst_addr->port); + } closesocket(sock); return -1; } @@ -446,13 +473,14 @@ static struct addrinfo *inet_parse_connect_saddr(InetSocketAddress *saddr, * * Returns: -1 on error, file descriptor on success. */ -int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) +int inet_connect_saddr(InetSocketAddress *dst_addr, + InetSocketAddress *src_addr, Error **errp) { Error *local_err = NULL; struct addrinfo *res, *e; int sock = -1; - res = inet_parse_connect_saddr(saddr, errp); + res = inet_parse_connect_saddr(dst_addr, errp); if (!res) { return -1; } @@ -462,12 +490,12 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) local_err = NULL; #ifdef HAVE_IPPROTO_MPTCP - if (saddr->has_mptcp && saddr->mptcp) { + if (dst_addr->has_mptcp && dst_addr->mptcp) { e->ai_protocol = IPPROTO_MPTCP; } #endif - sock = inet_connect_addr(saddr, e, &local_err); + sock = inet_connect_addr(dst_addr, src_addr, e, &local_err); if (sock >= 0) { break; } @@ -480,7 +508,7 @@ int inet_connect_saddr(InetSocketAddress *saddr, Error **errp) return sock; } - if (saddr->keep_alive) { + if (dst_addr->keep_alive) { int val = 1; int ret = setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)); @@ -506,7 +534,7 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr, Error *err = NULL; /* lookup peer addr */ - memset(&ai,0, sizeof(ai)); + memset(&ai, 0, sizeof(ai)); ai.ai_flags = AI_CANONNAME | AI_V4MAPPED | AI_ADDRCONFIG; ai.ai_family = inet_ai_family_from_address(sraddr, &err); ai.ai_socktype = SOCK_DGRAM; @@ -533,7 +561,7 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr, } /* lookup local addr */ - memset(&ai,0, sizeof(ai)); + memset(&ai, 0, sizeof(ai)); ai.ai_flags = AI_PASSIVE; ai.ai_family = peer->ai_family; ai.ai_socktype = SOCK_DGRAM; @@ -574,7 +602,7 @@ static int inet_dgram_saddr(InetSocketAddress *sraddr, } /* connect to peer */ - if (connect(sock,peer->ai_addr,peer->ai_addrlen) < 0) { + if (connect(sock, peer->ai_addr, peer->ai_addrlen) < 0) { error_setg_errno(errp, errno, "Failed to connect to '%s:%s'", addr, port); goto err; @@ -727,7 +755,7 @@ int inet_connect(const char *str, Error **errp) InetSocketAddress *addr = g_new(InetSocketAddress, 1); if (!inet_parse(addr, str, errp)) { - sock = inet_connect_saddr(addr, errp); + sock = inet_connect_saddr(addr, NULL, errp); } qapi_free_InetSocketAddress(addr); return sock; @@ -1182,25 +1210,26 @@ int socket_address_parse_named_fd(SocketAddress *addr, Error **errp) return 0; } -int socket_connect(SocketAddress *addr, Error **errp) +int socket_connect(SocketAddress *dst_addr, SocketAddress *src_addr, Error **errp) { int fd; - switch (addr->type) { + switch (dst_addr->type) { case SOCKET_ADDRESS_TYPE_INET: - fd = inet_connect_saddr(&addr->u.inet, errp); + fd = inet_connect_saddr(&dst_addr->u.inet, src_addr ? + &src_addr->u.inet : NULL, errp); break; case SOCKET_ADDRESS_TYPE_UNIX: - fd = unix_connect_saddr(&addr->u.q_unix, errp); + fd = unix_connect_saddr(&dst_addr->u.q_unix, errp); break; case SOCKET_ADDRESS_TYPE_FD: - fd = socket_get_fd(addr->u.fd.str, errp); + fd = socket_get_fd(dst_addr->u.fd.str, errp); break; case SOCKET_ADDRESS_TYPE_VSOCK: - fd = vsock_connect_saddr(&addr->u.vsock, errp); + fd = vsock_connect_saddr(&dst_addr->u.vsock, errp); break; default: From patchwork Thu Jun 9 07:33:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Het Gala X-Patchwork-Id: 12875727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40B7BC433EF for ; Thu, 9 Jun 2022 14:43:15 +0000 (UTC) Received: from localhost ([::1]:54848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzJNS-000139-9D for qemu-devel@archiver.kernel.org; Thu, 09 Jun 2022 10:43:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfW-0002B2-Cf for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:29 -0400 Received: from mx0a-002c1b01.pphosted.com ([148.163.151.68]:41250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzCfT-0007w0-2Q for qemu-devel@nongnu.org; Thu, 09 Jun 2022 03:33:26 -0400 Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25964FQm010057; Thu, 9 Jun 2022 00:33:21 -0700 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=SgdqbDOFodEcUcSC6wl/6KpFmB82pJiFuaR/ner+dVA=; b=0NKMZzVEwVoovhz04IgxQTKP1ZtwYqSPAGQpXnv2xradF6nIw6WtsrNxn+hituxfB+k/ bi7s4B+K3GANYFkr98vC40RcfTQ2vreKSzZOkA1Z9aMu1BZ44/dkk8/k/Yq225ga8aGR M5ZiXVNQNoFzgAe3jGCz/0RCsVgUzDBezxvzn6b99DaDq1yLOBdLAHFZHD6dVG318vNi a1XfCls7AXfnThFlYcmH4SK0h0qaDPjiTyHJqWEihz0w123dbM90HZp+zjmDhg+XvYQ4 3dB8Vu24bWMt6uJXGnjW4QdqtcT4XfBwsjcjr5j/W1dmLBz29phUV3EoAhfyVP0QQ5B4 cg== Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3gg6fha4e9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Jun 2022 00:33:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZR3dxSd4BaVwHapyfpn7j00bBED9b1WXU2qXWnauH46aqzq0L198PLfzIjUBTNvLWRI4YipAiuKdAAC3s5QdAWL2L1Pm2LcT/Yamm3mxzCp+HNIdH5pyatFvcl52tgSDDc+qbPOYWiLuFc+VszwCtWvdaGYg0j7HSoighS4PPP/gl9df6QnwWfmah1UwgcAQJtwLTj0nSMQShOOBAhGDhRiVrheuAAmUaQ1vSN415FlUUcwRvkB8bAoMHyuCrjIVndFnA9lmLA/PJ0y2CCc2CYt/Gpg9f4sefoTTgBEE1tpGFDWAWt7q003wo5vS/eyxsYtJi8oCftpQUY4HBsVPg== 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=SgdqbDOFodEcUcSC6wl/6KpFmB82pJiFuaR/ner+dVA=; b=U8LQrjoDlr8DHaAwpcdAgYmcSVTwZnZxxQbZTE4bdrlQAhWKVn2HzNlCNCjnwBlge0/5mlUmE/V5IzhVA8stOKyzuLoLfljY0KZE5JkqsX+8JnwkgX/9eXUdkxLQZBQV4IxQuZgEOy05BsWgkJy1Fl/yOASSvRzRuJZLcl2fCFJRu5sAG48rnoeVNvRMqjCBxM8cA33WGCF0Tja8HQMU5KjQ10ysxGDlZfJjOsMabK8A4FAVGpGwJCOWC+bbrOFoGt47sws215VHgC72YHlrbgI4YEGHHn1UpI/sMAehwscCfjSWij2fQAi1DWVVMo2sQrHqKkz9U8qbwGfuvS4kiA== 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 Received: from BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) by SA1PR02MB8639.namprd02.prod.outlook.com (2603:10b6:806:1fe::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Thu, 9 Jun 2022 07:33:19 +0000 Received: from BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f]) by BYAPR02MB4343.namprd02.prod.outlook.com ([fe80::1493:404b:3242:8e0f%5]) with mapi id 15.20.5314.019; Thu, 9 Jun 2022 07:33:19 +0000 From: Het Gala To: qemu-devel@nongnu.org Cc: quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com, armbru@redhat.com, eblake@redhat.com, Het Gala , Manish Mishra Subject: [PATCH 4/4] Adding support for multi-FD connections dynamically Date: Thu, 9 Jun 2022 07:33:05 +0000 Message-Id: <20220609073305.142515-5-het.gala@nutanix.com> X-Mailer: git-send-email 2.22.3 In-Reply-To: <20220609073305.142515-1-het.gala@nutanix.com> References: <20220609073305.142515-1-het.gala@nutanix.com> X-ClientProxiedBy: BY5PR04CA0002.namprd04.prod.outlook.com (2603:10b6:a03:1d0::12) To BYAPR02MB4343.namprd02.prod.outlook.com (2603:10b6:a03:57::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6926655-3f7a-47f2-f45f-08da49ea5314 X-MS-TrafficTypeDiagnostic: SA1PR02MB8639:EE_ X-Microsoft-Antispam-PRVS: 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: N91vxyOOtQHcrwjy0nhoPyxrQlGap2/f3cEz18O2hKLrGF5A1epA9+U4w3ihYkuFnR+geEUpyEK4tR7PNMrlAJ7S38gfkt4YqHaRITy7bjEkLA+L6X3xLYJj2lchsJnF+xHw1bCsigaYBllwRH0blsKwA4AyITtZlyg2iGw/rQqWoRWsEUGFOmu1/YCT33sR3/45qo9EFk8vXwGPeRzzaMGUZ6RKrxtBKO5jYKN8O3/hRFS8A7LtCEAWCLaNcim0mr+U0qpDJQE4eRmbmzdjedcY0su6uNWaaNS8f55XFVdDQKpLW4qbhYZiZ749CywBkopqQ5xa4t3o6YElqJeTQPk3uBLJKe6fsitJlzZ1DLvsa+HWdeJKTaety7HsQyA8Qs27czQ7PN7oDxwmyb4L1dyTqZxUs3FEEemrqRFiBSJS+3KMppgZpr1HPUMVD0E6cg5SikWXil8lnJ8INRShqW8rokCZfIkP/KRef/PGb3OoBYbHexi5Wd+YA1Dh055PF4TGeZGHJNDzM++JidZldmTg7BMsJhiNFZ6VNhsi5rPrjifhd/uY/M8FyfKDWV68cyOdFU5afi0n5bxzztcWlXCIKc+O6q6wrFcNaLJhtt2d9M+07nu5HzXbrRUhyPkpZfZPow9xiEx417WxsEOc2oMhwJ7OH6NXN+kJbPJusEP9nsSvmDOmaMrJUHC3dK3+S34E0Oci76XUGp4fqVkGiA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR02MB4343.namprd02.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(107886003)(6666004)(1076003)(2906002)(8936002)(52116002)(54906003)(86362001)(6506007)(186003)(5660300002)(30864003)(83380400001)(6486002)(44832011)(38350700002)(26005)(38100700002)(36756003)(6512007)(2616005)(316002)(66556008)(66946007)(4326008)(6916009)(8676002)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VSX/weg3BjGVSummcLW/MkhLvE4w5lzTRp0Dl6woGO5XrM7kddnCu+xxlQL/U582LEcR6G3biMxjGtvipv5kvZDKANkBDorLDAdpPEE4gEIFk2GY40z4aCvd/GQM56B2xyh/VWwhQ32FmY4FiulQdCiIVtyzaZj6ftRbmEm8ugssYMwlhXkDZhsnt2kywb07oEW7/vlZBFmv7r+J+oGVhQnu4wdu4j9nZyNcUhMt/k/Jg2CFmF+fxnTzApUDHy7bM1SsV0xJfw+FLWtMv863Tsb5bfUkNem7ruS87jGtKYOUhzHdvoeK3XYgMejw+et+Qux5Xts0fmw63tQH7qGuW5W4XcE3uBSPwHgdTgLGT87S6AmSmOOwKhDVkNPuf0x+5z0MOuzX15jIQIGg1rEFMxcpPt2P4gmIUxGLds+HSTCONM03qSoKk3qHpnhRlxOy559Z4BSy8t3wG//F2Mr2bR8YjvlU0iVCIQBiWmya2pOvYNy2zu17k/UTCvHUr8VRjQX00RV1IDgraJtpO/TuJZfiFqog+GYA9PRcdWXcooeViU9B0Nyp783MfOjZJ+GQs4homuhAzzkCo9oe/N74n2AsKPN3O7pHdroze3JV5Lq4CFZAUCjgIk7ph3RYyQoTIzXhxxOvT1uMB3Qw9xu6zu3NtZ2oJAcTAYrCirrRfdJQQUnqSTKjnmk4gQAQKl4TmAnnxm9kdWf1LPDXl5QsdGmr6aFYZwpCqbnwXbSHbqqCMdfSv1qaUK/VjNbdWQD2hpOPDwUQMq6o98fLQM5fRPv9cHRXTDSKolJ2f9hX52ZL1iQObchvEi8gahU8EcCVUieT0VCJ+gkDYDppjlg2lhiwtlyGv6SuieQ22R+FEOKf9F2J9Ztgb90bbROkewq8SKzMJAZ536IHIu0JHS1RbUQE/A67rwJdj0ppeBO3i6tSiS2vU4pvMKtphZXjiCaxhPNy2Y+xF6rS4jPe8iNw2fKkqaf4K8ec6NtelakFD5g4Atf9RlL6vgMMA5LqEpy9v+uI3fRjCn+7NMovXvjjGkz8RbDZ93BSjKhXDwMVFtCR5dqTxIonye2aeR0f6RQ2RKcbxPpUaPVEfOOO7dLkcCLV/FjulXFTnCEgY9fToioVZzWM+NhvpJlN7jOz03PMbC/TntFp4S7D+fmr556DRvzSCG4ncaY76t57RAh7uIenkB4mNKIx+QxgGr6pmcqgD97ItEm9jWxCrvfxMe+U5NoC5j3NxBwQo32ZcdAHLZIAsWZq2/ObNNV/MHSTEg/UJwYVmAMECjZDFbhGiH243KLgWiaI3dMhxJeP7OF95/w5f2tcs8Unwjlf266yT1qKb0OglysMaKXG+CWul4G22U59cdCu5bFgcW/ozJsVwdczLJYEcKrpSowB8hsdFsz+xIbiwo61Hs7mH+3vrapSKFxgG2xKw/dvIIrq0KmvE+oV7trYI05Xk61/++NnmsKAYAseZ2Elx27aKcIY987HjAtHOMVpeCwtM58vJSZ0Qarf3BqBBulMhr4N52jGkBRZZPKzFabA7gEuA5deDoj5v9HszzyuJAdHj1PAGTGikr5/IExcZVLiWsC8bwmyzUazrpY9n6KnW2aHOLmOGZ9q2MSxyW+uFPFa4ZLFplkBifu2SNTVxKDM+Hsuv2YhyxAboCSP1KiU32VmlDHZDv+Nn+g9dA9AIswvvHvKXYYPIqhFZCGBMk9m2i0O36ZkiOjDECJlXkJngCmVkOM1XCzxE/M1BIhyZpmotXJIJ/6sUGs= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6926655-3f7a-47f2-f45f-08da49ea5314 X-MS-Exchange-CrossTenant-AuthSource: BYAPR02MB4343.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2022 07:33:19.2184 (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: KtmlNjGJAQcQKoXd8EDeEB1lLg8xnm/m5ND9b51IGxS91n/3Nu5xNXWQtf2jMQigMofGvZ7obcmHAAwXXB1WOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB8639 X-Proofpoint-GUID: 6qw_rsmNpvt1WQZskN3ck8W62N9QxCCX X-Proofpoint-ORIG-GUID: 6qw_rsmNpvt1WQZskN3ck8W62N9QxCCX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-09_07,2022-06-07_02,2022-02-23_01 X-Proofpoint-Spam-Reason: safe Received-SPF: pass client-ip=148.163.151.68; envelope-from=het.gala@nutanix.com; helo=mx0a-002c1b01.pphosted.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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-Mailman-Approved-At: Thu, 09 Jun 2022 09:30:28 -0400 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" i) Dynamically decide appropriate source and destination ip pairs for the corresponding multi-FD channel to be connected. ii) Removed the support for setting the number of multi-fd channels from qmp commands. As now all multiFD parameters will be passed via qmp: migrate command or incoming flag itself. Suggested-by: Manish Mishra Signed-off-by: Het Gala --- migration/migration.c | 15 --------------- migration/migration.h | 1 - migration/multifd.c | 42 +++++++++++++++++++++--------------------- migration/socket.c | 42 +++++++++++++++++++++++++++++++++--------- migration/socket.h | 4 +++- monitor/hmp-cmds.c | 4 ---- qapi/migration.json | 6 ------ 7 files changed, 57 insertions(+), 57 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 9b0ad732e7..57dd4494b4 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1585,9 +1585,6 @@ static void migrate_params_test_apply(MigrateSetParameters *params, if (params->has_block_incremental) { dest->block_incremental = params->block_incremental; } - if (params->has_multifd_channels) { - dest->multifd_channels = params->multifd_channels; - } if (params->has_multifd_compression) { dest->multifd_compression = params->multifd_compression; } @@ -1702,9 +1699,6 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp) if (params->has_block_incremental) { s->parameters.block_incremental = params->block_incremental; } - if (params->has_multifd_channels) { - s->parameters.multifd_channels = params->multifd_channels; - } if (params->has_multifd_compression) { s->parameters.multifd_compression = params->multifd_compression; } @@ -2686,15 +2680,6 @@ bool migrate_pause_before_switchover(void) MIGRATION_CAPABILITY_PAUSE_BEFORE_SWITCHOVER]; } -int migrate_multifd_channels(void) -{ - MigrationState *s; - - s = migrate_get_current(); - - return s->parameters.multifd_channels; -} - MultiFDCompression migrate_multifd_compression(void) { MigrationState *s; diff --git a/migration/migration.h b/migration/migration.h index fa8717ec9e..9464de8ef7 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -372,7 +372,6 @@ bool migrate_validate_uuid(void); bool migrate_auto_converge(void); bool migrate_use_multifd(void); bool migrate_pause_before_switchover(void); -int migrate_multifd_channels(void); MultiFDCompression migrate_multifd_compression(void); int migrate_multifd_zlib_level(void); int migrate_multifd_zstd_level(void); diff --git a/migration/multifd.c b/migration/multifd.c index 9282ab6aa4..ce017436fb 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -225,7 +225,7 @@ static int multifd_recv_initial_packet(QIOChannel *c, Error **errp) return -1; } - if (msg.id > migrate_multifd_channels()) { + if (msg.id > total_multifd_channels()) { error_setg(errp, "multifd: received channel version %u " "expected %u", msg.version, MULTIFD_VERSION); return -1; @@ -410,8 +410,8 @@ static int multifd_send_pages(QEMUFile *f) * using more channels, so ensure it doesn't overflow if the * limit is lower now. */ - next_channel %= migrate_multifd_channels(); - for (i = next_channel;; i = (i + 1) % migrate_multifd_channels()) { + next_channel %= total_multifd_channels(); + for (i = next_channel;; i = (i + 1) % total_multifd_channels()) { p = &multifd_send_state->params[i]; qemu_mutex_lock(&p->mutex); @@ -422,7 +422,7 @@ static int multifd_send_pages(QEMUFile *f) } if (!p->pending_job) { p->pending_job++; - next_channel = (i + 1) % migrate_multifd_channels(); + next_channel = (i + 1) % total_multifd_channels(); break; } qemu_mutex_unlock(&p->mutex); @@ -500,7 +500,7 @@ static void multifd_send_terminate_threads(Error *err) return; } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; qemu_mutex_lock(&p->mutex); @@ -521,14 +521,14 @@ void multifd_save_cleanup(void) return; } multifd_send_terminate_threads(NULL); - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; if (p->running) { qemu_thread_join(&p->thread); } } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; Error *local_err = NULL; @@ -594,7 +594,7 @@ int multifd_send_sync_main(QEMUFile *f) flush_zero_copy = migrate_use_zero_copy_send(); - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; trace_multifd_send_sync_main_signal(p->id); @@ -627,7 +627,7 @@ int multifd_send_sync_main(QEMUFile *f) } } } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; trace_multifd_send_sync_main_wait(p->id); @@ -903,7 +903,7 @@ int multifd_save_setup(Error **errp) int thread_count; uint32_t page_count = MULTIFD_PACKET_SIZE / qemu_target_page_size(); uint8_t i; - + int idx; if (!migrate_use_multifd()) { return 0; } @@ -912,7 +912,7 @@ int multifd_save_setup(Error **errp) return -1; } - thread_count = migrate_multifd_channels(); + thread_count = total_multifd_channels(); multifd_send_state = g_malloc0(sizeof(*multifd_send_state)); multifd_send_state->params = g_new0(MultiFDSendParams, thread_count); multifd_send_state->pages = multifd_pages_init(page_count); @@ -945,8 +945,8 @@ int multifd_save_setup(Error **errp) } else { p->write_flags = 0; } - - socket_send_channel_create(multifd_new_send_channel_async, p); + idx = multifd_index(i); + socket_send_channel_create(multifd_new_send_channel_async, p, idx); } for (i = 0; i < thread_count; i++) { @@ -991,7 +991,7 @@ static void multifd_recv_terminate_threads(Error *err) } } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; qemu_mutex_lock(&p->mutex); @@ -1017,7 +1017,7 @@ int multifd_load_cleanup(Error **errp) return 0; } multifd_recv_terminate_threads(NULL); - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; if (p->running) { @@ -1030,7 +1030,7 @@ int multifd_load_cleanup(Error **errp) qemu_thread_join(&p->thread); } } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; migration_ioc_unregister_yank(p->c); @@ -1065,13 +1065,13 @@ void multifd_recv_sync_main(void) if (!migrate_use_multifd()) { return; } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; trace_multifd_recv_sync_main_wait(p->id); qemu_sem_wait(&multifd_recv_state->sem_sync); } - for (i = 0; i < migrate_multifd_channels(); i++) { + for (i = 0; i < total_multifd_channels(); i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; WITH_QEMU_LOCK_GUARD(&p->mutex) { @@ -1166,7 +1166,7 @@ int multifd_load_setup(Error **errp) error_setg(errp, "multifd is not supported by current protocol"); return -1; } - thread_count = migrate_multifd_channels(); + thread_count = total_multifd_channels(); multifd_recv_state = g_malloc0(sizeof(*multifd_recv_state)); multifd_recv_state->params = g_new0(MultiFDRecvParams, thread_count); qatomic_set(&multifd_recv_state->count, 0); @@ -1204,7 +1204,7 @@ int multifd_load_setup(Error **errp) bool multifd_recv_all_channels_created(void) { - int thread_count = migrate_multifd_channels(); + int thread_count = total_multifd_channels(); if (!migrate_use_multifd()) { return true; @@ -1259,5 +1259,5 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) QEMU_THREAD_JOINABLE); qatomic_inc(&multifd_recv_state->count); return qatomic_read(&multifd_recv_state->count) == - migrate_multifd_channels(); + total_multifd_channels(); } diff --git a/migration/socket.c b/migration/socket.c index d0cb7cc6a6..c0ac6dbbe2 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -28,9 +28,6 @@ #include "trace.h" -struct SocketOutgoingArgs { - SocketAddress *saddr; -} outgoing_args; struct SocketArgs { struct SrcDestAddr data; @@ -43,20 +40,47 @@ struct OutgoingMigrateParams { uint64_t total_multifd_channel; } outgoing_migrate_params; -void socket_send_channel_create(QIOTaskFunc f, void *data) + +int total_multifd_channels(void) +{ + return outgoing_migrate_params.total_multifd_channel; +} + +int multifd_index(int i) +{ + int length = outgoing_migrate_params.length; + int j = 0; + int runn_sum = 0; + while (j < length) { + runn_sum += outgoing_migrate_params.socket_args[j].multifd_channels; + if (i >= runn_sum) { + j++; + } else { + break; + } + } + return j; +} + +void socket_send_channel_create(QIOTaskFunc f, void *data, int idx) { QIOChannelSocket *sioc = qio_channel_socket_new(); - qio_channel_socket_connect_async(sioc, outgoing_args.saddr, - f, data, NULL, NULL, NULL); + qio_channel_socket_connect_async(sioc, + outgoing_migrate_params.socket_args[idx].data.dst_addr, + f, data, NULL, NULL, + outgoing_migrate_params.socket_args[idx].data.src_addr); } int socket_send_channel_destroy(QIOChannel *send) { /* Remove channel */ object_unref(OBJECT(send)); - if (outgoing_args.saddr) { - qapi_free_SocketAddress(outgoing_args.saddr); - outgoing_args.saddr = NULL; + if (outgoing_migrate_params.socket_args != NULL) { + g_free(outgoing_migrate_params.socket_args); + outgoing_migrate_params.socket_args = NULL; + } + if (outgoing_migrate_params.length) { + outgoing_migrate_params.length = 0; } if (outgoing_migrate_params.socket_args != NULL) { diff --git a/migration/socket.h b/migration/socket.h index b9e3699167..c8b9252384 100644 --- a/migration/socket.h +++ b/migration/socket.h @@ -27,7 +27,9 @@ struct SrcDestAddr { SocketAddress *src_addr; }; -void socket_send_channel_create(QIOTaskFunc f, void *data); +int total_multifd_channels(void); +int multifd_index(int i); +void socket_send_channel_create(QIOTaskFunc f, void *data, int idx); int socket_send_channel_destroy(QIOChannel *send); void socket_start_incoming_migration(const char *str, uint8_t number, diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 32a6b67d5f..9a3d76d6ba 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1281,10 +1281,6 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_block_incremental = true; visit_type_bool(v, param, &p->block_incremental, &err); break; - case MIGRATION_PARAMETER_MULTIFD_CHANNELS: - p->has_multifd_channels = true; - visit_type_uint8(v, param, &p->multifd_channels, &err); - break; case MIGRATION_PARAMETER_MULTIFD_COMPRESSION: p->has_multifd_compression = true; visit_type_MultiFDCompression(v, param, &p->multifd_compression, diff --git a/qapi/migration.json b/qapi/migration.json index 62a7b22d19..1b1c6d01d3 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -877,11 +877,6 @@ # migrated and the destination must already have access to the # same backing chain as was used on the source. (since 2.10) # -# @multifd-channels: Number of channels used to migrate data in -# parallel. This is the same number that the -# number of sockets used for migration. The -# default value is 2 (since 4.0) -# # @xbzrle-cache-size: cache size to be used by XBZRLE migration. It # needs to be a multiple of the target page size # and a power of 2 @@ -965,7 +960,6 @@ '*x-checkpoint-delay': { 'type': 'uint32', 'features': [ 'unstable' ] }, '*block-incremental': 'bool', - '*multifd-channels': 'uint8', '*xbzrle-cache-size': 'size', '*max-postcopy-bandwidth': 'size', '*max-cpu-throttle': 'uint8',