[JFFS2] When retiring nextblock, allocate a node_ref for the wasted space

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Sun Jun 18 13:59:01 EDT 2006


Commit:     fc6612f627c697b348a4ef64f16fb373d86dbd76
Parent:     2ba72cb754bb091bb24a44e9682f7105110f7f38
commit fc6612f627c697b348a4ef64f16fb373d86dbd76
Author:     David Woodhouse <dwmw2 at infradead.org>
AuthorDate: Sun Jun 18 18:35:10 2006 +0100
Commit:     David Woodhouse <dwmw2 at infradead.org>
CommitDate: Sun Jun 18 18:39:38 2006 +0100

    [JFFS2] When retiring nextblock, allocate a node_ref for the wasted space
    
    Failing to do so makes the calculated length of the last node incorrect,
    when we're not using eraseblock summaries.
    
    Signed-off-by: David Woodhouse <dwmw2 at infradead.org>
---
 fs/jffs2/nodemgmt.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 71d1630..8bedfd2 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -317,6 +317,8 @@ static int jffs2_do_reserve_space(struct
 		}
 	} else {
 		if (jeb && minsize > jeb->free_size) {
+			uint32_t waste;
+
 			/* Skip the end of this block and file it as having some dirty space */
 			/* If there's a pending write to it, flush now */
 
@@ -329,10 +331,26 @@ static int jffs2_do_reserve_space(struct
 				goto restart;
 			}
 
-			c->wasted_size += jeb->free_size;
-			c->free_size -= jeb->free_size;
-			jeb->wasted_size += jeb->free_size;
-			jeb->free_size = 0;
+			spin_unlock(&c->erase_completion_lock);
+
+			ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
+			if (ret)
+				return ret;
+			/* Just lock it again and continue. Nothing much can change because
+			   we hold c->alloc_sem anyway. In fact, it's not entirely clear why
+			   we hold c->erase_completion_lock in the majority of this function...
+			   but that's a question for another (more caffeine-rich) day. */
+			spin_lock(&c->erase_completion_lock);
+
+			waste = jeb->free_size;
+			jffs2_link_node_ref(c, jeb,
+					    (jeb->offset + c->sector_size - waste) | REF_OBSOLETE,
+					    waste, NULL);
+			/* FIXME: that made it count as dirty. Convert to wasted */
+			jeb->dirty_size -= waste;
+			c->dirty_size -= waste;
+			jeb->wasted_size += waste;
+			c->wasted_size += waste;
 
 			jffs2_close_nextblock(c, jeb);
 			jeb = NULL;



More information about the linux-mtd-cvs mailing list