Skip to contentSkip to conversation

jfs: use i_size helpers in open and truncate paths

PATCH New Cen Zhang 1 participant 1 message May 5 JFS filesystem

lore
Share & tools
lore

Cen Zhang

author
#0 lore raw

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.

---
 fs/jfs/file.c      | 4 ++--
 fs/jfs/jfs_xtree.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/jfs/file.c +2 -2
index 246568cb9a6e..c2eee945b339 100644
@@ -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
index 28c3cf960c6f..8658a21cbf89 100644
@@ -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