Skip to content

Commit 5838d03

Browse files
author
Darrick J. Wong
committed
xfs: reset child dir '..' entry when unlinking child
While running xfs/168, I noticed a second source of post-shrink corruption errors causing shutdowns. Let's say that directory B has a low inode number and is a child of directory A, which has a high number. If B is empty but open, and unlinked from A, B's dotdot link continues to point to A. If A is then unlinked and the filesystem shrunk so that A is no longer a valid inode, a subsequent AIL push of B will trip the inode verifiers because the dotdot entry points outside of the filesystem. To avoid this problem, reset B's dotdot entry to the root directory when unlinking directories, since the root directory cannot be removed. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Gao Xiang <[email protected]>
1 parent da062d1 commit 5838d03

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/xfs/xfs_inode.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,19 @@ xfs_remove(
27632763
error = xfs_droplink(tp, ip);
27642764
if (error)
27652765
goto out_trans_cancel;
2766+
2767+
/*
2768+
* Point the unlinked child directory's ".." entry to the root
2769+
* directory to eliminate back-references to inodes that may
2770+
* get freed before the child directory is closed. If the fs
2771+
* gets shrunk, this can lead to dirent inode validation errors.
2772+
*/
2773+
if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) {
2774+
error = xfs_dir_replace(tp, ip, &xfs_name_dotdot,
2775+
tp->t_mountp->m_sb.sb_rootino, 0);
2776+
if (error)
2777+
return error;
2778+
}
27662779
} else {
27672780
/*
27682781
* When removing a non-directory we need to log the parent

0 commit comments

Comments
 (0)