fs/btrfs/tests/chunk-allocation-tests.c

Source file repositories/reference/linux-study-clean/fs/btrfs/tests/chunk-allocation-tests.c

File Facts

System
Linux kernel
Corpus path
fs/btrfs/tests/chunk-allocation-tests.c
Extension
.c
Size
11975 bytes
Lines
477
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 pending_extent_test_case {
	const char *name;
	/* Input range to search. */
	u64 hole_start;
	u64 hole_len;
	/* The size of hole we are searching for. */
	u64 min_hole_size;
	/*
	 * Pending extents to set up (up to 2 for up to 3 holes)
	 * If len == 0, then it is skipped.
	 */
	struct {
		u64 start;
		u64 len;
	} pending_extents[2];
	/* Expected outputs. */
	bool expected_found;
	u64 expected_start;
	u64 expected_len;
};

static const struct pending_extent_test_case find_hole_tests[] = {
	{
		.name = "no pending extents",
		.hole_start = 0,
		.hole_len = 10ULL * SZ_1G,
		.min_hole_size = SZ_1G,
		.pending_extents = { },
		.expected_found = true,
		.expected_start = 0,
		.expected_len = 10ULL * SZ_1G,
	},
	{
		.name = "pending extent at start of range",
		.hole_start = 0,
		.hole_len = 10ULL * SZ_1G,
		.min_hole_size = SZ_1G,
		.pending_extents = {
			{ .start = 0, .len = SZ_1G },
		},
		.expected_found = true,
		.expected_start = SZ_1G,
		.expected_len = 9ULL * SZ_1G,
	},
	{
		.name = "pending extent overlapping start of range",
		.hole_start = SZ_1G,
		.hole_len = 9ULL * SZ_1G,
		.min_hole_size = SZ_1G,
		.pending_extents = {
			{ .start = 0, .len = SZ_2G },
		},
		.expected_found = true,
		.expected_start = SZ_2G,
		.expected_len = 8ULL * SZ_1G,
	},
	{
		.name = "two holes; first hole is exactly big enough",
		.hole_start = 0,
		.hole_len = 10ULL * SZ_1G,
		.min_hole_size = SZ_1G,
		.pending_extents = {
			{ .start = SZ_1G, .len = SZ_1G },
		},
		.expected_found = true,
		.expected_start = 0,
		.expected_len = SZ_1G,
	},
	{
		.name = "two holes; first hole is big enough",
		.hole_start = 0,
		.hole_len = 10ULL * SZ_1G,
		.min_hole_size = SZ_1G,
		.pending_extents = {
			{ .start = SZ_2G, .len = SZ_1G },
		},
		.expected_found = true,
		.expected_start = 0,
		.expected_len = SZ_2G,
	},
	{
		.name = "two holes; second hole is big enough",
		.hole_start = 0,
		.hole_len = 10ULL * SZ_1G,
		.min_hole_size = SZ_2G,
		.pending_extents = {
			{ .start = SZ_1G, .len = SZ_1G },
		},
		.expected_found = true,
		.expected_start = SZ_2G,

Annotation

Implementation Notes