diff mbox

[RFC,net-next,2/6] net_sched: introduce tcf_hash_replace()

Message ID 1472795840-31901-3-git-send-email-xiyou.wangcong@gmail.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Cong Wang Sept. 2, 2016, 5:57 a.m. UTC
This API is used to replace the old action in hash table
with the new one. It is used by the following patch.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 include/net/act_api.h |  2 ++
 net/sched/act_api.c   | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

Comments

Jamal Hadi Salim Sept. 6, 2016, 12:52 p.m. UTC | #1
On 16-09-02 01:57 AM, Cong Wang wrote:

> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  include/net/act_api.h |  2 ++
>  net/sched/act_api.c   | 20 ++++++++++++++++++++
>  2 files changed, 22 insertions(+)
>
> diff --git a/include/net/act_api.h b/include/net/act_api.h
> index 82f3c91..a374bab 100644
> --- a/include/net/act_api.h

>
> +void tcf_hash_replace(struct tc_action_net *tn, struct tc_action **old,
> +		      struct tc_action *new, int bind)
> +{
> +	struct tcf_hashinfo *hinfo = tn->hinfo;
> +	unsigned int h = tcf_hash(new->tcfa_index, hinfo->hmask);
> +

WWhy do you need to recreate the index?
Old index was fine since this is just a replacement..

The rest of the patches seem fine - will let Eric comment on the
mirred.

Note: I am going to still push forward with skbmod action and I think
so should the new tunnel action code i.e we make them independent.
I'd like to switch to this when we think it is stable.

cheers,
jamal
Cong Wang Sept. 6, 2016, 10:34 p.m. UTC | #2
On Tue, Sep 6, 2016 at 5:52 AM, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> On 16-09-02 01:57 AM, Cong Wang wrote:
>
>> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
>> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
>> ---
>>  include/net/act_api.h |  2 ++
>>  net/sched/act_api.c   | 20 ++++++++++++++++++++
>>  2 files changed, 22 insertions(+)
>>
>> diff --git a/include/net/act_api.h b/include/net/act_api.h
>> index 82f3c91..a374bab 100644
>> --- a/include/net/act_api.h
>
>
>>
>> +void tcf_hash_replace(struct tc_action_net *tn, struct tc_action **old,
>> +                     struct tc_action *new, int bind)
>> +{
>> +       struct tcf_hashinfo *hinfo = tn->hinfo;
>> +       unsigned int h = tcf_hash(new->tcfa_index, hinfo->hmask);
>> +
>
>
> WWhy do you need to recreate the index?
> Old index was fine since this is just a replacement..

A new index is possible created by tcf_hash_create(), but later
overwritten by tcf_hash_copy(). I know this is a bit ugly, so
feel free to suggest any better API here.


>
> The rest of the patches seem fine - will let Eric comment on the
> mirred.
>
> Note: I am going to still push forward with skbmod action and I think
> so should the new tunnel action code i.e we make them independent.
> I'd like to switch to this when we think it is stable.

You don't have to rebase or change, I will take care of it because they
will probably be merged before this patchset. At least I can hold on
this for a while to let that happen. ;)

Thanks.
diff mbox

Patch

diff --git a/include/net/act_api.h b/include/net/act_api.h
index 82f3c91..a374bab 100644
--- a/include/net/act_api.h
+++ b/include/net/act_api.h
@@ -164,6 +164,8 @@  int tcf_hash_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
 		    bool cpustats);
 void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
 void tcf_hash_insert(struct tc_action_net *tn, struct tc_action *a);
+void tcf_hash_replace(struct tc_action_net *tn, struct tc_action **old,
+		      struct tc_action *new, int bind);
 
 int __tcf_hash_release(struct tc_action *a, bool bind, bool strict);
 
diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 06111aa..db907e5 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -306,6 +306,26 @@  void tcf_hash_insert(struct tc_action_net *tn, struct tc_action *a)
 }
 EXPORT_SYMBOL(tcf_hash_insert);
 
+void tcf_hash_replace(struct tc_action_net *tn, struct tc_action **old,
+		      struct tc_action *new, int bind)
+{
+	struct tcf_hashinfo *hinfo = tn->hinfo;
+	unsigned int h = tcf_hash(new->tcfa_index, hinfo->hmask);
+
+	spin_lock_bh(&hinfo->lock);
+	if (*old)
+		hlist_replace_rcu(&(*old)->tcfa_head, &new->tcfa_head);
+	else
+		hlist_add_head_rcu(&new->tcfa_head, &hinfo->htab[h]);
+	spin_unlock_bh(&hinfo->lock);
+
+	if (*old)
+		tcf_hash_release(*old, bind);
+
+	rcu_assign_pointer(*old, new);
+}
+EXPORT_SYMBOL(tcf_hash_replace);
+
 void tcf_hashinfo_destroy(const struct tc_action_ops *ops,
 			  struct tcf_hashinfo *hinfo)
 {