xfs: set inode size after creating symlink
PATCH 1/1 xfs: set inode size after creating symlink
When XFS creates a new symlink, it writes its size to disk but not to the VFS inode. This causes i_size_read() to return 0 for that symlink until it is re-read from disk, for example when the system is rebooted.
I found this inconsistency while protecting directories with eCryptFS. The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if the symlink was created after the last reboot on an XFS root.
Call i_size_write() in xfs_symlink()
--- fs/xfs/xfs_symlink.c | 1 + 1 file changed, 1 insertion(+)
fs/xfs/xfs_symlink.c +1 -0
@@ -300,6 +300,7 @@ xfs_symlink( }ASSERT (pathlen ==0 ); } +i_size_write (VFS_I (ip), ip->i_d.di_size);/* * Create the directory entry for the symlink.
Signature · 1 line
2.25.1
Quoted 5 lines · Jeffrey Mitchell
When XFS creates a new symlink, it writes its size to disk but not to the VFS inode. This causes
i_size_read()to return 0 for that symlink until it is re-read from disk, for example when the system is rebooted.I found this inconsistency while protecting directories with eCryptFS.
Heh. No doubt caused by the fact that we only call i_size_write for regular files, ecryptfs copies i_size_read() of the lower dentry into the ecryptfs inode, and ecryptfs_getattr_link and doesn't call ->getattr on the lower inode.
Do directories have the same problem? I'm guessing no because every other file type calls vfs_getattr on the lower dentry, which should link us to xfs_vn_getattr.
--D
Quoted 25 lines
The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if the symlink was created after the last reboot on an XFS root.
Call
i_size_write()inxfs_symlink()Signed-off-by Jeffrey Mitchell <[email protected]>--- fs/xfs/xfs_symlink.c | 1 + 1 file changed, 1 insertion(+)fs/xfs/xfs_symlink.c +1
-0@@ -300,6 +300,7 @@ xfs_symlink( }ASSERT (pathlen ==0 ); } +i_size_write (VFS_I (ip), ip->i_d.di_size);/* * Create the directory entry for the symlink. Signature · 1 line
2.25.1
Quoted 1 line · Darrick J. Wong
Do directories have the same problem?
Yes, I just checked in a VM. While ecryptfs does call vfs_getattr(), it only uses the "blocks" value to supplement the data from an identical generic_fillattr() call to what ecryptfs_getattr_link() uses. The reported size still comes from i_size_read().
V/R,
Jeffrey Mitchell
Quoted 4 lines · Jeffrey Mitchell
When XFS creates a new symlink, it writes its size to disk but not to the VFS inode. This causes
i_size_read()to return 0 for that symlink until it is re-read from disk, for example when the system is rebooted.
Quoted 8 lines
I found this inconsistency while protecting directories with eCryptFS. The command "stat path/to/symlink/in/ecryptfs" will report "Size: 0" if the symlink was created after the last reboot on an XFS root.
Call
i_size_write()inxfs_symlink()Signed-off-by Jeffrey Mitchell <[email protected]>---
Quoted 18 lines
fs/xfs/xfs_symlink.c | 1 + 1 file changed, 1 insertion(+)fs/xfs/xfs_symlink.c +1
-0@@ -300,6 +300,7 @@ xfs_symlink( }ASSERT (pathlen ==0 ); } +i_size_write (VFS_I (ip), ip->i_d.di_size);/* * Create the directory entry for the symlink. Signature · 1 line
2.25.1
Looks good,