From patchwork Tue Nov 14 18:15:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 837975 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 3ybwg25f3sz9s7c for ; Wed, 15 Nov 2017 05:15:58 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 2F983AE7; Tue, 14 Nov 2017 18:15:20 +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 44B78414 for ; Tue, 14 Nov 2017 18:15:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DDB01488 for ; Tue, 14 Nov 2017 18:15:17 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C3CC61720BF; Tue, 14 Nov 2017 19:15:15 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 14 Nov 2017 10:15:10 -0800 Message-Id: <20171114181511.12904-2-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20171114181511.12904-1-blp@ovn.org> References: <20171114181511.12904-1-blp@ovn.org> X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW autolearn=disabled 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 v2 1/2] netdev: Indentation and style fixes. 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 White space changes only. Signed-off-by: Ben Pfaff Acked-by: William Tu --- lib/netdev.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 7aa3e0aedb4c..8dd35864d7cb 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2314,10 +2314,10 @@ netdev_ifindex_to_odp_port(int ifindex) ovs_mutex_lock(&netdev_hmap_mutex); HMAP_FOR_EACH_WITH_HASH(data, node, ifindex, &ifindex_to_port) { - if (data->ifindex == ifindex) { - ret = data->port; - break; - } + if (data->ifindex == ifindex) { + ret = data->port; + break; + } } ovs_mutex_unlock(&netdev_hmap_mutex); @@ -2330,7 +2330,7 @@ netdev_ports_flow_flush(const struct dpif_class *dpif_class) struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { if (data->dpif_class == dpif_class) { netdev_flow_flush(data->netdev); } @@ -2347,7 +2347,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports) int i = 0; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { if (data->dpif_class == dpif_class) { count++; } @@ -2355,7 +2355,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports) dumps = count ? xzalloc(sizeof *dumps * count) : NULL; - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { if (data->dpif_class == dpif_class) { if (netdev_flow_dump_create(data->netdev, &dumps[i])) { continue; @@ -2379,7 +2379,7 @@ netdev_ports_flow_del(const struct dpif_class *dpif_class, struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { if (data->dpif_class == dpif_class && !netdev_flow_del(data->netdev, ufid, stats)) { ovs_mutex_unlock(&netdev_hmap_mutex); @@ -2399,7 +2399,7 @@ netdev_ports_flow_get(const struct dpif_class *dpif_class, struct match *match, struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { if (data->dpif_class == dpif_class && !netdev_flow_get(data->netdev, match, actions, ufid, stats, buf)) { @@ -2418,7 +2418,7 @@ netdev_ports_flow_init(void) struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH(data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, node, &port_to_netdev) { netdev_init_flow_api(data->netdev); } ovs_mutex_unlock(&netdev_hmap_mutex); From patchwork Tue Nov 14 18:15:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 837976 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 3ybwgv41grz9s7C for ; Wed, 15 Nov 2017 05:16:43 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 489A7B14; Tue, 14 Nov 2017 18:15:23 +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 D7C95ACB for ; Tue, 14 Nov 2017 18:15:19 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5614E488 for ; Tue, 14 Nov 2017 18:15:19 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 3D7CE17209F; Tue, 14 Nov 2017 19:15:16 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Tue, 14 Nov 2017 10:15:11 -0800 Message-Id: <20171114181511.12904-3-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20171114181511.12904-1-blp@ovn.org> References: <20171114181511.12904-1-blp@ovn.org> X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW autolearn=disabled 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 v2 2/2] netdev: Eliminate redundant ifindex mapping. 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 Until now, the code for mapping ODP port number to ifindexes and vice versa has maintained two completely separate data structures, one for each direction. It was possible for the two mappings to become out of sync with each other since either one could change independently. This commit merges them into a single data structure (with two indexes), which at least means that if one is removed then the other is as well. Signed-off-by: Ben Pfaff Acked-by: William Tu --- lib/netdev.c | 71 +++++++++++++++--------------------------------------------- 1 file changed, 17 insertions(+), 54 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 8dd35864d7cb..c52680659e3f 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -2166,17 +2166,12 @@ static struct hmap ifindex_to_port OVS_GUARDED_BY(netdev_hmap_mutex) = HMAP_INITIALIZER(&ifindex_to_port); struct port_to_netdev_data { - struct hmap_node node; + struct hmap_node portno_node; /* By (dpif_class, dpif_port.port_no). */ + struct hmap_node ifindex_node; /* By (dpif_class, ifindex). */ struct netdev *netdev; struct dpif_port dpif_port; const struct dpif_class *dpif_class; -}; - -struct ifindex_to_port_data { - struct hmap_node node; int ifindex; - odp_port_t port; - const struct dpif_class *dpif_class; }; static uint32_t @@ -2191,7 +2186,7 @@ netdev_ports_lookup(odp_port_t port_no, const struct dpif_class *dpif_class) { struct port_to_netdev_data *data; - HMAP_FOR_EACH_WITH_HASH (data, node, + HMAP_FOR_EACH_WITH_HASH (data, portno_node, netdev_ports_hash(port_no, dpif_class), &port_to_netdev) { if (data->dpif_class == dpif_class @@ -2207,7 +2202,6 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, struct dpif_port *dpif_port) { struct port_to_netdev_data *data; - struct ifindex_to_port_data *ifidx; int ifindex = netdev_get_ifindex(netdev); if (ifindex < 0) { @@ -2224,15 +2218,11 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class, data->netdev = netdev_ref(netdev); data->dpif_class = dpif_class; dpif_port_clone(&data->dpif_port, dpif_port); + data->ifindex = ifindex; - ifidx = xzalloc(sizeof *ifidx); - ifidx->ifindex = ifindex; - ifidx->port = dpif_port->port_no; - ifidx->dpif_class = dpif_class; - - hmap_insert(&port_to_netdev, &data->node, + hmap_insert(&port_to_netdev, &data->portno_node, netdev_ports_hash(dpif_port->port_no, dpif_class)); - hmap_insert(&ifindex_to_port, &ifidx->node, ifidx->ifindex); + hmap_insert(&ifindex_to_port, &data->ifindex_node, ifindex); ovs_mutex_unlock(&netdev_hmap_mutex); netdev_init_flow_api(netdev); @@ -2265,38 +2255,11 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class) ovs_mutex_lock(&netdev_hmap_mutex); data = netdev_ports_lookup(port_no, dpif_class); - if (data) { - int ifindex = netdev_get_ifindex(data->netdev); - struct ifindex_to_port_data *ifidx = NULL; - - if (ifindex > 0) { - HMAP_FOR_EACH_WITH_HASH (ifidx, node, ifindex, &ifindex_to_port) { - if (ifidx->port == port_no) { - hmap_remove(&ifindex_to_port, &ifidx->node); - free(ifidx); - break; - } - } - ovs_assert(ifidx); - } else { - /* case where the interface is already deleted form the datapath - * (e.g. tunctl -d or ip tuntap del), then the ifindex is not - * valid anymore. Traverse the HMAP for the port number. */ - HMAP_FOR_EACH (ifidx, node, &ifindex_to_port) { - if (ifidx->port == port_no && - ifidx->dpif_class == dpif_class) { - hmap_remove(&ifindex_to_port, &ifidx->node); - free(ifidx); - break; - } - } - ovs_assert(ifidx); - } - dpif_port_destroy(&data->dpif_port); netdev_close(data->netdev); /* unref and possibly close */ - hmap_remove(&port_to_netdev, &data->node); + hmap_remove(&port_to_netdev, &data->portno_node); + hmap_remove(&ifindex_to_port, &data->ifindex_node); free(data); ret = 0; } @@ -2309,13 +2272,13 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class) odp_port_t netdev_ifindex_to_odp_port(int ifindex) { - struct ifindex_to_port_data *data; + struct port_to_netdev_data *data; odp_port_t ret = 0; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH_WITH_HASH(data, node, ifindex, &ifindex_to_port) { + HMAP_FOR_EACH_WITH_HASH (data, ifindex_node, ifindex, &ifindex_to_port) { if (data->ifindex == ifindex) { - ret = data->port; + ret = data->dpif_port.port_no; break; } } @@ -2330,7 +2293,7 @@ netdev_ports_flow_flush(const struct dpif_class *dpif_class) struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { if (data->dpif_class == dpif_class) { netdev_flow_flush(data->netdev); } @@ -2347,7 +2310,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports) int i = 0; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { if (data->dpif_class == dpif_class) { count++; } @@ -2355,7 +2318,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports) dumps = count ? xzalloc(sizeof *dumps * count) : NULL; - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { if (data->dpif_class == dpif_class) { if (netdev_flow_dump_create(data->netdev, &dumps[i])) { continue; @@ -2379,7 +2342,7 @@ netdev_ports_flow_del(const struct dpif_class *dpif_class, struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { if (data->dpif_class == dpif_class && !netdev_flow_del(data->netdev, ufid, stats)) { ovs_mutex_unlock(&netdev_hmap_mutex); @@ -2399,7 +2362,7 @@ netdev_ports_flow_get(const struct dpif_class *dpif_class, struct match *match, struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { if (data->dpif_class == dpif_class && !netdev_flow_get(data->netdev, match, actions, ufid, stats, buf)) { @@ -2418,7 +2381,7 @@ netdev_ports_flow_init(void) struct port_to_netdev_data *data; ovs_mutex_lock(&netdev_hmap_mutex); - HMAP_FOR_EACH (data, node, &port_to_netdev) { + HMAP_FOR_EACH (data, portno_node, &port_to_netdev) { netdev_init_flow_api(data->netdev); } ovs_mutex_unlock(&netdev_hmap_mutex);