xfs: remove nr_to_write writeback windup.
[safe/jmp/linux-2.6] / net / ipv4 / inet_fragment.c
index 5ab399c..a2ca6ae 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/random.h>
 #include <linux/skbuff.h>
 #include <linux/rtnetlink.h>
+#include <linux/slab.h>
 
 #include <net/inet_frag.h>
 
@@ -47,7 +48,7 @@ static void inet_frag_secret_rebuild(unsigned long dummy)
        }
        write_unlock(&f->lock);
 
-       mod_timer(&f->secret_timer, now + f->ctl->secret_interval);
+       mod_timer(&f->secret_timer, now + f->secret_interval);
 }
 
 void inet_frags_init(struct inet_frags *f)
@@ -57,7 +58,6 @@ void inet_frags_init(struct inet_frags *f)
        for (i = 0; i < INETFRAGS_HASHSZ; i++)
                INIT_HLIST_HEAD(&f->hash[i]);
 
-       INIT_LIST_HEAD(&f->lru_list);
        rwlock_init(&f->lock);
 
        f->rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
@@ -65,7 +65,7 @@ void inet_frags_init(struct inet_frags *f)
 
        setup_timer(&f->secret_timer, inet_frag_secret_rebuild,
                        (unsigned long)f);
-       f->secret_timer.expires = jiffies + f->ctl->secret_interval;
+       f->secret_timer.expires = jiffies + f->secret_interval;
        add_timer(&f->secret_timer);
 }
 EXPORT_SYMBOL(inet_frags_init);
@@ -74,6 +74,7 @@ void inet_frags_init_net(struct netns_frags *nf)
 {
        nf->nqueues = 0;
        atomic_set(&nf->mem, 0);
+       INIT_LIST_HEAD(&nf->lru_list);
 }
 EXPORT_SYMBOL(inet_frags_init_net);
 
@@ -83,6 +84,16 @@ void inet_frags_fini(struct inet_frags *f)
 }
 EXPORT_SYMBOL(inet_frags_fini);
 
+void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f)
+{
+       nf->low_thresh = 0;
+
+       local_bh_disable();
+       inet_frag_evictor(nf, f);
+       local_bh_enable();
+}
+EXPORT_SYMBOL(inet_frags_exit_net);
+
 static inline void fq_unlink(struct inet_frag_queue *fq, struct inet_frags *f)
 {
        write_lock(&f->lock);
@@ -97,10 +108,10 @@ void inet_frag_kill(struct inet_frag_queue *fq, struct inet_frags *f)
        if (del_timer(&fq->timer))
                atomic_dec(&fq->refcnt);
 
-       if (!(fq->last_in & COMPLETE)) {
+       if (!(fq->last_in & INET_FRAG_COMPLETE)) {
                fq_unlink(fq, f);
                atomic_dec(&fq->refcnt);
-               fq->last_in |= COMPLETE;
+               fq->last_in |= INET_FRAG_COMPLETE;
        }
 }
 
@@ -124,8 +135,8 @@ void inet_frag_destroy(struct inet_frag_queue *q, struct inet_frags *f,
        struct sk_buff *fp;
        struct netns_frags *nf;
 
-       BUG_TRAP(q->last_in & COMPLETE);
-       BUG_TRAP(del_timer(&q->timer) == 0);
+       WARN_ON(!(q->last_in & INET_FRAG_COMPLETE));
+       WARN_ON(del_timer(&q->timer) != 0);
 
        /* Release all fragment data. */
        fp = q->fragments;
@@ -156,18 +167,18 @@ int inet_frag_evictor(struct netns_frags *nf, struct inet_frags *f)
        work = atomic_read(&nf->mem) - nf->low_thresh;
        while (work > 0) {
                read_lock(&f->lock);
-               if (list_empty(&f->lru_list)) {
+               if (list_empty(&nf->lru_list)) {
                        read_unlock(&f->lock);
                        break;
                }
 
-               q = list_first_entry(&f->lru_list,
+               q = list_first_entry(&nf->lru_list,
                                struct inet_frag_queue, lru_list);
                atomic_inc(&q->refcnt);
                read_unlock(&f->lock);
 
                spin_lock(&q->lock);
-               if (!(q->last_in & COMPLETE))
+               if (!(q->last_in & INET_FRAG_COMPLETE))
                        inet_frag_kill(q, f);
                spin_unlock(&q->lock);
 
@@ -182,14 +193,21 @@ EXPORT_SYMBOL(inet_frag_evictor);
 
 static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
                struct inet_frag_queue *qp_in, struct inet_frags *f,
-               unsigned int hash, void *arg)
+               void *arg)
 {
        struct inet_frag_queue *qp;
 #ifdef CONFIG_SMP
        struct hlist_node *n;
 #endif
+       unsigned int hash;
 
        write_lock(&f->lock);
+       /*
+        * While we stayed w/o the lock other CPU could update
+        * the rnd seed, so we need to re-calculate the hash
+        * chain. Fortunatelly the qp_in can be used to get one.
+        */
+       hash = f->hashfn(qp_in);
 #ifdef CONFIG_SMP
        /* With SMP race we have to recheck hash table, because
         * such entry could be created on other cpu, while we
@@ -199,7 +217,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
                if (qp->net == nf && f->match(qp, arg)) {
                        atomic_inc(&qp->refcnt);
                        write_unlock(&f->lock);
-                       qp_in->last_in |= COMPLETE;
+                       qp_in->last_in |= INET_FRAG_COMPLETE;
                        inet_frag_put(qp_in, f);
                        return qp;
                }
@@ -211,7 +229,7 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
 
        atomic_inc(&qp->refcnt);
        hlist_add_head(&qp->list, &f->hash[hash]);
-       list_add_tail(&qp->lru_list, &f->lru_list);
+       list_add_tail(&qp->lru_list, &nf->lru_list);
        nf->nqueues++;
        write_unlock(&f->lock);
        return qp;
@@ -237,7 +255,7 @@ static struct inet_frag_queue *inet_frag_alloc(struct netns_frags *nf,
 }
 
 static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf,
-               struct inet_frags *f, void *arg, unsigned int hash)
+               struct inet_frags *f, void *arg)
 {
        struct inet_frag_queue *q;
 
@@ -245,16 +263,16 @@ static struct inet_frag_queue *inet_frag_create(struct netns_frags *nf,
        if (q == NULL)
                return NULL;
 
-       return inet_frag_intern(nf, q, f, hash, arg);
+       return inet_frag_intern(nf, q, f, arg);
 }
 
 struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
                struct inet_frags *f, void *key, unsigned int hash)
+       __releases(&f->lock)
 {
        struct inet_frag_queue *q;
        struct hlist_node *n;
 
-       read_lock(&f->lock);
        hlist_for_each_entry(q, n, &f->hash[hash], list) {
                if (q->net == nf && f->match(q, key)) {
                        atomic_inc(&q->refcnt);
@@ -264,6 +282,6 @@ struct inet_frag_queue *inet_frag_find(struct netns_frags *nf,
        }
        read_unlock(&f->lock);
 
-       return inet_frag_create(nf, f, key, hash);
+       return inet_frag_create(nf, f, key);
 }
 EXPORT_SYMBOL(inet_frag_find);