fs/xfs/scrub/fscounters.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/fscounters.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/fscounters.c- Extension
.c- Size
- 17133 bytes
- Lines
- 622
- 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_log_format.hxfs_trans.hxfs_mount.hxfs_alloc.hxfs_ialloc.hxfs_health.hxfs_btree.hxfs_ag.hxfs_rtbitmap.hxfs_inode.hxfs_icache.hxfs_rtgroup.hscrub/scrub.hscrub/common.hscrub/trace.hscrub/fscounters.h
Detected Declarations
function Copyrightfunction xchk_fsfreezefunction xchk_fsthawfunction xchk_fscounters_freezefunction xchk_fscounters_cleanupfunction xchk_setup_fscountersfunction countsfunction xchk_fscount_aggregate_agcountsfunction xchk_fscount_add_frextentfunction xchk_fscount_count_frextentsfunction xchk_fscount_count_frextentsfunction xchk_fscount_within_rangefunction xchk_fscounters
Annotated Snippet
if (xfs_has_lazysbcount(sc->mp)) {
fsc->fdblocks += pag->pagf_btreeblks;
} else {
error = xchk_fscount_btreeblks(sc, fsc, pag_agno(pag));
if (error)
break;
}
/*
* Per-AG reservations are taken out of the incore counters,
* so they must be left out of the free blocks computation.
*/
fsc->fdblocks -= pag->pag_meta_resv.ar_reserved;
fsc->fdblocks -= pag->pag_rmapbt_resv.ar_orig_reserved;
}
if (pag)
xfs_perag_rele(pag);
if (error) {
xchk_set_incomplete(sc);
return error;
}
/*
* The global incore space reservation is taken from the incore
* counters, so leave that out of the computation.
*/
fsc->fdblocks -= mp->m_free[XC_FREE_BLOCKS].res_avail;
/*
* Delayed allocation reservations are taken out of the incore counters
* but not recorded on disk, so leave them and their indlen blocks out
* of the computation.
*/
delayed = percpu_counter_sum(&mp->m_delalloc_blks);
fsc->fdblocks -= delayed;
trace_xchk_fscounters_calc(mp, fsc->icount, fsc->ifree, fsc->fdblocks,
delayed);
/* Bail out if the values we compute are totally nonsense. */
if (fsc->icount < fsc->icount_min || fsc->icount > fsc->icount_max ||
fsc->fdblocks > mp->m_sb.sb_dblocks ||
fsc->ifree > fsc->icount_max)
return -EFSCORRUPTED;
/*
* If ifree > icount then we probably had some perturbation in the
* counters while we were calculating things. We'll try a few times
* to maintain ifree <= icount before giving up.
*/
if (fsc->ifree > fsc->icount) {
if (tries--)
goto retry;
return -EDEADLOCK;
}
return 0;
}
#ifdef CONFIG_XFS_RT
STATIC int
xchk_fscount_add_frextent(
struct xfs_rtgroup *rtg,
struct xfs_trans *tp,
const struct xfs_rtalloc_rec *rec,
void *priv)
{
struct xchk_fscounters *fsc = priv;
int error = 0;
fsc->frextents += rec->ar_extcount;
xchk_should_terminate(fsc->sc, &error);
return error;
}
/* Calculate the number of free realtime extents from the realtime bitmap. */
STATIC int
xchk_fscount_count_frextents(
struct xfs_scrub *sc,
struct xchk_fscounters *fsc)
{
struct xfs_mount *mp = sc->mp;
struct xfs_rtgroup *rtg = NULL;
int error;
fsc->frextents = 0;
fsc->frextents_delayed = 0;
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_log_format.h`, `xfs_trans.h`, `xfs_mount.h`.
- Detected declarations: `function Copyright`, `function xchk_fsfreeze`, `function xchk_fsthaw`, `function xchk_fscounters_freeze`, `function xchk_fscounters_cleanup`, `function xchk_setup_fscounters`, `function counts`, `function xchk_fscount_aggregate_agcounts`, `function xchk_fscount_add_frextent`, `function xchk_fscount_count_frextents`.
- 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.