btrfs: add check in remove_range_from_remap_tree() for a NULL block group
PATCH 1/1 btrfs: add check in remove_range_from_remap_tree() for a NULL block group
Add a check in remove_range_from_remap_tree() after we call btrfs_lookup_block_group(), to check if it is NULL. This shouldn't happen, but if it does we at least get an error rather than a segfault.
This fixes a bug introduced in the patch "btrfs: handle deletions from remapped block group" in for-next.
--- fs/btrfs/relocation.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/relocation.c +3 -0
@@ -6003,6 +6003,9 @@ static int remove_range_from_remap_tree(struct btrfs_trans_handle *trans,struct btrfs_block_group *dest_bg; dest_bg =btrfs_lookup_block_group (fs_info, new_addr); +if (!dest_bg) +return -EUCLEAN ; +adjust_block_group_remap_bytes (trans, dest_bg, -overlap_length);btrfs_put_block_group (dest_bg); ret = btrfs_add_to_free_space_tree(trans,
Signature · 1 line
2.52.0
Quoted 7 lines · Mark Harmstone
Add a check in
remove_range_from_remap_tree()after we callbtrfs_lookup_block_group(), to check if it is NULL. This shouldn't happen, but if it does we at least get an error rather than a segfault.This fixes a bug introduced in the patch "btrfs: handle deletions from remapped block group" in for-next.
Same comment as for the other patch, that change is already in Linus' tree, so we can and should add here a:
Quoted 13 lines
Signed-off-by Mark Harmstone <[email protected]>Suggested-by Chris Mason <[email protected]>--- fs/btrfs/relocation.c | 3 +++ 1 file changed, 3 insertions(+)fs/btrfs/relocation.c +0
-0
fs/btrfs/relocation.c static int remove_range_from_remap_tree(struct btrfs_trans_handle *trans, · line 6007
Quoted 5 lines
fs/btrfs/relocation.c +2
-0@@ -6003,6 +6003,9 @@ static int remove_range_from_remap_tree(struct btrfs_trans_handle *trans,struct btrfs_block_group *dest_bg; dest_bg =btrfs_lookup_block_group (fs_info, new_addr); +if (!dest_bg) +return -EUCLEAN ;
Since this is a EUCLEAN and highly unexpected, we can use unlikely here, see: https://btrfs.readthedocs.io/en/latest/dev/Development-notes.html
With those two changes:
Thanks.
Quoted 8 lines
fs/btrfs/relocation.c +1
-1+adjust_block_group_remap_bytes (trans, dest_bg, -overlap_length);btrfs_put_block_group (dest_bg); ret = btrfs_add_to_free_space_tree(trans, --2.52.0