mtd/fs/jffs2 gc.c,1.108,1.109

David Woodhouse dwmw2 at infradead.org
Tue Oct 7 09:10:05 EDT 2003


Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv32732

Modified Files:
	gc.c 
Log Message:
Retry when on write failure in jffs2_garbage_collect_pristine(). 
Also fix the fact that we were freeing the wrong raw node ref.


Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- gc.c	4 Oct 2003 08:33:06 -0000	1.108
+++ gc.c	7 Oct 2003 13:10:03 -0000	1.109
@@ -493,6 +493,7 @@
 	int ret;
 	uint32_t phys_ofs, alloclen;
 	uint32_t crc;
+	int retried = 0;
 
 	D1(printk(KERN_DEBUG "Going to GC REF_PRISTINE node at 0x%08x\n", ref_offset(raw)));
 
@@ -573,13 +574,15 @@
 		ret = -ENOMEM;
 		goto out_node;
 	}
+
+	/* OK, all the CRCs are good; this node can just be copied as-is. */
+ retry:
 	nraw->flash_offset = phys_ofs;
 	nraw->totlen = raw->totlen;
 	nraw->next_phys = NULL;
 
-	/* OK, all the CRCs are good; this node can just be copied as-is. */
-
 	ret = jffs2_flash_write(c, phys_ofs, raw->totlen, &retlen, (char *)node);
+
 	if (ret || (retlen != raw->totlen)) {
 		printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n",
                        raw->totlen, phys_ofs, ret, retlen);
@@ -592,8 +595,34 @@
 			jffs2_mark_node_obsolete(c, nraw);
 		} else {
 			printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", nraw->flash_offset);
-                        jffs2_free_raw_node_ref(raw);
+                        jffs2_free_raw_node_ref(nraw);
+		}
+		if (!retried && (nraw == jffs2_alloc_raw_node_ref())) {
+			/* Try to reallocate space and retry */
+			uint32_t dummy;
+			struct jffs2_eraseblock *jeb = &c->blocks[phys_ofs / c->sector_size];
+
+			retried = 1;
+
+			D1(printk(KERN_DEBUG "Retrying failed write of REF_PRISTINE node.\n"));
+			
+			ACCT_SANITY_CHECK(c,jeb);
+			D1(ACCT_PARANOIA_CHECK(jeb));
+
+			ret = jffs2_reserve_space_gc(c, raw->totlen, &phys_ofs, &dummy);
+
+			if (!ret) {
+				D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", phys_ofs));
+
+				ACCT_SANITY_CHECK(c,jeb);
+				D1(ACCT_PARANOIA_CHECK(jeb));
+
+				goto retry;
+			}
+			D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
+			jffs2_free_raw_node_ref(nraw);
 		}
+
 		if (!ret)
 			ret = -EIO;
 		goto out_node;




More information about the linux-mtd-cvs mailing list