fs/xfs/scrub/cow_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/cow_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/cow_repair.c- Extension
.c- Size
- 20605 bytes
- Lines
- 751
- 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_log_format.hxfs_trans.hxfs_inode.hxfs_inode_fork.hxfs_alloc.hxfs_bmap.hxfs_rmap.hxfs_refcount.hxfs_quota.hxfs_ialloc.hxfs_ag.hxfs_error.hxfs_errortag.hxfs_icache.hxfs_refcount_btree.hxfs_rtalloc.hxfs_rtbitmap.hxfs_rtgroup.hscrub/xfs_scrub.hscrub/scrub.hscrub/common.hscrub/trace.hscrub/repair.hscrub/bitmap.h
Detected Declarations
struct xrep_cowstruct xrep_cow_extentfunction xrep_cow_mark_file_rangefunction xrep_cow_trim_refcountfunction xrep_cow_mark_shared_stagingfunction xrep_cow_mark_missing_stagingfunction xrep_cow_mark_missing_staging_rmapfunction xrep_cow_find_badfunction xrep_cow_find_bad_rtfunction xrep_cow_allocfunction xrep_cow_alloc_rtfunction xrep_cow_find_mappingfunction xrep_cow_replace_mappingfunction xrep_cow_replace_rangefunction xrep_cow_replacefunction xrep_bmap_cowfunction for_each_xfs_iext
Annotated Snippet
struct xrep_cow {
struct xfs_scrub *sc;
/* Bitmap of file offset ranges that need replacing. */
struct xoff_bitmap bad_fileoffs;
/* Bitmap of fsblocks that were removed from the CoW fork. */
union {
struct xfsb_bitmap old_cowfork_fsblocks;
struct xrtb_bitmap old_cowfork_rtblocks;
};
/* CoW fork mappings used to scan for bad CoW staging extents. */
struct xfs_bmbt_irec irec;
/* refcount btree block number of irec.br_startblock */
unsigned int irec_startbno;
/* refcount btree block number of the next refcount record we expect */
unsigned int next_bno;
};
/* CoW staging extent. */
struct xrep_cow_extent {
xfs_fsblock_t fsbno;
xfs_extlen_t len;
};
/*
* Mark the part of the file range that corresponds to the given physical
* space. Caller must ensure that the physical range is within xc->irec.
*/
STATIC int
xrep_cow_mark_file_range(
struct xrep_cow *xc,
xfs_fsblock_t startblock,
xfs_filblks_t blockcount)
{
xfs_fileoff_t startoff;
startoff = xc->irec.br_startoff +
(startblock - xc->irec.br_startblock);
trace_xrep_cow_mark_file_range(xc->sc->ip, startblock, startoff,
blockcount);
return xoff_bitmap_set(&xc->bad_fileoffs, startoff, blockcount);
}
/*
* Trim @src to fit within the CoW fork mapping being examined, and put the
* result in @dst.
*/
static inline void
xrep_cow_trim_refcount(
struct xrep_cow *xc,
struct xfs_refcount_irec *dst,
const struct xfs_refcount_irec *src)
{
unsigned int adj;
memcpy(dst, src, sizeof(*dst));
if (dst->rc_startblock < xc->irec_startbno) {
adj = xc->irec_startbno - dst->rc_startblock;
dst->rc_blockcount -= adj;
dst->rc_startblock += adj;
}
if (dst->rc_startblock + dst->rc_blockcount >
xc->irec_startbno + xc->irec.br_blockcount) {
adj = (dst->rc_startblock + dst->rc_blockcount) -
(xc->irec_startbno + xc->irec.br_blockcount);
dst->rc_blockcount -= adj;
}
}
/* Mark any shared CoW staging extents. */
STATIC int
xrep_cow_mark_shared_staging(
struct xfs_btree_cur *cur,
const struct xfs_refcount_irec *rec,
void *priv)
{
struct xrep_cow *xc = priv;
struct xfs_refcount_irec rrec;
if (!xfs_refcount_check_domain(rec) ||
rec->rc_domain != XFS_REFC_DOMAIN_SHARED)
return -EFSCORRUPTED;
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_cow`, `struct xrep_cow_extent`, `function xrep_cow_mark_file_range`, `function xrep_cow_trim_refcount`, `function xrep_cow_mark_shared_staging`, `function xrep_cow_mark_missing_staging`, `function xrep_cow_mark_missing_staging_rmap`, `function xrep_cow_find_bad`, `function xrep_cow_find_bad_rt`, `function xrep_cow_alloc`.
- 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.