Skip to contentSkip to conversation

act_mirred: optimization

PATCH In review Changli Gao 4 participants 13 messages Nov 16, 2009 – Nov 17, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 act_mirred: optimization

act_mirred: optimization.

move checking if eaction is valid in tcf_mirred_init()

----

 net/sched/act_mirred.c |   60
 +++++++++++++++++++++++--------------------------
  1 file changed, 29 insertions(+), 31 deletions(-)
net/sched/act_mirred.c +29 -31
@@ -65,48 +65,53 @@
 	struct tc_mirred *parm;
 	struct tcf_mirred *m;
 	struct tcf_common *pc;
-	struct net_device *dev = NULL;
-	int ret = 0, err;
-	int ok_push = 0;
+	struct net_device *dev;
+	int ret, ok_push = 0;
 
 	if (nla == NULL)
 		return -EINVAL;
-
-	err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
-	if (err < 0)
-		return err;
-
+	ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
+	if (ret < 0)
+		return ret;
 	if (tb[TCA_MIRRED_PARMS] == NULL)
 		return -EINVAL;
 	parm = nla_data(tb[TCA_MIRRED_PARMS]);
-
+	switch (parm->eaction) {
+	case TCA_EGRESS_MIRROR:
+	case TCA_EGRESS_REDIR:
+		break;
+	default:
+		return -EINVAL;
+	}
 	if (parm->ifindex) {
 		dev = __dev_get_by_index(&init_net, parm->ifindex);
 		if (dev == NULL)
 			return -ENODEV;
 		switch (dev->type) {
-			case ARPHRD_TUNNEL:
-			case ARPHRD_TUNNEL6:
-			case ARPHRD_SIT:
-			case ARPHRD_IPGRE:
-			case ARPHRD_VOID:
-			case ARPHRD_NONE:
-				ok_push = 0;
-				break;
-			default:
-				ok_push = 1;
-				break;
+		case ARPHRD_TUNNEL:
+		case ARPHRD_TUNNEL6:
+		case ARPHRD_SIT:
+		case ARPHRD_IPGRE:
+		case ARPHRD_VOID:
+		case ARPHRD_NONE:
+			ok_push = 0;
+			break;
+		default:
+			ok_push = 1;
+			break;
 		}
+	} else {
+		dev = NULL;
 	}
 
 	pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info);
 	if (!pc) {
-		if (!parm->ifindex)
+		if (dev == NULL)
 			return -EINVAL;
 		pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
 				     &mirred_idx_gen, &mirred_hash_info);
 		if (IS_ERR(pc))
