fs/xfs/libxfs/xfs_ialloc.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_ialloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_ialloc.c- Extension
.c- Size
- 85650 bytes
- Lines
- 3186
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_bit.hxfs_mount.hxfs_inode.hxfs_btree.hxfs_ialloc.hxfs_ialloc_btree.hxfs_alloc.hxfs_errortag.hxfs_error.hxfs_bmap.hxfs_trans.hxfs_buf_item.hxfs_icreate_item.hxfs_icache.hxfs_trace.hxfs_log.hxfs_rmap.hxfs_ag.hxfs_health.h
Detected Declarations
struct xfs_ialloc_count_inodesfunction xfs_inobt_btrec_to_irecfunction xfs_inobt_rec_freecountfunction xfs_inobt_check_irecfunction xfs_inobt_complain_bad_recfunction xfs_inobt_get_recfunction xfs_inobt_insert_recfunction xfs_inobt_insertfunction xfs_check_agi_freecountfunction themfunction XFS_AGB_TO_AGINOfunction insertionfunction xfs_ialloc_ag_allocfunction xfs_ialloc_next_recfunction xfs_ialloc_get_recfunction xfs_inobt_first_free_inodefunction xfs_dialloc_check_inofunction xfs_dialloc_ag_inobtfunction xfs_dialloc_ag_finobt_nearfunction xfs_dialloc_ag_finobt_newinofunction xfs_dialloc_agfunction xfs_dialloc_rollfunction xfs_dialloc_good_agfunction xfs_dialloc_try_agfunction xfs_dialloc_pick_agfunction xfs_diallocfunction percpu_counter_read_positivefunction xfs_igetfunction xfs_difree_inode_chunkfunction xfs_difree_inobtfunction chunksfunction btreefunction xfs_imap_lookupfunction pag_groupfunction hdrfunction xfs_agi_verifyfunction xfs_agi_read_verifyfunction xfs_agi_write_verifyfunction headerfunction xfs_ialloc_read_agifunction xfs_ialloc_count_ondiskfunction xfs_ialloc_has_inodes_at_extentfunction xfs_ialloc_count_inodes_recfunction xfs_ialloc_count_inodesfunction xfs_ialloc_setup_geometryfunction usersfunction xfs_ialloc_calc_rootinofunction xfs_ialloc_check_shrink
Annotated Snippet
struct xfs_ialloc_count_inodes {
xfs_agino_t count;
xfs_agino_t freecount;
};
/* Record inode counts across all inobt records. */
STATIC int
xfs_ialloc_count_inodes_rec(
struct xfs_btree_cur *cur,
const union xfs_btree_rec *rec,
void *priv)
{
struct xfs_inobt_rec_incore irec;
struct xfs_ialloc_count_inodes *ci = priv;
xfs_failaddr_t fa;
xfs_inobt_btrec_to_irec(cur->bc_mp, rec, &irec);
fa = xfs_inobt_check_irec(to_perag(cur->bc_group), &irec);
if (fa)
return xfs_inobt_complain_bad_rec(cur, fa, &irec);
ci->count += irec.ir_count;
ci->freecount += irec.ir_freecount;
return 0;
}
/* Count allocated and free inodes under an inobt. */
int
xfs_ialloc_count_inodes(
struct xfs_btree_cur *cur,
xfs_agino_t *count,
xfs_agino_t *freecount)
{
struct xfs_ialloc_count_inodes ci = {0};
int error;
ASSERT(xfs_btree_is_ino(cur->bc_ops));
error = xfs_btree_query_all(cur, xfs_ialloc_count_inodes_rec, &ci);
if (error)
return error;
*count = ci.count;
*freecount = ci.freecount;
return 0;
}
/*
* Initialize inode-related geometry information.
*
* Compute the inode btree min and max levels and set maxicount.
*
* Set the inode cluster size. This may still be overridden by the file
* system block size if it is larger than the chosen cluster size.
*
* For v5 filesystems, scale the cluster size with the inode size to keep a
* constant ratio of inode per cluster buffer, but only if mkfs has set the
* inode alignment value appropriately for larger cluster sizes.
*
* Then compute the inode cluster alignment information.
*/
void
xfs_ialloc_setup_geometry(
struct xfs_mount *mp)
{
struct xfs_sb *sbp = &mp->m_sb;
struct xfs_ino_geometry *igeo = M_IGEO(mp);
uint64_t icount;
uint inodes;
igeo->new_diflags2 = 0;
if (xfs_has_bigtime(mp))
igeo->new_diflags2 |= XFS_DIFLAG2_BIGTIME;
if (xfs_has_large_extent_counts(mp))
igeo->new_diflags2 |= XFS_DIFLAG2_NREXT64;
/* Compute inode btree geometry. */
igeo->agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
igeo->inobt_mxr[0] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, true);
igeo->inobt_mxr[1] = xfs_inobt_maxrecs(mp, sbp->sb_blocksize, false);
igeo->inobt_mnr[0] = igeo->inobt_mxr[0] / 2;
igeo->inobt_mnr[1] = igeo->inobt_mxr[1] / 2;
igeo->ialloc_inos = max_t(uint16_t, XFS_INODES_PER_CHUNK,
sbp->sb_inopblock);
igeo->ialloc_blks = igeo->ialloc_inos >> sbp->sb_inopblog;
if (sbp->sb_spino_align)
igeo->ialloc_min_blks = sbp->sb_spino_align;
else
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_ialloc_count_inodes`, `function xfs_inobt_btrec_to_irec`, `function xfs_inobt_rec_freecount`, `function xfs_inobt_check_irec`, `function xfs_inobt_complain_bad_rec`, `function xfs_inobt_get_rec`, `function xfs_inobt_insert_rec`, `function xfs_inobt_insert`, `function xfs_check_agi_freecount`, `function them`.
- 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.