Skip to content

Commit

Permalink
net_sched: init struct tcf_hashinfo at register time
Browse files Browse the repository at this point in the history
It looks weird to store the lock out of the struct but
still points to a static variable. Just move them into the struct.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
WANG Cong authored and David S. Miller committed Dec 18, 2013
1 parent 5da57f4 commit 369ba56
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 95 deletions.
18 changes: 17 additions & 1 deletion include/net/act_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,30 @@ struct tcf_common {
struct tcf_hashinfo {
struct tcf_common **htab;
unsigned int hmask;
rwlock_t *lock;
rwlock_t lock;
};

static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
{
return index & hmask;
}

static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
{
rwlock_init(&hf->lock);
hf->hmask = mask;
hf->htab = kzalloc((mask + 1) * sizeof(struct tcf_common *),
GFP_KERNEL);
if (!hf->htab)
return -ENOMEM;
return 0;
}

static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf)
{
kfree(hf->htab);
}

#ifdef CONFIG_NET_CLS_ACT

#define ACT_P_CREATED 1
Expand Down
16 changes: 8 additions & 8 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)

for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) {
if (*p1p == p) {
write_lock_bh(hinfo->lock);
write_lock_bh(&hinfo->lock);
*p1p = p->tcfc_next;
write_unlock_bh(hinfo->lock);
write_unlock_bh(&hinfo->lock);
gen_kill_estimator(&p->tcfc_bstats,
&p->tcfc_rate_est);
/*
Expand Down Expand Up @@ -77,7 +77,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
int err = 0, index = -1, i = 0, s_i = 0, n_i = 0;
struct nlattr *nest;

read_lock_bh(hinfo->lock);
read_lock_bh(&hinfo->lock);

s_i = cb->args[0];

Expand Down Expand Up @@ -107,7 +107,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
}
}
done:
read_unlock_bh(hinfo->lock);
read_unlock_bh(&hinfo->lock);
if (n_i)
cb->args[0] += n_i;
return n_i;
Expand Down Expand Up @@ -170,13 +170,13 @@ struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
{
struct tcf_common *p;

read_lock_bh(hinfo->lock);
read_lock_bh(&hinfo->lock);
for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p;
p = p->tcfc_next) {
if (p->tcfc_index == index)
break;
}
read_unlock_bh(hinfo->lock);
read_unlock_bh(&hinfo->lock);

return p;
}
Expand Down Expand Up @@ -257,10 +257,10 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
{
unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);

write_lock_bh(hinfo->lock);
write_lock_bh(&hinfo->lock);
p->tcfc_next = hinfo->htab[h];
hinfo->htab[h] = p;
write_unlock_bh(hinfo->lock);
write_unlock_bh(&hinfo->lock);
}
EXPORT_SYMBOL(tcf_hash_insert);

Expand Down
13 changes: 5 additions & 8 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,8 @@
#include <net/tc_act/tc_csum.h>

#define CSUM_TAB_MASK 15
static struct tcf_common *tcf_csum_ht[CSUM_TAB_MASK + 1];
static u32 csum_idx_gen;
static DEFINE_RWLOCK(csum_lock);

static struct tcf_hashinfo csum_hash_info = {
.htab = tcf_csum_ht,
.hmask = CSUM_TAB_MASK,
.lock = &csum_lock,
};
static struct tcf_hashinfo csum_hash_info;

static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
[TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), },
Expand Down Expand Up @@ -593,6 +586,10 @@ MODULE_LICENSE("GPL");

static int __init csum_init_module(void)
{
int err = tcf_hashinfo_init(&csum_hash_info, CSUM_TAB_MASK+1);
if (err)
return err;

return tcf_register_action(&act_csum_ops);
}

Expand Down
13 changes: 5 additions & 8 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@
#include <net/tc_act/tc_gact.h>

#define GACT_TAB_MASK 15
static struct tcf_common *tcf_gact_ht[GACT_TAB_MASK + 1];
static u32 gact_idx_gen;
static DEFINE_RWLOCK(gact_lock);

static struct tcf_hashinfo gact_hash_info = {
.htab = tcf_gact_ht,
.hmask = GACT_TAB_MASK,
.lock = &gact_lock,
};
static struct tcf_hashinfo gact_hash_info;

#ifdef CONFIG_GACT_PROB
static int gact_net_rand(struct tcf_gact *gact)
Expand Down Expand Up @@ -215,6 +208,9 @@ MODULE_LICENSE("GPL");

static int __init gact_init_module(void)
{
int err = tcf_hashinfo_init(&gact_hash_info, GACT_TAB_MASK+1);
if (err)
return err;
#ifdef CONFIG_GACT_PROB
pr_info("GACT probability on\n");
#else
Expand All @@ -226,6 +222,7 @@ static int __init gact_init_module(void)
static void __exit gact_cleanup_module(void)
{
tcf_unregister_action(&act_gact_ops);
tcf_hashinfo_destroy(&gact_hash_info);
}

module_init(gact_init_module);
Expand Down
21 changes: 10 additions & 11 deletions net/sched/act_ipt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@


#define IPT_TAB_MASK 15
static struct tcf_common *tcf_ipt_ht[IPT_TAB_MASK + 1];
static u32 ipt_idx_gen;
static DEFINE_RWLOCK(ipt_lock);

static struct tcf_hashinfo ipt_hash_info = {
.htab = tcf_ipt_ht,
.hmask = IPT_TAB_MASK,
.lock = &ipt_lock,
};
static struct tcf_hashinfo ipt_hash_info;

static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook)
{
Expand Down Expand Up @@ -320,24 +313,30 @@ MODULE_ALIAS("act_xt");

static int __init ipt_init_module(void)
{
int ret1, ret2;
int ret1, ret2, err;
err = tcf_hashinfo_init(&ipt_hash_info, IPT_TAB_MASK+1);
if (err)
return err;

ret1 = tcf_register_action(&act_xt_ops);
if (ret1 < 0)
printk("Failed to load xt action\n");
ret2 = tcf_register_action(&act_ipt_ops);
if (ret2 < 0)
printk("Failed to load ipt action\n");

if (ret1 < 0 && ret2 < 0)
if (ret1 < 0 && ret2 < 0) {
tcf_hashinfo_destroy(&ipt_hash_info);
return ret1;
else
} else
return 0;
}

static void __exit ipt_cleanup_module(void)
{
tcf_unregister_action(&act_xt_ops);
tcf_unregister_action(&act_ipt_ops);
tcf_hashinfo_destroy(&ipt_hash_info);
}

module_init(ipt_init_module);
Expand Down
16 changes: 7 additions & 9 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,9 @@
#include <linux/if_arp.h>

#define MIRRED_TAB_MASK 7
static struct tcf_common *tcf_mirred_ht[MIRRED_TAB_MASK + 1];
static u32 mirred_idx_gen;
static DEFINE_RWLOCK(mirred_lock);
static LIST_HEAD(mirred_list);

static struct tcf_hashinfo mirred_hash_info = {
.htab = tcf_mirred_ht,
.hmask = MIRRED_TAB_MASK,
.lock = &mirred_lock,
};
static struct tcf_hashinfo mirred_hash_info;

static int tcf_mirred_release(struct tcf_mirred *m, int bind)
{
Expand Down Expand Up @@ -261,7 +254,6 @@ static struct notifier_block mirred_device_notifier = {
.notifier_call = mirred_device_event,
};


static struct tc_action_ops act_mirred_ops = {
.kind = "mirred",
.hinfo = &mirred_hash_info,
Expand All @@ -284,13 +276,19 @@ static int __init mirred_init_module(void)
if (err)
return err;

err = tcf_hashinfo_init(&mirred_hash_info, MIRRED_TAB_MASK+1);
if (err) {
unregister_netdevice_notifier(&mirred_device_notifier);
return err;
}
pr_info("Mirror/redirect action on\n");
return tcf_register_action(&act_mirred_ops);
}

static void __exit mirred_cleanup_module(void)
{
unregister_netdevice_notifier(&mirred_device_notifier);
tcf_hashinfo_destroy(&mirred_hash_info);
tcf_unregister_action(&act_mirred_ops);
}

Expand Down
12 changes: 5 additions & 7 deletions net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@


#define NAT_TAB_MASK 15
static struct tcf_common *tcf_nat_ht[NAT_TAB_MASK + 1];
static u32 nat_idx_gen;
static DEFINE_RWLOCK(nat_lock);

static struct tcf_hashinfo nat_hash_info = {
.htab = tcf_nat_ht,
.hmask = NAT_TAB_MASK,
.lock = &nat_lock,
};
static struct tcf_hashinfo nat_hash_info;

static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = {
[TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) },
Expand Down Expand Up @@ -316,12 +310,16 @@ MODULE_LICENSE("GPL");

static int __init nat_init_module(void)
{
int err = tcf_hashinfo_init(&nat_hash_info, NAT_TAB_MASK+1);
if (err)
return err;
return tcf_register_action(&act_nat_ops);
}

static void __exit nat_cleanup_module(void)
{
tcf_unregister_action(&act_nat_ops);
tcf_hashinfo_destroy(&nat_hash_info);
}

module_init(nat_init_module);
Expand Down
12 changes: 5 additions & 7 deletions net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@
#include <net/tc_act/tc_pedit.h>

#define PEDIT_TAB_MASK 15
static struct tcf_common *tcf_pedit_ht[PEDIT_TAB_MASK + 1];
static u32 pedit_idx_gen;
static DEFINE_RWLOCK(pedit_lock);

static struct tcf_hashinfo pedit_hash_info = {
.htab = tcf_pedit_ht,
.hmask = PEDIT_TAB_MASK,
.lock = &pedit_lock,
};
static struct tcf_hashinfo pedit_hash_info;

static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = {
[TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) },
Expand Down Expand Up @@ -252,11 +246,15 @@ MODULE_LICENSE("GPL");

static int __init pedit_init_module(void)
{
int err = tcf_hashinfo_init(&pedit_hash_info, PEDIT_TAB_MASK+1);
if (err)
return err;
return tcf_register_action(&act_pedit_ops);
}

static void __exit pedit_cleanup_module(void)
{
tcf_hashinfo_destroy(&pedit_hash_info);
tcf_unregister_action(&act_pedit_ops);
}

Expand Down
Loading

0 comments on commit 369ba56

Please sign in to comment.