fs/xfs/libxfs/xfs_alloc.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_alloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_alloc.c- Extension
.c- Size
- 114601 bytes
- Lines
- 4193
- 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_format.hxfs_log_format.hxfs_shared.hxfs_trans_resv.hxfs_bit.hxfs_mount.hxfs_defer.hxfs_btree.hxfs_rmap.hxfs_alloc_btree.hxfs_alloc.hxfs_extent_busy.hxfs_errortag.hxfs_error.hxfs_trace.hxfs_trans.hxfs_buf_item.hxfs_log.hxfs_ag.hxfs_ag_resv.hxfs_bmap.hxfs_health.hxfs_extfree_item.h
Detected Declarations
struct xfs_alloc_curstruct xfs_alloc_query_range_infofunction xfs_agfl_sizefunction xfs_refc_blockfunction xfs_prealloc_blocksfunction bufferfunction xfs_alloc_ag_max_usablefunction xfs_alloc_lookupfunction xfs_alloc_cur_activefunction xfs_alloc_btrec_to_irecfunction xfs_alloc_check_irecfunction xfs_alloc_complain_bad_recfunction xfs_alloc_compute_alignedfunction xfs_alloc_fixup_longestfunction xfs_cntbt_longestfunction xfs_alloc_cursor_at_lastrecfunction xfs_alloc_get_freelistfunction xfs_agfl_read_verifyfunction xfs_agfl_write_verifyfunction xfs_alloc_read_agflfunction xfs_alloc_update_countersfunction xfs_alloc_cur_setupfunction xfs_alloc_cur_closefunction xfs_alloc_cur_checkfunction rangefunction xfs_alloc_cur_finishfunction xfs_alloc_cntbt_iterfunction xfs_alloc_walk_iterfunction xfs_alloc_ag_vextent_localityfunction xfs_alloc_cur_activefunction xfs_alloc_ag_vextent_lastblockfunction xfs_alloc_ag_vextent_nearfunction xfs_alloc_ag_vextent_sizefunction be32_to_cpufunction xfs_free_ag_extentfunction xfs_alloc_longest_free_extentfunction xfs_alloc_min_freelistfunction xfs_alloc_space_availablefunction xfs_agfl_needs_resetfunction xfs_agfl_resetfunction sortedfunction xfs_free_extent_laterfunction xfs_alloc_schedule_autoreapfunction xfs_alloc_cancel_autoreapfunction xfs_alloc_commit_autoreapfunction xfs_exact_minlen_extent_availablefunction xfs_alloc_get_freelistfunction xfs_alloc_log_agf
Annotated Snippet
struct xfs_alloc_cur {
struct xfs_btree_cur *cnt; /* btree cursors */
struct xfs_btree_cur *bnolt;
struct xfs_btree_cur *bnogt;
xfs_extlen_t cur_len;/* current search length */
xfs_agblock_t rec_bno;/* extent startblock */
xfs_extlen_t rec_len;/* extent length */
xfs_agblock_t bno; /* alloc bno */
xfs_extlen_t len; /* alloc len */
xfs_extlen_t diff; /* diff from search bno */
unsigned int busy_gen;/* busy state */
bool busy;
};
/*
* Set up cursors, etc. in the extent allocation cursor. This function can be
* called multiple times to reset an initialized structure without having to
* reallocate cursors.
*/
static int
xfs_alloc_cur_setup(
struct xfs_alloc_arg *args,
struct xfs_alloc_cur *acur)
{
int error;
int i;
acur->cur_len = args->maxlen;
acur->rec_bno = 0;
acur->rec_len = 0;
acur->bno = 0;
acur->len = 0;
acur->diff = -1;
acur->busy = false;
acur->busy_gen = 0;
/*
* Perform an initial cntbt lookup to check for availability of maxlen
* extents. If this fails, we'll return -ENOSPC to signal the caller to
* attempt a small allocation.
*/
if (!acur->cnt)
acur->cnt = xfs_cntbt_init_cursor(args->mp, args->tp,
args->agbp, args->pag);
error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i);
if (error)
return error;
/*
* Allocate the bnobt left and right search cursors.
*/
if (!acur->bnolt)
acur->bnolt = xfs_bnobt_init_cursor(args->mp, args->tp,
args->agbp, args->pag);
if (!acur->bnogt)
acur->bnogt = xfs_bnobt_init_cursor(args->mp, args->tp,
args->agbp, args->pag);
return i == 1 ? 0 : -ENOSPC;
}
static void
xfs_alloc_cur_close(
struct xfs_alloc_cur *acur,
bool error)
{
int cur_error = XFS_BTREE_NOERROR;
if (error)
cur_error = XFS_BTREE_ERROR;
if (acur->cnt)
xfs_btree_del_cursor(acur->cnt, cur_error);
if (acur->bnolt)
xfs_btree_del_cursor(acur->bnolt, cur_error);
if (acur->bnogt)
xfs_btree_del_cursor(acur->bnogt, cur_error);
acur->cnt = acur->bnolt = acur->bnogt = NULL;
}
/*
* Check an extent for allocation and track the best available candidate in the
* allocation structure. The cursor is deactivated if it has entered an out of
* range state based on allocation arguments. Optionally return the extent
* extent geometry and allocation status if requested by the caller.
*/
static int
xfs_alloc_cur_check(
struct xfs_alloc_arg *args,
struct xfs_alloc_cur *acur,
struct xfs_btree_cur *cur,
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_shared.h`, `xfs_trans_resv.h`, `xfs_bit.h`, `xfs_mount.h`.
- Detected declarations: `struct xfs_alloc_cur`, `struct xfs_alloc_query_range_info`, `function xfs_agfl_size`, `function xfs_refc_block`, `function xfs_prealloc_blocks`, `function buffer`, `function xfs_alloc_ag_max_usable`, `function xfs_alloc_lookup`, `function xfs_alloc_cur_active`, `function xfs_alloc_btrec_to_irec`.
- 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.