summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorNaohiro Aota <naohiro.aota@wdc.com>2021-08-19 21:19:19 +0900
committerDavid Sterba <dsterba@suse.com>2021-10-26 19:07:59 +0200
commit2e654e4bb9aca11abf36ae37202daecf396e0119 (patch)
tree4972cc0171315d602589d78af3df727f9c95cead /fs/btrfs/extent-tree.c
parent68a384b5ab4d3925c35f94ab5723c39bf605466c (diff)
downloadlinux-2e654e4bb9aca11abf36ae37202daecf396e0119.tar.gz
linux-2e654e4bb9aca11abf36ae37202daecf396e0119.tar.bz2
linux-2e654e4bb9aca11abf36ae37202daecf396e0119.zip
btrfs: zoned: activate block group on allocation
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>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 165acee66b07..e0932624c53c 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -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);