netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, Cong Wang <xiyou.wangcong@gmail.com>
Subject: [RFC Patch net-next 6/6] net_sched: switch to RCU API for act_mirred
Date: Thu,  1 Sep 2016 22:57:20 -0700	[thread overview]
Message-ID: <1472795840-31901-7-git-send-email-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <1472795840-31901-1-git-send-email-xiyou.wangcong@gmail.com>

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/act_mirred.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 6038c85..90a024c 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -60,6 +60,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
 {
 	struct tc_action_net *tn = net_generic(net, mirred_net_id);
 	struct nlattr *tb[TCA_MIRRED_MAX + 1];
+	struct tc_action *n;
 	struct tc_mirred *parm;
 	struct tcf_mirred *m;
 	struct net_device *dev;
@@ -108,44 +109,40 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
 			ok_push = 1;
 			break;
 		}
-	} else {
-		dev = NULL;
+	} else if (!exists) {
+		return -EINVAL;
+	}
+
+	if (exists && !ovr) {
+		tcf_hash_release(*a, bind);
+		return -EEXIST;
 	}
 
-	if (!exists) {
-		if (dev == NULL)
-			return -EINVAL;
-		ret = tcf_hash_create(tn, parm->index, est, a,
-				      &act_mirred_ops, bind, true);
-		if (ret)
-			return ret;
-		ret = ACT_P_CREATED;
-	} else {
+	ret = tcf_hash_create(tn, parm->index, est, &n,
+			      &act_mirred_ops, bind, true);
+	if (ret) {
 		tcf_hash_release(*a, bind);
-		if (!ovr)
-			return -EEXIST;
+		return ret;
 	}
-	m = to_mirred(*a);
+
+	tcf_hash_copy(n, *a);
+	m = to_mirred(n);
 
 	ASSERT_RTNL();
 	m->tcf_action = parm->action;
 	m->tcfm_eaction = parm->eaction;
 	if (dev != NULL) {
 		m->tcfm_ifindex = parm->ifindex;
-		if (ret != ACT_P_CREATED)
-			dev_put(rcu_dereference_protected(m->tcfm_dev, 1));
 		dev_hold(dev);
 		rcu_assign_pointer(m->tcfm_dev, dev);
 		m->tcfm_ok_push = ok_push;
 	}
 
-	if (ret == ACT_P_CREATED) {
-		spin_lock_bh(&mirred_list_lock);
-		list_add(&m->tcfm_list, &mirred_list);
-		spin_unlock_bh(&mirred_list_lock);
-		tcf_hash_insert(tn, *a);
-	}
+	spin_lock_bh(&mirred_list_lock);
+	list_add(&m->tcfm_list, &mirred_list);
+	spin_unlock_bh(&mirred_list_lock);
 
+	tcf_hash_replace(tn, a, n, bind);
 	return ret;
 }
 
-- 
2.1.0

  parent reply	other threads:[~2016-09-02  5:57 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-02  5:57 [RFC Patch net-next 0/6] net_sched: really switch to RCU for tc actions Cong Wang
2016-09-02  5:57 ` [RFC Patch net-next 1/6] net_sched: use RCU for action hash table Cong Wang
2016-09-06 12:47   ` Jamal Hadi Salim
2016-09-06 22:37     ` Cong Wang
2016-09-02  5:57 ` [RFC Patch net-next 2/6] net_sched: introduce tcf_hash_replace() Cong Wang
2016-09-06 12:52   ` Jamal Hadi Salim
2016-09-06 22:34     ` Cong Wang
2016-09-02  5:57 ` [RFC Patch net-next 3/6] net_sched: return NULL in tcf_hash_check() Cong Wang
2016-09-02  5:57 ` [RFC Patch net-next 4/6] net_sched: introduce tcf_hash_copy() Cong Wang
2016-09-02  5:57 ` [RFC Patch net-next 5/6] net_sched: use rcu in fast path Cong Wang
2016-09-06 14:52   ` Eric Dumazet
2016-09-08  6:04     ` John Fastabend
2016-09-08 13:28       ` Eric Dumazet
2016-09-08 15:35         ` [PATCH net] net_sched: act_mirred: full rcu conversion Eric Dumazet
2016-09-08 15:47           ` John Fastabend
2016-09-08 15:51             ` Eric Dumazet
2016-09-09  5:26               ` Cong Wang
2016-09-09 12:23                 ` Eric Dumazet
2016-09-09 15:52                 ` John Fastabend
2016-09-12  6:12                   ` Cong Wang
2016-09-12 15:34                     ` John Fastabend
2016-09-09  5:24           ` Cong Wang
2016-09-09  5:48             ` Alexei Starovoitov
2016-09-09  5:59               ` Cong Wang
2016-09-09 12:25                 ` Eric Dumazet
2016-09-09 12:23             ` Eric Dumazet
2016-09-12  5:46               ` Cong Wang
2016-09-08 15:49         ` [RFC Patch net-next 5/6] net_sched: use rcu in fast path John Fastabend
2016-09-09  5:54           ` Cong Wang
2016-09-09 15:25             ` John Fastabend
2016-09-09  5:49     ` Cong Wang
2016-09-02  5:57 ` Cong Wang [this message]
2016-09-02  7:09 ` [RFC Patch net-next 0/6] net_sched: really switch to RCU for tc actions Jiri Pirko
2016-09-02 19:44   ` Cong Wang
2016-09-07 16:23 ` John Fastabend
2016-09-08  6:05   ` John Fastabend
2016-09-09  5:22   ` Cong Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472795840-31901-7-git-send-email-xiyou.wangcong@gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).