All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH NFSv2] Drop inode after rename
@ 2005-07-11 10:46 Olaf Kirch
  2005-07-11 10:50 ` Olaf Kirch
  2005-07-11 11:05 ` Trond Myklebust
  0 siblings, 2 replies; 9+ messages in thread
From: Olaf Kirch @ 2005-07-11 10:46 UTC (permalink / raw)
  To: nfs; +Cc: Michael Schroeder

With recent kernels, we were seeing frequent corruption of files on NFSv2
immediately after creation, often containing pieces of of frequently
written files such as .viminfo and the like.

The problem turns out to be caused by rename. The applications
encountering this problem were all rewriting files by first creating a
temporary copy, and finally renaming it, replacing the original file.

When doing a rename on a NFSv2 mount on top of an existing file, the
inode of the overwritten file would remain, with all caches intact. If
a new file created subsequently ended up with the same inode number, it
would pick up the stale cache.

The fix is to decrement i_nlink of the overwritten inode, like we
do for unlink, rmdir etc already.

Signed-off-by: okir@suse.de


Index: linux-2.6.11/fs/nfs/dir.c
===================================================================
--- linux-2.6.11.orig/fs/nfs/dir.c
+++ linux-2.6.11/fs/nfs/dir.c
@@ -1429,8 +1429,15 @@ go_ahead:
 		shrink_dcache_parent(old_dentry);
 	}
 
-	if (new_inode)
+	/* d_delete will currently not do a dentry_iput
+	 * because new_dentry->d_count is at least 2 when
+	 * we get here. As a matter of caution
+	 * let's grab a reference to the inode anyway.
+	 */
+	if (new_inode && igrab(new_inode)) {
+		nfs_begin_data_update(new_inode);
 		d_delete(new_dentry);
+	}
 
 	nfs_begin_data_update(old_dir);
 	nfs_begin_data_update(new_dir);
@@ -1440,6 +1447,17 @@ go_ahead:
 	nfs_end_data_update(old_inode);
 	nfs_end_data_update(new_dir);
 	nfs_end_data_update(old_dir);
+
+	if (new_inode) {
+		/* If this was the last reference to the inode make
+		 * sure the VFS zaps it and all associated caches.
+		 */
+		if (error == 0)
+			new_inode->i_nlink--;
+		nfs_end_data_update(new_inode);  
+		iput(new_inode);
+	}
+
 out:
 	if (rehash)
 		d_rehash(rehash);

-- 
Olaf Kirch   |  --- o --- Nous sommes du soleil we love when we play
okir@suse.de |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-07-11 12:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-11 10:46 [PATCH NFSv2] Drop inode after rename Olaf Kirch
2005-07-11 10:50 ` Olaf Kirch
2005-07-11 11:05 ` Trond Myklebust
2005-07-11 11:07   ` Olaf Kirch
2005-07-11 11:14     ` Trond Myklebust
2005-07-11 11:24       ` Olaf Kirch
2005-07-11 11:56         ` Trond Myklebust
2005-07-11 12:28           ` Michael Schroeder
2005-07-11 12:34             ` Trond Myklebust

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.