From patchwork Wed May 10 11:15:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nickcooper-zhangtonghao X-Patchwork-Id: 760542 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 3wNDDn2zDrz9rxl for ; Wed, 10 May 2017 21:15:36 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BC899B2F; Wed, 10 May 2017 11:15:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp2.linuxfoundation.org (smtp2.linux-foundation.org [172.17.192.36]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 1F47B94F for ; Wed, 10 May 2017 11:15:31 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtpbg202.qq.com (smtpbg202.qq.com [184.105.206.29]) by smtp2.linuxfoundation.org (Postfix) with ESMTPS id 1E5591DF17 for ; Wed, 10 May 2017 11:15:28 +0000 (UTC) X-QQ-mid: bizesmtp13t1494414923twz01g6w Received: from local.opencloud.tech.localdomai (unknown [106.120.127.10]) by esmtp4.qq.com (ESMTP) with id ; Wed, 10 May 2017 19:15:16 +0800 (CST) X-QQ-SSF: 01100000000000F0FG80 X-QQ-FEAT: oIoGrveFQB9vt4dK4IRxk5Fi8VNzK1ffsqzSJGo3zycJILSvxpSrTgaedbb/9 Q4PlIyCtfN7LTBWsdmhILWbnsr/LMEQzpF3cc40m0NrK1cxKwC1LCPHIuojF9mkE4Ebee59 k4afDqnqmwt4noHg7ljfkxtSd9UABGHPZbAlwUUXpXft1xPWHaoVqJP78cs0D9rcFjlg+n/ Q5abbmva84MWNEoElgztBJd4pvtig9FWA/jlk5erBXGu65fZ/Hb8Gcg34v1uZ01o6eCNM1Y X2/g== X-QQ-GoodBg: 0 From: nickcooper-zhangtonghao To: dev@openvswitch.org Date: Wed, 10 May 2017 04:15:02 -0700 Message-Id: <1494414906-71269-1-git-send-email-nic@opencloud.tech> X-Mailer: git-send-email 1.8.3.1 X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp2.linux-foundation.org Subject: [ovs-dev] [PATCH v2 1/5] rstp: Init a recursive mutex for rstp. 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 will be used for next patch. The 'rstp/show' command, which uses the mutex, calls functions which also use the mutex. We should init it as a recursive mutex. * Some rstp tests of OvS, which run with ovstest, does not run rstp_init in the bridge_init. We should call rstp_init when creating the rstp and stp also do that, otherwise tests fail. * This patch remove the rstp_mutex in header file and make it static in c file because we only use it in lib/rstp.c Signed-off-by: nickcooper-zhangtonghao --- lib/rstp.c | 15 ++++++++++++--- lib/rstp.h | 6 ------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/rstp.c b/lib/rstp.c index 907a907..6f1c1e3 100644 --- a/lib/rstp.c +++ b/lib/rstp.c @@ -50,7 +50,7 @@ VLOG_DEFINE_THIS_MODULE(rstp); -struct ovs_mutex rstp_mutex = OVS_MUTEX_INITIALIZER; +static struct ovs_mutex rstp_mutex; static struct ovs_list all_rstps__ = OVS_LIST_INITIALIZER(&all_rstps__); static struct ovs_list *const all_rstps OVS_GUARDED_BY(rstp_mutex) = &all_rstps__; @@ -239,8 +239,15 @@ void rstp_init(void) OVS_EXCLUDED(rstp_mutex) { - unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn, - NULL); + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + + if (ovsthread_once_start(&once)) { + ovs_mutex_init_recursive(&rstp_mutex); + + unixctl_command_register("rstp/tcn", "[bridge]", 0, 1, rstp_unixctl_tcn, + NULL); + ovsthread_once_done(&once); + } } /* Creates and returns a new RSTP instance that initially has no ports. */ @@ -255,6 +262,8 @@ rstp_create(const char *name, rstp_identifier bridge_address, VLOG_DBG("Creating RSTP instance"); + rstp_init(); + rstp = xzalloc(sizeof *rstp); rstp->name = xstrdup(name); diff --git a/lib/rstp.h b/lib/rstp.h index 4942d59..78e07fb 100644 --- a/lib/rstp.h +++ b/lib/rstp.h @@ -36,12 +36,6 @@ #include "compiler.h" #include "util.h" -/* Thread Safety: Callers passing in RSTP and RSTP port object - * pointers must hold a reference to the passed object to ensure that - * the object does not become stale while it is being accessed. */ - -extern struct ovs_mutex rstp_mutex; - #define RSTP_MAX_PORTS 4095 struct dp_packet;