Skip to content

Commit 89e4228

Browse files
fdmananaopsiff
authored andcommitted
btrfs: error on missing block group when unaccounting log tree extent buffers
commit fc57999 upstream. Currently we only log an error message if we can't find the block group for a log tree extent buffer when unaccounting it (while freeing a log tree). A missing block group means something is seriously wrong and we end up leaking space from the metadata space info. So return -ENOENT in case we don't find the block group. CC: stable@vger.kernel.org # 6.12+ Reviewed-by: Boris Burkov <boris@bur.io> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 58e66d83e1ace9e21efc6b23a13ba0db543c7fb7)
1 parent e518ff9 commit 89e4228

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

fs/btrfs/tree-log.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,14 +2587,14 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
25872587
/*
25882588
* Correctly adjust the reserved bytes occupied by a log tree extent buffer
25892589
*/
2590-
static void unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
2590+
static int unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
25912591
{
25922592
struct btrfs_block_group *cache;
25932593

25942594
cache = btrfs_lookup_block_group(fs_info, start);
25952595
if (!cache) {
25962596
btrfs_err(fs_info, "unable to find block group for %llu", start);
2597-
return;
2597+
return -ENOENT;
25982598
}
25992599

26002600
spin_lock(&cache->space_info->lock);
@@ -2605,27 +2605,22 @@ static void unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
26052605
spin_unlock(&cache->space_info->lock);
26062606

26072607
btrfs_put_block_group(cache);
2608+
2609+
return 0;
26082610
}
26092611

26102612
static int clean_log_buffer(struct btrfs_trans_handle *trans,
26112613
struct extent_buffer *eb)
26122614
{
2613-
int ret;
2614-
26152615
btrfs_tree_lock(eb);
26162616
btrfs_clear_buffer_dirty(trans, eb);
26172617
wait_on_extent_buffer_writeback(eb);
26182618
btrfs_tree_unlock(eb);
26192619

2620-
if (trans) {
2621-
ret = btrfs_pin_reserved_extent(trans, eb);
2622-
if (ret)
2623-
return ret;
2624-
} else {
2625-
unaccount_log_buffer(eb->fs_info, eb->start);
2626-
}
2620+
if (trans)
2621+
return btrfs_pin_reserved_extent(trans, eb);
26272622

2628-
return 0;
2623+
return unaccount_log_buffer(eb->fs_info, eb->start);
26292624
}
26302625

26312626
static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)