fs/btrfs/extent-io-tree.c
Source file repositories/reference/linux-study-clean/fs/btrfs/extent-io-tree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/extent-io-tree.c- Extension
.c- Size
- 55622 bytes
- Lines
- 2051
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.htrace/events/btrfs.hmessages.hctree.hextent_io.hextent-io-tree.hbtrfs_inode.h
Detected Declarations
function extent_state_in_treefunction btrfs_leak_debug_add_statefunction btrfs_leak_debug_del_statefunction btrfs_extent_state_leak_debug_checkfunction __btrfs_debug_check_extent_io_rangefunction btrfs_extent_io_tree_initfunction btrfs_extent_io_tree_releasefunction btrfs_free_extent_statefunction add_extent_changesetfunction merge_prev_statefunction merge_next_statefunction sleepingfunction set_state_bitsfunction insert_state_fastfunction split_statefunction state_wake_upfunction neededfunction set_gfp_mask_from_bitsfunction btrfs_clear_extent_bit_changesetfunction wait_extent_bitfunction cache_state_if_flagsfunction cache_statefunction btrfs_find_first_extent_bitfunction btrfs_find_contiguous_extent_bitfunction btrfs_find_delalloc_rangefunction set_extent_bitfunction btrfs_set_extent_bitfunction btrfs_convert_extent_bitfunction spansfunction bitfunction btrfs_test_range_bit_existsfunction btrfs_get_range_bitsfunction btrfs_test_range_bitfunction btrfs_set_record_extent_bitsfunction btrfs_clear_record_extent_bitsfunction btrfs_try_lock_extent_bitsfunction btrfs_lock_extent_bitsfunction btrfs_extent_state_free_cachepfunction btrfs_extent_state_init_cachep
Annotated Snippet
if (state->end < entry->start) {
if (try_merge && end == entry->start &&
state->state == entry->state) {
if (tree->owner == IO_TREE_INODE_IO)
btrfs_merge_delalloc_extent(tree->inode,
state, entry);
entry->start = state->start;
merge_prev_state(tree, entry);
state->state = 0;
return entry;
}
node = &(*node)->rb_left;
} else if (state->end > entry->end) {
if (try_merge && entry->end == start &&
state->state == entry->state) {
if (tree->owner == IO_TREE_INODE_IO)
btrfs_merge_delalloc_extent(tree->inode,
state, entry);
entry->end = state->end;
merge_next_state(tree, entry);
state->state = 0;
return entry;
}
node = &(*node)->rb_right;
} else {
return ERR_PTR(-EEXIST);
}
}
rb_link_node(&state->rb_node, parent, node);
rb_insert_color(&state->rb_node, &tree->state);
return state;
}
/*
* Insert state to @tree to the location given by @node and @parent.
*/
static void insert_state_fast(struct extent_io_tree *tree,
struct extent_state *state, struct rb_node **node,
struct rb_node *parent, unsigned bits,
struct extent_changeset *changeset)
{
set_state_bits(tree, state, bits, changeset);
rb_link_node(&state->rb_node, parent, node);
rb_insert_color(&state->rb_node, &tree->state);
merge_state(tree, state);
}
/*
* Split a given extent state struct in two, inserting the preallocated
* struct 'prealloc' as the newly created second half. 'split' indicates an
* offset inside 'orig' where it should be split.
*
* Before calling,
* the tree has 'orig' at [orig->start, orig->end]. After calling, there
* are two extent state structs in the tree:
* prealloc: [orig->start, split - 1]
* orig: [ split, orig->end ]
*
* The tree locks are not taken by this function. They need to be held
* by the caller.
*/
static int split_state(struct extent_io_tree *tree, struct extent_state *orig,
struct extent_state *prealloc, u64 split)
{
struct rb_node *parent = NULL;
struct rb_node **node;
if (tree->owner == IO_TREE_INODE_IO)
btrfs_split_delalloc_extent(tree->inode, orig, split);
prealloc->start = orig->start;
prealloc->end = split - 1;
prealloc->state = orig->state;
orig->start = split;
parent = &orig->rb_node;
node = &parent;
while (*node) {
struct extent_state *entry;
parent = *node;
entry = rb_entry(parent, struct extent_state, rb_node);
if (prealloc->end < entry->start) {
node = &(*node)->rb_left;
} else if (prealloc->end > entry->end) {
node = &(*node)->rb_right;
} else {
Annotation
- Immediate include surface: `linux/slab.h`, `trace/events/btrfs.h`, `messages.h`, `ctree.h`, `extent_io.h`, `extent-io-tree.h`, `btrfs_inode.h`.
- Detected declarations: `function extent_state_in_tree`, `function btrfs_leak_debug_add_state`, `function btrfs_leak_debug_del_state`, `function btrfs_extent_state_leak_debug_check`, `function __btrfs_debug_check_extent_io_range`, `function btrfs_extent_io_tree_init`, `function btrfs_extent_io_tree_release`, `function btrfs_free_extent_state`, `function add_extent_changeset`, `function merge_prev_state`.
- 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.