Skip to content

Commit 0ae9ae0

Browse files
naotakdave
authored andcommitted
btrfs-progs: zoned: support zone capacity
The userland tools did not load and use the zone capacity. Support it properly. 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 3b696cf commit 0ae9ae0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

kernel-shared/ctree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ struct btrfs_block_group {
285285
*/
286286
u64 alloc_offset;
287287
u64 write_offset;
288+
u64 zone_capacity;
288289

289290
u64 global_root_id;
290291
};

kernel-shared/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int noinline find_search_start(struct btrfs_root *root,
300300
goto new_group;
301301

302302
if (btrfs_is_zoned(root->fs_info)) {
303-
if (cache->length - cache->alloc_offset < num)
303+
if (cache->zone_capacity - cache->alloc_offset < num)
304304
goto new_group;
305305
*start_ret = cache->start + cache->alloc_offset;
306306
cache->alloc_offset += num;

kernel-shared/zoned.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ static int calculate_alloc_pointer(struct btrfs_fs_info *fs_info,
776776
length = fs_info->nodesize;
777777

778778
if (!(found_key.objectid >= cache->start &&
779-
found_key.objectid + length <= cache->start + cache->length)) {
779+
found_key.objectid + length <= cache->start + cache->zone_capacity)) {
780780
ret = -EUCLEAN;
781781
goto out;
782782
}
@@ -830,6 +830,7 @@ bool zoned_profile_supported(u64 map_type, bool rst)
830830

831831
struct zone_info {
832832
u64 physical;
833+
u64 capacity;
833834
u64 alloc_offset;
834835
};
835836

@@ -894,6 +895,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
894895
if (!is_sequential) {
895896
num_conventional++;
896897
info->alloc_offset = WP_CONVENTIONAL;
898+
info->capacity = device->zone_info->zone_size;
897899
continue;
898900
}
899901

@@ -904,6 +906,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
904906
WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size));
905907
zone = device->zone_info->zones[info->physical / fs_info->zone_size];
906908

909+
info->capacity = (zone.capacity << SECTOR_SHIFT);
910+
907911
switch (zone.cond) {
908912
case BLK_ZONE_COND_OFFLINE:
909913
case BLK_ZONE_COND_READONLY:
@@ -927,6 +931,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
927931
}
928932

929933
if (num_conventional > 0) {
934+
/* Zone capacity is always zone size in emulation */
935+
cache->zone_capacity = cache->length;
930936
ret = calculate_alloc_pointer(fs_info, cache, &last_alloc);
931937
if (ret || map->num_stripes == num_conventional) {
932938
if (!ret)
@@ -946,6 +952,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info,
946952
goto out;
947953
}
948954
cache->alloc_offset = zone_info[0].alloc_offset;
955+
cache->zone_capacity = zone_info[0].capacity;
949956

950957
out:
951958
/* An extent is allocated after the write pointer */

0 commit comments

Comments
 (0)