linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] VFS: Fix race with new inode creation
@ 2009-04-10 15:31 Curt Wohlgemuth
  2009-04-10 16:01 ` Al Viro
  0 siblings, 1 reply; 5+ messages in thread
From: Curt Wohlgemuth @ 2009-04-10 15:31 UTC (permalink / raw)
  To: linux-fsdevel

This patch fixes a race between a task creating a new inode, and one writing
that same new, dirty inode out to disk.

We found this using a particular workload (fsstress) along with other
ancillary processes running on the same machine.  The symptom is one or more
hung unkillable (uniterruptible sleep) tasks that try to operate on this new
inode.

The original comment block is wrong.  Since the inode gets marked dirty
after it's created, but before its I_LOCK bit is cleared, there _can_ be
somebody else doing something with this inode -- e.g., a writeback task
(in our case, __sync_single_inode()).

	Signed-off-by: Curt Wohlgemuth  <curtw@google.com>
---

--- linux-2.6.29.1/fs/inode.c.orig	2009-04-02 13:55:27.000000000 -0700
+++ linux-2.6.29.1/fs/inode.c	2009-04-09 11:16:03.000000000 -0700
@@ -651,15 +651,14 @@ void unlock_new_inode(struct inode *inod
 	}
 #endif
 	/*
-	 * This is special!  We do not need the spinlock
-	 * when clearing I_LOCK, because we're guaranteed
-	 * that nobody else tries to do anything about the
-	 * state of the inode when it is locked, as we
-	 * just created it (so there can be no old holders
-	 * that haven't tested I_LOCK).
+	 * We need to hold the inode lock while clearing these bits, because
+	 * there is a race between this code and the writeback path, since all
+	 * of the new inode allocation routines will mark the inode as dirty.
 	 */
 	WARN_ON((inode->i_state & (I_LOCK|I_NEW)) != (I_LOCK|I_NEW));
+	spin_lock(&inode_lock);
 	inode->i_state &= ~(I_LOCK|I_NEW);
+	spin_unlock(&inode_lock);
 	wake_up_inode(inode);
 }

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

end of thread, other threads:[~2009-04-14 17:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-10 15:31 [PATCH] VFS: Fix race with new inode creation Curt Wohlgemuth
2009-04-10 16:01 ` Al Viro
2009-04-10 16:08   ` Curt Wohlgemuth
2009-04-14 16:57   ` Andrew Morton
2009-04-14 17:30     ` Nick Piggin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).