From 180bfb31fef77815d56b875d4f28d353fdc87bf8 Mon Sep 17 00:00:00 2001 From: Vitaly Wool Date: Tue, 6 Mar 2007 17:01:04 +0300 Subject: [JFFS2] Fix writebuffer recovery in the first page of a block For the case when nand_write_page fail with -EIO for the first page in an eraseblock, jffs2_wbuf_recover ends up producing a BUG in jffs2_block_refile as jeb->first_node is not yet set up (it's set up later in jffs2_wbuf_recover). This BUG is not really a bug; it's just jffs2_wbuf_recover calling jffs2_block_refile with the wrong second parameter. This patch takes care of this situation. Signed-off-by: Vitaly Wool Signed-off-by: Thomas Gleixner Signed-off-by: David Woodhouse --- fs/jffs2/wbuf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index de718e3..23028b3 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -238,7 +238,10 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c) jeb = &c->blocks[c->wbuf_ofs / c->sector_size]; spin_lock(&c->erase_completion_lock); - jffs2_block_refile(c, jeb, REFILE_NOTEMPTY); + if (c->wbuf_ofs % c->mtd->erasesize) + jffs2_block_refile(c, jeb, REFILE_NOTEMPTY); + else + jffs2_block_refile(c, jeb, REFILE_ANYWAY); spin_unlock(&c->erase_completion_lock); BUG_ON(!ref_obsolete(jeb->last_node)); -- cgit v1.1 From f8a922c7bb4d93bd84b7371a8e2571e667d2afb5 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 8 Mar 2007 10:28:30 +0000 Subject: [JFFS2] Use yield() between GC passes in background thread. The garbage collection thread is strictly an optimisation. Everything it does would also be done just-in-time in the context of something in userspace trying to access the file system. Sometimes, however, it's a pessimisation. Especially during early boot when it's checksumming nodes and scanning inodes which are shortly going to be pulled in by read_inode anyway. We end up building the rbtree of node coverage twice for the same inode. By switching to yield() instead of cond_resched() in the main loop, we observe boot times on the OLPC system going down from about 100 seconds to 60. Signed-off-by: David Woodhouse --- fs/jffs2/background.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/jffs2/background.c b/fs/jffs2/background.c index 6eb3dae..888f236 100644 --- a/fs/jffs2/background.c +++ b/fs/jffs2/background.c @@ -99,7 +99,13 @@ static int jffs2_garbage_collect_thread(void *_c) if (try_to_freeze()) continue; - cond_resched(); + /* This thread is purely an optimisation. But if it runs when + other things could be running, it actually makes things a + lot worse. Use yield() and put it at the back of the runqueue + every time. Especially during boot, pulling an inode in + with read_inode() is much preferable to having the GC thread + get there first. */ + yield(); /* Put_super will send a SIGKILL and then wait on the sem. */ -- cgit v1.1 From c7258a4477b5ed0243c28ec107b98bb946757448 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Fri, 9 Mar 2007 11:44:00 +0000 Subject: [JFFS2] Check for all-zero node headers Due to a poor choice of CRC32 seed, a node header which is all zeroes would pass the CRC32 check. Explicitly check for this case, and treat it as we do a CRC failure. Signed-off-by: David Woodhouse --- fs/jffs2/readinode.c | 16 +++++++++++++++- fs/jffs2/scan.c | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c index 58a0b91..717a48c 100644 --- a/fs/jffs2/readinode.c +++ b/fs/jffs2/readinode.c @@ -373,7 +373,14 @@ free_out: static inline int read_unknown(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref, struct jffs2_unknown_node *un) { /* We don't mark unknown nodes as REF_UNCHECKED */ - BUG_ON(ref_flags(ref) == REF_UNCHECKED); + if (ref_flags(ref) == REF_UNCHECKED) { + JFFS2_ERROR("REF_UNCHECKED but unknown node at %#08x\n", + ref_offset(ref)); + JFFS2_ERROR("Node is {%04x,%04x,%08x,%08x}. Please report this error.\n", + je16_to_cpu(un->magic), je16_to_cpu(un->nodetype), + je32_to_cpu(un->totlen), je32_to_cpu(un->hdr_crc)); + return 1; + } un->nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(un->nodetype)); @@ -576,6 +583,13 @@ static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_inf jffs2_mark_node_obsolete(c, ref); goto cont; } + /* Due to poor choice of crc32 seed, an all-zero node will have a correct CRC */ + if (!je32_to_cpu(node->u.hdr_crc) && !je16_to_cpu(node->u.nodetype) && + !je16_to_cpu(node->u.magic) && !je32_to_cpu(node->u.totlen)) { + JFFS2_NOTICE("All zero node header at %#08x.\n", ref_offset(ref)); + jffs2_mark_node_obsolete(c, ref); + goto cont; + } switch (je16_to_cpu(node->u.nodetype)) { diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 31c1475..7fb45bd 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -734,6 +734,15 @@ scan_more: ofs += 4; continue; } + /* Due to poor choice of crc32 seed, an all-zero node will have a correct CRC */ + if (!je32_to_cpu(node->hdr_crc) && !je16_to_cpu(node->nodetype) && + !je16_to_cpu(node->magic) && !je32_to_cpu(node->totlen)) { + noisy_printk(&noise, "jffs2_scan_eraseblock(): All zero node header at 0x%08x.\n", ofs); + if ((err = jffs2_scan_dirty_space(c, jeb, 4))) + return err; + ofs += 4; + continue; + } if (ofs + je32_to_cpu(node->totlen) > jeb->offset + c->sector_size) { -- cgit v1.1 From 0feba829ee82a6e43baabe3f0bdf91bd937a67a1 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 8 Mar 2007 10:35:10 +0200 Subject: [JFFS2] print a message when marking bad block New bad eraseblock is an event which is important enough to be printed about. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- fs/jffs2/wbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index 23028b3..4fac6dd 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -1090,7 +1090,7 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock * if (!c->mtd->block_markbad) return 1; // What else can we do? - D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Marking bad block at %08x\n", bad_offset)); + printk(KERN_WARNING "JFFS2: marking eraseblock at %08x\n as bad", bad_offset); ret = c->mtd->block_markbad(c->mtd, bad_offset); if (ret) { -- cgit v1.1