Skip to content

Commit

Permalink
Btrfs: read inode size after acquiring the mutex when punching a hole
Browse files Browse the repository at this point in the history
In a previous change, commit 12870f1,
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>
  • Loading branch information
Filipe Manana authored and Chris Mason committed Jun 10, 2014
1 parent 7fb18a0 commit a1a50f6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a1a50f6

Please sign in to comment.