Skip to content

Commit 1077b2d

Browse files
jankaratytso
authored andcommitted
ext4: fix fsync for non-directories
Commit e360c6e ("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: e360c6e ("ext4: Drop special handling of journalled data from ext4_sync_file()") Reported-by: Eric Whitney <enwlinux@gmail.com> Link: https://lore.kernel.org/all/ZFqO3xVnmhL7zv1x@debian-BULLSEYE-live-builder-AMD64 Signed-off-by: Jan Kara <jack@suse.cz> Tested-by: Eric Whitney <enwlinux@gmail.com> Link: https://lore.kernel.org/r/20230524104453.8734-1-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent aff3bea commit 1077b2d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/ext4/fsync.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ static int ext4_fsync_journal(struct inode *inode, bool datasync,
108108
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
109109
tid_t commit_tid = datasync ? ei->i_datasync_tid : ei->i_sync_tid;
110110

111+
/*
112+
* Fastcommit does not really support fsync on directories or other
113+
* special files. Force a full commit.
114+
*/
115+
if (!S_ISREG(inode->i_mode))
116+
return ext4_force_commit(inode->i_sb);
117+
111118
if (journal->j_flags & JBD2_BARRIER &&
112119
!jbd2_trans_will_send_data_barrier(journal, commit_tid))
113120
*needs_barrier = true;

0 commit comments

Comments
 (0)