fs/xfs/scrub/rmap_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rmap_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/rmap_repair.c- Extension
.c- Size
- 46947 bytes
- Lines
- 1735
- 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_defer.hxfs_btree.hxfs_btree_staging.hxfs_buf_mem.hxfs_btree_mem.hxfs_bit.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_alloc.hxfs_alloc_btree.hxfs_ialloc.hxfs_ialloc_btree.hxfs_rmap.hxfs_rmap_btree.hxfs_inode.hxfs_icache.hxfs_bmap.hxfs_bmap_btree.hxfs_refcount.hxfs_refcount_btree.hxfs_ag.hxfs_rtrmap_btree.hxfs_rtgroup.hxfs_rtrefcount_btree.hscrub/xfs_scrub.h
Detected Declarations
struct xrep_rmapstruct xrep_rmap_stash_runstruct xrep_rmap_iforkstruct xrep_rmap_inodesstruct xrep_rmap_agflstruct xrep_rmap_find_gapsfunction xrep_setup_ag_rmapbtfunction xrep_rmap_check_mappingfunction xrep_rmap_stashfunction xrep_rmap_stash_runfunction xrep_rmap_stash_bitmapfunction xrep_rmap_stash_accumulatedfunction xrep_rmap_visit_bmbtfunction xrep_rmap_visit_iroot_btree_blockfunction xrep_rmap_scan_iroot_btreefunction xrep_rmap_scan_bmbtfunction xrep_rmap_scan_iextfunction for_each_xfs_iextfunction xrep_rmap_scan_meta_btreefunction xrep_rmap_scan_iforkfunction xrep_rmap_scan_ilockfunction xrep_rmap_scan_inodefunction xrep_rmap_walk_inobtfunction xrep_rmap_find_inode_rmapsfunction xrep_rmap_walk_cowblocksfunction xrep_rmap_find_refcount_rmapsfunction xrep_rmap_find_agheader_rmapsfunction xrep_rmap_find_log_rmapsfunction xrep_rmap_check_recordfunction xrep_rmap_find_rmapsfunction xrep_rmap_walk_agflfunction xrep_rmap_try_reservefunction xrep_rmap_reserve_spacefunction xrep_rmap_reset_countersfunction xrep_rmap_get_recordsfunction xrep_rmap_claim_blockfunction xrep_rmap_alloc_vextentfunction xrep_rmap_count_recordsfunction xrep_rmap_build_new_treefunction xrep_rmap_find_freespfunction xrep_rmap_find_gapsfunction xrep_rmap_remove_old_treefunction xrep_rmapbt_want_live_updatefunction xrep_rmapbt_live_updatefunction xrep_rmap_setup_scanfunction xrep_rmap_teardownfunction xrep_rmapbt
Annotated Snippet
struct xrep_rmap {
/* new rmapbt information */
struct xrep_newbt new_btree;
/* lock for the xfbtree and xfile */
struct mutex lock;
/* rmap records generated from primary metadata */
struct xfbtree rmap_btree;
struct xfs_scrub *sc;
/* in-memory btree cursor for the xfs_btree_bload iteration */
struct xfs_btree_cur *mcur;
/* Hooks into rmap update code. */
struct xfs_rmap_hook rhook;
/* inode scan cursor */
struct xchk_iscan iscan;
/* Number of non-freespace records found. */
unsigned long long nr_records;
/* bnobt/cntbt contribution to btreeblks */
xfs_agblock_t freesp_btblocks;
/* old agf_rmap_blocks counter */
unsigned int old_rmapbt_fsbcount;
};
/* Set us up to repair reverse mapping btrees. */
int
xrep_setup_ag_rmapbt(
struct xfs_scrub *sc)
{
struct xrep_rmap *rr;
int error;
xchk_fsgates_enable(sc, XCHK_FSGATES_RMAP);
error = xrep_setup_xfbtree(sc, "reverse mapping records");
if (error)
return error;
rr = kzalloc_obj(struct xrep_rmap, XCHK_GFP_FLAGS);
if (!rr)
return -ENOMEM;
rr->sc = sc;
sc->buf = rr;
return 0;
}
/* Make sure there's nothing funny about this mapping. */
STATIC int
xrep_rmap_check_mapping(
struct xfs_scrub *sc,
const struct xfs_rmap_irec *rec)
{
enum xbtree_recpacking outcome;
int error;
if (xfs_rmap_check_irec(sc->sa.pag, rec) != NULL)
return -EFSCORRUPTED;
/* Make sure this isn't free space. */
error = xfs_alloc_has_records(sc->sa.bno_cur, rec->rm_startblock,
rec->rm_blockcount, &outcome);
if (error)
return error;
if (outcome != XBTREE_RECPACKING_EMPTY)
return -EFSCORRUPTED;
return 0;
}
/* Store a reverse-mapping record. */
static inline int
xrep_rmap_stash(
struct xrep_rmap *rr,
xfs_agblock_t startblock,
xfs_extlen_t blockcount,
uint64_t owner,
uint64_t offset,
unsigned int flags)
{
struct xfs_rmap_irec rmap = {
.rm_startblock = startblock,
.rm_blockcount = blockcount,
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_defer.h`, `xfs_btree.h`.
- Detected declarations: `struct xrep_rmap`, `struct xrep_rmap_stash_run`, `struct xrep_rmap_ifork`, `struct xrep_rmap_inodes`, `struct xrep_rmap_agfl`, `struct xrep_rmap_find_gaps`, `function xrep_setup_ag_rmapbt`, `function xrep_rmap_check_mapping`, `function xrep_rmap_stash`, `function xrep_rmap_stash_run`.
- 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.