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.

Dependency Surface

Detected Declarations

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

Implementation Notes