From patchwork Mon Aug 8 16:54:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1664649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M1j3b1tJzz9sB4 for ; Tue, 9 Aug 2022 02:54:35 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2898960DED; Mon, 8 Aug 2022 16:54:33 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2898960DED X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VJ4YqPODYLD5; Mon, 8 Aug 2022 16:54:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4CFC0605E0; Mon, 8 Aug 2022 16:54:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4CFC0605E0 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8CF13C007F; Mon, 8 Aug 2022 16:54:29 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5828BC0033 for ; Mon, 8 Aug 2022 16:54:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 2392C607F2 for ; Mon, 8 Aug 2022 16:54:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 2392C607F2 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NHayysKOQtfb for ; Mon, 8 Aug 2022 16:54:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org ACB2E605E0 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::225]) by smtp3.osuosl.org (Postfix) with ESMTPS id ACB2E605E0 for ; Mon, 8 Aug 2022 16:54:25 +0000 (UTC) Received: (Authenticated sender: hzhou@ovn.org) by mail.gandi.net (Postfix) with ESMTPSA id 71A501C0003; Mon, 8 Aug 2022 16:54:21 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Mon, 8 Aug 2022 09:54:00 -0700 Message-Id: <20220808165401.3684424-1-hzhou@ovn.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Cc: Ariel Levkovich Subject: [ovs-dev] [PATCH 1/2] netdev-offload: Expose error when init_flow_api() returns EBUSY. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" init_flow_api() can fail due to errors, such as netlink "Device or resource busy". Today the errors are ignored except just an INFO log. This ends up with an interface created without offload enabled, and application won't notice it. This patch expose the error to the OVSDB record, and reverts the dpif port changes upon failure. Signed-off-by: Han Zhou Acked-by: Mike Pattrick --- lib/dpif.c | 12 ++++++++++-- lib/netdev-offload.c | 32 +++++++++++++++++++++++--------- lib/netdev-offload.h | 1 - 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/dpif.c b/lib/dpif.c index 40f5fe446..b68929bae 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -609,9 +609,17 @@ dpif_port_add(struct dpif *dpif, struct netdev *netdev, odp_port_t *port_nop) dpif_port.type = CONST_CAST(char *, netdev_get_type(netdev)); dpif_port.name = CONST_CAST(char *, netdev_name); dpif_port.port_no = port_no; - netdev_ports_insert(netdev, &dpif_port); + error = netdev_ports_insert(netdev, &dpif_port); + if (error) { + if (error == EEXIST) { + error = 0; + } else { + dpif->dpif_class->port_del(dpif, port_no); + } + } } - } else { + } + if (error) { VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s", dpif_name(dpif), netdev_name, ovs_strerror(error)); port_no = ODPP_NONE; diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index 9fde5f7a9..f30b20673 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -179,21 +179,29 @@ static int netdev_assign_flow_api(struct netdev *netdev) { struct netdev_registered_flow_api *rfa; - + int ret = -1; CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { - if (!rfa->flow_api->init_flow_api(netdev)) { + int error = rfa->flow_api->init_flow_api(netdev); + if (!error) { ovs_refcount_ref(&rfa->refcnt); ovsrcu_set(&netdev->flow_api, rfa->flow_api); VLOG_INFO("%s: Assigned flow API '%s'.", netdev_get_name(netdev), rfa->flow_api->type); return 0; + } else { + VLOG_DBG("%s: flow API '%s' is not suitable.", + netdev_get_name(netdev), rfa->flow_api->type); + if (ret == EBUSY) { + /* If all API fail and at least one of the error is EBUSY, we + * will return this error code EBUSY so that the upper layer + * can decide to retry later. */ + ret = error; + } } - VLOG_DBG("%s: flow API '%s' is not suitable.", - netdev_get_name(netdev), rfa->flow_api->type); } VLOG_INFO("%s: No suitable flow API found.", netdev_get_name(netdev)); - return -1; + return ret; } void @@ -368,7 +376,7 @@ netdev_flow_get_n_flows(struct netdev *netdev, uint64_t *n_flows) : EOPNOTSUPP; } -int +static int netdev_init_flow_api(struct netdev *netdev) { if (!netdev_is_flow_api_enabled()) { @@ -379,7 +387,10 @@ netdev_init_flow_api(struct netdev *netdev) return 0; } - if (netdev_assign_flow_api(netdev)) { + int error = netdev_assign_flow_api(netdev); + if (error == EBUSY) { + return error; + } else if (error) { return EOPNOTSUPP; } @@ -729,8 +740,11 @@ netdev_ports_insert(struct netdev *netdev, struct dpif_port *dpif_port) netdev_ports_hash(dpif_port->port_no, dpif_type)); ovs_rwlock_unlock(&netdev_hmap_rwlock); - netdev_init_flow_api(netdev); - + int error = netdev_init_flow_api(netdev); + if (error && error != EOPNOTSUPP) { + netdev_ports_remove(dpif_port->port_no, dpif_type); + return error; + } return 0; } diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 249a3102a..2974e5497 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -118,7 +118,6 @@ int netdev_flow_get(struct netdev *, struct match *, struct nlattr **actions, struct dpif_flow_attrs *, struct ofpbuf *wbuffer); int netdev_flow_del(struct netdev *, const ovs_u128 *, struct dpif_flow_stats *); -int netdev_init_flow_api(struct netdev *); void netdev_uninit_flow_api(struct netdev *); uint32_t netdev_get_block_id(struct netdev *); int netdev_get_hw_info(struct netdev *, int);