@@ -3536,6 +3536,16 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
return ret;
}
+ /* delete free space items associated with this block group */
+ ret = remove_block_group_free_space(trans, block_group);
+ if (ret < 0) {
+ fprintf(stderr,
+ "failed to remove free space associated with block group for [%llu,%llu)\n",
+ bytenr, bytenr + len);
+ btrfs_unpin_extent(fs_info, bytenr, len);
+ return ret;
+ }
+
/* Now release the block_group_cache */
ret = free_block_group_cache(trans, fs_info, bytenr, len);
btrfs_unpin_extent(fs_info, bytenr, len);
@@ -1171,6 +1171,9 @@ int remove_block_group_free_space(struct btrfs_trans_handle *trans,
int done = 0, nr;
int ret;
+ if (!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
+ return 0;
+
path = btrfs_alloc_path();
if (!path) {
ret = -ENOMEM;
In the upstream equivalent of btrfs_remove_block_group(), the function remove_block_group_free_space() is called to delete free spaces associated with the block group being freed. However, this function is defined in btrfs-progs but not called anywhere. To address this issue, I added a call to remove_block_group_free_space() in btrfs_remove_block_group(). This ensures that the free spaces are properly deleted when a block group is removed. I also added a check to remove_block_group_free_space to make sure that free-space-tree is enabled. Signed-off-by: Leo Martins <loemra.dev@gmail.com> --- CHANGELOG: v3: - No change v2: - Added the check to make sure that free-space-tree is enabled --- kernel-shared/extent-tree.c | 10 ++++++++++ kernel-shared/free-space-tree.c | 3 +++ 2 files changed, 13 insertions(+)