Skip to content

Commit b430b77

Browse files
jmaggard10kdave
authored andcommitted
btrfs: Fix quota reservation leak on preallocated files
Commit c6887cd ("Btrfs: don't do nocow check unless we have to") changed the behavior of __btrfs_buffered_write() so that it first tries to get a data space reservation, and then skips the relatively expensive nocow check if the reservation succeeded. If we have quotas enabled, the data space reservation also includes a quota reservation. But in the rewrite case, the space has already been accounted for in qgroups. So btrfs_check_data_free_space() increases the quota reservation, but it never gets decreased when the data actually gets written and overwrites the pre-existing data. So we're left with both the qgroup and qgroup reservation accounting for the same space. This commit adds the missing btrfs_qgroup_free_data() call in the case of BTRFS_ORDERED_PREALLOC extents. Fixes: c6887cd ("Btrfs: don't do nocow check unless we have to") Signed-off-by: Justin Maggard <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ea37d59 commit b430b77

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,6 +3005,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
30053005
compress_type = ordered_extent->compress_type;
30063006
if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
30073007
BUG_ON(compress_type);
3008+
btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset,
3009+
ordered_extent->len);
30083010
ret = btrfs_mark_extent_written(trans, BTRFS_I(inode),
30093011
ordered_extent->file_offset,
30103012
ordered_extent->file_offset +

0 commit comments

Comments
 (0)