summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorJustin Maggard <jmaggard10@gmail.com>2017-10-30 18:29:10 -0400
committerDavid Sterba <dsterba@suse.com>2017-12-06 18:28:12 -0500
commitb430b7751286b3acff2d324553c8cec4f1e87764 (patch)
treeca2af23f06f099dadbf6b58524e9a45e5025496c /fs/btrfs
parentea37d5998b50a72b9045ba60a132eeb20e1c4230 (diff)
btrfs: Fix quota reservation leak on preallocated files
Commit c6887cd11149 ("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: c6887cd11149 ("Btrfs: don't do nocow check unless we have to") Signed-off-by: Justin Maggard <jmaggard@netgear.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/inode.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 993061f83067..e1a7f3cb5be9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3005,6 +3005,8 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
3005 compress_type = ordered_extent->compress_type; 3005 compress_type = ordered_extent->compress_type;
3006 if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) { 3006 if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered_extent->flags)) {
3007 BUG_ON(compress_type); 3007 BUG_ON(compress_type);
3008 btrfs_qgroup_free_data(inode, NULL, ordered_extent->file_offset,
3009 ordered_extent->len);
3008 ret = btrfs_mark_extent_written(trans, BTRFS_I(inode), 3010 ret = btrfs_mark_extent_written(trans, BTRFS_I(inode),
3009 ordered_extent->file_offset, 3011 ordered_extent->file_offset,
3010 ordered_extent->file_offset + 3012 ordered_extent->file_offset +