From patchwork Tue Aug 8 18:23:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 799390 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 3xRjXN3ZqKz9s75 for ; Wed, 9 Aug 2017 04:26:28 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D7B9BB6A; Tue, 8 Aug 2017 18:25:31 +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 1677AB56 for ; Tue, 8 Aug 2017 18:25:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9B5E33FF for ; Tue, 8 Aug 2017 18:23:56 +0000 (UTC) X-Originating-IP: 208.91.1.34 Received: from carno.eng.vmware.com (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 06135FB882 for ; Tue, 8 Aug 2017 20:23:54 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Tue, 8 Aug 2017 11:23:32 -0700 Message-Id: <20170808182332.24497-2-joe@ovn.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170808182332.24497-1-joe@ovn.org> References: <20170808182332.24497-1-joe@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCHv2 2/2] dpif: Fix clean up of dpif_ports on dpif_close(). 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 Commit 32b77c316d9982("dpif: Save added ports in a port map.") introduced tracking of all dpif ports by taking a reference on each available netdev when the dpif is opened, but it failed to clear out and release references to these netdevs when the dpif is closed. One of the problems introduced by this was that upon clean exit of ovs-vswitchd via "ovs-appctl exit --cleanup", the "ovs-netdev" device was not deleted. This which could cause problems in subsequent start up. Commit 5119e258da92 ("dpif: Fix cleanup of userspace datapath.") fixed this particular problem by not adding such devices to the netdev_ports map, but the referencing/unreferencing upon dpif_open()/dpif_close() is still not balanced. Balance the referencing of netdevs by introducing netdev_ports_flush() and clearing these during dpif_close(). Fixes: 32b77c316d9982("dpif: Save added ports in a port map.") Signed-off-by: Joe Stringer Acked-by: Paul Blakey --- v2: Update commit message. Rebase. v1: Initial posting. --- lib/dpif.c | 1 + lib/netdev.c | 15 +++++++++++++++ lib/netdev.h | 1 + 3 files changed, 17 insertions(+) diff --git a/lib/dpif.c b/lib/dpif.c index e71f6a3d1475..53bdf39f6e20 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -437,6 +437,7 @@ dpif_close(struct dpif *dpif) struct registered_dpif_class *rc; rc = shash_find_data(&dpif_classes, dpif->dpif_class->type); + netdev_ports_flush(dpif->dpif_class); dpif_uninit(dpif, true); dp_class_unref(rc); } diff --git a/lib/netdev.c b/lib/netdev.c index 3e8b211857d7..94f9e486d8b1 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2284,6 +2284,21 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class) return ret; } +void +netdev_ports_flush(const struct dpif_class *class) +{ + struct port_to_netdev_data *data, *next; + + ovs_mutex_lock(&netdev_hmap_mutex); + HMAP_FOR_EACH_SAFE (data, next, node, &port_to_netdev) { + if (data->dpif_class == class) { + netdev_port_data_destroy(data); + } + } + + ovs_mutex_unlock(&netdev_hmap_mutex); +} + odp_port_t netdev_ifindex_to_odp_port(int ifindex) { diff --git a/lib/netdev.h b/lib/netdev.h index f8482f787e39..2d02be5826f6 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -215,6 +215,7 @@ int netdev_ports_insert(struct netdev *, const struct dpif_class *, struct dpif_port *); struct netdev *netdev_ports_get(odp_port_t port, const struct dpif_class *); int netdev_ports_remove(odp_port_t port, const struct dpif_class *); +void netdev_ports_flush(const struct dpif_class *); odp_port_t netdev_ifindex_to_odp_port(int ifindex); struct netdev_flow_dump **netdev_ports_flow_dump_create( const struct dpif_class *,