diff options
| author | WANG Cong <xiyou.wangcong@gmail.com> | 2013-12-15 23:15:08 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2013-12-18 12:52:07 -0500 |
| commit | 369ba56787d7469c0afda70bb9ff76ad5faaead5 (patch) | |
| tree | 58425d3d564e3255c6660185bf22c80b76305ff5 | |
| parent | 5da57f422d89c504a1d72dadd4e19d3dca8e974e (diff) | |
net_sched: init struct tcf_hashinfo at register time
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>
| -rw-r--r-- | include/net/act_api.h | 18 | ||||
| -rw-r--r-- | net/sched/act_api.c | 16 | ||||
| -rw-r--r-- | net/sched/act_csum.c | 13 | ||||
| -rw-r--r-- | net/sched/act_gact.c | 13 | ||||
| -rw-r--r-- | net/sched/act_ipt.c | 21 | ||||
| -rw-r--r-- | net/sched/act_mirred.c | 16 | ||||
| -rw-r--r-- | net/sched/act_nat.c | 12 | ||||
| -rw-r--r-- | net/sched/act_pedit.c | 12 | ||||
| -rw-r--r-- | net/sched/act_police.c | 38 | ||||
| -rw-r--r-- | net/sched/act_simple.c | 20 | ||||
| -rw-r--r-- | net/sched/act_skbedit.c | 13 |
11 files changed, 97 insertions, 95 deletions
diff --git a/include/net/act_api.h b/include/net/act_api.h index a72642610790..2b5ec5abfeb3 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h | |||
| @@ -38,7 +38,7 @@ struct tcf_common { | |||
| 38 | struct tcf_hashinfo { | 38 | struct tcf_hashinfo { |
| 39 | struct tcf_common **htab; | 39 | struct tcf_common **htab; |
| 40 | unsigned int hmask; | 40 | unsigned int hmask; |
| 41 | rwlock_t *lock; | 41 | rwlock_t lock; |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | static inline unsigned int tcf_hash(u32 index, unsigned int hmask) | 44 | static inline unsigned int tcf_hash(u32 index, unsigned int hmask) |
| @@ -46,6 +46,22 @@ static inline unsigned int tcf_hash(u32 index, unsigned int hmask) | |||
| 46 | return index & hmask; | 46 | return index & hmask; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask) | ||
| 50 | { | ||
| 51 | rwlock_init(&hf->lock); | ||
| 52 | hf->hmask = mask; | ||
| 53 | hf->htab = kzalloc((mask + 1) * sizeof(struct tcf_common *), | ||
| 54 | GFP_KERNEL); | ||
| 55 | if (!hf->htab) | ||
| 56 | return -ENOMEM; | ||
| 57 | return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf) | ||
| 61 | { | ||
| 62 | kfree(hf->htab); | ||
| 63 | } | ||
| 64 | |||
| 49 | #ifdef CONFIG_NET_CLS_ACT | 65 | #ifdef CONFIG_NET_CLS_ACT |
| 50 | 66 | ||
| 51 | #define ACT_P_CREATED 1 | 67 | #define ACT_P_CREATED 1 |
diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 7d84183b633e..125673d5d877 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c | |||
| @@ -34,9 +34,9 @@ void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo) | |||
| 34 | 34 | ||
| 35 | for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) { | 35 | for (p1p = &hinfo->htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) { |
| 36 | if (*p1p == p) { | 36 | if (*p1p == p) { |
| 37 | write_lock_bh(hinfo->lock); | 37 | write_lock_bh(&hinfo->lock); |
| 38 | *p1p = p->tcfc_next; | 38 | *p1p = p->tcfc_next; |
| 39 | write_unlock_bh(hinfo->lock); | 39 | write_unlock_bh(&hinfo->lock); |
| 40 | gen_kill_estimator(&p->tcfc_bstats, | 40 | gen_kill_estimator(&p->tcfc_bstats, |
| 41 | &p->tcfc_rate_est); | 41 | &p->tcfc_rate_est); |
| 42 | /* | 42 | /* |
| @@ -77,7 +77,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb, | |||
| 77 | int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; | 77 | int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; |
| 78 | struct nlattr *nest; | 78 | struct nlattr *nest; |
| 79 | 79 | ||
| 80 | read_lock_bh(hinfo->lock); | 80 | read_lock_bh(&hinfo->lock); |
| 81 | 81 | ||
| 82 | s_i = cb->args[0]; | 82 | s_i = cb->args[0]; |
| 83 | 83 | ||
| @@ -107,7 +107,7 @@ static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb, | |||
| 107 | } | 107 | } |
| 108 | } | 108 | } |
| 109 | done: | 109 | done: |
| 110 | read_unlock_bh(hinfo->lock); | 110 | read_unlock_bh(&hinfo->lock); |
| 111 | if (n_i) | 111 | if (n_i) |
| 112 | cb->args[0] += n_i; | 112 | cb->args[0] += n_i; |
| 113 | return n_i; | 113 | return n_i; |
| @@ -170,13 +170,13 @@ struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo) | |||
| 170 | { | 170 | { |
| 171 | struct tcf_common *p; | 171 | struct tcf_common *p; |
| 172 | 172 | ||
| 173 | read_lock_bh(hinfo->lock); | 173 | read_lock_bh(&hinfo->lock); |
| 174 | for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p; | 174 | for (p = hinfo->htab[tcf_hash(index, hinfo->hmask)]; p; |
| 175 | p = p->tcfc_next) { | 175 | p = p->tcfc_next) { |
| 176 | if (p->tcfc_index == index) | 176 | if (p->tcfc_index == index) |
| 177 | break; | 177 | break; |
| 178 | } | 178 | } |
| 179 | read_unlock_bh(hinfo->lock); | 179 | read_unlock_bh(&hinfo->lock); |
| 180 | 180 | ||
| 181 | return p; | 181 | return p; |
| 182 | } | 182 | } |
| @@ -257,10 +257,10 @@ void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo) | |||
| 257 | { | 257 | { |
| 258 | unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask); | 258 | unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask); |
| 259 | 259 | ||
| 260 | write_lock_bh(hinfo->lock); | 260 | write_lock_bh(&hinfo->lock); |
| 261 | p->tcfc_next = hinfo->htab[h]; | 261 | p->tcfc_next = hinfo->htab[h]; |
| 262 | hinfo->htab[h] = p; | 262 | hinfo->htab[h] = p; |
| 263 | write_unlock_bh(hinfo->lock); | 263 | write_unlock_bh(&hinfo->lock); |
| 264 | } | 264 | } |
| 265 | EXPORT_SYMBOL(tcf_hash_insert); | 265 | EXPORT_SYMBOL(tcf_hash_insert); |
| 266 | 266 | ||
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c index 5c5edf56adbd..5d350c57af3f 100644 --- a/net/sched/act_csum.c +++ b/net/sched/act_csum.c | |||
| @@ -37,15 +37,8 @@ | |||
| 37 | #include <net/tc_act/tc_csum.h> | 37 | #include <net/tc_act/tc_csum.h> |
| 38 | 38 | ||
| 39 | #define CSUM_TAB_MASK 15 | 39 | #define CSUM_TAB_MASK 15 |
| 40 | static struct tcf_common *tcf_csum_ht[CSUM_TAB_MASK + 1]; | ||
| 41 | static u32 csum_idx_gen; | 40 | static u32 csum_idx_gen; |
| 42 | static DEFINE_RWLOCK(csum_lock); | 41 | static struct tcf_hashinfo csum_hash_info; |
| 43 | |||
| 44 | static struct tcf_hashinfo csum_hash_info = { | ||
| 45 | .htab = tcf_csum_ht, | ||
| 46 | .hmask = CSUM_TAB_MASK, | ||
| 47 | .lock = &csum_lock, | ||
| 48 | }; | ||
| 49 | 42 | ||
| 50 | static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { | 43 | static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { |
| 51 | [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, | 44 | [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, |
| @@ -593,6 +586,10 @@ MODULE_LICENSE("GPL"); | |||
| 593 | 586 | ||
| 594 | static int __init csum_init_module(void) | 587 | static int __init csum_init_module(void) |
| 595 | { | 588 | { |
| 589 | int err = tcf_hashinfo_init(&csum_hash_info, CSUM_TAB_MASK+1); | ||
| 590 | if (err) | ||
| 591 | return err; | ||
| 592 | |||
| 596 | return tcf_register_action(&act_csum_ops); | 593 | return tcf_register_action(&act_csum_ops); |
| 597 | } | 594 | } |
| 598 | 595 | ||
diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c index 5645a4d32abd..1e6e0e765243 100644 --- a/net/sched/act_gact.c +++ b/net/sched/act_gact.c | |||
| @@ -24,15 +24,8 @@ | |||
| 24 | #include <net/tc_act/tc_gact.h> | 24 | #include <net/tc_act/tc_gact.h> |
| 25 | 25 | ||
| 26 | #define GACT_TAB_MASK 15 | 26 | #define GACT_TAB_MASK 15 |
| 27 | static struct tcf_common *tcf_gact_ht[GACT_TAB_MASK + 1]; | ||
| 28 | static u32 gact_idx_gen; | 27 | static u32 gact_idx_gen; |
| 29 | static DEFINE_RWLOCK(gact_lock); | 28 | static struct tcf_hashinfo gact_hash_info; |
| 30 | |||
| 31 | static struct tcf_hashinfo gact_hash_info = { | ||
| 32 | .htab = tcf_gact_ht, | ||
| 33 | .hmask = GACT_TAB_MASK, | ||
| 34 | .lock = &gact_lock, | ||
| 35 | }; | ||
| 36 | 29 | ||
| 37 | #ifdef CONFIG_GACT_PROB | 30 | #ifdef CONFIG_GACT_PROB |
| 38 | static int gact_net_rand(struct tcf_gact *gact) | 31 | static int gact_net_rand(struct tcf_gact *gact) |
| @@ -215,6 +208,9 @@ MODULE_LICENSE("GPL"); | |||
| 215 | 208 | ||
| 216 | static int __init gact_init_module(void) | 209 | static int __init gact_init_module(void) |
| 217 | { | 210 | { |
| 211 | int err = tcf_hashinfo_init(&gact_hash_info, GACT_TAB_MASK+1); | ||
| 212 | if (err) | ||
| 213 | return err; | ||
| 218 | #ifdef CONFIG_GACT_PROB | 214 | #ifdef CONFIG_GACT_PROB |
| 219 | pr_info("GACT probability on\n"); | 215 | pr_info("GACT probability on\n"); |
| 220 | #else | 216 | #else |
| @@ -226,6 +222,7 @@ static int __init gact_init_module(void) | |||
| 226 | static void __exit gact_cleanup_module(void) | 222 | static void __exit gact_cleanup_module(void) |
| 227 | { | 223 | { |
| 228 | tcf_unregister_action(&act_gact_ops); | 224 | tcf_unregister_action(&act_gact_ops); |
| 225 | tcf_hashinfo_destroy(&gact_hash_info); | ||
| 229 | } | 226 | } |
| 230 | 227 | ||
| 231 | module_init(gact_init_module); | 228 | module_init(gact_init_module); |
diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index 882a89762f77..8344380ebaf1 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c | |||
| @@ -29,15 +29,8 @@ | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | #define IPT_TAB_MASK 15 | 31 | #define IPT_TAB_MASK 15 |
| 32 | static struct tcf_common *tcf_ipt_ht[IPT_TAB_MASK + 1]; | ||
| 33 | static u32 ipt_idx_gen; | 32 | static u32 ipt_idx_gen; |
| 34 | static DEFINE_RWLOCK(ipt_lock); | 33 | static struct tcf_hashinfo ipt_hash_info; |
| 35 | |||
| 36 | static struct tcf_hashinfo ipt_hash_info = { | ||
| 37 | .htab = tcf_ipt_ht, | ||
| 38 | .hmask = IPT_TAB_MASK, | ||
| 39 | .lock = &ipt_lock, | ||
| 40 | }; | ||
| 41 | 34 | ||
| 42 | static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook) | 35 | static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook) |
| 43 | { | 36 | { |
| @@ -320,7 +313,11 @@ MODULE_ALIAS("act_xt"); | |||
| 320 | 313 | ||
| 321 | static int __init ipt_init_module(void) | 314 | static int __init ipt_init_module(void) |
| 322 | { | 315 | { |
| 323 | int ret1, ret2; | 316 | int ret1, ret2, err; |
| 317 | err = tcf_hashinfo_init(&ipt_hash_info, IPT_TAB_MASK+1); | ||
| 318 | if (err) | ||
| 319 | return err; | ||
| 320 | |||
| 324 | ret1 = tcf_register_action(&act_xt_ops); | 321 | ret1 = tcf_register_action(&act_xt_ops); |
| 325 | if (ret1 < 0) | 322 | if (ret1 < 0) |
| 326 | printk("Failed to load xt action\n"); | 323 | printk("Failed to load xt action\n"); |
| @@ -328,9 +325,10 @@ static int __init ipt_init_module(void) | |||
| 328 | if (ret2 < 0) | 325 | if (ret2 < 0) |
| 329 | printk("Failed to load ipt action\n"); | 326 | printk("Failed to load ipt action\n"); |
| 330 | 327 | ||
| 331 | if (ret1 < 0 && ret2 < 0) | 328 | if (ret1 < 0 && ret2 < 0) { |
| 329 | tcf_hashinfo_destroy(&ipt_hash_info); | ||
| 332 | return ret1; | 330 | return ret1; |
| 333 | else | 331 | } else |
| 334 | return 0; | 332 | return 0; |
| 335 | } | 333 | } |
| 336 | 334 | ||
| @@ -338,6 +336,7 @@ static void __exit ipt_cleanup_module(void) | |||
| 338 | { | 336 | { |
| 339 | tcf_unregister_action(&act_xt_ops); | 337 | tcf_unregister_action(&act_xt_ops); |
| 340 | tcf_unregister_action(&act_ipt_ops); | 338 | tcf_unregister_action(&act_ipt_ops); |
| 339 | tcf_hashinfo_destroy(&ipt_hash_info); | ||
| 341 | } | 340 | } |
| 342 | 341 | ||
| 343 | module_init(ipt_init_module); | 342 | module_init(ipt_init_module); |
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c index 252378121ce7..199fc9838af3 100644 --- a/net/sched/act_mirred.c +++ b/net/sched/act_mirred.c | |||
| @@ -30,16 +30,9 @@ | |||
| 30 | #include <linux/if_arp.h> | 30 | #include <linux/if_arp.h> |
| 31 | 31 | ||
| 32 | #define MIRRED_TAB_MASK 7 | 32 | #define MIRRED_TAB_MASK 7 |
| 33 | static struct tcf_common *tcf_mirred_ht[MIRRED_TAB_MASK + 1]; | ||
| 34 | static u32 mirred_idx_gen; | 33 | static u32 mirred_idx_gen; |
| 35 | static DEFINE_RWLOCK(mirred_lock); | ||
| 36 | static LIST_HEAD(mirred_list); | 34 | static LIST_HEAD(mirred_list); |
| 37 | 35 | static struct tcf_hashinfo mirred_hash_info; | |
| 38 | static struct tcf_hashinfo mirred_hash_info = { | ||
| 39 | .htab = tcf_mirred_ht, | ||
| 40 | .hmask = MIRRED_TAB_MASK, | ||
| 41 | .lock = &mirred_lock, | ||
| 42 | }; | ||
| 43 | 36 | ||
| 44 | static int tcf_mirred_release(struct tcf_mirred *m, int bind) | 37 | static int tcf_mirred_release(struct tcf_mirred *m, int bind) |
| 45 | { | 38 | { |
| @@ -261,7 +254,6 @@ static struct notifier_block mirred_device_notifier = { | |||
| 261 | .notifier_call = mirred_device_event, | 254 | .notifier_call = mirred_device_event, |
| 262 | }; | 255 | }; |
| 263 | 256 | ||
| 264 | |||
| 265 | static struct tc_action_ops act_mirred_ops = { | 257 | static struct tc_action_ops act_mirred_ops = { |
| 266 | .kind = "mirred", | 258 | .kind = "mirred", |
| 267 | .hinfo = &mirred_hash_info, | 259 | .hinfo = &mirred_hash_info, |
| @@ -284,6 +276,11 @@ static int __init mirred_init_module(void) | |||
| 284 | if (err) | 276 | if (err) |
| 285 | return err; | 277 | return err; |
| 286 | 278 | ||
| 279 | err = tcf_hashinfo_init(&mirred_hash_info, MIRRED_TAB_MASK+1); | ||
| 280 | if (err) { | ||
| 281 | unregister_netdevice_notifier(&mirred_device_notifier); | ||
| 282 | return err; | ||
| 283 | } | ||
| 287 | pr_info("Mirror/redirect action on\n"); | 284 | pr_info("Mirror/redirect action on\n"); |
| 288 | return tcf_register_action(&act_mirred_ops); | 285 | return tcf_register_action(&act_mirred_ops); |
| 289 | } | 286 | } |
| @@ -291,6 +288,7 @@ static int __init mirred_init_module(void) | |||
| 291 | static void __exit mirred_cleanup_module(void) | 288 | static void __exit mirred_cleanup_module(void) |
| 292 | { | 289 | { |
| 293 | unregister_netdevice_notifier(&mirred_device_notifier); | 290 | unregister_netdevice_notifier(&mirred_device_notifier); |
| 291 | tcf_hashinfo_destroy(&mirred_hash_info); | ||
| 294 | tcf_unregister_action(&act_mirred_ops); | 292 | tcf_unregister_action(&act_mirred_ops); |
| 295 | } | 293 | } |
| 296 | 294 | ||
diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c index 6a15ace00241..409fe7181c5f 100644 --- a/net/sched/act_nat.c +++ b/net/sched/act_nat.c | |||
| @@ -30,15 +30,9 @@ | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | #define NAT_TAB_MASK 15 | 32 | #define NAT_TAB_MASK 15 |
| 33 | static struct tcf_common *tcf_nat_ht[NAT_TAB_MASK + 1]; | ||
| 34 | static u32 nat_idx_gen; | 33 | static u32 nat_idx_gen; |
| 35 | static DEFINE_RWLOCK(nat_lock); | ||
| 36 | 34 | ||
| 37 | static struct tcf_hashinfo nat_hash_info = { | 35 | static struct tcf_hashinfo nat_hash_info; |
| 38 | .htab = tcf_nat_ht, | ||
| 39 | .hmask = NAT_TAB_MASK, | ||
| 40 | .lock = &nat_lock, | ||
| 41 | }; | ||
| 42 | 36 | ||
| 43 | static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = { | 37 | static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = { |
| 44 | [TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) }, | 38 | [TCA_NAT_PARMS] = { .len = sizeof(struct tc_nat) }, |
| @@ -316,12 +310,16 @@ MODULE_LICENSE("GPL"); | |||
| 316 | 310 | ||
| 317 | static int __init nat_init_module(void) | 311 | static int __init nat_init_module(void) |
| 318 | { | 312 | { |
| 313 | int err = tcf_hashinfo_init(&nat_hash_info, NAT_TAB_MASK+1); | ||
| 314 | if (err) | ||
| 315 | return err; | ||
| 319 | return tcf_register_action(&act_nat_ops); | 316 | return tcf_register_action(&act_nat_ops); |
| 320 | } | 317 | } |
| 321 | 318 | ||
| 322 | static void __exit nat_cleanup_module(void) | 319 | static void __exit nat_cleanup_module(void) |
| 323 | { | 320 | { |
| 324 | tcf_unregister_action(&act_nat_ops); | 321 | tcf_unregister_action(&act_nat_ops); |
| 322 | tcf_hashinfo_destroy(&nat_hash_info); | ||
| 325 | } | 323 | } |
| 326 | 324 | ||
| 327 | module_init(nat_init_module); | 325 | module_init(nat_init_module); |
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 03b67674169c..aa5347c1b9f1 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c | |||
| @@ -24,15 +24,9 @@ | |||
| 24 | #include <net/tc_act/tc_pedit.h> | 24 | #include <net/tc_act/tc_pedit.h> |
| 25 | 25 | ||
| 26 | #define PEDIT_TAB_MASK 15 | 26 | #define PEDIT_TAB_MASK 15 |
| 27 | static struct tcf_common *tcf_pedit_ht[PEDIT_TAB_MASK + 1]; | ||
| 28 | static u32 pedit_idx_gen; | 27 | static u32 pedit_idx_gen; |
| 29 | static DEFINE_RWLOCK(pedit_lock); | ||
| 30 | 28 | ||
| 31 | static struct tcf_hashinfo pedit_hash_info = { | 29 | static struct tcf_hashinfo pedit_hash_info; |
| 32 | .htab = tcf_pedit_ht, | ||
| 33 | .hmask = PEDIT_TAB_MASK, | ||
| 34 | .lock = &pedit_lock, | ||
| 35 | }; | ||
| 36 | 30 | ||
| 37 | static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = { | 31 | static const struct nla_policy pedit_policy[TCA_PEDIT_MAX + 1] = { |
| 38 | [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) }, | 32 | [TCA_PEDIT_PARMS] = { .len = sizeof(struct tc_pedit) }, |
| @@ -252,11 +246,15 @@ MODULE_LICENSE("GPL"); | |||
| 252 | 246 | ||
| 253 | static int __init pedit_init_module(void) | 247 | static int __init pedit_init_module(void) |
| 254 | { | 248 | { |
| 249 | int err = tcf_hashinfo_init(&pedit_hash_info, PEDIT_TAB_MASK+1); | ||
| 250 | if (err) | ||
| 251 | return err; | ||
| 255 | return tcf_register_action(&act_pedit_ops); | 252 | return tcf_register_action(&act_pedit_ops); |
| 256 | } | 253 | } |
| 257 | 254 | ||
| 258 | static void __exit pedit_cleanup_module(void) | 255 | static void __exit pedit_cleanup_module(void) |
| 259 | { | 256 | { |
| 257 | tcf_hashinfo_destroy(&pedit_hash_info); | ||
| 260 | tcf_unregister_action(&act_pedit_ops); | 258 | tcf_unregister_action(&act_pedit_ops); |
| 261 | } | 259 | } |
| 262 | 260 | ||
diff --git a/net/sched/act_police.c b/net/sched/act_police.c index 16a62c36928a..f201576d25c2 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c | |||
| @@ -41,15 +41,8 @@ struct tcf_police { | |||
| 41 | container_of(pc, struct tcf_police, common) | 41 | container_of(pc, struct tcf_police, common) |
| 42 | 42 | ||
| 43 | #define POL_TAB_MASK 15 | 43 | #define POL_TAB_MASK 15 |
| 44 | static struct tcf_common *tcf_police_ht[POL_TAB_MASK + 1]; | ||
| 45 | static u32 police_idx_gen; | 44 | static u32 police_idx_gen; |
| 46 | static DEFINE_RWLOCK(police_lock); | 45 | static struct tcf_hashinfo police_hash_info; |
| 47 | |||
| 48 | static struct tcf_hashinfo police_hash_info = { | ||
| 49 | .htab = tcf_police_ht, | ||
| 50 | .hmask = POL_TAB_MASK, | ||
| 51 | .lock = &police_lock, | ||
| 52 | }; | ||
| 53 | 46 | ||
| 54 | /* old policer structure from before tc actions */ | 47 | /* old policer structure from before tc actions */ |
| 55 | struct tc_police_compat { | 48 | struct tc_police_compat { |
| @@ -71,12 +64,12 @@ static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *c | |||
| 71 | int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; | 64 | int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; |
| 72 | struct nlattr *nest; | 65 | struct nlattr *nest; |
| 73 | 66 | ||
| 74 | read_lock_bh(&police_lock); | 67 | read_lock_bh(&police_hash_info.lock); |
| 75 | 68 | ||
| 76 | s_i = cb->args[0]; | 69 | s_i = cb->args[0]; |
| 77 | 70 | ||
| 78 | for (i = 0; i < (POL_TAB_MASK + 1); i++) { | 71 | for (i = 0; i < (POL_TAB_MASK + 1); i++) { |
| 79 | p = tcf_police_ht[tcf_hash(i, POL_TAB_MASK)]; | 72 | p = police_hash_info.htab[tcf_hash(i, POL_TAB_MASK)]; |
| 80 | 73 | ||
| 81 | for (; p; p = p->tcfc_next) { | 74 | for (; p; p = p->tcfc_next) { |
| 82 | index++; | 75 | index++; |
| @@ -101,7 +94,7 @@ static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *c | |||
| 101 | } | 94 | } |
| 102 | } | 95 | } |
| 103 | done: | 96 | done: |
| 104 | read_unlock_bh(&police_lock); | 97 | read_unlock_bh(&police_hash_info.lock); |
| 105 | if (n_i) | 98 | if (n_i) |
| 106 | cb->args[0] += n_i; | 99 | cb->args[0] += n_i; |
| 107 | return n_i; | 100 | return n_i; |
| @@ -116,11 +109,11 @@ static void tcf_police_destroy(struct tcf_police *p) | |||
| 116 | unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK); | 109 | unsigned int h = tcf_hash(p->tcf_index, POL_TAB_MASK); |
| 117 | struct tcf_common **p1p; | 110 | struct tcf_common **p1p; |
| 118 | 111 | ||
| 119 | for (p1p = &tcf_police_ht[h]; *p1p; p1p = &(*p1p)->tcfc_next) { | 112 | for (p1p = &police_hash_info.htab[h]; *p1p; p1p = &(*p1p)->tcfc_next) { |
| 120 | if (*p1p == &p->common) { | 113 | if (*p1p == &p->common) { |
| 121 | write_lock_bh(&police_lock); | 114 | write_lock_bh(&police_hash_info.lock); |
| 122 | *p1p = p->tcf_next; | 115 | *p1p = p->tcf_next; |
| 123 | write_unlock_bh(&police_lock); | 116 | write_unlock_bh(&police_hash_info.lock); |
| 124 | gen_kill_estimator(&p->tcf_bstats, | 117 | gen_kill_estimator(&p->tcf_bstats, |
| 125 | &p->tcf_rate_est); | 118 | &p->tcf_rate_est); |
| 126 | /* | 119 | /* |
| @@ -266,10 +259,10 @@ override: | |||
| 266 | police->tcf_index = parm->index ? parm->index : | 259 | police->tcf_index = parm->index ? parm->index : |
| 267 | tcf_hash_new_index(&police_idx_gen, &police_hash_info); | 260 | tcf_hash_new_index(&police_idx_gen, &police_hash_info); |
| 268 | h = tcf_hash(police->tcf_index, POL_TAB_MASK); | 261 | h = tcf_hash(police->tcf_index, POL_TAB_MASK); |
| 269 | write_lock_bh(&police_lock); | 262 | write_lock_bh(&police_hash_info.lock); |
| 270 | police->tcf_next = tcf_police_ht[h]; | 263 | police->tcf_next = police_hash_info.htab[h]; |
| 271 | tcf_police_ht[h] = &police->common; | 264 | police_hash_info.htab[h] = &police->common; |
| 272 | write_unlock_bh(&police_lock); | 265 | write_unlock_bh(&police_hash_info.lock); |
| 273 | 266 | ||
| 274 | a->priv = police; | 267 | a->priv = police; |
| 275 | return ret; | 268 | return ret; |
| @@ -414,12 +407,19 @@ static struct tc_action_ops act_police_ops = { | |||
| 414 | static int __init | 407 | static int __init |
| 415 | police_init_module(void) | 408 | police_init_module(void) |
| 416 | { | 409 | { |
| 417 | return tcf_register_action(&act_police_ops); | 410 | int err = tcf_hashinfo_init(&police_hash_info, POL_TAB_MASK+1); |
| 411 | if (err) | ||
| 412 | return err; | ||
| 413 | err = tcf_register_action(&act_police_ops); | ||
| 414 | if (err) | ||
| 415 | tcf_hashinfo_destroy(&police_hash_info); | ||
| 416 | return err; | ||
| 418 | } | 417 | } |
| 419 | 418 | ||
| 420 | static void __exit | 419 | static void __exit |
| 421 | police_cleanup_module(void) | 420 | police_cleanup_module(void) |
| 422 | { | 421 | { |
| 422 | tcf_hashinfo_destroy(&police_hash_info); | ||
| 423 | tcf_unregister_action(&act_police_ops); | 423 | tcf_unregister_action(&act_police_ops); |
| 424 | } | 424 | } |
| 425 | 425 | ||
diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c index 31157d3e729c..2d7a0eb11c69 100644 --- a/net/sched/act_simple.c +++ b/net/sched/act_simple.c | |||
| @@ -25,15 +25,8 @@ | |||
| 25 | #include <net/tc_act/tc_defact.h> | 25 | #include <net/tc_act/tc_defact.h> |
| 26 | 26 | ||
| 27 | #define SIMP_TAB_MASK 7 | 27 | #define SIMP_TAB_MASK 7 |
| 28 | static struct tcf_common *tcf_simp_ht[SIMP_TAB_MASK + 1]; | ||
| 29 | static u32 simp_idx_gen; | 28 | static u32 simp_idx_gen; |
| 30 | static DEFINE_RWLOCK(simp_lock); | 29 | static struct tcf_hashinfo simp_hash_info; |
| 31 | |||
| 32 | static struct tcf_hashinfo simp_hash_info = { | ||
| 33 | .htab = tcf_simp_ht, | ||
| 34 | .hmask = SIMP_TAB_MASK, | ||
| 35 | .lock = &simp_lock, | ||
| 36 | }; | ||
| 37 | 30 | ||
| 38 | #define SIMP_MAX_DATA 32 | 31 | #define SIMP_MAX_DATA 32 |
| 39 | static int tcf_simp(struct sk_buff *skb, const struct tc_action *a, | 32 | static int tcf_simp(struct sk_buff *skb, const struct tc_action *a, |
| @@ -209,14 +202,23 @@ MODULE_LICENSE("GPL"); | |||
| 209 | 202 | ||
| 210 | static int __init simp_init_module(void) | 203 | static int __init simp_init_module(void) |
| 211 | { | 204 | { |
| 212 | int ret = tcf_register_action(&act_simp_ops); | 205 | int err, ret; |
| 206 | err = tcf_hashinfo_init(&simp_hash_info, SIMP_TAB_MASK+1); | ||
| 207 | if (err) | ||
| 208 | return err; | ||
| 209 | |||
| 210 | ret = tcf_register_action(&act_simp_ops); | ||
| 213 | if (!ret) | 211 | if (!ret) |
| 214 | pr_info("Simple TC action Loaded\n"); | 212 | pr_info("Simple TC action Loaded\n"); |
| 213 | else | ||
| 214 | tcf_hashinfo_destroy(&simp_hash_info); | ||
| 215 | |||
| 215 | return ret; | 216 | return ret; |
| 216 | } | 217 | } |
| 217 | 218 | ||
| 218 | static void __exit simp_cleanup_module(void) | 219 | static void __exit simp_cleanup_module(void) |
| 219 | { | 220 | { |
| 221 | tcf_hashinfo_destroy(&simp_hash_info); | ||
| 220 | tcf_unregister_action(&act_simp_ops); | 222 | tcf_unregister_action(&act_simp_ops); |
| 221 | } | 223 | } |
| 222 | 224 | ||
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c index cf20add1c3ff..90ed04a83cf3 100644 --- a/net/sched/act_skbedit.c +++ b/net/sched/act_skbedit.c | |||
| @@ -28,15 +28,8 @@ | |||
| 28 | #include <net/tc_act/tc_skbedit.h> | 28 | #include <net/tc_act/tc_skbedit.h> |
| 29 | 29 | ||
| 30 | #define SKBEDIT_TAB_MASK 15 | 30 | #define SKBEDIT_TAB_MASK 15 |
| 31 | static struct tcf_common *tcf_skbedit_ht[SKBEDIT_TAB_MASK + 1]; | ||
| 32 | static u32 skbedit_idx_gen; | 31 | static u32 skbedit_idx_gen; |
| 33 | static DEFINE_RWLOCK(skbedit_lock); | 32 | static struct tcf_hashinfo skbedit_hash_info; |
| 34 | |||
| 35 | static struct tcf_hashinfo skbedit_hash_info = { | ||
| 36 | .htab = tcf_skbedit_ht, | ||
| 37 | .hmask = SKBEDIT_TAB_MASK, | ||
| 38 | .lock = &skbedit_lock, | ||
| 39 | }; | ||
| 40 | 33 | ||
| 41 | static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a, | 34 | static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a, |
| 42 | struct tcf_result *res) | 35 | struct tcf_result *res) |
| @@ -210,11 +203,15 @@ MODULE_LICENSE("GPL"); | |||
| 210 | 203 | ||
| 211 | static int __init skbedit_init_module(void) | 204 | static int __init skbedit_init_module(void) |
| 212 | { | 205 | { |
| 206 | int err = tcf_hashinfo_init(&skbedit_hash_info, SKBEDIT_TAB_MASK+1); | ||
| 207 | if (err) | ||
| 208 | return err; | ||
| 213 | return tcf_register_action(&act_skbedit_ops); | 209 | return tcf_register_action(&act_skbedit_ops); |
| 214 | } | 210 | } |
| 215 | 211 | ||
| 216 | static void __exit skbedit_cleanup_module(void) | 212 | static void __exit skbedit_cleanup_module(void) |
| 217 | { | 213 | { |
| 214 | tcf_hashinfo_destroy(&skbedit_hash_info); | ||
| 218 | tcf_unregister_action(&act_skbedit_ops); | 215 | tcf_unregister_action(&act_skbedit_ops); |
| 219 | } | 216 | } |
| 220 | 217 | ||
