btrfs: zoned: factor out prepare_allocation_zoned()
authorNaohiro Aota <naohiro.aota@wdc.com>
Mon, 18 Dec 2023 16:02:28 +0000 (01:02 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Feb 2024 00:19:10 +0000 (16:19 -0800)
[ Upstream commit b271fee9a41ca1474d30639fd6cc912c9901d0f8 ]

Factor out prepare_allocation_zoned() for further extension. While at
it, optimize the if-branch a bit.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 02444f2ac26e ("btrfs: zoned: optimize hint byte for zoned allocator")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/extent-tree.c

index d421e28..69abb6e 100644 (file)
@@ -4139,6 +4139,24 @@ static int prepare_allocation_clustered(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
+static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
+                                   struct find_free_extent_ctl *ffe_ctl)
+{
+       if (ffe_ctl->for_treelog) {
+               spin_lock(&fs_info->treelog_bg_lock);
+               if (fs_info->treelog_bg)
+                       ffe_ctl->hint_byte = fs_info->treelog_bg;
+               spin_unlock(&fs_info->treelog_bg_lock);
+       } else if (ffe_ctl->for_data_reloc) {
+               spin_lock(&fs_info->relocation_bg_lock);
+               if (fs_info->data_reloc_bg)
+                       ffe_ctl->hint_byte = fs_info->data_reloc_bg;
+               spin_unlock(&fs_info->relocation_bg_lock);
+       }
+
+       return 0;
+}
+
 static int prepare_allocation(struct btrfs_fs_info *fs_info,
                              struct find_free_extent_ctl *ffe_ctl,
                              struct btrfs_space_info *space_info,
@@ -4149,19 +4167,7 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info,
                return prepare_allocation_clustered(fs_info, ffe_ctl,
                                                    space_info, ins);
        case BTRFS_EXTENT_ALLOC_ZONED:
-               if (ffe_ctl->for_treelog) {
-                       spin_lock(&fs_info->treelog_bg_lock);
-                       if (fs_info->treelog_bg)
-                               ffe_ctl->hint_byte = fs_info->treelog_bg;
-                       spin_unlock(&fs_info->treelog_bg_lock);
-               }
-               if (ffe_ctl->for_data_reloc) {
-                       spin_lock(&fs_info->relocation_bg_lock);
-                       if (fs_info->data_reloc_bg)
-                               ffe_ctl->hint_byte = fs_info->data_reloc_bg;
-                       spin_unlock(&fs_info->relocation_bg_lock);
-               }
-               return 0;
+               return prepare_allocation_zoned(fs_info, ffe_ctl);
        default:
                BUG();
        }