drivers/md/persistent-data/dm-btree.c
Source file repositories/reference/linux-study-clean/drivers/md/persistent-data/dm-btree.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/persistent-data/dm-btree.c- Extension
.c- Size
- 38839 bytes
- Lines
- 1638
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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
dm-btree-internal.hdm-space-map.hdm-transaction-manager.hlinux/export.hlinux/device-mapper.h
Detected Declarations
struct framestruct del_stackfunction Copyrightfunction array_insertfunction bsearchfunction lower_boundfunction upper_boundfunction inc_childrenfunction insert_atfunction entriesfunction dm_btree_emptyfunction top_framefunction unprocessed_framesfunction prefetch_childrenfunction is_internal_levelfunction push_framefunction pop_framefunction unlock_all_framesfunction dm_btree_delfunction btree_lookup_rawfunction dm_btree_lookupfunction dm_btree_lookup_next_singlefunction dm_btree_lookup_nextfunction copy_entriesfunction move_entriesfunction shift_downfunction shift_upfunction redistribute2function redistribute3function split_one_into_twofunction shadow_childfunction split_two_into_threefunction btree_split_beneathfunction rebalance_leftfunction rebalance_rightfunction get_node_free_spacefunction rebalance_or_splitfunction contains_keyfunction has_space_for_insertfunction btree_insert_rawfunction __btree_get_overwrite_leaffunction btree_get_overwrite_leaffunction need_insertfunction insertfunction dm_btree_insertfunction dm_btree_insert_notifyfunction find_keyfunction dm_btree_find_key
Annotated Snippet
struct frame {
struct dm_block *b;
struct btree_node *n;
unsigned int level;
unsigned int nr_children;
unsigned int current_child;
};
struct del_stack {
struct dm_btree_info *info;
struct dm_transaction_manager *tm;
int top;
struct frame spine[MAX_SPINE_DEPTH];
};
static int top_frame(struct del_stack *s, struct frame **f)
{
if (s->top < 0) {
DMERR("btree deletion stack empty");
return -EINVAL;
}
*f = s->spine + s->top;
return 0;
}
static int unprocessed_frames(struct del_stack *s)
{
return s->top >= 0;
}
static void prefetch_children(struct del_stack *s, struct frame *f)
{
unsigned int i;
struct dm_block_manager *bm = dm_tm_get_bm(s->tm);
for (i = 0; i < f->nr_children; i++)
dm_bm_prefetch(bm, value64(f->n, i));
}
static bool is_internal_level(struct dm_btree_info *info, struct frame *f)
{
return f->level < (info->levels - 1);
}
static int push_frame(struct del_stack *s, dm_block_t b, unsigned int level)
{
int r;
uint32_t ref_count;
if (s->top >= MAX_SPINE_DEPTH - 1) {
DMERR("btree deletion stack out of memory");
return -ENOMEM;
}
r = dm_tm_ref(s->tm, b, &ref_count);
if (r)
return r;
if (ref_count > 1)
/*
* This is a shared node, so we can just decrement it's
* reference counter and leave the children.
*/
dm_tm_dec(s->tm, b);
else {
uint32_t flags;
struct frame *f = s->spine + ++s->top;
r = dm_tm_read_lock(s->tm, b, &btree_node_validator, &f->b);
if (r) {
s->top--;
return r;
}
f->n = dm_block_data(f->b);
f->level = level;
f->nr_children = le32_to_cpu(f->n->header.nr_entries);
f->current_child = 0;
flags = le32_to_cpu(f->n->header.flags);
if (flags & INTERNAL_NODE || is_internal_level(s->info, f))
prefetch_children(s, f);
}
return 0;
}
Annotation
- Immediate include surface: `dm-btree-internal.h`, `dm-space-map.h`, `dm-transaction-manager.h`, `linux/export.h`, `linux/device-mapper.h`.
- Detected declarations: `struct frame`, `struct del_stack`, `function Copyright`, `function array_insert`, `function bsearch`, `function lower_bound`, `function upper_bound`, `function inc_children`, `function insert_at`, `function entries`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: integration 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.