Commit 0f6925fa authored by Qu Wenruo's avatar Qu Wenruo Committed by Chris Mason

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: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent dc6c5fb3
...@@ -2584,7 +2584,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -2584,7 +2584,7 @@ static long btrfs_fallocate(struct file *file, int mode,
alloc_start); alloc_start);
if (ret) if (ret)
goto out; goto out;
} else { } else if (offset + len > inode->i_size) {
/* /*
* If we are fallocating from the end of the file onward we * 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 * need to zero out the end of the page if i_size lands in the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment