[PATCH v2 3/3] ocfs2: use READ_ONCE for lockless jinode reads
From: Li Chen
Date: Thu Feb 19 2026 - 06:49:30 EST
ocfs2 journal commit callback reads jbd2_inode dirty range fields without
holding journal->j_list_lock.
Use READ_ONCE() for these reads to match the lockless access pattern.
Convert the dirty range from PAGE_SIZE units back to byte offsets before
passing it to writeback.
Suggested-by: Jan Kara <jack@xxxxxxx>
Signed-off-by: Li Chen <me@linux.beauty>
---
Changes since v1:
- Convert the jinode dirty range from PAGE_SIZE units (pgoff_t) back to byte
offsets before passing it to writeback.
fs/ocfs2/journal.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 85239807dec7..0b40383ebcdf 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -902,8 +902,17 @@ int ocfs2_journal_alloc(struct ocfs2_super *osb)
static int ocfs2_journal_submit_inode_data_buffers(struct jbd2_inode *jinode)
{
- return filemap_fdatawrite_range(jinode->i_vfs_inode->i_mapping,
- jinode->i_dirty_start, jinode->i_dirty_end);
+ struct address_space *mapping = jinode->i_vfs_inode->i_mapping;
+ pgoff_t dirty_start = READ_ONCE(jinode->i_dirty_start);
+ pgoff_t dirty_end = READ_ONCE(jinode->i_dirty_end);
+ loff_t start_byte, end_byte;
+
+ if (dirty_end == JBD2_INODE_DIRTY_RANGE_NONE)
+ return 0;
+ start_byte = (loff_t)dirty_start << PAGE_SHIFT;
+ end_byte = ((loff_t)dirty_end << PAGE_SHIFT) + PAGE_SIZE - 1;
+
+ return filemap_fdatawrite_range(mapping, start_byte, end_byte);
}
int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty)
--
2.52.0