nfsd: minor write_pool_threads exit cleanup
[safe/jmp/linux-2.6] / net / sched / cls_api.c
index 5cafdd4..09cdcdf 100644 (file)
@@ -135,6 +135,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
        unsigned long cl;
        unsigned long fh;
        int err;
+       int tp_created = 0;
 
        if (net != &init_net)
                return -EINVAL;
@@ -205,7 +206,7 @@ replay:
                }
        }
 
-       root_lock = qdisc_root_lock(q);
+       root_lock = qdisc_root_sleeping_lock(q);
 
        if (tp == NULL) {
                /* Proto-tcf does not exist, create new one */
@@ -227,7 +228,7 @@ replay:
                err = -ENOENT;
                tp_ops = tcf_proto_lookup_ops(tca[TCA_KIND]);
                if (tp_ops == NULL) {
-#ifdef CONFIG_KMOD
+#ifdef CONFIG_MODULES
                        struct nlattr *kind = tca[TCA_KIND];
                        char name[IFNAMSIZ];
 
@@ -254,7 +255,7 @@ replay:
                }
                tp->ops = tp_ops;
                tp->protocol = protocol;
-               tp->prio = nprio ? : tcf_auto_prio(*back);
+               tp->prio = nprio ? : TC_H_MAJ(tcf_auto_prio(*back));
                tp->q = q;
                tp->classify = tp_ops->classify;
                tp->classid = parent;
@@ -266,10 +267,7 @@ replay:
                        goto errout;
                }
 
-               spin_lock_bh(root_lock);
-               tp->next = *back;
-               *back = tp;
-               spin_unlock_bh(root_lock);
+               tp_created = 1;
 
        } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind))
                goto errout;
@@ -296,8 +294,11 @@ replay:
                switch (n->nlmsg_type) {
                case RTM_NEWTFILTER:
                        err = -EEXIST;
-                       if (n->nlmsg_flags & NLM_F_EXCL)
+                       if (n->nlmsg_flags & NLM_F_EXCL) {
+                               if (tp_created)
+                                       tcf_destroy(tp);
                                goto errout;
+                       }
                        break;
                case RTM_DELTFILTER:
                        err = tp->ops->delete(tp, fh);
@@ -314,8 +315,18 @@ replay:
        }
 
        err = tp->ops->change(tp, cl, t->tcm_handle, tca, &fh);
-       if (err == 0)
+       if (err == 0) {
+               if (tp_created) {
+                       spin_lock_bh(root_lock);
+                       tp->next = *back;
+                       *back = tp;
+                       spin_unlock_bh(root_lock);
+               }
                tfilter_notify(skb, n, tp, fh, RTM_NEWTFILTER);
+       } else {
+               if (tp_created)
+                       tcf_destroy(tp);
+       }
 
 errout:
        if (cl)
@@ -531,7 +542,8 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
        if (src->action) {
                struct tc_action *act;
                tcf_tree_lock(tp);
-               act = xchg(&dst->action, src->action);
+               act = dst->action;
+               dst->action = src->action;
                tcf_tree_unlock(tp);
                if (act)
                        tcf_action_destroy(act, TCA_ACT_UNBIND);