Skip to content

Commit fe188c0

Browse files
committed
ext4: Assure that metadata blocks are written during fsync in no journal mode
When there is no journal present, we must attach buffer heads associated with extent tree and indirect blocks to the inode's mapping->private_list via mark_buffer_dirty_inode() so that ext4_sync_file() --- which is called to service fsync() and fdatasync() system calls --- can write out the inode's metadata blocks by calling sync_mapping_buffers(). Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent c7acb4c commit fe188c0

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎fs/ext4/ext4_jbd2.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ int __ext4_handle_dirty_metadata(const char *where, handle_t *handle,
8989
ext4_journal_abort_handle(where, __func__, bh,
9090
handle, err);
9191
} else {
92-
mark_buffer_dirty(bh);
92+
if (inode && bh)
93+
mark_buffer_dirty_inode(bh, inode);
94+
else
95+
mark_buffer_dirty(bh);
9396
if (inode && inode_needs_sync(inode)) {
9497
sync_dirty_buffer(bh);
9598
if (buffer_req(bh) && !buffer_uptodate(bh)) {

‎fs/ext4/fsync.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync)
5050
{
5151
struct inode *inode = dentry->d_inode;
5252
journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
53-
int ret = 0;
53+
int err, ret = 0;
5454

5555
J_ASSERT(ext4_journal_current_handle() == NULL);
5656

@@ -79,6 +79,9 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync)
7979
goto out;
8080
}
8181

82+
if (!journal)
83+
ret = sync_mapping_buffers(inode->i_mapping);
84+
8285
if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
8386
goto out;
8487

@@ -91,7 +94,9 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync)
9194
.sync_mode = WB_SYNC_ALL,
9295
.nr_to_write = 0, /* sys_fsync did this */
9396
};
94-
ret = sync_inode(inode, &wbc);
97+
err = sync_inode(inode, &wbc);
98+
if (ret == 0)
99+
ret = err;
95100
}
96101
out:
97102
if (journal && (journal->j_flags & JBD2_BARRIER))

0 commit comments

Comments
 (0)