aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r--fs/btrfs/file.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index d75412bf7c4a..700ffd266da3 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1859,9 +1859,9 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
1859 struct btrfs_path *path; 1859 struct btrfs_path *path;
1860 struct btrfs_block_rsv *rsv; 1860 struct btrfs_block_rsv *rsv;
1861 struct btrfs_trans_handle *trans; 1861 struct btrfs_trans_handle *trans;
1862 u64 mask = BTRFS_I(inode)->root->sectorsize - 1; 1862 u64 lockstart = round_up(offset, BTRFS_I(inode)->root->sectorsize);
1863 u64 lockstart = (offset + mask) & ~mask; 1863 u64 lockend = round_down(offset + len,
1864 u64 lockend = ((offset + len) & ~mask) - 1; 1864 BTRFS_I(inode)->root->sectorsize) - 1;
1865 u64 cur_offset = lockstart; 1865 u64 cur_offset = lockstart;
1866 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1); 1866 u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
1867 u64 drop_end; 1867 u64 drop_end;
@@ -1896,10 +1896,12 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
1896 } 1896 }
1897 1897
1898 /* zero the front end of the last page */ 1898 /* zero the front end of the last page */
1899 ret = btrfs_truncate_page(inode, offset + len, 0, 1); 1899 if (offset + len < round_up(inode->i_size, PAGE_CACHE_SIZE)) {
1900 if (ret) { 1900 ret = btrfs_truncate_page(inode, offset + len, 0, 1);
1901 mutex_unlock(&inode->i_mutex); 1901 if (ret) {
1902 return ret; 1902 mutex_unlock(&inode->i_mutex);
1903 return ret;
1904 }
1903 } 1905 }
1904 1906
1905 if (lockend < lockstart) { 1907 if (lockend < lockstart) {