Skip to content

Commit b271fee

Browse files
naotakdave
authored andcommitted
btrfs: zoned: factor out prepare_allocation_zoned()
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>
1 parent e94dfb7 commit b271fee

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

fs/btrfs/extent-tree.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,6 +4298,24 @@ static int prepare_allocation_clustered(struct btrfs_fs_info *fs_info,
42984298
return 0;
42994299
}
43004300

4301+
static int prepare_allocation_zoned(struct btrfs_fs_info *fs_info,
4302+
struct find_free_extent_ctl *ffe_ctl)
4303+
{
4304+
if (ffe_ctl->for_treelog) {
4305+
spin_lock(&fs_info->treelog_bg_lock);
4306+
if (fs_info->treelog_bg)
4307+
ffe_ctl->hint_byte = fs_info->treelog_bg;
4308+
spin_unlock(&fs_info->treelog_bg_lock);
4309+
} else if (ffe_ctl->for_data_reloc) {
4310+
spin_lock(&fs_info->relocation_bg_lock);
4311+
if (fs_info->data_reloc_bg)
4312+
ffe_ctl->hint_byte = fs_info->data_reloc_bg;
4313+
spin_unlock(&fs_info->relocation_bg_lock);
4314+
}
4315+
4316+
return 0;
4317+
}
4318+
43014319
static int prepare_allocation(struct btrfs_fs_info *fs_info,
43024320
struct find_free_extent_ctl *ffe_ctl,
43034321
struct btrfs_space_info *space_info,
@@ -4308,19 +4326,7 @@ static int prepare_allocation(struct btrfs_fs_info *fs_info,
43084326
return prepare_allocation_clustered(fs_info, ffe_ctl,
43094327
space_info, ins);
43104328
case BTRFS_EXTENT_ALLOC_ZONED:
4311-
if (ffe_ctl->for_treelog) {
4312-
spin_lock(&fs_info->treelog_bg_lock);
4313-
if (fs_info->treelog_bg)
4314-
ffe_ctl->hint_byte = fs_info->treelog_bg;
4315-
spin_unlock(&fs_info->treelog_bg_lock);
4316-
}
4317-
if (ffe_ctl->for_data_reloc) {
4318-
spin_lock(&fs_info->relocation_bg_lock);
4319-
if (fs_info->data_reloc_bg)
4320-
ffe_ctl->hint_byte = fs_info->data_reloc_bg;
4321-
spin_unlock(&fs_info->relocation_bg_lock);
4322-
}
4323-
return 0;
4329+
return prepare_allocation_zoned(fs_info, ffe_ctl);
43244330
default:
43254331
BUG();
43264332
}

0 commit comments

Comments
 (0)