From patchwork Thu Jun 1 03:38:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nickcooper-zhangtonghao X-Patchwork-Id: 769476 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.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 3wdY3b4RBlz9sNJ for ; Thu, 1 Jun 2017 13:38:51 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C27DCBE1; Thu, 1 Jun 2017 03:38:47 +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 4941287A for ; Thu, 1 Jun 2017 03:38:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpbg65.qq.com (smtpbg65.qq.com [103.7.28.233]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 856DFE2 for ; Thu, 1 Jun 2017 03:38:43 +0000 (UTC) X-QQ-mid: bizesmtp16t1496288318tm4h1rx9 Received: from local.opencloud.tech.localdomai (unknown [106.120.127.10]) by esmtp4.qq.com (ESMTP) with id ; Thu, 01 Jun 2017 11:38:38 +0800 (CST) X-QQ-SSF: 01100000002000F0FG90B00A0000000 X-QQ-FEAT: q17Yoz/cMVoD1ZRHE/jcGN+vvgO8kiaF09Inqka6UXSi17Wfz9qRz6UX0nGBY hsHqC8JZxuedFV08fUY9sluPpKMz5v151e3FN4UW/7/iXXdP/19wXqGYOkv2gcQsZpuz13c AntkABDJJF/qAeVhv3z50rsduGkWsTnOKpyoq+TND364igKHT2h9o5eyvDG/us8ceX61KZm ciUKWr2GaTzJmik2Z3bJitln9w9iamWxHKT5++vaL2QwlzUpeq9Qd8kkf/YBt0m1pcP39ee 7kUAcEYK9VOowX X-QQ-GoodBg: 0 From: nickcooper-zhangtonghao To: dev@openvswitch.org Date: Wed, 31 May 2017 20:38:15 -0700 Message-Id: <1496288296-2755-2-git-send-email-nic@opencloud.tech> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496288296-2755-1-git-send-email-nic@opencloud.tech> References: <1496288296-2755-1-git-send-email-nic@opencloud.tech> X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v4 2/3] rstp: Add internal functions without locks. 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 This patch adds some internal functions which does not use the locks. This patch is used for next patch. Signed-off-by: nickcooper-zhangtonghao --- lib/rstp.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++------------- lib/rstp.h | 2 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/lib/rstp.c b/lib/rstp.c index 67e6912..4455c4a 100644 --- a/lib/rstp.c +++ b/lib/rstp.c @@ -120,6 +120,16 @@ static void rstp_port_set_mcheck__(struct rstp_port *, bool mcheck) OVS_REQUIRES(rstp_mutex); static void reinitialize_port__(struct rstp_port *p) OVS_REQUIRES(rstp_mutex); +static bool rstp_is_root_bridge__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex); +static uint32_t rstp_get_root_path_cost__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex); +static struct rstp_port *rstp_get_root_port__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex); +static rstp_identifier rstp_get_root_id__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex); +static void rstp_unixctl_tcn(struct unixctl_conn *, int argc, + const char *argv[], void *aux); const char * rstp_state_name(enum rstp_state state) @@ -208,9 +218,6 @@ rstp_port_get_number(const struct rstp_port *p) return number; } -static void rstp_unixctl_tcn(struct unixctl_conn *, int argc, - const char *argv[], void *aux); - /* Decrements the State Machines' timers. */ void rstp_tick_timers(struct rstp *rstp) @@ -796,6 +803,13 @@ rstp_port_set_path_cost__(struct rstp_port *port, uint32_t path_cost) } /* Gets the root path cost. */ +static uint32_t +rstp_get_root_path_cost__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex) +{ + return rstp->root_priority.root_path_cost; +} + uint32_t rstp_get_root_path_cost(const struct rstp *rstp) OVS_EXCLUDED(rstp_mutex) @@ -803,7 +817,7 @@ rstp_get_root_path_cost(const struct rstp *rstp) uint32_t cost; ovs_mutex_lock(&rstp_mutex); - cost = rstp->root_priority.root_path_cost; + cost = rstp_get_root_path_cost__(rstp); ovs_mutex_unlock(&rstp_mutex); return cost; } @@ -1313,6 +1327,13 @@ rstp_get_designated_id(const struct rstp *rstp) } /* Returns the root bridge id. */ +static rstp_identifier +rstp_get_root_id__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex) +{ + return rstp->root_priority.root_bridge_id; +} + rstp_identifier rstp_get_root_id(const struct rstp *rstp) OVS_EXCLUDED(rstp_mutex) @@ -1320,7 +1341,7 @@ rstp_get_root_id(const struct rstp *rstp) rstp_identifier root_id; ovs_mutex_lock(&rstp_mutex); - root_id = rstp->root_priority.root_bridge_id; + root_id = rstp_get_root_id__(rstp); ovs_mutex_unlock(&rstp_mutex); return root_id; @@ -1357,6 +1378,14 @@ rstp_get_bridge_port_id(const struct rstp *rstp) /* Returns true if the bridge believes to the be root of the spanning tree, * false otherwise. */ +static bool +rstp_is_root_bridge__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex) +{ + return rstp->bridge_identifier == + rstp->root_priority.designated_bridge_id; +} + bool rstp_is_root_bridge(const struct rstp *rstp) OVS_EXCLUDED(rstp_mutex) @@ -1364,8 +1393,7 @@ rstp_is_root_bridge(const struct rstp *rstp) bool is_root; ovs_mutex_lock(&rstp_mutex); - is_root = rstp->bridge_identifier == - rstp->root_priority.designated_bridge_id; + is_root = rstp_is_root_bridge__(rstp); ovs_mutex_unlock(&rstp_mutex); return is_root; @@ -1388,23 +1416,32 @@ rstp_get_designated_root(const struct rstp *rstp) /* Returns the port connecting 'rstp' to the root bridge, or a null pointer if * there is no such port. */ -struct rstp_port * -rstp_get_root_port(struct rstp *rstp) - OVS_EXCLUDED(rstp_mutex) +static struct rstp_port * +rstp_get_root_port__(const struct rstp *rstp) + OVS_REQUIRES(rstp_mutex) { struct rstp_port *p; - ovs_mutex_lock(&rstp_mutex); HMAP_FOR_EACH (p, node, &rstp->ports) { if (p->port_id == rstp->root_port_id) { - ovs_mutex_unlock(&rstp_mutex); return p; } } - ovs_mutex_unlock(&rstp_mutex); return NULL; } +struct rstp_port * +rstp_get_root_port(const struct rstp *rstp) + OVS_EXCLUDED(rstp_mutex) +{ + struct rstp_port *p; + + ovs_mutex_lock(&rstp_mutex); + p = rstp_get_root_port__(rstp); + ovs_mutex_unlock(&rstp_mutex); + return p; +} + /* Returns the state of port 'p'. */ enum rstp_state rstp_port_get_state(const struct rstp_port *p) diff --git a/lib/rstp.h b/lib/rstp.h index 5213f98..39a13b5 100644 --- a/lib/rstp.h +++ b/lib/rstp.h @@ -207,7 +207,7 @@ uint16_t rstp_get_designated_port_id(const struct rstp *) OVS_EXCLUDED(rstp_mutex); uint16_t rstp_get_bridge_port_id(const struct rstp *) OVS_EXCLUDED(rstp_mutex); -struct rstp_port * rstp_get_root_port(struct rstp *) +struct rstp_port * rstp_get_root_port(const struct rstp *) OVS_EXCLUDED(rstp_mutex); rstp_identifier rstp_get_designated_root(const struct rstp *) OVS_EXCLUDED(rstp_mutex);