Skip to content

Commit 82a25b0

Browse files
jankaratytso
authored andcommitted
ext4: wait for outstanding dio during truncate in nojournal mode
We didn't wait for outstanding direct IO during truncate in nojournal mode (as we skip orphan handling in that case). This can lead to fs corruption or stale data exposure if truncate ends up freeing blocks and these get reallocated before direct IO finishes. Fix the condition determining whether the wait is necessary. CC: [email protected] Fixes: 1c9114f ("ext4: serialize unlocked dio reads with truncate") Reviewed-by: Ira Weiny <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0a944e8 commit 82a25b0

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

fs/ext4/inode.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,20 +5630,17 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
56305630
goto err_out;
56315631
}
56325632
}
5633-
if (!shrink)
5633+
if (!shrink) {
56345634
pagecache_isize_extended(inode, oldsize, inode->i_size);
5635-
5636-
/*
5637-
* Blocks are going to be removed from the inode. Wait
5638-
* for dio in flight. Temporarily disable
5639-
* dioread_nolock to prevent livelock.
5640-
*/
5641-
if (orphan) {
5642-
if (!ext4_should_journal_data(inode)) {
5643-
inode_dio_wait(inode);
5644-
} else
5645-
ext4_wait_for_tail_page_commit(inode);
5635+
} else {
5636+
/*
5637+
* Blocks are going to be removed from the inode. Wait
5638+
* for dio in flight.
5639+
*/
5640+
inode_dio_wait(inode);
56465641
}
5642+
if (orphan && ext4_should_journal_data(inode))
5643+
ext4_wait_for_tail_page_commit(inode);
56475644
down_write(&EXT4_I(inode)->i_mmap_sem);
56485645

56495646
rc = ext4_break_layouts(inode);

0 commit comments

Comments
 (0)