Commit a7f8b1c2 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: file: reserve qgroup space after the hole punch range is locked

The incoming qgroup reserved space timing will move the data reservation
to ordered extent completely.

However in btrfs_punch_hole_lock_range() will call
btrfs_invalidate_page(), which will clear QGROUP_RESERVED bit for the
range.

In current stage it's OK, but if we're making ordered extents handle the
reserved space, then btrfs_punch_hole_lock_range() can clear the
QGROUP_RESERVED bit before we submit ordered extent, leading to qgroup
reserved space leakage.

So here change the timing to make reserve data space after
btrfs_punch_hole_lock_range().
The new timing is fine for either current code or the new code.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9729f10a
...@@ -3174,14 +3174,14 @@ static int btrfs_zero_range(struct inode *inode, ...@@ -3174,14 +3174,14 @@ static int btrfs_zero_range(struct inode *inode,
if (ret < 0) if (ret < 0)
goto out; goto out;
space_reserved = true; space_reserved = true;
ret = btrfs_qgroup_reserve_data(inode, &data_reserved,
alloc_start, bytes_to_reserve);
if (ret)
goto out;
ret = btrfs_punch_hole_lock_range(inode, lockstart, lockend, ret = btrfs_punch_hole_lock_range(inode, lockstart, lockend,
&cached_state); &cached_state);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_qgroup_reserve_data(inode, &data_reserved,
alloc_start, bytes_to_reserve);
if (ret)
goto out;
ret = btrfs_prealloc_file_range(inode, mode, alloc_start, ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
alloc_end - alloc_start, alloc_end - alloc_start,
i_blocksize(inode), i_blocksize(inode),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment