LOOP_NO_EMPTY_SIZE is solely dedicated for clustered allocation. So, we can skip this stage and go to LOOP_GIVEUP stage to indicate we gave up the allocation. This commit also moves the scope of the "clustered" variable. Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> --- fs/btrfs/extent-tree.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 123b1a4e797a..2631ce2e123c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3373,6 +3373,7 @@ enum btrfs_loop_type { LOOP_CACHING_WAIT, LOOP_ALLOC_CHUNK, LOOP_NO_EMPTY_SIZE, + LOOP_GIVEUP, }; static inline void @@ -3789,7 +3790,6 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, bool full_search) { struct btrfs_root *root = fs_info->extent_root; - struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; int ret; if ((ffe_ctl->loop == LOOP_CACHING_NOWAIT) && @@ -3863,6 +3863,14 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, } if (ffe_ctl->loop == LOOP_NO_EMPTY_SIZE) { + struct clustered_alloc_info *clustered = + ffe_ctl->alloc_info; + + if (ffe_ctl->policy != BTRFS_EXTENT_ALLOC_CLUSTERED) { + ffe_ctl->loop = LOOP_GIVEUP; + return -ENOSPC; + } + /* * Don't loop again if we already have no empty_size and * no empty_cluster. -- 2.25.0