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

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

net_sched: act: move idx_gen into struct tcf_hashinfo



There is no need to store the index separatedly
since tcf_hashinfo is allocated statically too.

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 600adc18
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ struct tcf_hashinfo {
	struct hlist_head	*htab;
	struct hlist_head	*htab;
	unsigned int		hmask;
	unsigned int		hmask;
	spinlock_t		lock;
	spinlock_t		lock;
	u32			index;
};
};


static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
@@ -51,6 +52,7 @@ static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
	int i;
	int i;


	spin_lock_init(&hf->lock);
	spin_lock_init(&hf->lock);
	hf->index = 0;
	hf->hmask = mask;
	hf->hmask = mask;
	hf->htab = kzalloc((mask + 1) * sizeof(struct hlist_head),
	hf->htab = kzalloc((mask + 1) * sizeof(struct hlist_head),
			   GFP_KERNEL);
			   GFP_KERNEL);
@@ -105,13 +107,12 @@ struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo);
void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo);
void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo);
int tcf_hash_release(struct tcf_common *p, int bind,
int tcf_hash_release(struct tcf_common *p, int bind,
		     struct tcf_hashinfo *hinfo);
		     struct tcf_hashinfo *hinfo);
u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo);
u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a,
struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a,
				  int bind, struct tcf_hashinfo *hinfo);
				  int bind, struct tcf_hashinfo *hinfo);
struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
				   struct tc_action *a, int size,
				   struct tc_action *a, int size,
				   int bind, u32 *idx_gen,
				   int bind, struct tcf_hashinfo *hinfo);
				   struct tcf_hashinfo *hinfo);
void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo);
void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo);


int tcf_register_action(struct tc_action_ops *a);
int tcf_register_action(struct tc_action_ops *a);
+5 −5
Original line number Original line Diff line number Diff line
@@ -173,16 +173,16 @@ struct tcf_common *tcf_hash_lookup(u32 index, struct tcf_hashinfo *hinfo)
}
}
EXPORT_SYMBOL(tcf_hash_lookup);
EXPORT_SYMBOL(tcf_hash_lookup);


u32 tcf_hash_new_index(u32 *idx_gen, struct tcf_hashinfo *hinfo)
u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo)
{
{
	u32 val = *idx_gen;
	u32 val = hinfo->index;


	do {
	do {
		if (++val == 0)
		if (++val == 0)
			val = 1;
			val = 1;
	} while (tcf_hash_lookup(val, hinfo));
	} while (tcf_hash_lookup(val, hinfo));


	*idx_gen = val;
	hinfo->index = val;
	return val;
	return val;
}
}
EXPORT_SYMBOL(tcf_hash_new_index);
EXPORT_SYMBOL(tcf_hash_new_index);
@@ -215,7 +215,7 @@ EXPORT_SYMBOL(tcf_hash_check);


struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
				   struct tc_action *a, int size, int bind,
				   struct tc_action *a, int size, int bind,
				   u32 *idx_gen, struct tcf_hashinfo *hinfo)
				   struct tcf_hashinfo *hinfo)
{
{
	struct tcf_common *p = kzalloc(size, GFP_KERNEL);
	struct tcf_common *p = kzalloc(size, GFP_KERNEL);


@@ -227,7 +227,7 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,


	spin_lock_init(&p->tcfc_lock);
	spin_lock_init(&p->tcfc_lock);
	INIT_HLIST_NODE(&p->tcfc_head);
	INIT_HLIST_NODE(&p->tcfc_head);
	p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
	p->tcfc_index = index ? index : tcf_hash_new_index(hinfo);
	p->tcfc_tm.install = jiffies;
	p->tcfc_tm.install = jiffies;
	p->tcfc_tm.lastuse = jiffies;
	p->tcfc_tm.lastuse = jiffies;
	if (est) {
	if (est) {
+1 −2
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@
#include <net/tc_act/tc_csum.h>
#include <net/tc_act/tc_csum.h>


#define CSUM_TAB_MASK 15
#define CSUM_TAB_MASK 15
static u32 csum_idx_gen;
static struct tcf_hashinfo csum_hash_info;
static struct tcf_hashinfo csum_hash_info;


static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = {
@@ -67,7 +66,7 @@ static int tcf_csum_init(struct net *n, struct nlattr *nla, struct nlattr *est,
	pc = tcf_hash_check(parm->index, a, bind, &csum_hash_info);
	pc = tcf_hash_check(parm->index, a, bind, &csum_hash_info);
	if (!pc) {
	if (!pc) {
		pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
		pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
				     &csum_idx_gen, &csum_hash_info);
				     &csum_hash_info);
		if (IS_ERR(pc))
		if (IS_ERR(pc))
			return PTR_ERR(pc);
			return PTR_ERR(pc);
		ret = ACT_P_CREATED;
		ret = ACT_P_CREATED;
+1 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@
#include <net/tc_act/tc_gact.h>
#include <net/tc_act/tc_gact.h>


#define GACT_TAB_MASK	15
#define GACT_TAB_MASK	15
static u32 gact_idx_gen;
static struct tcf_hashinfo gact_hash_info;
static struct tcf_hashinfo gact_hash_info;


#ifdef CONFIG_GACT_PROB
#ifdef CONFIG_GACT_PROB
@@ -90,7 +89,7 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
	pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info);
	pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info);
	if (!pc) {
	if (!pc) {
		pc = tcf_hash_create(parm->index, est, a, sizeof(*gact),
		pc = tcf_hash_create(parm->index, est, a, sizeof(*gact),
				     bind, &gact_idx_gen, &gact_hash_info);
				     bind, &gact_hash_info);
		if (IS_ERR(pc))
		if (IS_ERR(pc))
			return PTR_ERR(pc);
			return PTR_ERR(pc);
		ret = ACT_P_CREATED;
		ret = ACT_P_CREATED;
+1 −2
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@




#define IPT_TAB_MASK     15
#define IPT_TAB_MASK     15
static u32 ipt_idx_gen;
static struct tcf_hashinfo ipt_hash_info;
static struct tcf_hashinfo ipt_hash_info;


static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook)
static int ipt_init_target(struct xt_entry_target *t, char *table, unsigned int hook)
@@ -129,7 +128,7 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, struct nlattr *est,
	pc = tcf_hash_check(index, a, bind, &ipt_hash_info);
	pc = tcf_hash_check(index, a, bind, &ipt_hash_info);
	if (!pc) {
	if (!pc) {
		pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind,
		pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind,
				     &ipt_idx_gen, &ipt_hash_info);
				     &ipt_hash_info);
		if (IS_ERR(pc))
		if (IS_ERR(pc))
			return PTR_ERR(pc);
			return PTR_ERR(pc);
		ret = ACT_P_CREATED;
		ret = ACT_P_CREATED;
Loading