Re: [PATCH v3 1/2] btrfs: zoned: reserve relocation block-group on mount

From: Johannes Thumshirn
Date: Wed May 22 2024 - 04:31:19 EST


On 21.05.24 17:23, Filipe Manana wrote:
>> +static u64 find_empty_block_group(struct btrfs_space_info *sinfo, u64 flags)
>> +{
>> + struct btrfs_block_group *bg;
>> +
>> + for (int i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
>> + list_for_each_entry(bg, &sinfo->block_groups[i], list) {
>> + if (bg->flags != flags)
>> + continue;
>> + if (bg->used == 0)
>> + return bg->start;
>> + }
>> + }
> I believe I commented about this in some previous patchset version,
> but here goes again.
>
> This happens at mount time, where we have already loaded all block groups.
> When we load them, if we find unused ones, we add them to the list of
> empty block groups, so that the next time the cleaner kthread runs it
> deletes them.
>
> I don't see any code here removing the selected block group from that
> list, or anything at btrfs_delete_unused_bgs() that prevents deleting
> a block group if it was selected as the data reloc bg.
>
> Maybe I'm missing something?
> How do ensure the selected block group isn't deleted by the cleaner kthread?

Indeed, I forgot about that.