@@ -512,6 +512,11 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
max_active_zones - nactive);
}
+ /* Cache the sb zone number */
+ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) {
+ zone_info->sb_zone_location[i] =
+ sb_zone_number(zone_info->zone_size_shift, i);
+ }
/* Validate superblock log */
nr_zones = BTRFS_NR_SB_LOG_ZONES;
for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
@@ -519,7 +524,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache)
u64 sb_wp;
int sb_pos = BTRFS_NR_SB_LOG_ZONES * i;
- sb_zone = sb_zone_number(zone_info->zone_size_shift, i);
+ sb_zone = zone_info->sb_zone_location[i];
if (sb_zone + 1 >= zone_info->nr_zones)
continue;
@@ -867,7 +872,7 @@ int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
return 0;
}
- zone_num = sb_zone_number(zinfo->zone_size_shift, mirror);
+ zone_num = zinfo->sb_zone_location[mirror];
if (zone_num + 1 >= zinfo->nr_zones)
return -ENOENT;
@@ -884,7 +889,7 @@ static inline bool is_sb_log_zone(struct btrfs_zoned_device_info *zinfo,
if (!zinfo)
return false;
- zone_num = sb_zone_number(zinfo->zone_size_shift, mirror);
+ zone_num = zinfo->sb_zone_location[mirror];
if (zone_num + 1 >= zinfo->nr_zones)
return false;
@@ -1012,7 +1017,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,
u32 sb_zone;
u64 sb_pos;
- sb_zone = sb_zone_number(shift, i);
+ sb_zone = zinfo->sb_zone_location[i];
if (!(end <= sb_zone ||
sb_zone + BTRFS_NR_SB_LOG_ZONES <= begin)) {
have_sb = true;
@@ -31,6 +31,7 @@ struct btrfs_zoned_device_info {
unsigned long *active_zones;
struct blk_zone *zone_cache;
struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX];
+ u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX];
};
#ifdef CONFIG_BLK_DEV_ZONED