net_sched: act: refactor cleanup ops
authorWANG Cong <xiyou.wangcong@gmail.com>
Wed, 12 Feb 2014 01:07:32 +0000 (17:07 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Feb 2014 00:23:32 +0000 (19:23 -0500)
For bindcnt and refcnt etc., they are common for all actions,
not need to repeat such operations for their own, they can be unified
now. Actions just need to do its specific cleanup if needed.

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>
include/net/act_api.h
net/sched/act_api.c
net/sched/act_csum.c
net/sched/act_gact.c
net/sched/act_ipt.c
net/sched/act_mirred.c
net/sched/act_nat.c
net/sched/act_pedit.c
net/sched/act_police.c
net/sched/act_simple.c
net/sched/act_skbedit.c

index 24ae910609cebda73bb5853fb4e3ddd5ef11307c..3d22f42b6eec61bab6a715f052c2dde479ad12b4 100644 (file)
@@ -89,7 +89,7 @@ struct tc_action_ops {
        struct module           *owner;
        int     (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
        int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
-       int     (*cleanup)(struct tc_action *, int bind);
+       void    (*cleanup)(struct tc_action *, int bind);
        int     (*lookup)(struct tc_action *, u32);
        int     (*init)(struct net *net, struct nlattr *nla,
                        struct nlattr *est, struct tc_action *act, int ovr,
index 4f2b807b3621b58aff1cfc0dd7b402b6026ecd99..a5bf9351ce5c2dc13d7da68d4fbd0c8153585605 100644 (file)
@@ -56,6 +56,8 @@ int tcf_hash_release(struct tc_action *a, int bind)
 
                p->tcfc_refcnt--;
                if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
+                       if (a->ops->cleanup)
+                               a->ops->cleanup(a, bind);
                        tcf_hash_destroy(a);
                        ret = 1;
                }
@@ -277,8 +279,8 @@ int tcf_register_action(struct tc_action_ops *act)
 {
        struct tc_action_ops *a;
 
-       /* Must supply act, dump, cleanup and init */
-       if (!act->act || !act->dump || !act->cleanup || !act->init)
+       /* Must supply act, dump and init */
+       if (!act->act || !act->dump || !act->init)
                return -EINVAL;
 
        /* Supply defaults */
@@ -390,7 +392,7 @@ void tcf_action_destroy(struct list_head *actions, int bind)
        struct tc_action *a, *tmp;
 
        list_for_each_entry_safe(a, tmp, actions, list) {
-               if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
+               if (tcf_hash_release(a, bind) == ACT_P_DELETED)
                        module_put(a->ops->owner);
                list_del(&a->list);
                kfree(a);
index f0f6e7a625d17cef8dce461dd76733aca426ceda..8df3060e7ac1535fe88741a3b4b522c5be388b62 100644 (file)
@@ -566,7 +566,6 @@ static struct tc_action_ops act_csum_ops = {
        .owner          = THIS_MODULE,
        .act            = tcf_csum,
        .dump           = tcf_csum_dump,
-       .cleanup        = tcf_hash_release,
        .init           = tcf_csum_init,
 };
 
index af6c0acd9bf14144dcd8a49e2b697d724852f6b0..094a1b509d756076d031e7226d15965c1f241e27 100644 (file)
@@ -185,7 +185,6 @@ static struct tc_action_ops act_gact_ops = {
        .owner          =       THIS_MODULE,
        .act            =       tcf_gact,
        .dump           =       tcf_gact_dump,
-       .cleanup        =       tcf_hash_release,
        .init           =       tcf_gact_init,
 };
 
index f5e69782d400be7495ef569feb949ce9026f68aa..71f29f1b5a20e8eb3de28feb76e6750f53311566 100644 (file)
@@ -69,23 +69,12 @@ static void ipt_destroy_target(struct xt_entry_target *t)
        module_put(par.target->me);
 }
 
-static int tcf_ipt_release(struct tc_action *a, int bind)
+static void tcf_ipt_release(struct tc_action *a, int bind)
 {
        struct tcf_ipt *ipt = to_ipt(a);
-       int ret = 0;
-       if (ipt) {
-               if (bind)
-                       ipt->tcf_bindcnt--;
-               ipt->tcf_refcnt--;
-               if (ipt->tcf_bindcnt <= 0 && ipt->tcf_refcnt <= 0) {
-                       ipt_destroy_target(ipt->tcfi_t);
-                       kfree(ipt->tcfi_tname);
-                       kfree(ipt->tcfi_t);
-                       tcf_hash_destroy(a);
-                       ret = ACT_P_DELETED;
-               }
-       }
-       return ret;
+       ipt_destroy_target(ipt->tcfi_t);
+       kfree(ipt->tcfi_tname);
+       kfree(ipt->tcfi_t);
 }
 
 static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = {
@@ -133,7 +122,7 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, struct nlattr *est,
        } else {
                if (bind)/* dont override defaults */
                        return 0;
-               tcf_ipt_release(a, bind);
+               tcf_hash_release(a, bind);
 
                if (!ovr)
                        return -EEXIST;
index 3edeecafba2fbdd1bb16fc5052066837d4f2c185..0f00eb96af84641e44e97a5e81576de95e224d3b 100644 (file)
 static LIST_HEAD(mirred_list);
 static struct tcf_hashinfo mirred_hash_info;
 
-static int tcf_mirred_release(struct tc_action *a, int bind)
+static void tcf_mirred_release(struct tc_action *a, int bind)
 {
        struct tcf_mirred *m = to_mirred(a);
-       if (m) {
-               if (bind)
-                       m->tcf_bindcnt--;
-               m->tcf_refcnt--;
-               if (!m->tcf_bindcnt && m->tcf_refcnt <= 0) {
-                       list_del(&m->tcfm_list);
-                       if (m->tcfm_dev)
-                               dev_put(m->tcfm_dev);
-                       tcf_hash_destroy(a);
-                       return 1;
-               }
-       }
-       return 0;
+       list_del(&m->tcfm_list);
+       if (m->tcfm_dev)
+               dev_put(m->tcfm_dev);
 }
 
 static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
@@ -110,7 +100,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
                ret = ACT_P_CREATED;
        } else {
                if (!ovr) {
-                       tcf_mirred_release(a, bind);
+                       tcf_hash_release(a, bind);
                        return -EEXIST;
                }
        }
index ce9a3914ed4af2f7e02f3aa09370a32a998ee9a8..9a3cb1d16d19a5e458e27b86b2fb72102471a687 100644 (file)
@@ -289,7 +289,6 @@ static struct tc_action_ops act_nat_ops = {
        .owner          =       THIS_MODULE,
        .act            =       tcf_nat,
        .dump           =       tcf_nat_dump,
-       .cleanup        =       tcf_hash_release,
        .init           =       tcf_nat_init,
 };
 
index 091ced38a3762a8096b25b65705f9e2a2b84ba3e..8aa795b275f201b87ed6c6fc8ed3cbbdd26a5175 100644 (file)
@@ -99,18 +99,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
        return ret;
 }
 
-static int tcf_pedit_cleanup(struct tc_action *a, int bind)
+static void tcf_pedit_cleanup(struct tc_action *a, int bind)
 {
        struct tcf_pedit *p = a->priv;
-
-       if (p) {
-               struct tc_pedit_key *keys = p->tcfp_keys;
-               if (tcf_hash_release(a, bind)) {
-                       kfree(keys);
-                       return 1;
-               }
-       }
-       return 0;
+       struct tc_pedit_key *keys = p->tcfp_keys;
+       kfree(keys);
 }
 
 static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
index 4695d02bd249a8d36e650662c89dd68d797bf377..7ff7bef065bf215717ddf95d5c07ba982ad43375 100644 (file)
@@ -354,7 +354,6 @@ static struct tc_action_ops act_police_ops = {
        .owner          =       THIS_MODULE,
        .act            =       tcf_act_police,
        .dump           =       tcf_act_police_dump,
-       .cleanup        =       tcf_hash_release,
        .init           =       tcf_act_police_locate,
        .walk           =       tcf_act_police_walker
 };
index 11c2922bb900a3d7e6f4a3a3b205a68153e6c287..14b5e362a1d6312f0b79ba2c78991479bb664059 100644 (file)
@@ -47,21 +47,10 @@ static int tcf_simp(struct sk_buff *skb, const struct tc_action *a,
        return d->tcf_action;
 }
 
-static int tcf_simp_release(struct tc_action *a, int bind)
+static void tcf_simp_release(struct tc_action *a, int bind)
 {
        struct tcf_defact *d = to_defact(a);
-       int ret = 0;
-       if (d) {
-               if (bind)
-                       d->tcf_bindcnt--;
-               d->tcf_refcnt--;
-               if (d->tcf_bindcnt <= 0 && d->tcf_refcnt <= 0) {
-                       kfree(d->tcfd_defdata);
-                       tcf_hash_destroy(a);
-                       ret = 1;
-               }
-       }
-       return ret;
+       kfree(d->tcfd_defdata);
 }
 
 static int alloc_defdata(struct tcf_defact *d, char *defdata)
@@ -132,7 +121,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
 
                if (bind)
                        return 0;
-               tcf_simp_release(a, bind);
+               tcf_hash_release(a, bind);
                if (!ovr)
                        return -EEXIST;
 
index 71fd2d4991098798a09db810df1d5b4127b31cd5..9f91928fcaebdd1d9effb25d15f57814ee92f8cf 100644 (file)
@@ -180,7 +180,6 @@ static struct tc_action_ops act_skbedit_ops = {
        .owner          =       THIS_MODULE,
        .act            =       tcf_skbedit,
        .dump           =       tcf_skbedit_dump,
-       .cleanup        =       tcf_hash_release,
        .init           =       tcf_skbedit_init,
 };
 
This page took 0.083714 seconds and 5 git commands to generate.