fs/btrfs/tests/zoned-tests.c
Source file repositories/reference/linux-study-clean/fs/btrfs/tests/zoned-tests.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/tests/zoned-tests.c- Extension
.c- Size
- 17750 bytes
- Lines
- 676
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/sizes.hbtrfs-tests.h../space-info.h../volumes.h../zoned.h
Detected Declarations
struct load_zone_info_test_vectorstruct zone_infofunction test_load_zone_infofunction btrfs_test_zoned
Annotated Snippet
struct load_zone_info_test_vector {
u64 raid_type;
u64 num_stripes;
u64 alloc_offsets[8];
u64 last_alloc;
u64 bg_length;
bool degraded;
int expected_result;
u64 expected_alloc_offset;
const char *description;
};
struct zone_info {
u64 physical;
u64 capacity;
u64 alloc_offset;
};
static int test_load_zone_info(struct btrfs_fs_info *fs_info,
const struct load_zone_info_test_vector *test)
{
struct btrfs_block_group *bg __free(btrfs_free_dummy_block_group) = NULL;
struct btrfs_chunk_map *map __free(btrfs_free_chunk_map) = NULL;
struct zone_info AUTO_KFREE(zone_info);
unsigned long AUTO_KFREE(active);
int ret;
bg = btrfs_alloc_dummy_block_group(fs_info, test->bg_length);
if (!bg) {
test_std_err(TEST_ALLOC_BLOCK_GROUP);
return -ENOMEM;
}
map = btrfs_alloc_chunk_map(test->num_stripes, GFP_KERNEL);
if (!map) {
test_std_err(TEST_ALLOC_EXTENT_MAP);
return -ENOMEM;
}
zone_info = kzalloc_objs(*zone_info, test->num_stripes, GFP_KERNEL);
if (!zone_info) {
test_err("cannot allocate zone info");
return -ENOMEM;
}
active = bitmap_zalloc(test->num_stripes, GFP_KERNEL);
if (!zone_info) {
test_err("cannot allocate active bitmap");
return -ENOMEM;
}
map->type = test->raid_type;
map->num_stripes = test->num_stripes;
if (test->raid_type == BTRFS_BLOCK_GROUP_RAID10)
map->sub_stripes = 2;
for (int i = 0; i < test->num_stripes; i++) {
zone_info[i].physical = 0;
zone_info[i].alloc_offset = test->alloc_offsets[i];
zone_info[i].capacity = ZONE_SIZE;
if (zone_info[i].alloc_offset && zone_info[i].alloc_offset < ZONE_SIZE)
__set_bit(i, active);
}
if (test->degraded)
btrfs_set_opt(fs_info->mount_opt, DEGRADED);
else
btrfs_clear_opt(fs_info->mount_opt, DEGRADED);
ret = btrfs_load_block_group_by_raid_type(bg, map, zone_info, active,
test->last_alloc);
if (ret != test->expected_result) {
test_err("unexpected return value: ret %d expected %d", ret,
test->expected_result);
return -EINVAL;
}
if (!ret && bg->alloc_offset != test->expected_alloc_offset) {
test_err("unexpected alloc_offset: alloc_offset %llu expected %llu",
bg->alloc_offset, test->expected_alloc_offset);
return -EINVAL;
}
return 0;
}
static const struct load_zone_info_test_vector load_zone_info_tests[] = {
/* SINGLE */
{
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/sizes.h`, `btrfs-tests.h`, `../space-info.h`, `../volumes.h`, `../zoned.h`.
- Detected declarations: `struct load_zone_info_test_vector`, `struct zone_info`, `function test_load_zone_info`, `function btrfs_test_zoned`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.