Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 369ba567 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller
Browse files

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: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5da57f42
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ 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)
@@ -46,6 +46,22 @@ 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
+8 −8
Original line number Diff line number Diff line
@@ -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);
			/*
@@ -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];

@@ -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;
@@ -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;
}
@@ -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);

+5 −8
Original line number Diff line number Diff line
@@ -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), },
@@ -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);
}

+5 −8
Original line number Diff line number Diff line
@@ -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)
@@ -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
@@ -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);
+10 −11
Original line number Diff line number Diff line
@@ -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)
{
@@ -320,7 +313,11 @@ 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");
@@ -328,9 +325,10 @@ static int __init ipt_init_module(void)
	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;
}

@@ -338,6 +336,7 @@ 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);
Loading