fs/btrfs/ulist.c
Source file repositories/reference/linux-study-clean/fs/btrfs/ulist.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/ulist.c- Extension
.c- Size
- 7203 bytes
- Lines
- 299
- 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.
- 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/slab.hmessages.hulist.h
Detected Declarations
function ulist_initfunction ulist_releasefunction list_for_each_entry_safefunction ulist_reinitfunction ulist_preallocfunction ulist_freefunction ulist_node_val_key_cmpfunction ulist_rbtree_erasefunction ulist_node_val_cmpfunction ulist_rbtree_insertfunction ulist_addfunction ulist_add_mergefunction ulist_del
Annotated Snippet
* while ((elem = ulist_next(ulist, &uiter)) {
* for (all child nodes n in elem)
* ulist_add(ulist, n);
* do something useful with the node;
* }
* ulist_free(ulist);
*
* This assumes the graph nodes are addressable by u64. This stems from the
* usage for tree enumeration in btrfs, where the logical addresses are
* 64 bit.
*
* It is also useful for tree enumeration which could be done elegantly
* recursively, but is not possible due to kernel stack limitations. The
* loop would be similar to the above.
*/
/*
* Freshly initialize a ulist.
*
* @ulist: the ulist to initialize
*
* Note: don't use this function to init an already used ulist, use
* ulist_reinit instead.
*/
void ulist_init(struct ulist *ulist)
{
INIT_LIST_HEAD(&ulist->nodes);
ulist->root = RB_ROOT;
ulist->nnodes = 0;
ulist->prealloc = NULL;
}
/*
* Free up additionally allocated memory for the ulist.
*
* @ulist: the ulist from which to free the additional memory
*
* This is useful in cases where the base 'struct ulist' has been statically
* allocated.
*/
void ulist_release(struct ulist *ulist)
{
struct ulist_node *node;
struct ulist_node *next;
list_for_each_entry_safe(node, next, &ulist->nodes, list) {
kfree(node);
}
kfree(ulist->prealloc);
ulist->prealloc = NULL;
ulist->root = RB_ROOT;
INIT_LIST_HEAD(&ulist->nodes);
}
/*
* Prepare a ulist for reuse.
*
* @ulist: ulist to be reused
*
* Free up all additional memory allocated for the list elements and reinit
* the ulist.
*/
void ulist_reinit(struct ulist *ulist)
{
ulist_release(ulist);
ulist_init(ulist);
}
/*
* Dynamically allocate a ulist.
*
* @gfp_mask: allocation flags to for base allocation
*
* The allocated ulist will be returned in an initialized state.
*/
struct ulist *ulist_alloc(gfp_t gfp_mask)
{
struct ulist *ulist = kmalloc_obj(*ulist, gfp_mask);
if (!ulist)
return NULL;
ulist_init(ulist);
return ulist;
}
void ulist_prealloc(struct ulist *ulist, gfp_t gfp_mask)
{
if (!ulist->prealloc)
Annotation
- Immediate include surface: `linux/slab.h`, `messages.h`, `ulist.h`.
- Detected declarations: `function ulist_init`, `function ulist_release`, `function list_for_each_entry_safe`, `function ulist_reinit`, `function ulist_prealloc`, `function ulist_free`, `function ulist_node_val_key_cmp`, `function ulist_rbtree_erase`, `function ulist_node_val_cmp`, `function ulist_rbtree_insert`.
- 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.