aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_inode.c
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2015-05-28 18:14:55 -0400
committerDave Chinner <david@fromorbit.com>2015-05-28 18:14:55 -0400
commit22419ac9fe5e79483596cebdbd1d1209c18bac1a (patch)
tree334293b6a6b987030c9cc5c7a7af9d3bf486ab8c /fs/xfs/xfs_inode.c
parentcddc116228cb9d51d3224d23ba3e61fbbc3ec3d2 (diff)
xfs: fix broken i_nlink accounting for whiteout tmpfile inode
XFS uses the internal tmpfile() infrastructure for the whiteout inode used for RENAME_WHITEOUT operations. For tmpfile inodes, XFS allocates the inode, drops di_nlink, adds the inode to the agi unlinked list, calls d_tmpfile() which correspondingly drops i_nlink of the vfs inode, and then finishes the common inode setup (e.g., clear I_NEW and unlock). The d_tmpfile() call was originally made inxfs_create_tmpfile(), but was pulled up out of that function as part of the following commit to resolve a deadlock issue: 330033d6 xfs: fix tmpfile/selinux deadlock and initialize security As a result, callers of xfs_create_tmpfile() are responsible for either calling d_tmpfile() or fixing up i_nlink appropriately. The whiteout tmpfile allocation helper does neither. As a result, the vfs ->i_nlink becomes inconsistent with the on-disk ->di_nlink once xfs_rename() links it back into the source dentry and calls xfs_bumplink(). Update the assert in xfs_rename() to help detect this problem in the future and update xfs_rename_alloc_whiteout() to decrement the link count as part of the manual tmpfile inode setup. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_inode.c')
-rw-r--r--fs/xfs/xfs_inode.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 1117dd3ba123..539a85fddbc2 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2879,7 +2879,13 @@ xfs_rename_alloc_whiteout(
2879 if (error) 2879 if (error)
2880 return error; 2880 return error;
2881 2881
2882 /* Satisfy xfs_bumplink that this is a real tmpfile */ 2882 /*
2883 * Prepare the tmpfile inode as if it were created through the VFS.
2884 * Otherwise, the link increment paths will complain about nlink 0->1.
2885 * Drop the link count as done by d_tmpfile(), complete the inode setup
2886 * and flag it as linkable.
2887 */
2888 drop_nlink(VFS_I(tmpfile));
2883 xfs_finish_inode_setup(tmpfile); 2889 xfs_finish_inode_setup(tmpfile);
2884 VFS_I(tmpfile)->i_state |= I_LINKABLE; 2890 VFS_I(tmpfile)->i_state |= I_LINKABLE;
2885 2891
@@ -3147,7 +3153,7 @@ xfs_rename(
3147 * intermediate state on disk. 3153 * intermediate state on disk.
3148 */ 3154 */
3149 if (wip) { 3155 if (wip) {
3150 ASSERT(wip->i_d.di_nlink == 0); 3156 ASSERT(VFS_I(wip)->i_nlink == 0 && wip->i_d.di_nlink == 0);
3151 error = xfs_bumplink(tp, wip); 3157 error = xfs_bumplink(tp, wip);
3152 if (error) 3158 if (error)
3153 goto out_trans_abort; 3159 goto out_trans_abort;