X25: Move interrupt flag to bitfield
[safe/jmp/linux-2.6] / net / core / dst.c
index 7eceeba..9920722 100644 (file)
 #include <linux/workqueue.h>
 #include <linux/mm.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 #include <linux/netdevice.h>
 #include <linux/skbuff.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <net/net_namespace.h>
+#include <linux/sched.h>
 
 #include <net/dst.h>
 
@@ -42,7 +44,7 @@ static atomic_t                        dst_total = ATOMIC_INIT(0);
  */
 static struct {
        spinlock_t              lock;
-       struct dst_entry        *list;
+       struct dst_entry        *list;
        unsigned long           timer_inc;
        unsigned long           timer_expires;
 } dst_garbage = {
@@ -50,7 +52,7 @@ static struct {
        .timer_inc = DST_GC_MAX,
 };
 static void dst_gc_task(struct work_struct *work);
-static void ___dst_free(struct dst_entry * dst);
+static void ___dst_free(struct dst_entry *dst);
 
 static DECLARE_DELAYED_WORK(dst_gc_work, dst_gc_task);
 
@@ -79,6 +81,7 @@ loop:
        while ((dst = next) != NULL) {
                next = dst->next;
                prefetch(&next->next);
+               cond_resched();
                if (likely(atomic_read(&dst->__refcnt))) {
                        last->next = dst;
                        last = dst;
@@ -133,8 +136,8 @@ loop:
                }
                expires = dst_garbage.timer_expires;
                /*
-                * if the next desired timer is more than 4 seconds in the future
-                * then round the timer to whole seconds
+                * if the next desired timer is more than 4 seconds in the
+                * future then round the timer to whole seconds
                 */
                if (expires > 4*HZ)
                        expires = round_jiffies_relative(expires);
@@ -149,7 +152,8 @@ loop:
                " expires: %lu elapsed: %lu us\n",
                atomic_read(&dst_total), delayed, work_performed,
                expires,
-               elapsed.tv_sec * USEC_PER_SEC + elapsed.tv_nsec / NSEC_PER_USEC);
+               elapsed.tv_sec * USEC_PER_SEC +
+                 elapsed.tv_nsec / NSEC_PER_USEC);
 #endif
 }
 
@@ -160,12 +164,12 @@ int dst_discard(struct sk_buff *skb)
 }
 EXPORT_SYMBOL(dst_discard);
 
-void * dst_alloc(struct dst_ops * ops)
+void *dst_alloc(struct dst_ops *ops)
 {
-       struct dst_entry * dst;
+       struct dst_entry *dst;
 
        if (ops->gc && atomic_read(&ops->entries) > ops->gc_thresh) {
-               if (ops->gc())
+               if (ops->gc(ops))
                        return NULL;
        }
        dst = kmem_cache_zalloc(ops->kmem_cachep, GFP_ATOMIC);
@@ -182,19 +186,20 @@ void * dst_alloc(struct dst_ops * ops)
        atomic_inc(&ops->entries);
        return dst;
 }
+EXPORT_SYMBOL(dst_alloc);
 
-static void ___dst_free(struct dst_entry * dst)
+static void ___dst_free(struct dst_entry *dst)
 {
        /* The first case (dev==NULL) is required, when
           protocol module is unloaded.
         */
-       if (dst->dev == NULL || !(dst->dev->flags&IFF_UP)) {
+       if (dst->dev == NULL || !(dst->dev->flags&IFF_UP))
                dst->input = dst->output = dst_discard;
-       }
        dst->obsolete = 2;
 }
+EXPORT_SYMBOL(__dst_free);
 
-void __dst_free(struct dst_entry * dst)
+void __dst_free(struct dst_entry *dst)
 {
        spin_lock_bh(&dst_garbage.lock);
        ___dst_free(dst);
@@ -203,6 +208,7 @@ void __dst_free(struct dst_entry * dst)
        if (dst_garbage.timer_inc > DST_GC_INC) {
                dst_garbage.timer_inc = DST_GC_INC;
                dst_garbage.timer_expires = DST_GC_MIN;
+               cancel_delayed_work(&dst_gc_work);
                schedule_delayed_work(&dst_gc_work, dst_garbage.timer_expires);
        }
        spin_unlock_bh(&dst_garbage.lock);
@@ -258,6 +264,19 @@ again:
        }
        return NULL;
 }
+EXPORT_SYMBOL(dst_destroy);
+
+void dst_release(struct dst_entry *dst)
+{
+       if (dst) {
+               int newrefcnt;
+
+               smp_mb__before_atomic_dec();
+               newrefcnt = atomic_dec_return(&dst->__refcnt);
+               WARN_ON(newrefcnt < 0);
+       }
+}
+EXPORT_SYMBOL(dst_release);
 
 /* Dirty hack. We did it in 2.2 (in __dst_free),
  * we have _very_ good reasons not to repeat
@@ -267,8 +286,8 @@ again:
  *
  * Commented and originally written by Alexey.
  */
-static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev,
-                             int unregister)
+static void dst_ifdown(struct dst_entry *dst, struct net_device *dev,
+                      int unregister)
 {
        if (dst->ops->ifdown)
                dst->ops->ifdown(dst, dev, unregister);
@@ -279,7 +298,7 @@ static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev,
        if (!unregister) {
                dst->input = dst->output = dst_discard;
        } else {
-               dst->dev = dst->dev->nd_net->loopback_dev;
+               dst->dev = dev_net(dst->dev)->loopback_dev;
                dev_hold(dst->dev);
                dev_put(dev);
                if (dst->neighbour && dst->neighbour->dev == dev) {
@@ -290,14 +309,12 @@ static inline void dst_ifdown(struct dst_entry *dst, struct net_device *dev,
        }
 }
 
-static int dst_dev_event(struct notifier_block *this, unsigned long event, void *ptr)
+static int dst_dev_event(struct notifier_block *this, unsigned long event,
+                        void *ptr)
 {
        struct net_device *dev = ptr;
        struct dst_entry *dst, *last = NULL;
 
-       if (dev->nd_net != &init_net)
-               return NOTIFY_DONE;
-
        switch (event) {
        case NETDEV_UNREGISTER:
        case NETDEV_DOWN:
@@ -316,9 +333,8 @@ static int dst_dev_event(struct notifier_block *this, unsigned long event, void
                        last->next = dst;
                else
                        dst_busy_list = dst;
-               for (; dst; dst = dst->next) {
+               for (; dst; dst = dst->next)
                        dst_ifdown(dst, dev, event != NETDEV_DOWN);
-               }
                mutex_unlock(&dst_gc_mutex);
                break;
        }
@@ -333,7 +349,3 @@ void __init dst_init(void)
 {
        register_netdevice_notifier(&dst_dev_notifier);
 }
-
-EXPORT_SYMBOL(__dst_free);
-EXPORT_SYMBOL(dst_alloc);
-EXPORT_SYMBOL(dst_destroy);