[PATCH v17 05/10] ocfs2: record the fsync transaction when CoW makes clusters writable

From: Joseph Qi

Date: Sat Dec 05 2026 - 03:19:58 EST


From: Heming Zhao <heming.zhao@xxxxxxxx>

ocfs2_make_clusters_writable() changes the extent tree to break a
refcount sharing, but it does not record the transaction in the inode's
datasync tid. A subsequent O_DSYNC or fsync that relies on
i_datasync_tid can therefore consider the CoW already committed and skip
waiting for it.

Record it before committing, at out_commit, so the error exits after the
transaction started record it too: earlier loop iterations may already
have dirtied extent tree buffers that ocfs2_commit_trans() will write.

Fixes: 2931cdcb4919 ("ocfs2: improve fsync efficiency and fix deadlock between aio_write and sync_file")
Co-developed-by: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx>
Signed-off-by: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx>
Signed-off-by: Heming Zhao <heming.zhao@xxxxxxxx>
---
fs/ocfs2/refcounttree.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index 4f13b5a6faa7d..2e2f3becb8da9 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -3360,6 +3360,7 @@ static int ocfs2_make_clusters_writable(struct super_block *sb,
}

out_commit:
+ ocfs2_update_inode_fsync_trans(handle, context->inode, 1);
ocfs2_commit_trans(osb, handle);

out:
--
2.39.3