fs/xfs/scrub/refcount.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/refcount.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/refcount.c- Extension
.c- Size
- 17440 bytes
- Lines
- 633
- 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_log_format.hxfs_trans_resv.hxfs_mount.hxfs_trans.hxfs_ag.hxfs_btree.hxfs_rmap.hxfs_refcount.hscrub/scrub.hscrub/common.hscrub/btree.hscrub/trace.hscrub/repair.h
Detected Declarations
struct xchk_refcnt_fragstruct xchk_refcnt_checkstruct xchk_refcbt_recordsfunction Copyrightfunction xchk_refcountbt_rmap_checkfunction expectfunction list_for_each_entry_safefunction list_for_each_entry_safefunction xchk_refcountbt_xref_rmapfunction xchk_refcountbt_xreffunction xchk_refcountbt_rmap_check_gapfunction recordsfunction xchk_refcount_mergeablefunction xchk_refcountbt_check_mergeablefunction xchk_refcountbt_recfunction xchk_refcount_xref_rmapfunction xchk_refcountbtfunction xchk_xref_is_cow_stagingfunction xchk_xref_is_not_sharedfunction xchk_xref_is_not_cow_staging
Annotated Snippet
struct xchk_refcnt_frag {
struct list_head list;
struct xfs_rmap_irec rm;
};
struct xchk_refcnt_check {
struct xfs_scrub *sc;
struct list_head fragments;
/* refcount extent we're examining */
xfs_agblock_t bno;
xfs_extlen_t len;
xfs_nlink_t refcount;
/* number of owners seen */
xfs_nlink_t seen;
};
/*
* Decide if the given rmap is large enough that we can redeem it
* towards refcount verification now, or if it's a fragment, in
* which case we'll hang onto it in the hopes that we'll later
* discover that we've collected exactly the correct number of
* fragments as the refcountbt says we should have.
*/
STATIC int
xchk_refcountbt_rmap_check(
struct xfs_btree_cur *cur,
const struct xfs_rmap_irec *rec,
void *priv)
{
struct xchk_refcnt_check *refchk = priv;
struct xchk_refcnt_frag *frag;
xfs_agblock_t rm_last;
xfs_agblock_t rc_last;
int error = 0;
if (xchk_should_terminate(refchk->sc, &error))
return error;
rm_last = rec->rm_startblock + rec->rm_blockcount - 1;
rc_last = refchk->bno + refchk->len - 1;
/* Confirm that a single-owner refc extent is a CoW stage. */
if (refchk->refcount == 1 && rec->rm_owner != XFS_RMAP_OWN_COW) {
xchk_btree_xref_set_corrupt(refchk->sc, cur, 0);
return 0;
}
if (rec->rm_startblock <= refchk->bno && rm_last >= rc_last) {
/*
* The rmap overlaps the refcount record, so we can confirm
* one refcount owner seen.
*/
refchk->seen++;
} else {
/*
* This rmap covers only part of the refcount record, so
* save the fragment for later processing. If the rmapbt
* is healthy each rmap_irec we see will be in agbno order
* so we don't need insertion sort here.
*/
frag = kmalloc_obj(struct xchk_refcnt_frag, XCHK_GFP_FLAGS);
if (!frag)
return -ENOMEM;
memcpy(&frag->rm, rec, sizeof(frag->rm));
list_add_tail(&frag->list, &refchk->fragments);
}
return 0;
}
/*
* Given a bunch of rmap fragments, iterate through them, keeping
* a running tally of the refcount. If this ever deviates from
* what we expect (which is the refcountbt's refcount minus the
* number of extents that totally covered the refcountbt extent),
* we have a refcountbt error.
*/
STATIC void
xchk_refcountbt_process_rmap_fragments(
struct xchk_refcnt_check *refchk)
{
struct list_head worklist;
struct xchk_refcnt_frag *frag;
struct xchk_refcnt_frag *n;
xfs_agblock_t bno;
xfs_agblock_t rbno;
xfs_agblock_t next_rbno;
xfs_nlink_t nr;
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_mount.h`, `xfs_trans.h`.
- Detected declarations: `struct xchk_refcnt_frag`, `struct xchk_refcnt_check`, `struct xchk_refcbt_records`, `function Copyright`, `function xchk_refcountbt_rmap_check`, `function expect`, `function list_for_each_entry_safe`, `function list_for_each_entry_safe`, `function xchk_refcountbt_xref_rmap`, `function xchk_refcountbt_xref`.
- 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.