[PATCH] jfs: use i_size helpers in open and truncate paths

Cen Zhang posted 1 patch 1 month, 1 week ago
fs/jfs/file.c      | 4 ++--
fs/jfs/jfs_xtree.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
[PATCH] jfs: use i_size helpers in open and truncate paths
Posted by Cen Zhang 1 month, 1 week ago
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 <zzzccc427@gmail.com>
---
 fs/jfs/file.c      | 4 ++--
 fs/jfs/jfs_xtree.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index 246568cb9a6e..c2eee945b339 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -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) {
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index 28c3cf960c6f..8658a21cbf89 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -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);

-- 
2.43.0