btrfs: fix qgroup reservation leak on failure to allocate ordered extent
[ Upstream commit 1f2889f5594a2bc4c6a52634c4a51b93e785def5 ]
If we fail to allocate an ordered extent for a COW write we end up leaking
a qgroup data reservation since we called btrfs_qgroup_release_data() but
we didn't call btrfs_qgroup_free_refroot() (which would happen when
running the respective data delayed ref created by ordered extent
completion or when finishing the ordered extent in case an error happened).
So make sure we call btrfs_qgroup_free_refroot() if we fail to allocate an
ordered extent for a COW write.
Fixes: 7dbeaad0af
("btrfs: change timing for qgroup reserved space for ordered extents to fix reserved space leak")
CC: stable@vger.kernel.org # 6.1+
Reviewed-by: Boris Burkov <boris@bur.io>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
ccdd3eaec6
commit
3499dcb6c5
@@ -154,9 +154,10 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
|
|||||||
struct btrfs_ordered_extent *entry;
|
struct btrfs_ordered_extent *entry;
|
||||||
int ret;
|
int ret;
|
||||||
u64 qgroup_rsv = 0;
|
u64 qgroup_rsv = 0;
|
||||||
|
const bool is_nocow = (flags &
|
||||||
|
((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC)));
|
||||||
|
|
||||||
if (flags &
|
if (is_nocow) {
|
||||||
((1 << BTRFS_ORDERED_NOCOW) | (1 << BTRFS_ORDERED_PREALLOC))) {
|
|
||||||
/* For nocow write, we can release the qgroup rsv right now */
|
/* For nocow write, we can release the qgroup rsv right now */
|
||||||
ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
|
ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -171,8 +172,13 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
|
|||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
|
entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
|
||||||
if (!entry)
|
if (!entry) {
|
||||||
|
if (!is_nocow)
|
||||||
|
btrfs_qgroup_free_refroot(inode->root->fs_info,
|
||||||
|
btrfs_root_id(inode->root),
|
||||||
|
qgroup_rsv, BTRFS_QGROUP_RSV_DATA);
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
entry->file_offset = file_offset;
|
entry->file_offset = file_offset;
|
||||||
entry->num_bytes = num_bytes;
|
entry->num_bytes = num_bytes;
|
||||||
|
Reference in New Issue
Block a user