jfs: use i_size helpers in open and truncate paths
PATCH 1/1 jfs: use i_size helpers in open and truncate paths
jfs_open() reads inode->i_size without holding i_rwsem and can run concurrently with xtTruncate() publishing a new inode size, for example from failed extending direct I/O cleanup.
Use i_size_read() for the lockless open-time checks and publish xtTruncate()'s resulting size with i_size_write(). This follows the VFS inode size protocol, avoiding torn 64-bit accesses on 32-bit SMP and preserving the acquire/release ordering used by lockless size readers and writers.
The existing JFS serialization around truncate is unchanged.
Signed-off-by Cen Zhang <[email protected]>
--- fs/jfs/file.c | 4 ++-- fs/jfs/jfs_xtree.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
fs/jfs/file.c +2 -2
@@ -45,7 +45,7 @@ static int jfs_open(struct inode *inode, struct file *file) {int rc; -if (S_ISREG (inode->i_mode) && inode->i_size <0 ) +if (S_ISREG (inode->i_mode) &&i_size_read (inode) <0 )return -EIO ;if ((rc =dquot_file_open (inode, file)))
@@ -61,7 +61,7 @@ static int jfs_open(struct inode *inode, struct file *file)* file is actually grown. */ if (S_ISREG (inode->i_mode) && file->f_mode &FMODE_WRITE && - (inode->i_size ==0 )) { +i_size_read (inode) ==0 ) {struct jfs_inode_info *ji =JFS_IP (inode);spin_lock_irq (&ji->ag_lock);if (ji->active_ag ==-1 ) {
fs/jfs/jfs_xtree.c +2 -2
@@ -2715,9 +2715,9 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)/* set size */ if (S_ISDIR (ip->i_mode) && !newsize) - ip->i_size =1 ;/* fsck hates zero-length directories */ +i_size_write (ip,1 );/* fsck hates zero-length directories */ else - ip->i_size = newsize; +i_size_write (ip, newsize);/* update quota allocation to reflect freed blocks */ dquot_free_block (ip, nfreed);
Signature · 1 line
2.43.0