Skip to content

Commit 40b0a74

Browse files
fdmananakdave
authored andcommitted
btrfs: do not BUG_ON() on tree mod log failure at __btrfs_cow_block()
At __btrfs_cow_block(), instead of doing a BUG_ON() in case we fail to record a tree mod log root insertion operation, do a transaction abort instead. There's really no need for the BUG_ON(), we can properly release all resources in this context and turn the filesystem to RO mode and in an error state instead. 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 8793ed8 commit 40b0a74

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,14 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
584584
btrfs_header_backref_rev(buf) < BTRFS_MIXED_BACKREF_REV)
585585
parent_start = buf->start;
586586

587-
atomic_inc(&cow->refs);
588587
ret = btrfs_tree_mod_log_insert_root(root->node, cow, true);
589-
BUG_ON(ret < 0);
588+
if (ret < 0) {
589+
btrfs_tree_unlock(cow);
590+
free_extent_buffer(cow);
591+
btrfs_abort_transaction(trans, ret);
592+
return ret;
593+
}
594+
atomic_inc(&cow->refs);
590595
rcu_assign_pointer(root->node, cow);
591596

592597
btrfs_free_tree_block(trans, btrfs_root_id(root), buf,

0 commit comments

Comments
 (0)