From: David Woodhouse Date: Wed, 19 May 2010 15:37:13 +0000 (+0100) Subject: jffs2: Erase pending blocks in GC pass, avoid invalid -EIO return X-Git-Tag: v2.6.35-rc1~465^2~9 X-Git-Url: http://bbs.cooldavid.org/git/?a=commitdiff_plain;h=0717bf8411bb673dd2369aaa096f7396446b38f5;p=net-next-2.6.git jffs2: Erase pending blocks in GC pass, avoid invalid -EIO return jffs2_garbage_collect_pass() would previously return -EAGAIN if it couldn't find anything to garbage collect from, and there were blocks on the erase_pending_list. If the blocks were actually in the process of being erased, though, then they wouldn't be on that list. Check for nr_erasing_blocks being non-zero instead. Fix jffs2_reserve_space() to wait for the in-progress erases to complete, when jffs2_garbage_collect_pass() returns -EAGAIN. And fix jffs2_erase_succeeded() to actually wake up the erase_wait wq that jffs2_reserve_space() is now using. Signed-off-by: David Woodhouse --- diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c index b2d2b6a6e03..563c857ca54 100644 --- a/fs/jffs2/erase.c +++ b/fs/jffs2/erase.c @@ -172,6 +172,7 @@ static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblo mutex_unlock(&c->erase_free_sem); /* Ensure that kupdated calls us again to mark them clean */ jffs2_erase_pending_trigger(c); + wake_up(&c->erase_wait); } static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset) diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c index 3b6f2fa12cf..1ea4a843a43 100644 --- a/fs/jffs2/gc.c +++ b/fs/jffs2/gc.c @@ -214,6 +214,19 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c) return ret; } + /* If there are any blocks which need erasing, erase them now */ + if (!list_empty(&c->erase_complete_list) || + !list_empty(&c->erase_pending_list)) { + spin_unlock(&c->erase_completion_lock); + D1(printk(KERN_DEBUG "jffs2_garbage_collect_pass() erasing pending blocks\n")); + if (jffs2_erase_pending_blocks(c, 1)) { + mutex_unlock(&c->alloc_sem); + return 0; + } + D1(printk(KERN_DEBUG "No progress from erasing blocks; doing GC anyway\n")); + spin_lock(&c->erase_completion_lock); + } + /* First, work out which block we're garbage-collecting */ jeb = c->gcblock; @@ -222,7 +235,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c) if (!jeb) { /* Couldn't find a free block. But maybe we can just erase one and make 'progress'? */ - if (!list_empty(&c->erase_pending_list)) { + if (c->nr_erasing_blocks) { spin_unlock(&c->erase_completion_lock); mutex_unlock(&c->alloc_sem); return -EAGAIN; diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c index 191359dde4e..08e2c69fc14 100644 --- a/fs/jffs2/nodemgmt.c +++ b/fs/jffs2/nodemgmt.c @@ -116,9 +116,21 @@ int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize, ret = jffs2_garbage_collect_pass(c); - if (ret == -EAGAIN) - jffs2_erase_pending_blocks(c, 1); - else 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();