fs/btrfs/tests/free-space-tests.c
Source file repositories/reference/linux-study-clean/fs/btrfs/tests/free-space-tests.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/tests/free-space-tests.c- Extension
.c- Size
- 29788 bytes
- Lines
- 1060
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hbtrfs-tests.h../ctree.h../disk-io.h../free-space-cache.h../block-group.h
Detected Declarations
function Copyrightfunction test_bitmapsfunction test_bitmaps_and_extentsfunction test_use_bitmapfunction check_num_extents_and_bitmapsfunction check_cache_emptyfunction concurrencyfunction spacefunction spacefunction bytes_index_use_bitmapfunction test_bytes_indexfunction btrfs_test_free_space_cache
Annotated Snippet
if (ret) {
test_err("couldn't add extent entry %d\n", ret);
return ret;
}
offset += bytes + sectorsize;
}
for (node = rb_first_cached(&ctl->free_space_bytes), i = 9; node;
node = rb_next(node), i--) {
entry = rb_entry(node, struct btrfs_free_space, bytes_index);
bytes = (i + 1) * SZ_1M;
if (entry->bytes != bytes) {
test_err("invalid bytes index order, found %llu expected %llu",
entry->bytes, bytes);
return -EINVAL;
}
}
/* Now validate bitmaps do the correct thing. */
btrfs_remove_free_space_cache(cache);
for (i = 0; i < 2; i++) {
offset = i * BITS_PER_BITMAP * sectorsize;
bytes = (i + 1) * SZ_1M;
ret = test_add_free_space_entry(cache, offset, bytes, 1);
if (ret) {
test_err("couldn't add bitmap entry");
return ret;
}
}
for (node = rb_first_cached(&ctl->free_space_bytes), i = 1; node;
node = rb_next(node), i--) {
entry = rb_entry(node, struct btrfs_free_space, bytes_index);
bytes = (i + 1) * SZ_1M;
if (entry->bytes != bytes) {
test_err("invalid bytes index order, found %llu expected %llu",
entry->bytes, bytes);
return -EINVAL;
}
}
/* Now validate bitmaps with different ->max_extent_size. */
btrfs_remove_free_space_cache(cache);
orig_use_bitmap = cache->fs_info->use_bitmap;
cache->fs_info->use_bitmap = bytes_index_use_bitmap;
ret = test_add_free_space_entry(cache, 0, sectorsize, 1);
if (ret) {
test_err("couldn't add bitmap entry");
return ret;
}
offset = BITS_PER_BITMAP * sectorsize;
ret = test_add_free_space_entry(cache, offset, sectorsize, 1);
if (ret) {
test_err("couldn't add bitmap_entry");
return ret;
}
/*
* Now set a bunch of sectorsize extents in the first entry so it's
* ->bytes is large.
*/
for (i = 2; i < 20; i += 2) {
offset = sectorsize * i;
ret = btrfs_add_free_space(cache, offset, sectorsize);
if (ret) {
test_err("error populating sparse bitmap %d", ret);
return ret;
}
}
/*
* Now set a contiguous extent in the second bitmap so its
* ->max_extent_size is larger than the first bitmaps.
*/
offset = (BITS_PER_BITMAP * sectorsize) + sectorsize;
ret = btrfs_add_free_space(cache, offset, sectorsize);
if (ret) {
test_err("error adding contiguous extent %d", ret);
return ret;
}
/*
* Since we don't set ->max_extent_size unless we search everything
* should be indexed on bytes.
*/
entry = rb_entry(rb_first_cached(&ctl->free_space_bytes),
struct btrfs_free_space, bytes_index);
if (entry->bytes != (10 * sectorsize)) {
Annotation
- Immediate include surface: `linux/slab.h`, `btrfs-tests.h`, `../ctree.h`, `../disk-io.h`, `../free-space-cache.h`, `../block-group.h`.
- Detected declarations: `function Copyright`, `function test_bitmaps`, `function test_bitmaps_and_extents`, `function test_use_bitmap`, `function check_num_extents_and_bitmaps`, `function check_cache_empty`, `function concurrency`, `function space`, `function space`, `function bytes_index_use_bitmap`.
- 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.