Skip to contentSkip to conversation

ext4: Fix fsync for non-directories

PATCH Applied Jan Kara 3 participants 3 messages May 24, 2023 – May 30, 2023

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 ext4: Fix fsync for non-directories

Commit e360c6ed7274 ("ext4: Drop special handling of journalled data from ext4_sync_file()") simplified ext4_sync_file() by dropping special handling of journalled data mode as it was not needed anymore. However that branch was also used for directories and symlinks and since the fastcommit code does not track metadata changes to non-regular files, the change has caused e.g. fsync(2) on directories to not commit transaction as it should. Fix the problem by adding handling for non-regular files.

Fixes e360c6ed7274 ("ext4: Drop special handling of journalled data from ext4_sync_file()")
---
 fs/ext4/fsync.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/fsync.c +7 -0
index f65fdb27ce14..2a143209aa0c 100644
@@ -108,6 +108,13 @@ static int ext4_fsync_journal(struct inode *inode, bool datasync,
 	journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
 	tid_t commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
 
+	/*
+	 * Fastcommit does not really support fsync on directories or other
+	 * special files. Force a full commit.
+	 */
+	if (!S_ISREG(inode->i_mode))
+		return ext4_force_commit(inode->i_sb);
+
 	if (journal->j_flags & JBD2_BARRIER &&
 	    !jbd2_trans_will_send_data_barrier(journal, commit_tid))
 		*needs_barrier = true;
Signature · 1 line
2.35.3
Tested-by on v1 1/1
#1 lore raw

* Jan Kara <[email protected]>:

Quoted 37 lines

Commit e360c6ed7274 ("ext4: Drop special handling of journalled data from ext4_sync_file()") simplified ext4_sync_file() by dropping special handling of journalled data mode as it was not needed anymore. However that branch was also used for directories and symlinks and since the fastcommit code does not track metadata changes to non-regular files, the change has caused e.g. fsync(2) on directories to not commit transaction as it should. Fix the problem by adding handling for non-regular files.

Fixes e360c6ed7274 ("ext4: Drop special handling of journalled data from ext4_sync_file()")
---
 fs/ext4/fsync.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ext4/fsync.c +7 -0
index f65fdb27ce14..2a143209aa0c 100644
@@ -108,6 +108,13 @@ static int ext4_fsync_journal(struct inode *inode, bool datasync,
 	journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
 	tid_t commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
 
+	/*
+	 * Fastcommit does not really support fsync on directories or other
+	 * special files. Force a full commit.
+	 */
+	if (!S_ISREG(inode->i_mode))
+		return ext4_force_commit(inode->i_sb);
+
 	if (journal->j_flags & JBD2_BARRIER &&
 	    !jbd2_trans_will_send_data_barrier(journal, commit_tid))
 		*needs_barrier = true;
Signature · 1 line
2.35.3

Hi Jan:

100/100 trials of both the original test regressions - generic/065 and generic/535 - passed when I used kvm-xfstests to run them on a 6.4-rc3 kernel modified with this patch. A complete run of the adv test case also passed without new regressions.

So,

Thanks!
Eric

maintainer Applied
#2 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

Commit e360c6ed7274 ("ext4: Drop special handling of journalled data from ext4_sync_file()") simplified ext4_sync_file() by dropping special handling of journalled data mode as it was not needed anymore. However that branch was also used for directories and symlinks and since the fastcommit code does not track metadata changes to non-regular files, the change has caused e.g. fsync(2) on directories to not commit transaction as it should. Fix the problem by adding handling for non-regular files.

[...]

Applied, thanks!

[1/1] ext4: Fix fsync for non-directories

      commit: 47a71ba09a8473c81cb87ed11421ed2896f352d2

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>