From patchwork Wed Apr 17 09:15:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0KPRiNC60L7QsiDQlNCw0L3QuNC40Ls=?= X-Patchwork-Id: 139448 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A56D643E90; Wed, 17 Apr 2024 11:15:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2A6134029E; Wed, 17 Apr 2024 11:15:07 +0200 (CEST) Received: from mx4.mts.ru (mx4.mts.ru [213.87.44.6]) by mails.dpdk.org (Postfix) with ESMTP id BB25B4028B for ; Wed, 17 Apr 2024 11:15:05 +0200 (CEST) Received: from mx-v6.msk.mts.ru (unknown [10.73.8.205]) by mx4.mts.ru (Postfix) with ESMTP id 53BAA16199; Wed, 17 Apr 2024 12:15:05 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx4.mts.ru 53BAA16199 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mts.ru; s=mail; t=1713345305; bh=8H9bnToB0e4Ig0qqeTZ63jAlyMwV0uETJ/qz5BjSJho=; h=From:To:CC:Subject:Date:References:In-Reply-To:From; b=O/ED8vK3KhqjE+DHpGJ/j+Nzj/waz11ffEDC/4an+2EzsfP6xujD8xTWSJad1pnZr 5/zmTypPwM5vFXECsZzQpQ/zKtc3+0XTA4REMaJiVvkGbneXFTczhRzEXU2II0o1Xe i+qM+aThqm8W97ozebUt2ETjidABRH0riFr/PGng= Received: from 0001EX19MBX15.msk.mts.ru (0001EX19MBX15.msk.mts.ru [10.73.16.232]) by mx-v6.msk.mts.ru (Postfix) with ESMTP id 4VKFc92D3wzCy; Wed, 17 Apr 2024 12:15:05 +0300 (MSK) Received: from 0001EX19MBX15.msk.mts.ru (10.73.16.232) by 0001EX19MBX15.msk.mts.ru (10.73.16.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.25; Wed, 17 Apr 2024 12:15:05 +0300 Received: from 0001EX19MBX15.msk.mts.ru ([10.73.16.232]) by 0001EX19MBX15.msk.mts.ru ([10.73.16.232]) with mapi id 15.02.1258.025; Wed, 17 Apr 2024 12:15:05 +0300 From: =?utf-8?b?0KPRiNC60L7QsiDQlNCw0L3QuNC40Ls=?= To: "dev@dpdk.org" CC: =?utf-8?b?0KPRiNC60L7QsiDQlNCw0L3QuNC40Ls=?= , "Maxime Coquelin" , Chenbo Xia Subject: [PATCH v2] lib/vhost: add flag for async connection in client mode Thread-Topic: [PATCH v2] lib/vhost: add flag for async connection in client mode Thread-Index: AQHakKe7cZ91zLHm00iwKAOMAugPIA== Date: Wed, 17 Apr 2024 09:15:04 +0000 Message-ID: <20240417091250.187218-1-udav@mts.ru> References: <20240417083835.164456-1-udav@mts.ru> In-Reply-To: <20240417083835.164456-1-udav@mts.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.34.1 x-originating-ip: [10.75.216.11] Content-ID: <7925C0028C05CB4FA12AF41F8E09A047@mts.ru> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch introduces a new flag RTE_VHOST_USER_ASYNC_CONNECT, which in combination with the flag RTE_VHOST_USER_CLIENT makes rte_vhost_driver_start connect asynchronously to the vhost server. Signed-off-by: Ушков Даниил --- Fixes: 1. Fix warning about the name in signature. 2. Fix warning about coding style. P.S. Is it ok that name is not in ascii? Sorry, it could be hard to change it now. lib/vhost/rte_vhost.h | 1 + lib/vhost/socket.c | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) -- 2.34.1 diff --git a/lib/vhost/rte_vhost.h b/lib/vhost/rte_vhost.h index db92f05344..b0434c4b8d 100644 --- a/lib/vhost/rte_vhost.h +++ b/lib/vhost/rte_vhost.h @@ -41,6 +41,7 @@ extern "C" { #define RTE_VHOST_USER_ASYNC_COPY (1ULL << 7) #define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS (1ULL << 8) #define RTE_VHOST_USER_NET_STATS_ENABLE (1ULL << 9) +#define RTE_VHOST_USER_ASYNC_CONNECT (1ULL << 10) /* Features. */ #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c index 96b3ab5595..c681d53abb 100644 --- a/lib/vhost/socket.c +++ b/lib/vhost/socket.c @@ -45,6 +45,7 @@ struct vhost_user_socket { bool async_copy; bool net_compliant_ol_flags; bool stats_enabled; + bool async_connect; /* * The "supported_features" indicates the feature bits the @@ -533,21 +534,23 @@ vhost_user_start_client(struct vhost_user_socket *vsocket) const char *path = vsocket->path; struct vhost_user_reconnect *reconn; - ret = vhost_user_connect_nonblock(vsocket->path, fd, (struct sockaddr *)&vsocket->un, - sizeof(vsocket->un)); - if (ret == 0) { - vhost_user_add_connection(fd, vsocket); - return 0; - } + if (!vsocket->async_connect || !vsocket->reconnect) { + ret = vhost_user_connect_nonblock(vsocket->path, fd, + (struct sockaddr *)&vsocket->un, sizeof(vsocket->un)); + if (ret == 0) { + vhost_user_add_connection(fd, vsocket); + return 0; + } - VHOST_CONFIG_LOG(path, WARNING, "failed to connect: %s", strerror(errno)); + VHOST_CONFIG_LOG(path, WARNING, "failed to connect: %s", strerror(errno)); - if (ret == -2 || !vsocket->reconnect) { - close(fd); - return -1; - } + if (ret == -2 || !vsocket->reconnect) { + close(fd); + return -1; + } - VHOST_CONFIG_LOG(path, INFO, "reconnecting..."); + VHOST_CONFIG_LOG(path, INFO, "reconnecting..."); + } reconn = malloc(sizeof(*reconn)); if (reconn == NULL) { VHOST_CONFIG_LOG(path, ERR, "failed to allocate memory for reconnect"); @@ -930,6 +933,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY; vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS; vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE; + vsocket->async_connect = flags & RTE_VHOST_USER_ASYNC_CONNECT; if (vsocket->is_vduse) vsocket->iommu_support = true; else