From: Qu Wenruo Date: Wed, 14 Oct 2015 07:26:13 +0000 (+0800) Subject: btrfs: Avoid truncate tailing page if fallocate range doesn't exceed inode size X-Git-Tag: v4.1.12-92~197^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6f5632395d0f5571568a08abd8a96ff14c20d1a7;p=users%2Fjedix%2Flinux-maple.git btrfs: Avoid truncate tailing page if fallocate range doesn't exceed inode size Current code will always truncate tailing page if its alloc_start is smaller than inode size. For example, the file extent layout is like: 0 4K 8K 16K 32K |<-----Extent A---------------->| |<--Inode size: 18K---------->| But if calling fallocate even for range [0,4K), it will cause btrfs to re-truncate the range [16,32K), causing COW and a new extent. 0 4K 8K 16K 32K |///////| <- Fallocate call range |<-----Extent A-------->|<--B-->| The cause is quite easy, just a careless btrfs_truncate_inode() in a else branch without extra judgment. Fix it by add judgment on whether the fallocate range is beyond isize. Signed-off-by: Qu Wenruo Signed-off-by: Chris Mason Orabug: 22573877 (cherry picked from mainline commit 0f6925fa2907df58496cabc33fa4677c635e2223) Signed-off-by: Ashish Samant --- diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index b072e17479aa..24be5c12b66e 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2581,7 +2581,7 @@ static long btrfs_fallocate(struct file *file, int mode, alloc_start); if (ret) goto out; - } else { + } else if (offset + len > inode->i_size) { /* * If we are fallocating from the end of the file onward we * need to zero out the end of the page if i_size lands in the