-		    return PTR_ERR(pc);
+			return PTR_ERR(pc);
 		ret = ACT_P_CREATED;
 	} else {
 		if (!ovr) {
@@ -119,12 +124,12 @@
 	spin_lock_bh(&m->tcf_lock);
 	m->tcf_action = parm->action;
 	m->tcfm_eaction = parm->eaction;
-	if (parm->ifindex) {
+	if (dev != NULL) {
 		m->tcfm_ifindex = parm->ifindex;
 		if (ret != ACT_P_CREATED)
 			dev_put(m->tcfm_dev);
-		m->tcfm_dev = dev;
 		dev_hold(dev);
+		m->tcfm_dev = dev;
 		m->tcfm_ok_push = ok_push;
 	}
 	spin_unlock_bh(&m->tcf_lock);
@@ -154,13 +159,6 @@
 
 	spin_lock(&m->tcf_lock);
 	m->tcf_tm.lastuse = jiffies;
-	if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
-	    m->tcfm_eaction != TCA_EGRESS_REDIR) {
-		if (net_ratelimit())
-			printk("tcf_mirred unknown action %d\n",
-			       m->tcfm_eaction);
-		goto out;
-	}
 
 	dev = m->tcfm_dev;
 	if (!(dev->flags & IFF_UP)) {
#1 lore raw

On Mon, 2009-11-16 at 17:53 +0800, Changli Gao wrote:

Just one small comment; sorry, i missed this the first time:

net/sched/act_mirred.c line 114

Quoted 7 lines
net/sched/act_mirred.c +2 -1
+		if (dev == NULL)
 			return -EINVAL;
 		pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
 				     &mirred_idx_gen, &mirred_hash_info);
 		if (IS_ERR(pc))
-		    return PTR_ERR(pc);
+			return PTR_ERR(pc);

One indent too many?

cheers,
jamal

maintainer
#2 lore raw

From: jamal <[email protected]>
Date: Mon, 16 Nov 2009 05:06:30 -0500

Quoted 13 lines · Changli Gao

Just one small comment; sorry, i missed this the first time:

net/sched/act_mirred.c line 114

Quoted 7 lines
net/sched/act_mirred.c +2 -1
+		if (dev == NULL)
 			return -EINVAL;
 		pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
 				     &mirred_idx_gen, &mirred_hash_info);
 		if (IS_ERR(pc))
-		    return PTR_ERR(pc);
+			return PTR_ERR(pc);

One indent too many?

It's actually fixing some stray space characters into a real proper tab character.

#3 lore raw
Quoted 7 lines · David Miller

From: jamal <[email protected]>
Date: Mon, 16 Nov 2009 05:06:30 -0500

Quoted 1 line

One indent too many?

It's actually fixing some stray space characters into a real proper tab character.

good enough for me then.

cheers,
jamal

maintainer
#5 lore raw

From: David Miller <[email protected]>
Date: Mon, 16 Nov 2009 02:48:39 -0800 (PST)

Quoted 11 lines

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 17:53:29 +0800

Quoted 6 lines

act_mirred: optimization.

move checking if eaction is valid in tcf_mirred_init()

Also applied, thank you.

Nevermind, you're NOT TESTING the patches you are posting:

net/sched/act_mirred.c: In function ‘tcf_mirred’:
net/sched/act_mirred.c:168: error: label ‘out’ used but not defined net/sched/act_mirred.c:158: warning: unused variable ‘err’ net/sched/act_mirred.c:158: warning: unused variable ‘retval’ make[2]: *** [net/sched/act_mirred.o] Error 1
make[1]: *** [net/sched] Error 2
make[1]: *** Waiting for unfinished jobs....

I'm thus reverting both changes.

Don't submit changes which are untested, it wastes my time.

#6 lore raw
Quoted 25 lines · David Miller

From: David Miller <[email protected]>
Date: Mon, 16 Nov 2009 02:48:39 -0800 (PST)

Quoted 11 lines

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 17:53:29 +0800

Quoted 6 lines

act_mirred: optimization.

move checking if eaction is valid in tcf_mirred_init()

Also applied, thank you.

Nevermind, you're NOT TESTING the patches you are posting:

net/sched/act_mirred.c: In function ‘tcf_mirred’:
net/sched/act_mirred.c:168: error: label ‘out’ used but not defined net/sched/act_mirred.c:158: warning: unused variable ‘err’ net/sched/act_mirred.c:158: warning: unused variable ‘retval’ make[2]: *** [net/sched/act_mirred.o] Error 1
make[1]: *** [net/sched] Error 2
make[1]: *** Waiting for unfinished jobs....

Quoted 4 lines

I'm thus reverting both changes.

Don't submit changes which are untested, it wastes my time.

I am sorry about that. But I did test it before submitting these two, and I am just wondering if they are applied without any error. Would you post the file after being patched? I think it will be helpful to finger out the real problem.

BTW: since my email client thunderbird was broken, I used google webmail(with ViewSourceWith addon) to submit these two patches.

Signature · 2 lines
Regards,
Changli Gao([email protected])
maintainer
#7 lore raw

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 21:05:28 +0800

Quoted 4 lines

I am sorry about that. But I did test it before submitting these two, and I am just wondering if they are applied without any error. Would you post the file after being patched? I think it will be helpful to finger out the real problem.

I don't have time for that sorry.

I think the problem might be that you are developing against either net-2.6 or Linus's tree, whereas you should be working against net-next-2.6

#8 lore raw
Quoted 9 lines · David Miller

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 21:05:28 +0800

Quoted 4 lines

I am sorry about that. But I did test it before submitting these two, and I am just wondering if they are applied without any error. Would you post the file after being patched? I think it will be helpful to finger out the real problem.

I don't have time for that sorry.

Thanks all the same!

Quoted 5 lines

I think the problem might be that you are developing against either net-2.6 or Linus's tree, whereas you should be working against net-next-2.6

I am working against linux-next. I'll check if there is any difference. BTW: were these patches applied in order, 1 - 2?

Signature · 2 lines
Regards,
Changli Gao([email protected])
maintainer
#9 lore raw

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 21:22:46 +0800

Quoted 2 lines

I am working against linux-next. I'll check if there is any difference. BTW: were these patches applied in order, 1 - 2?

Yes, they were.

#10 lore raw
Quoted 8 lines · David Miller

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 21:22:46 +0800

Quoted 2 lines

I am working against linux-next. I'll check if there is any difference. BTW: were these patches applied in order, 1 - 2?

Yes, they were.

Patch is resubmitted as attachment.

Signature · 2 lines
Regards,
Changli Gao([email protected])
net/sched/act_mirred.c +29 -31
@@ -65,48 +65,53 @@
 	struct tc_mirred *parm;
 	struct tcf_mirred *m;
 	struct tcf_common *pc;
-	struct net_device *dev = NULL;
-	int ret = 0, err;
-	int ok_push = 0;
+	struct net_device *dev;
+	int ret, ok_push = 0;
 
 	if (nla == NULL)
 		return -EINVAL;
-
-	err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
-	if (err < 0)
-		return err;
-
+	ret = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, mirred_policy);
+	if (ret < 0)
+		return ret;
 	if (tb[TCA_MIRRED_PARMS] == NULL)
 		return -EINVAL;
 	parm = nla_data(tb[TCA_MIRRED_PARMS]);
