fs/xfs/scrub/rtrmap.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rtrmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/rtrmap.c- Extension
.c- Size
- 8191 bytes
- Lines
- 323
- 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.
- 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_bit.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_rmap.hxfs_rmap_btree.hxfs_rtrmap_btree.hxfs_inode.hxfs_rtalloc.hxfs_rtgroup.hxfs_metafile.hxfs_refcount.hscrub/xfs_scrub.hscrub/scrub.hscrub/common.hscrub/btree.hscrub/trace.hscrub/repair.h
Detected Declarations
struct xchk_rtrmapfunction Copyrightfunction xchk_rtrmapbt_is_shareablefunction xchk_rtrmapbt_check_overlappingfunction xchk_rtrmap_mergeablefunction xchk_rtrmapbt_check_mergeablefunction xchk_rtrmapbt_xref_rtrefcfunction xchk_rtrmapbt_xreffunction xchk_rtrmapbt_recfunction xchk_rtrmapbtfunction xchk_xref_has_no_rt_ownerfunction xchk_xref_has_rt_ownerfunction xchk_xref_is_only_rt_owned_by
Annotated Snippet
struct xchk_rtrmap {
/*
* The furthest-reaching of the rmapbt records that we've already
* processed. This enables us to detect overlapping records for space
* allocations that cannot be shared.
*/
struct xfs_rmap_irec overlap_rec;
/*
* The previous rmapbt record, so that we can check for two records
* that could be one.
*/
struct xfs_rmap_irec prev_rec;
};
static inline bool
xchk_rtrmapbt_is_shareable(
struct xfs_scrub *sc,
const struct xfs_rmap_irec *irec)
{
if (!xfs_has_rtreflink(sc->mp))
return false;
if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
return false;
return true;
}
/* Flag failures for records that overlap but cannot. */
STATIC void
xchk_rtrmapbt_check_overlapping(
struct xchk_btree *bs,
struct xchk_rtrmap *cr,
const struct xfs_rmap_irec *irec)
{
xfs_rtblock_t pnext, inext;
if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
return;
/* No previous record? */
if (cr->overlap_rec.rm_blockcount == 0)
goto set_prev;
/* Do overlap_rec and irec overlap? */
pnext = cr->overlap_rec.rm_startblock + cr->overlap_rec.rm_blockcount;
if (pnext <= irec->rm_startblock)
goto set_prev;
/* Overlap is only allowed if both records are data fork mappings. */
if (!xchk_rtrmapbt_is_shareable(bs->sc, &cr->overlap_rec) ||
!xchk_rtrmapbt_is_shareable(bs->sc, irec))
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
/* Save whichever rmap record extends furthest. */
inext = irec->rm_startblock + irec->rm_blockcount;
if (pnext > inext)
return;
set_prev:
memcpy(&cr->overlap_rec, irec, sizeof(struct xfs_rmap_irec));
}
/* Decide if two reverse-mapping records can be merged. */
static inline bool
xchk_rtrmap_mergeable(
struct xchk_rtrmap *cr,
const struct xfs_rmap_irec *r2)
{
const struct xfs_rmap_irec *r1 = &cr->prev_rec;
/* Ignore if prev_rec is not yet initialized. */
if (cr->prev_rec.rm_blockcount == 0)
return false;
if (r1->rm_owner != r2->rm_owner)
return false;
if (r1->rm_startblock + r1->rm_blockcount != r2->rm_startblock)
return false;
if ((unsigned long long)r1->rm_blockcount + r2->rm_blockcount >
XFS_RMAP_LEN_MAX)
return false;
if (r1->rm_flags != r2->rm_flags)
return false;
return r1->rm_offset + r1->rm_blockcount == r2->rm_offset;
}
/* Flag failures for records that could be merged. */
STATIC void
xchk_rtrmapbt_check_mergeable(
struct xchk_btree *bs,
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 xchk_rtrmap`, `function Copyright`, `function xchk_rtrmapbt_is_shareable`, `function xchk_rtrmapbt_check_overlapping`, `function xchk_rtrmap_mergeable`, `function xchk_rtrmapbt_check_mergeable`, `function xchk_rtrmapbt_xref_rtrefc`, `function xchk_rtrmapbt_xref`, `function xchk_rtrmapbt_rec`, `function xchk_rtrmapbt`.
- 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.