[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180809180450.5091-17-naota@elisp.net>
Date: Fri, 10 Aug 2018 03:04:49 +0900
From: Naohiro Aota <naota@...sp.net>
To: David Sterba <dsterba@...e.com>, linux-btrfs@...r.kernel.org
Cc: Chris Mason <clm@...com>, Josef Bacik <jbacik@...com>,
linux-kernel@...r.kernel.org, Hannes Reinecke <hare@...e.com>,
Damien Le Moal <damien.lemoal@....com>,
Bart Van Assche <bart.vanassche@....com>,
Matias Bjorling <mb@...htnvm.io>,
Naohiro Aota <naota@...sp.net>
Subject: [RFC PATCH 16/17] btrfs: wait 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 <naota@...sp.net>
---
fs/btrfs/inode.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 05f5e05ccf37..d3f35f81834f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5193,6 +5193,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.18.0
Powered by blists - more mailing lists