From patchwork Thu Aug 17 05:38:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roi Dayan X-Patchwork-Id: 802339 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=) 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 3xXw494Q0Fz9t2x for ; Thu, 17 Aug 2017 15:38:33 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DF363504; Thu, 17 Aug 2017 05:38:28 +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 8027D4A6 for ; Thu, 17 Aug 2017 05:38:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id D6920196 for ; Thu, 17 Aug 2017 05:38:26 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from roid@mellanox.com) with ESMTPS (AES256-SHA encrypted); 17 Aug 2017 08:38:22 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v7H5cMB7008129; Thu, 17 Aug 2017 08:38:22 +0300 From: Roi Dayan To: dev@openvswitch.org Date: Thu, 17 Aug 2017 08:38:14 +0300 Message-Id: <1502948295-30787-2-git-send-email-roid@mellanox.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1502948295-30787-1-git-send-email-roid@mellanox.com> References: <1502948295-30787-1-git-send-email-roid@mellanox.com> Cc: Simon Horman Subject: [ovs-dev] [PATCH V2 1/2] dpif: Fix cleanup of netdev_ports map 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 Executing dpctl commands from userspace also calls to dpif_open()/dpif_close() but not really creating another dpif but using a clone. As for netdev_ports map is global we avoid adding duplicate entries but also need to make sure we are not removing needed entries. With this commit we make sure only the last dpif close should clean the netdev_ports map. Fixes: 6595cb95a4a9 ("dpif: Clean up netdev_ports map on dpif_close().") Signed-off-by: Roi Dayan Reviewed-by: Paul Blakey --- lib/dpif.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/dpif.c b/lib/dpif.c index 4c5eac6..0c8b91b 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -428,6 +428,18 @@ dpif_create_and_open(const char *name, const char *type, struct dpif **dpifp) return error; } +static void +dpif_remove_netdev_ports(struct dpif *dpif) { + struct dpif_port_dump port_dump; + struct dpif_port dpif_port; + + DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) { + if (!dpif_is_internal_port(dpif_port.type)) { + netdev_ports_remove(dpif_port.port_no, dpif->dpif_class); + } + } +} + /* Closes and frees the connection to 'dpif'. Does not destroy the datapath * itself; call dpif_delete() first, instead, if that is desirable. */ void @@ -435,18 +447,14 @@ dpif_close(struct dpif *dpif) { if (dpif) { struct registered_dpif_class *rc; - struct dpif_port_dump port_dump; - struct dpif_port dpif_port; rc = shash_find_data(&dpif_classes, dpif->dpif_class->type); - DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) { - if (!dpif_is_internal_port(dpif_port.type)) { - netdev_ports_remove(dpif_port.port_no, dpif->dpif_class); - } - } dpif_uninit(dpif, true); dp_class_unref(rc); + if (rc->refcount == 0) { + dpif_remove_netdev_ports(dpif); + } } }