Skip to content

Commit 1b83d70

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: Protect inode->i_nlink updates using inode->i_lock
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent d67d1c7 commit 1b83d70

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/nfs/dir.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,14 @@ static int nfs_dentry_delete(struct dentry *dentry)
870870

871871
}
872872

873+
static void nfs_drop_nlink(struct inode *inode)
874+
{
875+
spin_lock(&inode->i_lock);
876+
if (inode->i_nlink > 0)
877+
drop_nlink(inode);
878+
spin_unlock(&inode->i_lock);
879+
}
880+
873881
/*
874882
* Called when the dentry loses inode.
875883
* We use it to clean up silly-renamed files.
@@ -1420,7 +1428,7 @@ static int nfs_safe_remove(struct dentry *dentry)
14201428
error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
14211429
/* The VFS may want to delete this inode */
14221430
if (error == 0)
1423-
drop_nlink(inode);
1431+
nfs_drop_nlink(inode);
14241432
nfs_mark_for_revalidate(inode);
14251433
} else
14261434
error = NFS_PROTO(dir)->remove(dir, &dentry->d_name);
@@ -1647,7 +1655,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
16471655
/* dentry still busy? */
16481656
goto out;
16491657
} else
1650-
drop_nlink(new_inode);
1658+
nfs_drop_nlink(new_inode);
16511659

16521660
go_ahead:
16531661
/*

0 commit comments

Comments
 (0)