Skip to content

Commit 11d6ae0

Browse files
fdmananakdave
authored andcommitted
btrfs: do not BUG_ON() on tree mod log failures at push_nodes_for_insert()
At push_nodes_for_insert(), 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 caller. 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. 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 eced687 commit 11d6ae0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,12 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
13081308
btrfs_node_key(mid, &disk_key, 0);
13091309
ret = btrfs_tree_mod_log_insert_key(parent, pslot,
13101310
BTRFS_MOD_LOG_KEY_REPLACE);
1311-
BUG_ON(ret < 0);
1311+
if (ret < 0) {
1312+
btrfs_tree_unlock(left);
1313+
free_extent_buffer(left);
1314+
btrfs_abort_transaction(trans, ret);
1315+
return ret;
1316+
}
13121317
btrfs_set_node_key(parent, &disk_key, pslot);
13131318
btrfs_mark_buffer_dirty(parent);
13141319
if (btrfs_header_nritems(left) > orig_slot) {
@@ -1363,7 +1368,12 @@ static noinline int push_nodes_for_insert(struct btrfs_trans_handle *trans,
13631368
btrfs_node_key(right, &disk_key, 0);
13641369
ret = btrfs_tree_mod_log_insert_key(parent, pslot + 1,
13651370
BTRFS_MOD_LOG_KEY_REPLACE);
1366-
BUG_ON(ret < 0);
1371+
if (ret < 0) {
1372+
btrfs_tree_unlock(right);
1373+
free_extent_buffer(right);
1374+
btrfs_abort_transaction(trans, ret);
1375+
return ret;
1376+
}
13671377
btrfs_set_node_key(parent, &disk_key, pslot + 1);
13681378
btrfs_mark_buffer_dirty(parent);
13691379

0 commit comments

Comments
 (0)