Message ID | 083c235db86e27f6191fc938fd5f61c980cc5e18.1726269996.git.loemra.dev@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs-progs: remove free space when block group freed | expand |
在 2024/9/14 09:00, Leo Martins 写道: > 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. The idea is correct, we should remove the free space of a block group from v1 or v2 free space cache. But remove_block_group_free_space() in btrfs-progs is not the same as the kernel one, as it doesn't check if the fs has free space tree enabled. Thus for a v1 space cached btrfs, this will lead to a NULL pointer dereference. Mind to add the free space tree checks before calling it inside btrfs_remove_block_group()? Another thing is, this is very hard to trigger since in btrfs-progs we seldom do deletion to trigger empty block groups removal. If you can find a way to test this corner case, it would be a great help. Thanks, Qu > > Signed-off-by: Leo Martins <loemra.dev@gmail.com> > --- > kernel-shared/extent-tree.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c > index af04b9ea..df843862 100644 > --- a/kernel-shared/extent-tree.c > +++ b/kernel-shared/extent-tree.c > @@ -3536,6 +3536,9 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, > return ret; > } > > + /* delete free space items associated with this block group */ > + remove_block_group_free_space(trans, block_group); > + > /* Now release the block_group_cache */ > ret = free_block_group_cache(trans, fs_info, bytenr, len); > btrfs_unpin_extent(fs_info, bytenr, len);
diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index af04b9ea..df843862 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -3536,6 +3536,9 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, return ret; } + /* delete free space items associated with this block group */ + remove_block_group_free_space(trans, block_group); + /* Now release the block_group_cache */ ret = free_block_group_cache(trans, fs_info, bytenr, len); btrfs_unpin_extent(fs_info, bytenr, len);
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. Signed-off-by: Leo Martins <loemra.dev@gmail.com> --- kernel-shared/extent-tree.c | 3 +++ 1 file changed, 3 insertions(+)