Skip to content

Commit 50475cd

Browse files
naotakdave
authored andcommitted
btrfs: add extent allocator hook to decide to allocate chunk or not
Introduce a new hook for an extent allocator policy. With the new hook, a policy can decide to allocate a new block group or not. If not, it will return -ENOSPC, so btrfs_reserve_extent() will cut the allocation size in half and retry the allocation if min_alloc_size is large enough. The hook has a place holder and will be replaced with the real implementation in the next patch. CC: [email protected] # 5.16 Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1ada69f commit 50475cd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,19 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl,
39743974
}
39753975
}
39763976

3977+
static bool can_allocate_chunk(struct btrfs_fs_info *fs_info,
3978+
struct find_free_extent_ctl *ffe_ctl)
3979+
{
3980+
switch (ffe_ctl->policy) {
3981+
case BTRFS_EXTENT_ALLOC_CLUSTERED:
3982+
return true;
3983+
case BTRFS_EXTENT_ALLOC_ZONED:
3984+
return true;
3985+
default:
3986+
BUG();
3987+
}
3988+
}
3989+
39773990
static int chunk_allocation_failed(struct find_free_extent_ctl *ffe_ctl)
39783991
{
39793992
switch (ffe_ctl->policy) {
@@ -4061,6 +4074,10 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,
40614074
struct btrfs_trans_handle *trans;
40624075
int exist = 0;
40634076

4077+
/*Check if allocation policy allows to create a new chunk */
4078+
if (!can_allocate_chunk(fs_info, ffe_ctl))
4079+
return -ENOSPC;
4080+
40644081
trans = current->journal_info;
40654082
if (trans)
40664083
exist = 1;

0 commit comments

Comments
 (0)