fs/xfs/libxfs/xfs_btree.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_btree.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_btree.c- Extension
.c- Size
- 150022 bytes
- Lines
- 5651
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_bit.hxfs_mount.hxfs_inode.hxfs_trans.hxfs_buf_item.hxfs_btree.hxfs_errortag.hxfs_error.hxfs_trace.hxfs_alloc.hxfs_log.hxfs_btree_staging.hxfs_ag.hxfs_alloc_btree.hxfs_ialloc_btree.hxfs_bmap_btree.hxfs_rmap_btree.hxfs_refcount_btree.hxfs_health.hxfs_buf_mem.hxfs_btree_mem.hxfs_rtrmap_btree.hxfs_bmap.hxfs_rmap.hxfs_quota.hxfs_metafile.h
Detected Declarations
struct xfs_btree_split_argsstruct xfs_btree_block_change_owner_infostruct xfs_btree_has_recordsfunction Copyrightfunction xfs_btree_check_fsblock_siblingsfunction xfs_btree_check_memblock_siblingsfunction xfs_btree_check_agblock_siblingsfunction __xfs_btree_check_lblock_hdrfunction __xfs_btree_check_fsblockfunction __xfs_btree_check_memblockfunction __xfs_btree_check_agblockfunction __xfs_btree_check_blockfunction xfs_btree_block_errtagfunction XFS_TEST_ERRORfunction __xfs_btree_check_ptrfunction givenfunction xfs_btree_fsblock_calc_crcfunction xfs_btree_fsblock_verify_crcfunction xfs_btree_agblock_calc_crcfunction xfs_btree_agblock_verify_crcfunction xfs_btree_free_blockfunction xfs_btree_buftargfunction xfs_btree_bbsizefunction shortfunction xfs_btree_rec_offsetfunction xfs_btree_key_offsetfunction xfs_btree_high_key_offsetfunction xfs_btree_ptr_offsetfunction xfs_btree_rec_addrfunction xfs_btree_key_addrfunction xfs_btree_high_key_addrfunction xfs_btree_ptr_addrfunction xfs_btree_ifork_ptrfunction xfs_btree_get_irootfunction xfs_btree_readahead_fsblockfunction xfs_btree_readahead_memblockfunction xfs_btree_readahead_agblockfunction xfs_btree_ptr_to_daddrfunction xfs_btree_readahead_ptrfunction xfs_btree_ptr_is_nullfunction xfs_btree_set_ptr_nullfunction xfs_btree_ptrs_equalfunction xfs_btree_get_siblingfunction xfs_btree_set_siblingfunction __xfs_btree_init_blockfunction xfs_btree_init_blockfunction xfs_btree_init_buffunction xfs_btree_owner
Annotated Snippet
struct xfs_btree_split_args {
struct xfs_btree_cur *cur;
int level;
union xfs_btree_ptr *ptrp;
union xfs_btree_key *key;
struct xfs_btree_cur **curp;
int *stat; /* success/failure */
int result;
bool kswapd; /* allocation in kswapd context */
struct completion *done;
struct work_struct work;
};
/*
* Stack switching interfaces for allocation
*/
static void
xfs_btree_split_worker(
struct work_struct *work)
{
struct xfs_btree_split_args *args = container_of(work,
struct xfs_btree_split_args, work);
unsigned long pflags;
unsigned long new_pflags = 0;
/*
* we are in a transaction context here, but may also be doing work
* in kswapd context, and hence we may need to inherit that state
* temporarily to ensure that we don't block waiting for memory reclaim
* in any way.
*/
if (args->kswapd)
new_pflags |= PF_MEMALLOC | PF_KSWAPD;
current_set_flags_nested(&pflags, new_pflags);
xfs_trans_set_context(args->cur->bc_tp);
args->result = __xfs_btree_split(args->cur, args->level, args->ptrp,
args->key, args->curp, args->stat);
xfs_trans_clear_context(args->cur->bc_tp);
current_restore_flags_nested(&pflags, new_pflags);
/*
* Do not access args after complete() has run here. We don't own args
* and the owner may run and free args before we return here.
*/
complete(args->done);
}
/*
* BMBT split requests often come in with little stack to work on so we push
* them off to a worker thread so there is lots of stack to use. For the other
* btree types, just call directly to avoid the context switch overhead here.
*
* Care must be taken here - the work queue rescuer thread introduces potential
* AGF <> worker queue deadlocks if the BMBT block allocation has to lock new
* AGFs to allocate blocks. A task being run by the rescuer could attempt to
* lock an AGF that is already locked by a task queued to run by the rescuer,
* resulting in an ABBA deadlock as the rescuer cannot run the lock holder to
* release it until the current thread it is running gains the lock.
*
* To avoid this issue, we only ever queue BMBT splits that don't have an AGF
* already locked to allocate from. The only place that doesn't hold an AGF
* locked is unwritten extent conversion at IO completion, but that has already
* been offloaded to a worker thread and hence has no stack consumption issues
* we have to worry about.
*/
STATIC int /* error */
xfs_btree_split(
struct xfs_btree_cur *cur,
int level,
union xfs_btree_ptr *ptrp,
union xfs_btree_key *key,
struct xfs_btree_cur **curp,
int *stat) /* success/failure */
{
struct xfs_btree_split_args args;
DECLARE_COMPLETION_ONSTACK(done);
if (!xfs_btree_is_bmap(cur->bc_ops) ||
cur->bc_tp->t_highest_agno == NULLAGNUMBER)
return __xfs_btree_split(cur, level, ptrp, key, curp, stat);
args.cur = cur;
args.level = level;
args.ptrp = ptrp;
args.key = key;
args.curp = curp;
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_bit.h`, `xfs_mount.h`.
- Detected declarations: `struct xfs_btree_split_args`, `struct xfs_btree_block_change_owner_info`, `struct xfs_btree_has_records`, `function Copyright`, `function xfs_btree_check_fsblock_siblings`, `function xfs_btree_check_memblock_siblings`, `function xfs_btree_check_agblock_siblings`, `function __xfs_btree_check_lblock_hdr`, `function __xfs_btree_check_fsblock`, `function __xfs_btree_check_memblock`.
- 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.