fs/xfs/scrub/refcount_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/refcount_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/refcount_repair.c- Extension
.c- Size
- 19655 bytes
- Lines
- 742
- 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.
- 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_inode.hxfs_bit.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_alloc.hxfs_ialloc.hxfs_rmap.hxfs_rmap_btree.hxfs_refcount.hxfs_refcount_btree.hxfs_error.hxfs_ag.hxfs_health.hscrub/xfs_scrub.hscrub/scrub.hscrub/common.hscrub/btree.hscrub/trace.hscrub/repair.hscrub/bitmap.hscrub/agb_bitmap.hscrub/xfile.h
Detected Declarations
struct xrep_refcfunction xrep_setup_ag_refcountbtfunction xrep_refc_check_extfunction xrep_refc_stashfunction xrep_refc_stash_cowfunction xrep_refc_rmap_shareablefunction xrep_refc_walk_rmapsfunction xrep_refc_encode_startblockfunction xrep_refc_extent_cmpfunction xrep_refc_sort_recordsfunction foreach_xfarray_idxfunction xrep_refc_push_rmaps_atfunction xrep_refc_find_refcountsfunction xrep_refc_get_recordsfunction xrep_refc_claim_blockfunction xrep_refc_reset_countersfunction xrep_refc_build_new_treefunction xrep_refc_remove_old_treefunction xrep_refcountbt
Annotated Snippet
struct xrep_refc {
/* refcount extents */
struct xfarray *refcount_records;
/* new refcountbt information */
struct xrep_newbt new_btree;
/* old refcountbt blocks */
struct xagb_bitmap old_refcountbt_blocks;
struct xfs_scrub *sc;
/* get_records()'s position in the refcount record array. */
xfarray_idx_t array_cur;
/* # of refcountbt blocks */
xfs_extlen_t btblocks;
};
/* Set us up to repair refcount btrees. */
int
xrep_setup_ag_refcountbt(
struct xfs_scrub *sc)
{
return xrep_setup_xfbtree(sc, "rmap record bag");
}
/* Check for any obvious conflicts with this shared/CoW staging extent. */
STATIC int
xrep_refc_check_ext(
struct xfs_scrub *sc,
const struct xfs_refcount_irec *rec)
{
enum xbtree_recpacking outcome;
int error;
if (xfs_refcount_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->rc_startblock,
rec->rc_blockcount, &outcome);
if (error)
return error;
if (outcome != XBTREE_RECPACKING_EMPTY)
return -EFSCORRUPTED;
/* Must not be an inode chunk. */
error = xfs_ialloc_has_inodes_at_extent(sc->sa.ino_cur,
rec->rc_startblock, rec->rc_blockcount, &outcome);
if (error)
return error;
if (outcome != XBTREE_RECPACKING_EMPTY)
return -EFSCORRUPTED;
return 0;
}
/* Record a reference count extent. */
STATIC int
xrep_refc_stash(
struct xrep_refc *rr,
enum xfs_refc_domain domain,
xfs_agblock_t agbno,
xfs_extlen_t len,
uint64_t refcount)
{
struct xfs_refcount_irec irec = {
.rc_startblock = agbno,
.rc_blockcount = len,
.rc_domain = domain,
};
struct xfs_scrub *sc = rr->sc;
int error = 0;
if (xchk_should_terminate(sc, &error))
return error;
irec.rc_refcount = min_t(uint64_t, XFS_REFC_REFCOUNT_MAX, refcount);
error = xrep_refc_check_ext(rr->sc, &irec);
if (error)
return error;
trace_xrep_refc_found(pag_group(sc->sa.pag), &irec);
return xfarray_append(rr->refcount_records, &irec);
}
/* Record a CoW staging extent. */
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_refc`, `function xrep_setup_ag_refcountbt`, `function xrep_refc_check_ext`, `function xrep_refc_stash`, `function xrep_refc_stash_cow`, `function xrep_refc_rmap_shareable`, `function xrep_refc_walk_rmaps`, `function xrep_refc_encode_startblock`, `function xrep_refc_extent_cmp`, `function xrep_refc_sort_records`.
- 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.