Skip to content

Commit 7f550e2

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. Reviewed-by: Boris Burkov <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent aa9d5f4 commit 7f550e2

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
@@ -2593,14 +2593,14 @@ static int replay_one_buffer(struct btrfs_root *log, struct extent_buffer *eb,
25932593
/*
25942594
* Correctly adjust the reserved bytes occupied by a log tree extent buffer
25952595
*/
2596-
static void unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
2596+
static int unaccount_log_buffer(struct btrfs_fs_info *fs_info, u64 start)
25972597
{
25982598
struct btrfs_block_group *cache;
25992599

26002600
cache = btrfs_lookup_block_group(fs_info, start);
26012601
if (!cache) {
26022602
btrfs_err(fs_info, "unable to find block group for %llu", start);
2603-
return;
2603+
return -ENOENT;
26042604
}
26052605

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

26132613
btrfs_put_block_group(cache);
2614+
2615+
return 0;
26142616
}
26152617

26162618
static int clean_log_buffer(struct btrfs_trans_handle *trans,
26172619
struct extent_buffer *eb)
26182620
{
2619-
int ret;
2620-
26212621
btrfs_tree_lock(eb);
26222622
btrfs_clear_buffer_dirty(trans, eb);
26232623
wait_on_extent_buffer_writeback(eb);
26242624
btrfs_tree_unlock(eb);
26252625

2626-
if (trans) {
2627-
ret = btrfs_pin_reserved_extent(trans, eb);
2628-
if (ret)
2629-
return ret;
2630-
} else {
2631-
unaccount_log_buffer(eb->fs_info, eb->start);
2632-
}
2626+
if (trans)
2627+
return btrfs_pin_reserved_extent(trans, eb);
26332628

2634-
return 0;
2629+
return unaccount_log_buffer(eb->fs_info, eb->start);
26352630
}
26362631

26372632
static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans,

0 commit comments

Comments
 (0)