Commit ca7f7986 authored by David Sterba's avatar David Sterba

btrfs: move transaction abort to the error site in btrfs_create_free_space_tree()

The recommended pattern for transaction abort after error is to place it
right after the error is handled. That way it's easier to locate where
it failed and help debugging.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 0896ce75
...@@ -1176,12 +1176,16 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1176,12 +1176,16 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
BTRFS_FREE_SPACE_TREE_OBJECTID); BTRFS_FREE_SPACE_TREE_OBJECTID);
if (IS_ERR(free_space_root)) { if (IS_ERR(free_space_root)) {
ret = PTR_ERR(free_space_root); ret = PTR_ERR(free_space_root);
goto abort; btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);
goto out_clear;
} }
ret = btrfs_global_root_insert(free_space_root); ret = btrfs_global_root_insert(free_space_root);
if (ret) { if (ret) {
btrfs_put_root(free_space_root); btrfs_put_root(free_space_root);
goto abort; btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);
goto out_clear;
} }
node = rb_first_cached(&fs_info->block_group_cache_tree); node = rb_first_cached(&fs_info->block_group_cache_tree);
...@@ -1189,8 +1193,11 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1189,8 +1193,11 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
block_group = rb_entry(node, struct btrfs_block_group, block_group = rb_entry(node, struct btrfs_block_group,
cache_node); cache_node);
ret = populate_free_space_tree(trans, block_group); ret = populate_free_space_tree(trans, block_group);
if (ret) if (ret) {
goto abort; btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);
goto out_clear;
}
node = rb_next(node); node = rb_next(node);
} }
...@@ -1206,11 +1213,9 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1206,11 +1213,9 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags); clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
return ret; return ret;
abort: out_clear:
clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags); clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags); clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
btrfs_abort_transaction(trans, ret);
btrfs_end_transaction(trans);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment