Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@gmail.com>2014-04-26 01:35:31 +0100
committerChris Mason <clm@fb.com>2014-06-09 17:20:24 -0700
commita1a50f60a6bf4f861eb94793420274bc1ccd409a (patch)
tree78460ac0f6e86d31174f15d018ef4c2ec87286fc
parent7fb18a06644a33f0a2eba810d57d4b3b2c982f5b (diff)
Btrfs: read inode size after acquiring the mutex when punching a hole
In a previous change, commit 12870f1c9b2de7d475d22e73fd7db1b418599725, I accidentally moved the roundup of inode->i_size to outside of the critical section delimited by the inode mutex, which is not atomic and not correct since the size can be changed by other task before we acquire the mutex. Therefore fix it. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r--fs/btrfs/file.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index ae6af072b635..e4ff2d52ea23 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2187,13 +2187,14 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
bool same_page = ((offset >> PAGE_CACHE_SHIFT) ==
((offset + len - 1) >> PAGE_CACHE_SHIFT));
bool no_holes = btrfs_fs_incompat(root->fs_info, NO_HOLES);
- u64 ino_size = round_up(inode->i_size, PAGE_CACHE_SIZE);
+ u64 ino_size;
ret = btrfs_wait_ordered_range(inode, offset, len);
if (ret)
return ret;
mutex_lock(&inode->i_mutex);
+ ino_size = round_up(inode->i_size, PAGE_CACHE_SIZE);
/*
* We needn't truncate any page which is beyond the end of the file
* because we are sure there is no data there.