fs/xfs/scrub/agheader_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/agheader_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/agheader_repair.c- Extension
.c- Size
- 46664 bytes
- Lines
- 1796
- 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_trans_resv.hxfs_mount.hxfs_btree.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_alloc.hxfs_alloc_btree.hxfs_ialloc.hxfs_ialloc_btree.hxfs_rmap.hxfs_rmap_btree.hxfs_refcount_btree.hxfs_ag.hxfs_inode.hxfs_iunlink_item.hscrub/scrub.hscrub/common.hscrub/trace.hscrub/repair.hscrub/bitmap.hscrub/agb_bitmap.hscrub/agino_bitmap.hscrub/reap.hscrub/xfile.hscrub/xfarray.h
Detected Declarations
struct xrep_agf_allocbtstruct xrep_agflstruct xrep_agfl_fillstruct xrep_agifunction Copyrightfunction xrep_agf_walk_allocbtfunction xrep_agf_check_agfl_blockfunction xrep_check_btree_rootfunction xrep_agf_find_btreesfunction xrep_agf_init_headerfunction xrep_agf_set_rootsfunction xrep_agf_calc_from_btreesfunction xrep_agf_commit_newfunction xrep_agffunction xrep_agfl_walk_rmapfunction xrep_agfl_check_extentfunction metadatafunction xrep_agfl_update_agffunction xrep_agfl_fillfunction xrep_agfl_init_headerfunction xrep_agflfunction xrep_agi_buf_cleanupfunction xrep_agi_find_btreesfunction xrep_agi_init_headerfunction xrep_agi_set_rootsfunction xrep_agi_calc_from_btreesfunction xrep_iunlink_store_nextfunction xrep_iunlink_store_prevfunction xrep_iunlink_nextfunction xrep_iunlink_reload_nextfunction xrep_iunlink_walk_ondisk_bucketfunction xrep_iunlink_igrabfunction xrep_iunlink_visitfunction xrep_iunlink_mark_incorefunction xrep_iunlink_mark_ondisk_recfunction xrep_iunlink_mark_ondiskfunction xrep_iunlink_resolve_bucketfunction xrep_iunlink_add_to_bucketfunction xrep_iunlink_add_lost_inodesfunction xrep_iunlink_rebuild_bucketsfunction xrep_iunlink_relink_nextfunction xrep_iunlink_relink_prevfunction xrep_iunlink_commitfunction xrep_agi_commit_newfunction xrep_agi
Annotated Snippet
struct xrep_agf_allocbt {
struct xfs_scrub *sc;
xfs_agblock_t freeblks;
xfs_agblock_t longest;
};
/* Record free space shape information. */
STATIC int
xrep_agf_walk_allocbt(
struct xfs_btree_cur *cur,
const struct xfs_alloc_rec_incore *rec,
void *priv)
{
struct xrep_agf_allocbt *raa = priv;
int error = 0;
if (xchk_should_terminate(raa->sc, &error))
return error;
raa->freeblks += rec->ar_blockcount;
if (rec->ar_blockcount > raa->longest)
raa->longest = rec->ar_blockcount;
return error;
}
/* Does this AGFL block look sane? */
STATIC int
xrep_agf_check_agfl_block(
struct xfs_mount *mp,
xfs_agblock_t agbno,
void *priv)
{
struct xfs_scrub *sc = priv;
if (!xfs_verify_agbno(sc->sa.pag, agbno))
return -EFSCORRUPTED;
return 0;
}
/*
* Offset within the xrep_find_ag_btree array for each btree type. Avoid the
* XFS_BTNUM_ names here to avoid creating a sparse array.
*/
enum {
XREP_AGF_BNOBT = 0,
XREP_AGF_CNTBT,
XREP_AGF_RMAPBT,
XREP_AGF_REFCOUNTBT,
XREP_AGF_END,
XREP_AGF_MAX
};
/* Check a btree root candidate. */
static inline bool
xrep_check_btree_root(
struct xfs_scrub *sc,
struct xrep_find_ag_btree *fab)
{
return xfs_verify_agbno(sc->sa.pag, fab->root) &&
fab->height <= fab->maxlevels;
}
/*
* Given the btree roots described by *fab, find the roots, check them for
* sanity, and pass the root data back out via *fab.
*
* This is /also/ a chicken and egg problem because we have to use the rmapbt
* (rooted in the AGF) to find the btrees rooted in the AGF. We also have no
* idea if the btrees make any sense. If we hit obvious corruptions in those
* btrees we'll bail out.
*/
STATIC int
xrep_agf_find_btrees(
struct xfs_scrub *sc,
struct xfs_buf *agf_bp,
struct xrep_find_ag_btree *fab,
struct xfs_buf *agfl_bp)
{
struct xfs_agf *old_agf = agf_bp->b_addr;
int error;
/* Go find the root data. */
error = xrep_find_ag_btree_roots(sc, agf_bp, fab, agfl_bp);
if (error)
return error;
/* We must find the bnobt, cntbt, and rmapbt roots. */
if (!xrep_check_btree_root(sc, &fab[XREP_AGF_BNOBT]) ||
!xrep_check_btree_root(sc, &fab[XREP_AGF_CNTBT]) ||
!xrep_check_btree_root(sc, &fab[XREP_AGF_RMAPBT]))
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_btree.h`, `xfs_log_format.h`.
- Detected declarations: `struct xrep_agf_allocbt`, `struct xrep_agfl`, `struct xrep_agfl_fill`, `struct xrep_agi`, `function Copyright`, `function xrep_agf_walk_allocbt`, `function xrep_agf_check_agfl_block`, `function xrep_check_btree_root`, `function xrep_agf_find_btrees`, `function xrep_agf_init_header`.
- 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.