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

David Woodhouse dwmw2 at infradead.org
Fri Oct 3 11:26:18 EDT 2003


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

Modified Files:
	write.c 
Log Message:
Retry for jffs2_write_dirent() too


Index: write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- write.c	3 Oct 2003 15:19:01 -0000	1.68
+++ write.c	3 Oct 2003 15:26:16 -0000	1.69
@@ -179,7 +179,7 @@
 			}
 
 			if (!ret) {
-				D1(printk(KERN_DEBUG "Allocated space to retry failed write at 0x%08x\n", flash_ofs));
+				D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", flash_ofs));
 				goto retry;
 			}
 			D1(printk(KERN_DEBUG "Failed to allocate space to retry failed write: %d!\n", ret));
@@ -213,10 +213,10 @@
 		  flash_ofs, ref_flags(raw), je32_to_cpu(ri->dsize), 
 		  je32_to_cpu(ri->csize), je32_to_cpu(ri->node_crc),
 		  je32_to_cpu(ri->data_crc), je32_to_cpu(ri->totlen)));
+
 	if (writelen)
 		*writelen = retlen;
 
-	f->inocache->nodes = raw;
 	return fn;
 }
 
@@ -226,6 +226,7 @@
 	struct jffs2_full_dirent *fd;
 	size_t retlen;
 	struct iovec vecs[2];
+	int retried = 1; /* Not yet */
 	int ret;
 
 	D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n", 
@@ -254,11 +255,6 @@
 		jffs2_free_raw_node_ref(raw);
 		return ERR_PTR(-ENOMEM);
 	}
-	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(sizeof(*rd)+namelen);
-	raw->next_in_ino = f->inocache->nodes;
-	f->inocache->nodes = raw;
-	raw->next_phys = NULL;
 
 	fd->version = je32_to_cpu(rd->version);
 	fd->ino = je32_to_cpu(rd->ino);
@@ -266,8 +262,14 @@
 	fd->type = rd->type;
 	memcpy(fd->name, name, namelen);
 	fd->name[namelen]=0;
+
+ retry:
 	fd->raw = raw;
 
+	raw->flash_offset = flash_ofs;
+	raw->totlen = PAD(sizeof(*rd)+namelen);
+	raw->next_phys = NULL;
+
 	ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,
 				 (alloc_mode==ALLOC_GC)?0:fd->ino);
 	if (ret || (retlen != sizeof(*rd) + namelen)) {
@@ -275,6 +277,7 @@
 			       sizeof(*rd)+namelen, flash_ofs, ret, retlen);
 		/* Mark the space as dirtied */
 		if (retlen) {
+			raw->next_in_ino = NULL;
 			raw->flash_offset |= REF_OBSOLETE;
 			jffs2_add_physical_node_ref(c, raw);
 			jffs2_mark_node_obsolete(c, raw);
@@ -282,7 +285,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(*rd) + namelen, &flash_ofs, &dummy);
+			} else {
+				/* Locking pain */
+				up(&f->sem);
+				jffs2_complete_reservation(c);
+			
+				ret = jffs2_reserve_space(c, sizeof(*rd) + namelen, &flash_ofs, &dummy, alloc_mode);
+			}
 
+			if (!ret) {
+				D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\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_dirent(fd);
 		if (writelen)
@@ -292,10 +319,13 @@
 	/* Mark the space used */
 	raw->flash_offset |= REF_PRISTINE;
 	jffs2_add_physical_node_ref(c, raw);
+
+	raw->next_in_ino = f->inocache->nodes;
+	f->inocache->nodes = raw;
+
 	if (writelen)
 		*writelen = retlen;
 
-	f->inocache->nodes = raw;
 	return fd;
 }
 




More information about the linux-mtd-cvs mailing list