]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[JFFS2] Fix jffs2_reserve_space() when all blocks are pending erasure.
authorDavid Woodhouse <dwmw2@infradead.org>
Wed, 23 Apr 2008 14:40:52 +0000 (15:40 +0100)
committerDavid Woodhouse <dwmw2@infradead.org>
Wed, 23 Apr 2008 15:01:37 +0000 (16:01 +0100)
When _all_ the blocks were on the erase_pending_list, we could't find a
block to GC from but there was no _actually_ free space, and
jffs2_reserve_space() would get a little unhappy.

Handle this case by returning -EAGAIN from jffs2_garbage_collect_pass().
There are two callers of that function -- jffs2_flush_wbuf_gc(), which
will interpret it as an error and flush the writebuffer by other means,
and jffs2_reserve_space(), which we modify to respond to -EAGAIN with an
immediate call to jffs2_erase_pending_blocks() and another run round the
loop.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
fs/jffs2/gc.c
fs/jffs2/nodemgmt.c

index 26c7992c45caef6d620203d486769b8b17b2c9a4..bad005664e308b1fd2f30e49ccad91d7afd57b91 100644 (file)
@@ -221,7 +221,13 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
                jeb = jffs2_find_gc_block(c);
 
        if (!jeb) {
-               D1 (printk(KERN_NOTICE "jffs2: Couldn't find erase block to garbage collect!\n"));
+               /* Couldn't find a free block. But maybe we can just erase one and make 'progress'? */
+               if (!list_empty(&c->erase_pending_list)) {
+                       spin_unlock(&c->erase_completion_lock);
+                       mutex_unlock(&c->alloc_sem);
+                       return -EAGAIN;
+               }
+               D1(printk(KERN_NOTICE "jffs2: Couldn't find erase block to garbage collect!\n"));
                spin_unlock(&c->erase_completion_lock);
                mutex_unlock(&c->alloc_sem);
                return -EIO;
index 747a73f0aa4d3b8dcf25dfec74fd4a1631fb4a0d..9df8f3ef20dfd8d8a39d59ee02d4e14ea2713927 100644 (file)
@@ -116,7 +116,10 @@ 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)
+                               jffs2_erase_pending_blocks(c, 1);
+                       else if (ret)
                                return ret;
 
                        cond_resched();