Skip to content

Commit

Permalink
Btrfs: fix off-by-one error of the reserved size of btrfs_allocate()
Browse files Browse the repository at this point in the history
alloc_end is not the real end of the current extent, it is the start of the
next adjoining extent. So we needn't +1 when calculating the size the space
that is about to be reserved.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
  • Loading branch information
Miao Xie authored and Chris Mason committed Dec 17, 2012
1 parent 797f427 commit 0ff6fab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ static long btrfs_fallocate(struct file *file, int mode,
* Make sure we have enough space before we do the
* allocation.
*/
ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start + 1);
ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start);
if (ret)
return ret;

Expand Down Expand Up @@ -2179,7 +2179,7 @@ static long btrfs_fallocate(struct file *file, int mode,
out:
mutex_unlock(&inode->i_mutex);
/* Let go of our reservation. */
btrfs_free_reserved_data_space(inode, alloc_end - alloc_start + 1);
btrfs_free_reserved_data_space(inode, alloc_end - alloc_start);
return ret;
}

Expand Down

0 comments on commit 0ff6fab

Please sign in to comment.