fs/btrfs/free-space-tree.c
Source file repositories/reference/linux-study-clean/fs/btrfs/free-space-tree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/free-space-tree.c- Extension
.c- Size
- 50450 bytes
- Lines
- 1853
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/sched/mm.hmessages.hctree.hdisk-io.hlocking.hfree-space-tree.htransaction.hblock-group.hfs.haccessors.hextent-tree.hroot-tree.h
Detected Declarations
function btrfs_set_free_space_tree_thresholdsfunction add_new_free_space_infofunction btrfs_search_slotfunction free_space_bitmap_sizefunction le_bitmap_setfunction btrfs_convert_free_space_to_bitmapsfunction btrfs_convert_free_space_to_extentsfunction update_free_space_extent_countfunction btrfs_free_space_test_bitfunction free_space_modify_bitsfunction btrfs_next_leaffunction modify_free_space_bitmapfunction remove_free_space_extentfunction using_bitmapsfunction __btrfs_remove_from_free_space_treefunction btrfs_remove_from_free_space_treefunction add_free_space_extentfunction keyfunction __btrfs_add_to_free_space_treefunction btrfs_add_to_free_space_treefunction populate_free_space_treefunction btrfs_create_free_space_treefunction clear_free_space_treefunction btrfs_delete_free_space_treefunction btrfs_rebuild_free_space_treefunction __add_block_group_free_spacefunction btrfs_add_block_group_free_spacefunction btrfs_remove_block_group_free_spacefunction validate_free_space_keyfunction load_free_space_bitmapsfunction load_free_space_extentsfunction btrfs_load_free_space_treefunction delete_orphan_free_space_entriesfunction btrfs_delete_orphan_free_space_entries
Annotated Snippet
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
goto out;
}
leaf = path->nodes[0];
nr = 0;
path->slots[0]++;
while (path->slots[0] > 0) {
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0] - 1);
if (found_key.type == BTRFS_FREE_SPACE_INFO_KEY) {
ASSERT(found_key.objectid == block_group->start);
ASSERT(found_key.offset == block_group->length);
done = true;
break;
} else if (found_key.type == BTRFS_FREE_SPACE_EXTENT_KEY) {
u64 first, last;
ASSERT(found_key.objectid >= start);
ASSERT(found_key.objectid < end);
ASSERT(found_key.objectid + found_key.offset <= end);
first = div_u64(found_key.objectid - start,
fs_info->sectorsize);
last = div_u64(found_key.objectid + found_key.offset - start,
fs_info->sectorsize);
le_bitmap_set(bitmap, first, last - first);
extent_count++;
nr++;
path->slots[0]--;
} else {
btrfs_err(fs_info, "unexpected free space tree key type %u",
found_key.type);
ret = -EUCLEAN;
btrfs_abort_transaction(trans, ret);
goto out;
}
}
ret = btrfs_del_items(trans, root, path, path->slots[0], nr);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
goto out;
}
btrfs_release_path(path);
}
info = btrfs_search_free_space_info(trans, block_group, path, 1);
if (IS_ERR(info)) {
ret = PTR_ERR(info);
btrfs_abort_transaction(trans, ret);
goto out;
}
leaf = path->nodes[0];
flags = btrfs_free_space_flags(leaf, info);
flags |= BTRFS_FREE_SPACE_USING_BITMAPS;
block_group->using_free_space_bitmaps = true;
block_group->using_free_space_bitmaps_cached = true;
btrfs_set_free_space_flags(leaf, info, flags);
expected_extent_count = btrfs_free_space_extent_count(leaf, info);
btrfs_release_path(path);
if (unlikely(extent_count != expected_extent_count)) {
btrfs_err(fs_info,
"incorrect extent count for %llu; counted %u, expected %u",
block_group->start, extent_count,
expected_extent_count);
ret = -EIO;
btrfs_abort_transaction(trans, ret);
goto out;
}
bitmap_cursor = (char *)bitmap;
bitmap_range = fs_info->sectorsize * BTRFS_FREE_SPACE_BITMAP_BITS;
i = start;
while (i < end) {
unsigned long ptr;
u64 extent_size;
u32 data_size;
extent_size = min(end - i, bitmap_range);
data_size = free_space_bitmap_size(fs_info, extent_size);
key.objectid = i;
key.type = BTRFS_FREE_SPACE_BITMAP_KEY;
key.offset = extent_size;
ret = btrfs_insert_empty_item(trans, root, path, &key,
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/mm.h`, `messages.h`, `ctree.h`, `disk-io.h`, `locking.h`, `free-space-tree.h`, `transaction.h`.
- Detected declarations: `function btrfs_set_free_space_tree_thresholds`, `function add_new_free_space_info`, `function btrfs_search_slot`, `function free_space_bitmap_size`, `function le_bitmap_set`, `function btrfs_convert_free_space_to_bitmaps`, `function btrfs_convert_free_space_to_extents`, `function update_free_space_extent_count`, `function btrfs_free_space_test_bit`, `function free_space_modify_bits`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.