Revert "writeback: fix WB_SYNC_NONE writeback from umount"
[safe/jmp/linux-2.6] / fs / jffs2 / nodemgmt.c
index a0313fa..694aa5b 100644 (file)
@@ -10,7 +10,6 @@
  */
 
 #include <linux/kernel.h>
-#include <linux/slab.h>
 #include <linux/mtd/mtd.h>
 #include <linux/compiler.h>
 #include <linux/sched.h> /* For cond_resched() */
@@ -48,7 +47,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
        minsize = PAD(minsize);
 
        D1(printk(KERN_DEBUG "jffs2_reserve_space(): Requested 0x%x bytes\n", minsize));
-       down(&c->alloc_sem);
+       mutex_lock(&c->alloc_sem);
 
        D1(printk(KERN_DEBUG "jffs2_reserve_space(): alloc sem got\n"));
 
@@ -57,7 +56,6 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
        /* this needs a little more thought (true <tglx> :)) */
        while(ret == -EAGAIN) {
                while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) {
-                       int ret;
                        uint32_t dirty, avail;
 
                        /* calculate real dirty size
@@ -82,7 +80,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
                                          dirty, c->unchecked_size, c->sector_size));
 
                                spin_unlock(&c->erase_completion_lock);
-                               up(&c->alloc_sem);
+                               mutex_unlock(&c->alloc_sem);
                                return -ENOSPC;
                        }
 
@@ -105,11 +103,11 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
                                D1(printk(KERN_DEBUG "max. available size 0x%08x  < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n",
                                          avail, blocksneeded * c->sector_size));
                                spin_unlock(&c->erase_completion_lock);
-                               up(&c->alloc_sem);
+                               mutex_unlock(&c->alloc_sem);
                                return -ENOSPC;
                        }
 
-                       up(&c->alloc_sem);
+                       mutex_unlock(&c->alloc_sem);
 
                        D1(printk(KERN_DEBUG "Triggering GC pass. nr_free_blocks %d, nr_erasing_blocks %d, free_size 0x%08x, dirty_size 0x%08x, wasted_size 0x%08x, used_size 0x%08x, erasing_size 0x%08x, bad_size 0x%08x (total 0x%08x of 0x%08x)\n",
                                  c->nr_free_blocks, c->nr_erasing_blocks, c->free_size, c->dirty_size, c->wasted_size, c->used_size, c->erasing_size, c->bad_size,
@@ -117,7 +115,22 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
                        spin_unlock(&c->erase_completion_lock);
 
                        ret = jffs2_garbage_collect_pass(c);
-                       if (ret)
+
+                       if (ret == -EAGAIN) {
+                               spin_lock(&c->erase_completion_lock);
+                               if (c->nr_erasing_blocks &&
+                                   list_empty(&c->erase_pending_list) &&
+                                   list_empty(&c->erase_complete_list)) {
+                                       DECLARE_WAITQUEUE(wait, current);
+                                       set_current_state(TASK_UNINTERRUPTIBLE);
+                                       add_wait_queue(&c->erase_wait, &wait);
+                                       D1(printk(KERN_DEBUG "%s waiting for erase to complete\n", __func__));
+                                       spin_unlock(&c->erase_completion_lock);
+
+                                       schedule();
+                               } else
+                                       spin_unlock(&c->erase_completion_lock);
+                       } else if (ret)
                                return ret;
 
                        cond_resched();
@@ -125,7 +138,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
                        if (signal_pending(current))
                                return -EINTR;
 
-                       down(&c->alloc_sem);
+                       mutex_lock(&c->alloc_sem);
                        spin_lock(&c->erase_completion_lock);
                }
 
@@ -138,7 +151,7 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
        if (!ret)
                ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
        if (ret)
-               up(&c->alloc_sem);
+               mutex_unlock(&c->alloc_sem);
        return ret;
 }
 
@@ -216,7 +229,7 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c)
                        ejeb = list_entry(c->erasable_list.next, struct jffs2_eraseblock, list);
                        list_move_tail(&ejeb->list, &c->erase_pending_list);
                        c->nr_erasing_blocks++;
-                       jffs2_erase_pending_trigger(c);
+                       jffs2_garbage_collect_trigger(c);
                        D1(printk(KERN_DEBUG "jffs2_find_nextblock: Triggering erase of erasable block at 0x%08x\n",
                                  ejeb->offset));
                }
@@ -259,6 +272,12 @@ static int jffs2_find_nextblock(struct jffs2_sb_info *c)
 
        jffs2_sum_reset_collected(c->summary); /* reset collected summary */
 
+#ifdef CONFIG_JFFS2_FS_WRITEBUFFER
+       /* adjust write buffer offset, else we get a non contiguous write bug */
+       if (!(c->wbuf_ofs % c->sector_size) && !c->wbuf_len)
+               c->wbuf_ofs = 0xffffffff;
+#endif
+
        D1(printk(KERN_DEBUG "jffs2_find_nextblock(): new nextblock = 0x%08x\n", c->nextblock->offset));
 
        return 0;
@@ -462,8 +481,10 @@ struct jffs2_raw_node_ref *jffs2_add_physical_node_ref(struct jffs2_sb_info *c,
 void jffs2_complete_reservation(struct jffs2_sb_info *c)
 {
        D1(printk(KERN_DEBUG "jffs2_complete_reservation()\n"));
+       spin_lock(&c->erase_completion_lock);
        jffs2_garbage_collect_trigger(c);
-       up(&c->alloc_sem);
+       spin_unlock(&c->erase_completion_lock);
+       mutex_unlock(&c->alloc_sem);
 }
 
 static inline int on_list(struct list_head *obj, struct list_head *head)
@@ -512,7 +533,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
                   any jffs2_raw_node_refs. So we don't need to stop erases from
                   happening, or protect against people holding an obsolete
                   jffs2_raw_node_ref without the erase_completion_lock. */
-               down(&c->erase_free_sem);
+               mutex_lock(&c->erase_free_sem);
        }
 
        spin_lock(&c->erase_completion_lock);
@@ -604,7 +625,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
                                D1(printk(KERN_DEBUG "...and adding to erase_pending_list\n"));
                                list_add_tail(&jeb->list, &c->erase_pending_list);
                                c->nr_erasing_blocks++;
-                               jffs2_erase_pending_trigger(c);
+                               jffs2_garbage_collect_trigger(c);
                        } else {
                                /* Sometimes, however, we leave it elsewhere so it doesn't get
                                   immediately reused, and we spread the load a bit. */
@@ -707,7 +728,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
                                break;
 #endif
                        default:
-                               if (ic->nodes == (void *)ic && ic->nlink == 0)
+                               if (ic->nodes == (void *)ic && ic->pino_nlink == 0)
                                        jffs2_del_ino_cache(c, ic);
                                break;
                }
@@ -715,7 +736,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
        }
 
  out_erase_sem:
-       up(&c->erase_free_sem);
+       mutex_unlock(&c->erase_free_sem);
 }
 
 int jffs2_thread_should_wake(struct jffs2_sb_info *c)
@@ -725,6 +746,10 @@ int jffs2_thread_should_wake(struct jffs2_sb_info *c)
        int nr_very_dirty = 0;
        struct jffs2_eraseblock *jeb;
 
+       if (!list_empty(&c->erase_complete_list) ||
+           !list_empty(&c->erase_pending_list))
+               return 1;
+
        if (c->unchecked_size) {
                D1(printk(KERN_DEBUG "jffs2_thread_should_wake(): unchecked_size %d, checked_ino #%d\n",
                          c->unchecked_size, c->checked_ino));