lkml.org 
[lkml]   [2019]   [Jun]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 16/19] btrfs: wait existing extents before truncating
Date
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>
---
fs/btrfs/inode.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 89542c19d09e..4e8c7921462f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5137,6 +5137,17 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
btrfs_end_write_no_snapshotting(root);
btrfs_end_transaction(trans);
} else {
+ struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
+
+ if (btrfs_fs_incompat(fs_info, HMZONED)) {
+ u64 sectormask = fs_info->sectorsize - 1;
+
+ ret = btrfs_wait_ordered_range(inode,
+ newsize & (~sectormask),
+ (u64)-1);
+ if (ret)
+ return ret;
+ }

/*
* We're truncating a file that used to have good data down to
--
2.21.0
\
 
 \ /
  Last update: 2019-06-07 15:12    [W:0.533 / U:0.464 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site