fs/xfs/scrub/rmap_repair.c

Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rmap_repair.c

File Facts

System
Linux kernel
Corpus path
fs/xfs/scrub/rmap_repair.c
Extension
.c
Size
46947 bytes
Lines
1735
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xrep_rmap {
	/* new rmapbt information */
	struct xrep_newbt	new_btree;

	/* lock for the xfbtree and xfile */
	struct mutex		lock;

	/* rmap records generated from primary metadata */
	struct xfbtree		rmap_btree;

	struct xfs_scrub	*sc;

	/* in-memory btree cursor for the xfs_btree_bload iteration */
	struct xfs_btree_cur	*mcur;

	/* Hooks into rmap update code. */
	struct xfs_rmap_hook	rhook;

	/* inode scan cursor */
	struct xchk_iscan	iscan;

	/* Number of non-freespace records found. */
	unsigned long long	nr_records;

	/* bnobt/cntbt contribution to btreeblks */
	xfs_agblock_t		freesp_btblocks;

	/* old agf_rmap_blocks counter */
	unsigned int		old_rmapbt_fsbcount;
};

/* Set us up to repair reverse mapping btrees. */
int
xrep_setup_ag_rmapbt(
	struct xfs_scrub	*sc)
{
	struct xrep_rmap	*rr;
	int			error;

	xchk_fsgates_enable(sc, XCHK_FSGATES_RMAP);

	error = xrep_setup_xfbtree(sc, "reverse mapping records");
	if (error)
		return error;

	rr = kzalloc_obj(struct xrep_rmap, XCHK_GFP_FLAGS);
	if (!rr)
		return -ENOMEM;

	rr->sc = sc;
	sc->buf = rr;
	return 0;
}

/* Make sure there's nothing funny about this mapping. */
STATIC int
xrep_rmap_check_mapping(
	struct xfs_scrub	*sc,
	const struct xfs_rmap_irec *rec)
{
	enum xbtree_recpacking	outcome;
	int			error;

	if (xfs_rmap_check_irec(sc->sa.pag, rec) != NULL)
		return -EFSCORRUPTED;

	/* Make sure this isn't free space. */
	error = xfs_alloc_has_records(sc->sa.bno_cur, rec->rm_startblock,
			rec->rm_blockcount, &outcome);
	if (error)
		return error;
	if (outcome != XBTREE_RECPACKING_EMPTY)
		return -EFSCORRUPTED;

	return 0;
}

/* Store a reverse-mapping record. */
static inline int
xrep_rmap_stash(
	struct xrep_rmap	*rr,
	xfs_agblock_t		startblock,
	xfs_extlen_t		blockcount,
	uint64_t		owner,
	uint64_t		offset,
	unsigned int		flags)
{
	struct xfs_rmap_irec	rmap = {
		.rm_startblock	= startblock,
		.rm_blockcount	= blockcount,

Annotation

Implementation Notes