Skip to content

Commit 87463f7

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: zoned: factor out DUP bg handling from btrfs_load_block_group_zone_info
Split the code handling a type DUP block group from btrfs_load_block_group_zone_info to make the code more readable. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9e0e3e7 commit 87463f7

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

fs/btrfs/zoned.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,47 @@ static int btrfs_load_block_group_single(struct btrfs_block_group *bg,
13921392
return 0;
13931393
}
13941394

1395+
static int btrfs_load_block_group_dup(struct btrfs_block_group *bg,
1396+
struct map_lookup *map,
1397+
struct zone_info *zone_info,
1398+
unsigned long *active)
1399+
{
1400+
if (map->type & BTRFS_BLOCK_GROUP_DATA) {
1401+
btrfs_err(bg->fs_info,
1402+
"zoned: profile DUP not yet supported on data bg");
1403+
return -EINVAL;
1404+
}
1405+
1406+
if (zone_info[0].alloc_offset == WP_MISSING_DEV) {
1407+
btrfs_err(bg->fs_info,
1408+
"zoned: cannot recover write pointer for zone %llu",
1409+
zone_info[0].physical);
1410+
return -EIO;
1411+
}
1412+
if (zone_info[1].alloc_offset == WP_MISSING_DEV) {
1413+
btrfs_err(bg->fs_info,
1414+
"zoned: cannot recover write pointer for zone %llu",
1415+
zone_info[1].physical);
1416+
return -EIO;
1417+
}
1418+
if (zone_info[0].alloc_offset != zone_info[1].alloc_offset) {
1419+
btrfs_err(bg->fs_info,
1420+
"zoned: write pointer offset mismatch of zones in DUP profile");
1421+
return -EIO;
1422+
}
1423+
1424+
if (test_bit(0, active) != test_bit(1, active)) {
1425+
if (!btrfs_zone_activate(bg))
1426+
return -EIO;
1427+
} else if (test_bit(0, active)) {
1428+
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &bg->runtime_flags);
1429+
}
1430+
1431+
bg->alloc_offset = zone_info[0].alloc_offset;
1432+
bg->zone_capacity = min(zone_info[0].capacity, zone_info[1].capacity);
1433+
return 0;
1434+
}
1435+
13951436
int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
13961437
{
13971438
struct btrfs_fs_info *fs_info = cache->fs_info;
@@ -1481,43 +1522,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
14811522
ret = btrfs_load_block_group_single(cache, &zone_info[0], active);
14821523
break;
14831524
case BTRFS_BLOCK_GROUP_DUP:
1484-
if (map->type & BTRFS_BLOCK_GROUP_DATA) {
1485-
btrfs_err(fs_info, "zoned: profile DUP not yet supported on data bg");
1486-
ret = -EINVAL;
1487-
goto out;
1488-
}
1489-
if (zone_info[0].alloc_offset == WP_MISSING_DEV) {
1490-
btrfs_err(fs_info,
1491-
"zoned: cannot recover write pointer for zone %llu",
1492-
zone_info[0].physical);
1493-
ret = -EIO;
1494-
goto out;
1495-
}
1496-
if (zone_info[1].alloc_offset == WP_MISSING_DEV) {
1497-
btrfs_err(fs_info,
1498-
"zoned: cannot recover write pointer for zone %llu",
1499-
zone_info[1].physical);
1500-
ret = -EIO;
1501-
goto out;
1502-
}
1503-
if (zone_info[0].alloc_offset != zone_info[1].alloc_offset) {
1504-
btrfs_err(fs_info,
1505-
"zoned: write pointer offset mismatch of zones in DUP profile");
1506-
ret = -EIO;
1507-
goto out;
1508-
}
1509-
if (test_bit(0, active) != test_bit(1, active)) {
1510-
if (!btrfs_zone_activate(cache)) {
1511-
ret = -EIO;
1512-
goto out;
1513-
}
1514-
} else {
1515-
if (test_bit(0, active))
1516-
set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE,
1517-
&cache->runtime_flags);
1518-
}
1519-
cache->alloc_offset = zone_info[0].alloc_offset;
1520-
cache->zone_capacity = min(zone_info[0].capacity, zone_info[1].capacity);
1525+
ret = btrfs_load_block_group_dup(cache, map, zone_info, active);
15211526
break;
15221527
case BTRFS_BLOCK_GROUP_RAID1:
15231528
case BTRFS_BLOCK_GROUP_RAID0:

0 commit comments

Comments
 (0)