Skip to contentSkip to conversation

Fix race in xfs_iunpin

REVIEW 4 of 4 David Chinner 1 participant 1 message Oct 24, 2006

lore
Share & tools
lore
#0 lore raw
Signature · 37 lines
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group


Close a race condition in xfs_iunpin() -  we need to guarantee the
atomicity of the last unpin and the checking of the XFS_IRECLAIM*
flags otherwise pre-emption or interrupt can cause us to race with
xfs_iget_core() which would now see the inode as unpinned and hence
clear the XFS_IRECLAIMABLE flag.

---
 fs/xfs/xfs_inode.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: 2.6.x-xfs-new/fs/xfs/xfs_inode.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/xfs_inode.c	2006-10-19 10:26:01.983441994 +1000
+++ 2.6.x-xfs-new/fs/xfs/xfs_inode.c	2006-10-19 10:29:31.008384156 +1000
@@ -2741,7 +2741,7 @@ xfs_iunpin(
 {
 	ASSERT(atomic_read(&ip->i_pincount) > 0);
 
-	if (atomic_dec_and_test(&ip->i_pincount)) {
+	if (atomic_dec_and_lock(&ip->i_pincount, &ip->i_flags_lock)) {
 
 		/*
 		 * If the inode is currently being reclaimed, the link between
@@ -2760,7 +2760,6 @@ xfs_iunpin(
 		 * unpinned.
 		 */
 
-		spin_lock(&ip->i_flags_lock);
 		if (!__xfs_iflags_test(ip, XFS_IRECLAIM|XFS_IRECLAIMABLE)) {
 			bhv_vnode_t	*vp = XFS_ITOV_NULL(ip);
 			struct inode *inode = NULL;