nfsd: minor write_pool_threads exit cleanup
[safe/jmp/linux-2.6] / net / sched / cls_api.c
index 5584e7c..09cdcdf 100644 (file)
@@ -118,8 +118,9 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
 
 static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
        struct nlattr *tca[TCA_MAX + 1];
+       spinlock_t *root_lock;
        struct tcmsg *t;
        u32 protocol;
        u32 prio;
@@ -134,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;
@@ -166,7 +168,8 @@ replay:
 
        /* Find qdisc */
        if (!parent) {
-               q = dev->qdisc_sleeping;
+               struct netdev_queue *dev_queue = netdev_get_tx_queue(dev, 0);
+               q = dev_queue->qdisc_sleeping;
                parent = q->handle;
        } else {
                q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent));
@@ -203,6 +206,8 @@ replay:
                }
        }
 
+       root_lock = qdisc_root_sleeping_lock(q);
+
        if (tp == NULL) {
                /* Proto-tcf does not exist, create new one */
 
@@ -220,10 +225,10 @@ replay:
                tp = kzalloc(sizeof(*tp), GFP_KERNEL);
                if (tp == NULL)
                        goto errout;
-               err = -EINVAL;
+               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];
 
@@ -250,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;
@@ -262,10 +267,7 @@ replay:
                        goto errout;
                }
 
-               qdisc_lock_tree(dev);
-               tp->next = *back;
-               *back = tp;
-               qdisc_unlock_tree(dev);
+               tp_created = 1;
 
        } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind))
                goto errout;
@@ -274,9 +276,9 @@ replay:
 
        if (fh == 0) {
                if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
-                       qdisc_lock_tree(dev);
+                       spin_lock_bh(root_lock);
                        *back = tp->next;
-                       qdisc_unlock_tree(dev);
+                       spin_unlock_bh(root_lock);
 
                        tfilter_notify(skb, n, tp, fh, RTM_DELTFILTER);
                        tcf_destroy(tp);
@@ -292,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);
@@ -310,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)
@@ -334,10 +349,10 @@ static int tcf_fill_node(struct sk_buff *skb, struct tcf_proto *tp,
        tcm->tcm_family = AF_UNSPEC;
        tcm->tcm__pad1 = 0;
        tcm->tcm__pad1 = 0;
-       tcm->tcm_ifindex = tp->q->dev->ifindex;
+       tcm->tcm_ifindex = qdisc_dev(tp->q)->ifindex;
        tcm->tcm_parent = tp->classid;
        tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
-       NLA_PUT(skb, TCA_KIND, IFNAMSIZ, tp->ops->kind);
+       NLA_PUT_STRING(skb, TCA_KIND, tp->ops->kind);
        tcm->tcm_handle = fh;
        if (RTM_DELTFILTER != event) {
                tcm->tcm_handle = 0;
@@ -389,7 +404,8 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
 
 static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
 {
-       struct net *net = skb->sk->sk_net;
+       struct net *net = sock_net(skb->sk);
+       struct netdev_queue *dev_queue;
        int t;
        int s_t;
        struct net_device *dev;
@@ -408,8 +424,9 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
        if ((dev = dev_get_by_index(&init_net, tcm->tcm_ifindex)) == NULL)
                return skb->len;
 
+       dev_queue = netdev_get_tx_queue(dev, 0);
        if (!tcm->tcm_parent)
-               q = dev->qdisc_sleeping;
+               q = dev_queue->qdisc_sleeping;
        else
                q = qdisc_lookup(dev, TC_H_MAJ(tcm->tcm_parent));
        if (!q)
@@ -482,7 +499,7 @@ EXPORT_SYMBOL(tcf_exts_destroy);
 
 int tcf_exts_validate(struct tcf_proto *tp, struct nlattr **tb,
                  struct nlattr *rate_tlv, struct tcf_exts *exts,
-                 struct tcf_ext_map *map)
+                 const struct tcf_ext_map *map)
 {
        memset(exts, 0, sizeof(*exts));
 
@@ -525,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);
@@ -535,7 +553,7 @@ void tcf_exts_change(struct tcf_proto *tp, struct tcf_exts *dst,
 EXPORT_SYMBOL(tcf_exts_change);
 
 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts,
-             struct tcf_ext_map *map)
+                 const struct tcf_ext_map *map)
 {
 #ifdef CONFIG_NET_CLS_ACT
        if (map->action && exts->action) {
@@ -571,7 +589,7 @@ EXPORT_SYMBOL(tcf_exts_dump);
 
 
 int tcf_exts_dump_stats(struct sk_buff *skb, struct tcf_exts *exts,
-                       struct tcf_ext_map *map)
+                       const struct tcf_ext_map *map)
 {
 #ifdef CONFIG_NET_CLS_ACT
        if (exts->action)