fs/btrfs/extent-tree.c
Source file repositories/reference/linux-study-clean/fs/btrfs/extent-tree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/extent-tree.c- Extension
.c- Size
- 197695 bytes
- Lines
- 6937
- 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/sched.hlinux/sched/signal.hlinux/pagemap.hlinux/writeback.hlinux/blkdev.hlinux/sort.hlinux/rcupdate.hlinux/kthread.hlinux/slab.hlinux/ratelimit.hlinux/percpu_counter.hlinux/lockdep.hlinux/crc32c.hctree.hextent-tree.htransaction.hdisk-io.hprint-tree.hvolumes.hraid56.hlocking.hfree-space-cache.hfree-space-tree.hqgroup.href-verify.hspace-info.hblock-rsv.hdiscard.hzoned.hdev-replace.hfs.haccessors.h
Detected Declarations
struct walk_controlenum btrfs_loop_typefunction block_group_bitsfunction btrfs_lookup_data_extentfunction btrfs_lookup_extent_infofunction btrfs_get_extent_inline_ref_typefunction hash_extent_data_reffunction hash_extent_data_ref_itemfunction match_extent_data_reffunction lookup_extent_data_reffunction insert_extent_data_reffunction remove_extent_data_reffunction extent_data_ref_countfunction lookup_tree_block_reffunction insert_tree_block_reffunction extent_ref_typefunction find_next_keyfunction lookup_inline_extent_backreffunction setup_inline_extent_backreffunction lookup_extent_backreffunction update_inline_extent_backreffunction setup_inline_extent_backreffunction insert_inline_extent_backreffunction remove_extent_backreffunction btrfs_issue_discardfunction do_discard_extentfunction btrfs_discard_extentfunction btrfs_inc_extent_reffunction __btrfs_free_extentfunction free_head_ref_squota_rsvfunction drop_remap_tree_reffunction run_delayed_data_reffunction __run_delayed_extent_opfunction run_delayed_extent_opfunction run_delayed_tree_reffunction run_one_delayed_reffunction run_and_cleanup_extent_opfunction btrfs_cleanup_ref_head_accountingfunction cleanup_ref_headfunction btrfs_run_delayed_refs_for_headfunction __btrfs_run_delayed_refsfunction find_middlefunction Usefunction btrfs_set_disk_extent_flagsfunction check_delayed_reffunction check_delayed_reffunction btrfs_cross_ref_existfunction check_delayed_ref
Annotated Snippet
struct walk_control {
u64 refs[BTRFS_MAX_LEVEL];
u64 flags[BTRFS_MAX_LEVEL];
struct btrfs_key update_progress;
struct btrfs_key drop_progress;
int drop_level;
int stage;
int level;
int shared_level;
int update_ref;
int keep_locks;
int reada_slot;
int reada_count;
int restarted;
/* Indicate that extent info needs to be looked up when walking the tree. */
int lookup_info;
};
/*
* This is our normal stage. We are traversing blocks the current snapshot owns
* and we are dropping any of our references to any children we are able to, and
* then freeing the block once we've processed all of the children.
*/
#define DROP_REFERENCE 1
/*
* We enter this stage when we have to walk into a child block (meaning we can't
* simply drop our reference to it from our current parent node) and there are
* more than one reference on it. If we are the owner of any of the children
* blocks from the current parent node then we have to do the FULL_BACKREF dance
* on them in order to drop our normal ref and add the shared ref.
*/
#define UPDATE_BACKREF 2
/*
* Decide if we need to walk down into this node to adjust the references.
*
* @root: the root we are currently deleting
* @wc: the walk control for this deletion
* @eb: the parent eb that we're currently visiting
* @flags: the flags for wc->level - 1
* @slot: the slot in the eb that we're currently checking
*
* This is meant to be called when we're evaluating if a node we point to at
* wc->level should be read and walked into, or if we can simply delete our
* reference to it. We return true if we should walk into the node, false if we
* can skip it.
*
* We have assertions in here to make sure this is called correctly. We assume
* that sanity checking on the blocks read to this point has been done, so any
* corrupted file systems must have been caught before calling this function.
*/
static bool visit_node_for_delete(struct btrfs_root *root, struct walk_control *wc,
struct extent_buffer *eb, u64 flags, int slot)
{
struct btrfs_key key;
u64 generation;
int level = wc->level;
ASSERT(level > 0);
ASSERT(wc->refs[level - 1] > 0);
/*
* The update backref stage we only want to skip if we already have
* FULL_BACKREF set, otherwise we need to read.
*/
if (wc->stage == UPDATE_BACKREF) {
if (level == 1 && flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)
return false;
return true;
}
/*
* We're the last ref on this block, we must walk into it and process
* any refs it's pointing at.
*/
if (wc->refs[level - 1] == 1)
return true;
/*
* If we're already FULL_BACKREF then we know we can just drop our
* current reference.
*/
if (level == 1 && flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)
return false;
/*
* This block is older than our creation generation, we can drop our
* reference to it.
*/
Annotation
- Immediate include surface: `linux/sched.h`, `linux/sched/signal.h`, `linux/pagemap.h`, `linux/writeback.h`, `linux/blkdev.h`, `linux/sort.h`, `linux/rcupdate.h`, `linux/kthread.h`.
- Detected declarations: `struct walk_control`, `enum btrfs_loop_type`, `function block_group_bits`, `function btrfs_lookup_data_extent`, `function btrfs_lookup_extent_info`, `function btrfs_get_extent_inline_ref_type`, `function hash_extent_data_ref`, `function hash_extent_data_ref_item`, `function match_extent_data_ref`, `function lookup_extent_data_ref`.
- 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.