Skip to content

Commit 8f8aa4c

Browse files
josefbacikkdave
authored andcommitted
btrfs: factor out do_free_extent_accounting helper
__btrfs_free_extent() does all of the hard work of updating the extent ref items, and then at the end if we dropped the extent completely it does the cleanup accounting work. We're going to only want to do that work for metadata with extent tree v2, so extract this bit into its own helper. Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 5b2a54b commit 8f8aa4c

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

fs/btrfs/extent-tree.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,35 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
28532853
return 0;
28542854
}
28552855

2856+
static int do_free_extent_accounting(struct btrfs_trans_handle *trans,
2857+
u64 bytenr, u64 num_bytes, bool is_data)
2858+
{
2859+
int ret;
2860+
2861+
if (is_data) {
2862+
struct btrfs_root *csum_root;
2863+
2864+
csum_root = btrfs_csum_root(trans->fs_info, bytenr);
2865+
ret = btrfs_del_csums(trans, csum_root, bytenr, num_bytes);
2866+
if (ret) {
2867+
btrfs_abort_transaction(trans, ret);
2868+
return ret;
2869+
}
2870+
}
2871+
2872+
ret = add_to_free_space_tree(trans, bytenr, num_bytes);
2873+
if (ret) {
2874+
btrfs_abort_transaction(trans, ret);
2875+
return ret;
2876+
}
2877+
2878+
ret = btrfs_update_block_group(trans, bytenr, num_bytes, false);
2879+
if (ret)
2880+
btrfs_abort_transaction(trans, ret);
2881+
2882+
return ret;
2883+
}
2884+
28562885
/*
28572886
* Drop one or more refs of @node.
28582887
*
@@ -3178,28 +3207,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
31783207
}
31793208
btrfs_release_path(path);
31803209

3181-
if (is_data) {
3182-
struct btrfs_root *csum_root;
3183-
csum_root = btrfs_csum_root(info, bytenr);
3184-
ret = btrfs_del_csums(trans, csum_root, bytenr,
3185-
num_bytes);
3186-
if (ret) {
3187-
btrfs_abort_transaction(trans, ret);
3188-
goto out;
3189-
}
3190-
}
3191-
3192-
ret = add_to_free_space_tree(trans, bytenr, num_bytes);
3193-
if (ret) {
3194-
btrfs_abort_transaction(trans, ret);
3195-
goto out;
3196-
}
3197-
3198-
ret = btrfs_update_block_group(trans, bytenr, num_bytes, false);
3199-
if (ret) {
3200-
btrfs_abort_transaction(trans, ret);
3201-
goto out;
3202-
}
3210+
ret = do_free_extent_accounting(trans, bytenr, num_bytes, is_data);
32033211
}
32043212
btrfs_release_path(path);
32053213

0 commit comments

Comments
 (0)