mtd/fs/jffs2 fs.c,1.36,1.37

David Woodhouse dwmw2 at infradead.org
Mon Jan 26 07:34:23 EST 2004


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

Modified Files:
	fs.c 
Log Message:
Potential fix for truncate/readpage race.


Index: fs.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/fs.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- fs.c	24 Nov 2003 12:07:28 -0000	1.36
+++ fs.c	26 Jan 2004 12:34:21 -0000	1.37
@@ -145,10 +145,8 @@
 
 	old_metadata = f->metadata;
 
-	if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size) {
-		vmtruncate(inode, iattr->ia_size);
+	if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size)
 		jffs2_truncate_fraglist (c, &f->fragtree, iattr->ia_size);
-	}
 
 	if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
 		jffs2_add_full_dnode_to_inode(c, f, new_metadata);
@@ -165,6 +163,14 @@
 
 	up(&f->sem);
 	jffs2_complete_reservation(c);
+
+	/* We have to do the vmtruncate() without f->sem held, since
+	   some pages may be locked and waiting for it in readpage(). 
+	   We are protected from a simultaneous write() extending i_size
+	   back past iattr->ia_size, because do_truncate() holds the
+	   generic inode semaphore. */
+	if (ivalid & ATTR_SIZE && inode->i_size > iattr->ia_size)
+		vmtruncate(inode, iattr->ia_size);
 
 	return 0;
 }




More information about the linux-mtd-cvs mailing list