Skip to content

Commit d09c515

Browse files
fdmananakdave
authored andcommitted
btrfs: add missing error handling when logging operation while COWing extent buffer
When COWing an extent buffer that is not the root node, we need to log in the tree mod log that we replaced a pointer in the parent node, otherwise a tree mod log user doing a search on the b+tree can return incorrect results (that miss something). We are doing the call to btrfs_tree_mod_log_insert_key() but we totally ignore its return value. So fix this by adding the missing error handling, resulting in a transaction abort and freeing the COWed extent buffer. Fixes: f230475 ("Btrfs: put all block modifications into the tree mod log") 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 f02c75e commit d09c515

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,14 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
595595
add_root_to_dirty_list(root);
596596
} else {
597597
WARN_ON(trans->transid != btrfs_header_generation(parent));
598-
btrfs_tree_mod_log_insert_key(parent, parent_slot,
599-
BTRFS_MOD_LOG_KEY_REPLACE);
598+
ret = btrfs_tree_mod_log_insert_key(parent, parent_slot,
599+
BTRFS_MOD_LOG_KEY_REPLACE);
600+
if (ret) {
601+
btrfs_tree_unlock(cow);
602+
free_extent_buffer(cow);
603+
btrfs_abort_transaction(trans, ret);
604+
return ret;
605+
}
600606
btrfs_set_node_blockptr(parent, parent_slot,
601607
cow->start);
602608
btrfs_set_node_ptr_generation(parent, parent_slot,

0 commit comments

Comments
 (0)