-
+	switch (parm->eaction) {
+	case TCA_EGRESS_MIRROR:
+	case TCA_EGRESS_REDIR:
+		break;
+	default:
+		return -EINVAL;
+	}
 	if (parm->ifindex) {
 		dev = __dev_get_by_index(&init_net, parm->ifindex);
 		if (dev == NULL)
 			return -ENODEV;
 		switch (dev->type) {
-			case ARPHRD_TUNNEL:
-			case ARPHRD_TUNNEL6:
-			case ARPHRD_SIT:
-			case ARPHRD_IPGRE:
-			case ARPHRD_VOID:
-			case ARPHRD_NONE:
-				ok_push = 0;
-				break;
-			default:
-				ok_push = 1;
-				break;
+		case ARPHRD_TUNNEL:
+		case ARPHRD_TUNNEL6:
+		case ARPHRD_SIT:
+		case ARPHRD_IPGRE:
+		case ARPHRD_VOID:
+		case ARPHRD_NONE:
+			ok_push = 0;
+			break;
+		default:
+			ok_push = 1;
+			break;
 		}
+	} else {
+		dev = NULL;
 	}
 
 	pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info);
 	if (!pc) {
-		if (!parm->ifindex)
+		if (dev == NULL)
 			return -EINVAL;
 		pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
 				     &mirred_idx_gen, &mirred_hash_info);
 		if (IS_ERR(pc))
-		    return PTR_ERR(pc);
+			return PTR_ERR(pc);
 		ret = ACT_P_CREATED;
 	} else {
 		if (!ovr) {
@@ -119,12 +124,12 @@
 	spin_lock_bh(&m->tcf_lock);
 	m->tcf_action = parm->action;
 	m->tcfm_eaction = parm->eaction;
-	if (parm->ifindex) {
+	if (dev != NULL) {
 		m->tcfm_ifindex = parm->ifindex;
 		if (ret != ACT_P_CREATED)
 			dev_put(m->tcfm_dev);
-		m->tcfm_dev = dev;
 		dev_hold(dev);
+		m->tcfm_dev = dev;
 		m->tcfm_ok_push = ok_push;
 	}
 	spin_unlock_bh(&m->tcf_lock);
@@ -154,13 +159,6 @@
 
 	spin_lock(&m->tcf_lock);
 	m->tcf_tm.lastuse = jiffies;
-	if (m->tcfm_eaction != TCA_EGRESS_MIRROR &&
-	    m->tcfm_eaction != TCA_EGRESS_REDIR) {
-		if (net_ratelimit())
-			printk("tcf_mirred unknown action %d\n",
-			       m->tcfm_eaction);
-		goto out;
-	}
 
 	dev = m->tcfm_dev;
 	if (!(dev->flags & IFF_UP)) {
maintainer
#11 lore raw

From: Changli Gao <[email protected]>
Date: Tue, 17 Nov 2009 13:49:00 +0800

Quoted 11 lines · David Miller
Quoted 8 lines

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 21:22:46 +0800

Quoted 2 lines

I am working against linux-next. I'll check if there is any difference. BTW: were these patches applied in order, 1 - 2?

Yes, they were.

Patch is resubmitted as attachment.

Also applied, thanks.

#12 lore raw
In reply to Changli Gao
Quoted 29 lines · Changli Gao
Quoted 23 lines · David Miller

From: David Miller <[email protected]>
Date: Mon, 16 Nov 2009 02:48:39 -0800 (PST)

Quoted 10 lines

From: Changli Gao <[email protected]>
Date: Mon, 16 Nov 2009 17:53:29 +0800

Quoted 6 lines

act_mirred: optimization.

move checking if eaction is valid in tcf_mirred_init()

Also applied, thank you.

Nevermind, you're NOT TESTING the patches you are posting:

net/sched/act_mirred.c: In function â??tcf_mirredâ??:
net/sched/act_mirred.c:168: error: label â??outâ?? used but not defined net/sched/act_mirred.c:158: warning: unused variable â??errâ?? net/sched/act_mirred.c:158: warning: unused variable â??retvalâ?? make[2]: *** [net/sched/act_mirred.o] Error 1
make[1]: *** [net/sched] Error 2
make[1]: *** Waiting for unfinished jobs....

Quoted 4 lines

I'm thus reverting both changes.

Don't submit changes which are untested, it wastes my time.

Quoted 8 lines

I am sorry about that. But I did test it before submitting these two, and I am just wondering if they are applied without any error. Would you post the file after being patched? I think it will be helpful to finger out the real problem.

BTW: since my email client thunderbird was broken, I used google webmail(with ViewSourceWith addon) to submit these two patches.

It seems PATCH 1/2 might be broken by email (but I got it second hand from gmail). checkpatch output:

ERROR: patch seems to be corrupt (line wrapped?)
#17: FILE: net/sched/act_mirred.c:147:
struct tc_action *a,

WARNING: printk() should include KERN_ facility level #34: FILE: net/sched/act_mirred.c:160:
+ printk("tcf_mirred unknown action %d\n",

total: 1 errors, 1 warnings, 89 lines checked

mirred1.diff has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

Jarek P.