btrfs: zoned: activate block group on allocation
authorNaohiro Aota <naohiro.aota@wdc.com>
Thu, 19 Aug 2021 12:19:19 +0000 (21:19 +0900)
committerDavid Sterba <dsterba@suse.com>
Tue, 26 Oct 2021 17:07:59 +0000 (19:07 +0200)
Activate a block group when trying to allocate an extent from it. We check
read-only case and no space left case before trying to activate a block
group not to consume the number of active zones uselessly.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c

index 165acee66b072f433be12293bb3d2d2ea4289e9b..e0932624c53c167b7c29bfedcc7b0189bc0f79ca 100644 (file)
@@ -3773,6 +3773,18 @@ static int do_allocation_zoned(struct btrfs_block_group *block_group,
        if (skip)
                return 1;
 
+       /* Check RO and no space case before trying to activate it */
+       spin_lock(&block_group->lock);
+       if (block_group->ro ||
+           block_group->alloc_offset == block_group->zone_capacity) {
+               spin_unlock(&block_group->lock);
+               return 1;
+       }
+       spin_unlock(&block_group->lock);
+
+       if (!btrfs_zone_activate(block_group))
+               return 1;
+
        spin_lock(&space_info->lock);
        spin_lock(&block_group->lock);
        spin_lock(&fs_info->treelog_bg_lock);