Skip to content

Commit 1308255

Browse files
jankaratytso
authored andcommitted
ext4: fix fsync(2) for nojournal mode
When inode metadata is changed, we sometimes just call ext4_mark_inode_dirty() to track modified metadata. This copies inode metadata into block buffer which is enough when we are journalling metadata. However when we are running in nojournal mode we currently fail to write the dirtied inode buffer during fsync(2) because the inode is not marked as dirty. Use explicit ext4_write_inode() call to make sure the inode table buffer is written to the disk. This is a band aid solution but proper solution requires a much larger rewrite including changes in metadata bh tracking infrastructure. Reported-by: Free Ekanayaka <free.ekanayaka@gmail.com> Link: https://lore.kernel.org/all/87il8nhxdm.fsf@x1.mail-host-address-is-not-set/ CC: stable@vger.kernel.org Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Link: https://patch.msgid.link/20260216164848.3074-4-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org
1 parent bd060af commit 1308255

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

fs/ext4/fsync.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,23 @@ static int ext4_fsync_nojournal(struct file *file, loff_t start, loff_t end,
8383
int datasync, bool *needs_barrier)
8484
{
8585
struct inode *inode = file->f_inode;
86+
struct writeback_control wbc = {
87+
.sync_mode = WB_SYNC_ALL,
88+
.nr_to_write = 0,
89+
};
8690
int ret;
8791

8892
ret = generic_buffers_fsync_noflush(file, start, end, datasync);
89-
if (!ret)
90-
ret = ext4_sync_parent(inode);
93+
if (ret)
94+
return ret;
95+
96+
/* Force writeout of inode table buffer to disk */
97+
ret = ext4_write_inode(inode, &wbc);
98+
if (ret)
99+
return ret;
100+
101+
ret = ext4_sync_parent(inode);
102+
91103
if (test_opt(inode->i_sb, BARRIER))
92104
*needs_barrier = true;
93105

0 commit comments

Comments
 (0)