Skip to content

Commit 24c0a72

Browse files
naotakdave
authored andcommitted
btrfs: zoned: wait for existing extents before truncating
When truncating a file, file buffers which have already been allocated but not yet written may be truncated. Truncating these buffers could cause breakage of a sequential write pattern in a block group if the truncated blocks are for example followed by blocks allocated to another file. To avoid this problem, always wait for write out of all unwritten buffers before proceeding with the truncate execution. Signed-off-by: Naohiro Aota <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0bc09ca commit 24c0a72

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/btrfs/inode.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5169,6 +5169,15 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
51695169
btrfs_drew_write_unlock(&root->snapshot_lock);
51705170
btrfs_end_transaction(trans);
51715171
} else {
5172+
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
5173+
5174+
if (btrfs_is_zoned(fs_info)) {
5175+
ret = btrfs_wait_ordered_range(inode,
5176+
ALIGN(newsize, fs_info->sectorsize),
5177+
(u64)-1);
5178+
if (ret)
5179+
return ret;
5180+
}
51725181

51735182
/*
51745183
* We're truncating a file that used to have good data down to

0 commit comments

Comments
 (0)