Skip to content

Commit

Permalink
btrfs: zoned: wait for existing extents before truncating
Browse files Browse the repository at this point in the history
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 <naohiro.aota@wdc.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Naohiro Aota authored and David Sterba committed Feb 9, 2021
1 parent 0bc09ca commit 24c0a72
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5169,6 +5169,15 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
btrfs_drew_write_unlock(&root->snapshot_lock);
btrfs_end_transaction(trans);
} else {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);

if (btrfs_is_zoned(fs_info)) {
ret = btrfs_wait_ordered_range(inode,
ALIGN(newsize, fs_info->sectorsize),
(u64)-1);
if (ret)
return ret;
}

/*
* We're truncating a file that used to have good data down to
Expand Down

0 comments on commit 24c0a72

Please sign in to comment.