mtd/fs/jffs2 write.c,1.67,1.68

David Woodhouse dwmw2 at infradead.org
Fri Oct 3 11:19:05 EDT 2003


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

Modified Files:
	write.c 
Log Message:
Retry code for jffs2_write_dnode()


Index: write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- write.c	3 Oct 2003 15:00:36 -0000	1.67
+++ write.c	3 Oct 2003 15:19:01 -0000	1.68
@@ -94,6 +94,7 @@
 	size_t retlen;
 	struct iovec vecs[2];
 	int ret;
+	int retried = 1; /* Don't activate this yet */
 	unsigned long cnt = 2;
 
 	D1(if(je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
@@ -120,18 +121,20 @@
 		jffs2_free_raw_node_ref(raw);
 		return ERR_PTR(-ENOMEM);
 	}
-	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(sizeof(*ri)+datalen);
-	raw->next_phys = NULL;
 
 	fn->ofs = je32_to_cpu(ri->offset);
 	fn->size = je32_to_cpu(ri->dsize);
 	fn->frags = 0;
-	fn->raw = raw;
 
 	/* check number of valid vecs */
 	if (!datalen || !data)
 		cnt = 1;
+ retry:
+	fn->raw = raw;
+
+	raw->flash_offset = flash_ofs;
+	raw->totlen = PAD(sizeof(*ri)+datalen);
+	raw->next_phys = NULL;
 
 	ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen,
 				 (alloc_mode==ALLOC_GC)?0:f->inocache->ino);
@@ -157,7 +160,31 @@
 			printk(KERN_NOTICE "Not marking the space at 0x%08x as dirty because the flash driver returned retlen zero\n", raw->flash_offset);
 			jffs2_free_raw_node_ref(raw);
 		}
-
+		if (!retried && (raw = jffs2_alloc_raw_node_ref())) {
+			/* Try to reallocate space and retry */
+			uint32_t dummy;
+
+			retried = 1;
+
+			D1(printk(KERN_DEBUG "Retrying failed write.\n"));
+
+			if (alloc_mode == ALLOC_GC) {
+				ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &flash_ofs, &dummy);
+			} else {
+				/* Locking pain */
+				up(&f->sem);
+				jffs2_complete_reservation(c);
+			
+				ret = jffs2_reserve_space(c, sizeof(*ri) + datalen, &flash_ofs, &dummy, alloc_mode);
+			}
+
+			if (!ret) {
+				D1(printk(KERN_DEBUG "Allocated space to retry failed write at 0x%08x\n", flash_ofs));
+				goto retry;
+			}
+			D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
+			jffs2_free_raw_node_ref(raw);
+		}
 		/* Release the full_dnode which is now useless, and return */
 		jffs2_free_full_dnode(fn);
 		if (writelen)




More information about the linux-mtd-cvs mailing list