btrfs: zoned: fix data relocation block group reservation
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 16 Jul 2025 07:59:53 +0000 (16:59 +0900)
committerDavid Sterba <dsterba@suse.com>
Wed, 13 Aug 2025 10:28:48 +0000 (12:28 +0200)
commitdaa0fde322350b467bc62bc1b141bf62df6123f8
treee931f398d6e587e81693905d260fcee0be1ac010
parentf0ba0e7172a222ea6043b61ecd86723c46d7bcf2
btrfs: zoned: fix data relocation block group reservation

btrfs_zoned_reserve_data_reloc_bg() is called on mount and at that point,
all data block groups belong to the primary data space_info. So, we don't
find anything in the data relocation space_info.

Also, the condition "bg->used > 0" can select a block group with full of
zone_unusable bytes for the candidate. As we cannot allocate from the block
group, it is useless to reserve it as the data relocation block group.

Furthermore, because of the space_info separation, we need to migrate the
selected block group to the data relocation space_info. If not, the extent
allocator cannot use the block group to do the allocation.

This commit fixes these three issues.

Fixes: e606ff985ec7 ("btrfs: zoned: reserve data_reloc block group on mount")
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zoned.c