Skip to content

Commit 186b524

Browse files
josefbacikgregkh
authored andcommitted
btrfs: fix insert_reserved error handling
commit 80ee54b upstream. We were not handling the reserved byte accounting properly for data references. Metadata was fine, if it errored out the error paths would free the bytes_reserved count and pin the extent, but it even missed one of the error cases. So instead move this handling up into run_one_delayed_ref so we are sure that both cases are properly cleaned up in case of a transaction abort. CC: [email protected] # 4.18+ Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5a1e9bf commit 186b524

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

fs/btrfs/extent-tree.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,9 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans,
23662366
insert_reserved);
23672367
else
23682368
BUG();
2369+
if (ret && insert_reserved)
2370+
btrfs_pin_extent(trans->fs_info, node->bytenr,
2371+
node->num_bytes, 1);
23692372
return ret;
23702373
}
23712374

@@ -7977,21 +7980,14 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
79777980
}
79787981

79797982
path = btrfs_alloc_path();
7980-
if (!path) {
7981-
btrfs_free_and_pin_reserved_extent(fs_info,
7982-
extent_key.objectid,
7983-
fs_info->nodesize);
7983+
if (!path)
79847984
return -ENOMEM;
7985-
}
79867985

79877986
path->leave_spinning = 1;
79887987
ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
79897988
&extent_key, size);
79907989
if (ret) {
79917990
btrfs_free_path(path);
7992-
btrfs_free_and_pin_reserved_extent(fs_info,
7993-
extent_key.objectid,
7994-
fs_info->nodesize);
79957991
return ret;
79967992
}
79977993

0 commit comments

Comments
 (0)