Skip to content

Commit 9e0c30a

Browse files
naotakdave
authored andcommitted
btrfs-progs: zoned: factor out SINGLE zone info loading
Currently, the userland tool only considers the SINGLE profile, which make it fail when a DUP block group is created over one conventional zone and one sequential required zone. Before adding the other profiles support, let's factor out per-profile code (actually, SINGLE only) into functions just like as the kernel side. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 70fc38f commit 9e0c30a

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

kernel-shared/zoned.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,26 @@ static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
958958
return 0;
959959
}
960960

961+
static int btrfs_load_block_group_single(struct btrfs_fs_info *fs_info,
962+
struct btrfs_block_group *bg,
963+
struct zone_info *info,
964+
unsigned long *active)
965+
{
966+
if (info->alloc_offset == WP_MISSING_DEV) {
967+
btrfs_err(fs_info,
968+
"zoned: cannot recover write pointer for zone %llu",
969+
info->physical);
970+
return -EIO;
971+
}
972+
973+
bg->alloc_offset = info->alloc_offset;
974+
bg->zone_capacity = info->capacity;
975+
if (test_bit(0, active))
976+
bg->zone_is_active = 1;
977+
return 0;
978+
}
979+
980+
961981
int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
962982
struct btrfs_block_group *cache)
963983
{
@@ -972,6 +992,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
972992
int i;
973993
u64 last_alloc = 0;
974994
u32 num_conventional = 0;
995+
u64 profile;
975996

976997
if (!btrfs_is_zoned(fs_info))
977998
return 0;
@@ -1039,10 +1060,28 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
10391060
ret = -EINVAL;
10401061
goto out;
10411062
}
1042-
/* SINGLE profile case. */
1043-
cache->alloc_offset = zone_info[0].alloc_offset;
1044-
cache->zone_capacity = zone_info[0].capacity;
1045-
cache->zone_is_active = test_bit(0, active);
1063+
1064+
profile = map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK;
1065+
switch (profile) {
1066+
case 0: /* single */
1067+
ret = btrfs_load_block_group_single(fs_info, cache, &zone_info[0], active);
1068+
break;
1069+
case BTRFS_BLOCK_GROUP_DUP:
1070+
case BTRFS_BLOCK_GROUP_RAID1:
1071+
case BTRFS_BLOCK_GROUP_RAID1C3:
1072+
case BTRFS_BLOCK_GROUP_RAID1C4:
1073+
case BTRFS_BLOCK_GROUP_RAID0:
1074+
case BTRFS_BLOCK_GROUP_RAID10:
1075+
/* Temporarily fails these case, until following commits. */
1076+
fallthrough;
1077+
case BTRFS_BLOCK_GROUP_RAID5:
1078+
case BTRFS_BLOCK_GROUP_RAID6:
1079+
default:
1080+
error("zoned: profile %s not yet supported",
1081+
btrfs_bg_type_to_raid_name(map->type));
1082+
ret = -EINVAL;
1083+
goto out;
1084+
}
10461085

10471086
out:
10481087
/* An extent is allocated after the write pointer */

0 commit comments

Comments
 (0)