diff options
-rw-r--r-- | fs/btrfs/file.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 700ffd266da3..71c2dc1ea15a 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1873,26 +1873,28 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) | |||
1873 | btrfs_wait_ordered_range(inode, offset, len); | 1873 | btrfs_wait_ordered_range(inode, offset, len); |
1874 | 1874 | ||
1875 | mutex_lock(&inode->i_mutex); | 1875 | mutex_lock(&inode->i_mutex); |
1876 | if (offset >= inode->i_size) { | 1876 | /* |
1877 | mutex_unlock(&inode->i_mutex); | 1877 | * We needn't truncate any page which is beyond the end of the file |
1878 | return 0; | 1878 | * because we are sure there is no data there. |
1879 | } | 1879 | */ |
1880 | |||
1881 | /* | 1880 | /* |
1882 | * Only do this if we are in the same page and we aren't doing the | 1881 | * Only do this if we are in the same page and we aren't doing the |
1883 | * entire page. | 1882 | * entire page. |
1884 | */ | 1883 | */ |
1885 | if (same_page && len < PAGE_CACHE_SIZE) { | 1884 | if (same_page && len < PAGE_CACHE_SIZE) { |
1886 | ret = btrfs_truncate_page(inode, offset, len, 0); | 1885 | if (offset < round_up(inode->i_size, PAGE_CACHE_SIZE)) |
1886 | ret = btrfs_truncate_page(inode, offset, len, 0); | ||
1887 | mutex_unlock(&inode->i_mutex); | 1887 | mutex_unlock(&inode->i_mutex); |
1888 | return ret; | 1888 | return ret; |
1889 | } | 1889 | } |
1890 | 1890 | ||
1891 | /* zero back part of the first page */ | 1891 | /* zero back part of the first page */ |
1892 | ret = btrfs_truncate_page(inode, offset, 0, 0); | 1892 | if (offset < round_up(inode->i_size, PAGE_CACHE_SIZE)) { |
1893 | if (ret) { | 1893 | ret = btrfs_truncate_page(inode, offset, 0, 0); |
1894 | mutex_unlock(&inode->i_mutex); | 1894 | if (ret) { |
1895 | return ret; | 1895 | mutex_unlock(&inode->i_mutex); |
1896 | return ret; | ||
1897 | } | ||
1896 | } | 1898 | } |
1897 | 1899 | ||
1898 | /* zero the front end of the last page */ | 1900 | /* zero the front end of the last page */ |