@@ -285,6 +285,7 @@ struct btrfs_block_group {
*/
u64 alloc_offset;
u64 write_offset;
+ u64 zone_capacity;
u64 global_root_id;
};
@@ -300,7 +300,7 @@ again:
goto new_group;
if (btrfs_is_zoned(root->fs_info)) {
- if (cache->length - cache->alloc_offset < num)
+ if (cache->zone_capacity - cache->alloc_offset < num)
goto new_group;
*start_ret = cache->start + cache->alloc_offset;
cache->alloc_offset += num;
@@ -776,7 +776,7 @@ static int calculate_alloc_pointer(struct btrfs_fs_info *fs_info,
length = fs_info->nodesize;
if (!(found_key.objectid >= cache->start &&
- found_key.objectid + length <= cache->start + cache->length)) {
+ found_key.objectid + length <= cache->start + cache->zone_capacity)) {
ret = -EUCLEAN;
goto out;
}
@@ -830,6 +830,7 @@ bool zoned_profile_supported(u64 map_type, bool rst)
struct zone_info {
u64 physical;
+ u64 capacity;
u64 alloc_offset;
};
@@ -894,6 +895,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
if (!is_sequential) {
num_conventional++;
info->alloc_offset = WP_CONVENTIONAL;
+ info->capacity = device->zone_info->zone_size;
continue;
}
@@ -904,6 +906,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size));
zone = device->zone_info->zones[info->physical / fs_info->zone_size];
+ info->capacity = (zone.capacity << SECTOR_SHIFT);
+
switch (zone.cond) {
case BLK_ZONE_COND_OFFLINE:
case BLK_ZONE_COND_READONLY:
@@ -927,6 +931,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
}
if (num_conventional > 0) {
+ /* Zone capacity is always zone size in emulation */
+ cache->zone_capacity = cache->length;
ret = calculate_alloc_pointer(fs_info, cache, &last_alloc);
if (ret || map->num_stripes == num_conventional) {
if (!ret)
@@ -946,6 +952,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
goto out;
}
cache->alloc_offset = zone_info[0].alloc_offset;
+ cache->zone_capacity = zone_info[0].capacity;
out:
/* An extent is allocated after the write pointer */
The userland tools did not load and use the zone capacity. Support it properly. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- kernel-shared/ctree.h | 1 + kernel-shared/extent-tree.c | 2 +- kernel-shared/zoned.c | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-)