Skip to content

Commit 39020d8

Browse files
fdmananakdave
authored andcommitted
btrfs: do not BUG_ON() on tree mod log failure at balance_level()
At balance_level(), instead of doing a BUG_ON() in case we fail to record tree mod log operations, do a transaction abort and return the error to the callers. There's really no need for the BUG_ON() as we can release all resources in this context, and we have to abort because other future tree searches that use the tree mod log (btrfs_search_old_slot()) may get inconsistent results if other operations modify the tree after that failure and before the tree mod log based search. CC: stable@vger.kernel.org # 5.4+ 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>
1 parent 40b0a74 commit 39020d8

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,12 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
10541054
}
10551055

10561056
ret = btrfs_tree_mod_log_insert_root(root->node, child, true);
1057-
BUG_ON(ret < 0);
1057+
if (ret < 0) {
1058+
btrfs_tree_unlock(child);
1059+
free_extent_buffer(child);
1060+
btrfs_abort_transaction(trans, ret);
1061+
goto enospc;
1062+
}
10581063
rcu_assign_pointer(root->node, child);
10591064

10601065
add_root_to_dirty_list(root);
@@ -1142,7 +1147,10 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11421147
btrfs_node_key(right, &right_key, 0);
11431148
ret = btrfs_tree_mod_log_insert_key(parent, pslot + 1,
11441149
BTRFS_MOD_LOG_KEY_REPLACE);
1145-
BUG_ON(ret < 0);
1150+
if (ret < 0) {
1151+
btrfs_abort_transaction(trans, ret);
1152+
goto enospc;
1153+
}
11461154
btrfs_set_node_key(parent, &right_key, pslot + 1);
11471155
btrfs_mark_buffer_dirty(parent);
11481156
}
@@ -1188,7 +1196,10 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
11881196
btrfs_node_key(mid, &mid_key, 0);
11891197
ret = btrfs_tree_mod_log_insert_key(parent, pslot,
11901198
BTRFS_MOD_LOG_KEY_REPLACE);
1191-
BUG_ON(ret < 0);
1199+
if (ret < 0) {
1200+
btrfs_abort_transaction(trans, ret);
1201+
goto enospc;
1202+
}
11921203
btrfs_set_node_key(parent, &mid_key, pslot);
11931204
btrfs_mark_buffer_dirty(parent);
11941205
}

0 commit comments

Comments
 (0)