Skip to content

Commit fc57999

Browse files
fdmananakdave
authored andcommitted
btrfs: error on missing block group when unaccounting log tree extent buffers
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: [email protected] # 6.12+ Reviewed-by: Boris Burkov <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent deaf895 commit fc57999

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

fs/btrfs/tree-log.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,14 +2605,14 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
26052605
/*
26062606
* Correctly adjust the reserved bytes occupied by a log tree extent buffer
26072607
*/
2608-
static void unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
2608+
static int unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
26092609
{
26102610
struct btrfs_block_group *cache;
26112611

26122612
cache = btrfs_lookup_block_group(fs_info, start);
26132613
if (!cache) {
26142614
btrfs_err(fs_info, "unable to find block group for %llu", start);
2615-
return;
2615+
return -ENOENT;
26162616
}
26172617

26182618
spin_lock(&cache->space_info->lock);
@@ -2623,27 +2623,22 @@ static void unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
26232623
spin_unlock(&cache->space_info->lock);
26242624

26252625
btrfs_put_block_group(cache);
2626+
2627+
return 0;
26262628
}
26272629

26282630
static int clean_log_buffer(struct btrfs_trans_handle *trans,
26292631
struct extent_buffer *eb)
26302632
{
2631-
int ret;
2632-
26332633
btrfs_tree_lock(eb);
26342634
btrfs_clear_buffer_dirty(trans, eb);
26352635
wait_on_extent_buffer_writeback(eb);
26362636
btrfs_tree_unlock(eb);
26372637

2638-
if (trans) {
2639-
ret = btrfs_pin_reserved_extent(trans, eb);
2640-
if (ret)
2641-
return ret;
2642-
} else {
2643-
unaccount_log_buffer(eb->fs_info, eb->start);
2644-
}
2638+
if (trans)
2639+
return btrfs_pin_reserved_extent(trans, eb);
26452640

2646-
return 0;
2641+
return unaccount_log_buffer(eb->fs_info, eb->start);
26472642
}
26482643

26492644
static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)