fs/xfs/scrub/rmap.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/rmap.c- Extension
.c- Size
- 16951 bytes
- Lines
- 649
- 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_btree.hxfs_rmap.hxfs_refcount.hxfs_ag.hxfs_bit.hxfs_alloc.hxfs_alloc_btree.hxfs_ialloc_btree.hxfs_refcount_btree.hscrub/scrub.hscrub/common.hscrub/btree.hscrub/bitmap.hscrub/agb_bitmap.hscrub/repair.h
Detected Declarations
struct xchk_rmapfunction Copyrightfunction xchk_rmapbt_xref_refcfunction xchk_rmapbt_xreffunction xchk_rmapbt_check_unwritten_in_keyflagsfunction xchk_rmapbt_is_shareablefunction xchk_rmapbt_check_overlappingfunction xchk_rmap_mergeablefunction xchk_rmapbt_check_mergeablefunction xchk_rmapbt_mark_bitmapfunction xchk_rmapbt_recfunction xchk_rmapbt_walk_agflfunction xchk_rmapbt_walk_ag_metadatafunction xchk_rmapbt_check_bitmapsfunction xchk_rmapbtfunction xchk_xref_is_only_owned_byfunction xchk_xref_is_not_owned_byfunction xchk_xref_has_no_owner
Annotated Snippet
struct xchk_rmap {
/*
* 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;
/* Bitmaps containing all blocks for each type of AG metadata. */
struct xagb_bitmap fs_owned;
struct xagb_bitmap log_owned;
struct xagb_bitmap ag_owned;
struct xagb_bitmap inobt_owned;
struct xagb_bitmap refcbt_owned;
/* Did we complete the AG space metadata bitmaps? */
bool bitmaps_complete;
};
/* Cross-reference a rmap against the refcount btree. */
STATIC void
xchk_rmapbt_xref_refc(
struct xfs_scrub *sc,
struct xfs_rmap_irec *irec)
{
xfs_agblock_t fbno;
xfs_extlen_t flen;
bool non_inode;
bool is_bmbt;
bool is_attr;
bool is_unwritten;
int error;
if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm))
return;
non_inode = XFS_RMAP_NON_INODE_OWNER(irec->rm_owner);
is_bmbt = irec->rm_flags & XFS_RMAP_BMBT_BLOCK;
is_attr = irec->rm_flags & XFS_RMAP_ATTR_FORK;
is_unwritten = irec->rm_flags & XFS_RMAP_UNWRITTEN;
/* If this is shared, must be a data fork extent. */
error = xfs_refcount_find_shared(sc->sa.refc_cur, irec->rm_startblock,
irec->rm_blockcount, &fbno, &flen, false);
if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
return;
if (flen != 0 && (non_inode || is_attr || is_bmbt || is_unwritten))
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
}
/* Cross-reference with the other btrees. */
STATIC void
xchk_rmapbt_xref(
struct xfs_scrub *sc,
struct xfs_rmap_irec *irec)
{
xfs_agblock_t agbno = irec->rm_startblock;
xfs_extlen_t len = irec->rm_blockcount;
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
return;
xchk_xref_is_used_space(sc, agbno, len);
if (irec->rm_owner == XFS_RMAP_OWN_INODES)
xchk_xref_is_inode_chunk(sc, agbno, len);
else
xchk_xref_is_not_inode_chunk(sc, agbno, len);
if (irec->rm_owner == XFS_RMAP_OWN_COW)
xchk_xref_is_cow_staging(sc, irec->rm_startblock,
irec->rm_blockcount);
else
xchk_rmapbt_xref_refc(sc, irec);
}
/*
* Check for bogus UNWRITTEN flags in the rmapbt node block keys.
*
* In reverse mapping records, the file mapping extent state
* (XFS_RMAP_OFF_UNWRITTEN) is a record attribute, not a key field. It is not
* involved in lookups in any way. In older kernels, the functions that
* convert rmapbt records to keys forgot to filter out the extent state bit,
* even though the key comparison functions have filtered the flag correctly.
* If we spot an rmap key with the unwritten bit set in rm_offset, we should
* mark the btree as needing optimization to rebuild the btree without those
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_rmap`, `function Copyright`, `function xchk_rmapbt_xref_refc`, `function xchk_rmapbt_xref`, `function xchk_rmapbt_check_unwritten_in_keyflags`, `function xchk_rmapbt_is_shareable`, `function xchk_rmapbt_check_overlapping`, `function xchk_rmap_mergeable`, `function xchk_rmapbt_check_mergeable`, `function xchk_rmapbt_mark_bitmap`.
- 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.