From patchwork Thu Jun 21 22:53:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 932991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41BcTF1LBgz9s01 for ; Fri, 22 Jun 2018 08:54:25 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4911AD6A; Thu, 21 Jun 2018 22:54:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 3BA9AD3C for ; Thu, 21 Jun 2018 22:54:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 636BB1A0 for ; Thu, 21 Jun 2018 22:54:19 +0000 (UTC) X-Originating-IP: 173.228.112.177 Received: from sigabrt.gateway.sonic.net (173-228-112-177.dsl.dynamic.fusionbroadband.com [173.228.112.177]) (Authenticated sender: blp@ovn.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id B3787240002; Thu, 21 Jun 2018 22:54:12 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 21 Jun 2018 15:53:53 -0700 Message-Id: <20180621225353.9303-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] ofproto-dpif: Let the dpif report when a port is a duplicate. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The port_add() function checks whether the port about to be added to the dpif is already present and adds it only if it is not. This duplicates a check also present (and necessary) in each dpif and races with it as well. When a dpif has a large number of ports, the check can be expensive (it is not efficiently implemented). It would be nice to made the check cheaper, but it also seems reasonable to do as done in this patch and just let the dpif report the duplication. Reported-by: Haifeng Lin Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- lib/dpif.c | 9 +++++++-- ofproto/ofproto-dpif.c | 7 +++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/dpif.c b/lib/dpif.c index f6a7f6a72e18..d78330bef3b8 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -591,8 +591,13 @@ dpif_port_add(struct dpif *dpif, struct netdev *netdev, odp_port_t *port_nop) netdev_ports_insert(netdev, dpif->dpif_class, &dpif_port); } } else { - VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s", - dpif_name(dpif), netdev_name, ovs_strerror(error)); + if (error != EEXIST) { + VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s", + dpif_name(dpif), netdev_name, ovs_strerror(error)); + } else { + /* It's fairly common for upper layers to try to add a duplicate + * port, and they know how to handle it properly. */ + } port_no = ODPP_NONE; } if (port_nop) { diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index ca4582cd5064..771be2fcc88a 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -3683,11 +3683,10 @@ port_add(struct ofproto *ofproto_, struct netdev *netdev) } dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf); - if (!dpif_port_exists(ofproto->backer->dpif, dp_port_name)) { - odp_port_t port_no = ODPP_NONE; - int error; - error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no); + odp_port_t port_no = ODPP_NONE; + int error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no); + if (error != EEXIST) { if (error) { return error; }