xref: /linux/fs/xfs/scrub/rtrmap.c (revision b477ff98d903618a1ab8247861f2ea6e70c0f0f8)
19a6cc4f6SDarrick J. Wong // SPDX-License-Identifier: GPL-2.0-or-later
29a6cc4f6SDarrick J. Wong /*
39a6cc4f6SDarrick J. Wong  * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
49a6cc4f6SDarrick J. Wong  * Author: Darrick J. Wong <djwong@kernel.org>
59a6cc4f6SDarrick J. Wong  */
69a6cc4f6SDarrick J. Wong #include "xfs.h"
79a6cc4f6SDarrick J. Wong #include "xfs_fs.h"
89a6cc4f6SDarrick J. Wong #include "xfs_shared.h"
99a6cc4f6SDarrick J. Wong #include "xfs_format.h"
109a6cc4f6SDarrick J. Wong #include "xfs_trans_resv.h"
119a6cc4f6SDarrick J. Wong #include "xfs_mount.h"
129a6cc4f6SDarrick J. Wong #include "xfs_defer.h"
139a6cc4f6SDarrick J. Wong #include "xfs_btree.h"
149a6cc4f6SDarrick J. Wong #include "xfs_bit.h"
159a6cc4f6SDarrick J. Wong #include "xfs_log_format.h"
169a6cc4f6SDarrick J. Wong #include "xfs_trans.h"
179a6cc4f6SDarrick J. Wong #include "xfs_sb.h"
189a6cc4f6SDarrick J. Wong #include "xfs_rmap.h"
199a6cc4f6SDarrick J. Wong #include "xfs_rmap_btree.h"
209a6cc4f6SDarrick J. Wong #include "xfs_rtrmap_btree.h"
219a6cc4f6SDarrick J. Wong #include "xfs_inode.h"
229a6cc4f6SDarrick J. Wong #include "xfs_rtalloc.h"
239a6cc4f6SDarrick J. Wong #include "xfs_rtgroup.h"
249a6cc4f6SDarrick J. Wong #include "xfs_metafile.h"
2591683bb3SDarrick J. Wong #include "xfs_refcount.h"
269a6cc4f6SDarrick J. Wong #include "scrub/xfs_scrub.h"
279a6cc4f6SDarrick J. Wong #include "scrub/scrub.h"
289a6cc4f6SDarrick J. Wong #include "scrub/common.h"
299a6cc4f6SDarrick J. Wong #include "scrub/btree.h"
309a6cc4f6SDarrick J. Wong #include "scrub/trace.h"
316a849bd8SDarrick J. Wong #include "scrub/repair.h"
329a6cc4f6SDarrick J. Wong 
339a6cc4f6SDarrick J. Wong /* Set us up with the realtime metadata locked. */
349a6cc4f6SDarrick J. Wong int
xchk_setup_rtrmapbt(struct xfs_scrub * sc)359a6cc4f6SDarrick J. Wong xchk_setup_rtrmapbt(
369a6cc4f6SDarrick J. Wong 	struct xfs_scrub	*sc)
379a6cc4f6SDarrick J. Wong {
389a6cc4f6SDarrick J. Wong 	int			error;
399a6cc4f6SDarrick J. Wong 
409a6cc4f6SDarrick J. Wong 	if (xchk_need_intent_drain(sc))
419a6cc4f6SDarrick J. Wong 		xchk_fsgates_enable(sc, XCHK_FSGATES_DRAIN);
429a6cc4f6SDarrick J. Wong 
436a849bd8SDarrick J. Wong 	if (xchk_could_repair(sc)) {
446a849bd8SDarrick J. Wong 		error = xrep_setup_rtrmapbt(sc);
456a849bd8SDarrick J. Wong 		if (error)
466a849bd8SDarrick J. Wong 			return error;
476a849bd8SDarrick J. Wong 	}
486a849bd8SDarrick J. Wong 
499a6cc4f6SDarrick J. Wong 	error = xchk_rtgroup_init(sc, sc->sm->sm_agno, &sc->sr);
509a6cc4f6SDarrick J. Wong 	if (error)
519a6cc4f6SDarrick J. Wong 		return error;
529a6cc4f6SDarrick J. Wong 
539a6cc4f6SDarrick J. Wong 	error = xchk_setup_rt(sc);
549a6cc4f6SDarrick J. Wong 	if (error)
559a6cc4f6SDarrick J. Wong 		return error;
569a6cc4f6SDarrick J. Wong 
579a6cc4f6SDarrick J. Wong 	error = xchk_install_live_inode(sc, rtg_rmap(sc->sr.rtg));
589a6cc4f6SDarrick J. Wong 	if (error)
599a6cc4f6SDarrick J. Wong 		return error;
609a6cc4f6SDarrick J. Wong 
619a6cc4f6SDarrick J. Wong 	return xchk_rtgroup_lock(sc, &sc->sr, XCHK_RTGLOCK_ALL);
629a6cc4f6SDarrick J. Wong }
639a6cc4f6SDarrick J. Wong 
649a6cc4f6SDarrick J. Wong /* Realtime reverse mapping. */
659a6cc4f6SDarrick J. Wong 
669a6cc4f6SDarrick J. Wong struct xchk_rtrmap {
679a6cc4f6SDarrick J. Wong 	/*
689a6cc4f6SDarrick J. Wong 	 * The furthest-reaching of the rmapbt records that we've already
699a6cc4f6SDarrick J. Wong 	 * processed.  This enables us to detect overlapping records for space
709a6cc4f6SDarrick J. Wong 	 * allocations that cannot be shared.
719a6cc4f6SDarrick J. Wong 	 */
729a6cc4f6SDarrick J. Wong 	struct xfs_rmap_irec	overlap_rec;
739a6cc4f6SDarrick J. Wong 
749a6cc4f6SDarrick J. Wong 	/*
759a6cc4f6SDarrick J. Wong 	 * The previous rmapbt record, so that we can check for two records
769a6cc4f6SDarrick J. Wong 	 * that could be one.
779a6cc4f6SDarrick J. Wong 	 */
789a6cc4f6SDarrick J. Wong 	struct xfs_rmap_irec	prev_rec;
799a6cc4f6SDarrick J. Wong };
809a6cc4f6SDarrick J. Wong 
81*2d9a3e98SDarrick J. Wong static inline bool
xchk_rtrmapbt_is_shareable(struct xfs_scrub * sc,const struct xfs_rmap_irec * irec)82*2d9a3e98SDarrick J. Wong xchk_rtrmapbt_is_shareable(
83*2d9a3e98SDarrick J. Wong 	struct xfs_scrub		*sc,
84*2d9a3e98SDarrick J. Wong 	const struct xfs_rmap_irec	*irec)
85*2d9a3e98SDarrick J. Wong {
86*2d9a3e98SDarrick J. Wong 	if (!xfs_has_rtreflink(sc->mp))
87*2d9a3e98SDarrick J. Wong 		return false;
88*2d9a3e98SDarrick J. Wong 	if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
89*2d9a3e98SDarrick J. Wong 		return false;
90*2d9a3e98SDarrick J. Wong 	return true;
91*2d9a3e98SDarrick J. Wong }
92*2d9a3e98SDarrick J. Wong 
939a6cc4f6SDarrick J. Wong /* Flag failures for records that overlap but cannot. */
949a6cc4f6SDarrick J. Wong STATIC void
xchk_rtrmapbt_check_overlapping(struct xchk_btree * bs,struct xchk_rtrmap * cr,const struct xfs_rmap_irec * irec)959a6cc4f6SDarrick J. Wong xchk_rtrmapbt_check_overlapping(
969a6cc4f6SDarrick J. Wong 	struct xchk_btree		*bs,
979a6cc4f6SDarrick J. Wong 	struct xchk_rtrmap		*cr,
989a6cc4f6SDarrick J. Wong 	const struct xfs_rmap_irec	*irec)
999a6cc4f6SDarrick J. Wong {
1009a6cc4f6SDarrick J. Wong 	xfs_rtblock_t			pnext, inext;
1019a6cc4f6SDarrick J. Wong 
1029a6cc4f6SDarrick J. Wong 	if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
1039a6cc4f6SDarrick J. Wong 		return;
1049a6cc4f6SDarrick J. Wong 
1059a6cc4f6SDarrick J. Wong 	/* No previous record? */
1069a6cc4f6SDarrick J. Wong 	if (cr->overlap_rec.rm_blockcount == 0)
1079a6cc4f6SDarrick J. Wong 		goto set_prev;
1089a6cc4f6SDarrick J. Wong 
1099a6cc4f6SDarrick J. Wong 	/* Do overlap_rec and irec overlap? */
1109a6cc4f6SDarrick J. Wong 	pnext = cr->overlap_rec.rm_startblock + cr->overlap_rec.rm_blockcount;
1119a6cc4f6SDarrick J. Wong 	if (pnext <= irec->rm_startblock)
1129a6cc4f6SDarrick J. Wong 		goto set_prev;
1139a6cc4f6SDarrick J. Wong 
114*2d9a3e98SDarrick J. Wong 	/* Overlap is only allowed if both records are data fork mappings. */
115*2d9a3e98SDarrick J. Wong 	if (!xchk_rtrmapbt_is_shareable(bs->sc, &cr->overlap_rec) ||
116*2d9a3e98SDarrick J. Wong 	    !xchk_rtrmapbt_is_shareable(bs->sc, irec))
1179a6cc4f6SDarrick J. Wong 		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
1189a6cc4f6SDarrick J. Wong 
1199a6cc4f6SDarrick J. Wong 	/* Save whichever rmap record extends furthest. */
1209a6cc4f6SDarrick J. Wong 	inext = irec->rm_startblock + irec->rm_blockcount;
1219a6cc4f6SDarrick J. Wong 	if (pnext > inext)
1229a6cc4f6SDarrick J. Wong 		return;
1239a6cc4f6SDarrick J. Wong 
1249a6cc4f6SDarrick J. Wong set_prev:
1259a6cc4f6SDarrick J. Wong 	memcpy(&cr->overlap_rec, irec, sizeof(struct xfs_rmap_irec));
1269a6cc4f6SDarrick J. Wong }
1279a6cc4f6SDarrick J. Wong 
1289a6cc4f6SDarrick J. Wong /* Decide if two reverse-mapping records can be merged. */
1299a6cc4f6SDarrick J. Wong static inline bool
xchk_rtrmap_mergeable(struct xchk_rtrmap * cr,const struct xfs_rmap_irec * r2)1309a6cc4f6SDarrick J. Wong xchk_rtrmap_mergeable(
1319a6cc4f6SDarrick J. Wong 	struct xchk_rtrmap		*cr,
1329a6cc4f6SDarrick J. Wong 	const struct xfs_rmap_irec	*r2)
1339a6cc4f6SDarrick J. Wong {
1349a6cc4f6SDarrick J. Wong 	const struct xfs_rmap_irec	*r1 = &cr->prev_rec;
1359a6cc4f6SDarrick J. Wong 
1369a6cc4f6SDarrick J. Wong 	/* Ignore if prev_rec is not yet initialized. */
1379a6cc4f6SDarrick J. Wong 	if (cr->prev_rec.rm_blockcount == 0)
1389a6cc4f6SDarrick J. Wong 		return false;
1399a6cc4f6SDarrick J. Wong 
1409a6cc4f6SDarrick J. Wong 	if (r1->rm_owner != r2->rm_owner)
1419a6cc4f6SDarrick J. Wong 		return false;
1429a6cc4f6SDarrick J. Wong 	if (r1->rm_startblock + r1->rm_blockcount != r2->rm_startblock)
1439a6cc4f6SDarrick J. Wong 		return false;
1449a6cc4f6SDarrick J. Wong 	if ((unsigned long long)r1->rm_blockcount + r2->rm_blockcount >
1459a6cc4f6SDarrick J. Wong 	    XFS_RMAP_LEN_MAX)
1469a6cc4f6SDarrick J. Wong 		return false;
1479a6cc4f6SDarrick J. Wong 	if (r1->rm_flags != r2->rm_flags)
1489a6cc4f6SDarrick J. Wong 		return false;
1499a6cc4f6SDarrick J. Wong 	return r1->rm_offset + r1->rm_blockcount == r2->rm_offset;
1509a6cc4f6SDarrick J. Wong }
1519a6cc4f6SDarrick J. Wong 
1529a6cc4f6SDarrick J. Wong /* Flag failures for records that could be merged. */
1539a6cc4f6SDarrick J. Wong STATIC void
xchk_rtrmapbt_check_mergeable(struct xchk_btree * bs,struct xchk_rtrmap * cr,const struct xfs_rmap_irec * irec)1549a6cc4f6SDarrick J. Wong xchk_rtrmapbt_check_mergeable(
1559a6cc4f6SDarrick J. Wong 	struct xchk_btree		*bs,
1569a6cc4f6SDarrick J. Wong 	struct xchk_rtrmap		*cr,
1579a6cc4f6SDarrick J. Wong 	const struct xfs_rmap_irec	*irec)
1589a6cc4f6SDarrick J. Wong {
1599a6cc4f6SDarrick J. Wong 	if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
1609a6cc4f6SDarrick J. Wong 		return;
1619a6cc4f6SDarrick J. Wong 
1629a6cc4f6SDarrick J. Wong 	if (xchk_rtrmap_mergeable(cr, irec))
1639a6cc4f6SDarrick J. Wong 		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
1649a6cc4f6SDarrick J. Wong 
1659a6cc4f6SDarrick J. Wong 	memcpy(&cr->prev_rec, irec, sizeof(struct xfs_rmap_irec));
1669a6cc4f6SDarrick J. Wong }
1679a6cc4f6SDarrick J. Wong 
16891683bb3SDarrick J. Wong /* Cross-reference a rmap against the refcount btree. */
16991683bb3SDarrick J. Wong STATIC void
xchk_rtrmapbt_xref_rtrefc(struct xfs_scrub * sc,struct xfs_rmap_irec * irec)17091683bb3SDarrick J. Wong xchk_rtrmapbt_xref_rtrefc(
17191683bb3SDarrick J. Wong 	struct xfs_scrub	*sc,
17291683bb3SDarrick J. Wong 	struct xfs_rmap_irec	*irec)
17391683bb3SDarrick J. Wong {
17491683bb3SDarrick J. Wong 	xfs_rgblock_t		fbno;
17591683bb3SDarrick J. Wong 	xfs_extlen_t		flen;
17691683bb3SDarrick J. Wong 	bool			is_inode;
17791683bb3SDarrick J. Wong 	bool			is_bmbt;
17891683bb3SDarrick J. Wong 	bool			is_attr;
17991683bb3SDarrick J. Wong 	bool			is_unwritten;
18091683bb3SDarrick J. Wong 	int			error;
18191683bb3SDarrick J. Wong 
18291683bb3SDarrick J. Wong 	if (!sc->sr.refc_cur || xchk_skip_xref(sc->sm))
18391683bb3SDarrick J. Wong 		return;
18491683bb3SDarrick J. Wong 
18591683bb3SDarrick J. Wong 	is_inode = !XFS_RMAP_NON_INODE_OWNER(irec->rm_owner);
18691683bb3SDarrick J. Wong 	is_bmbt = irec->rm_flags & XFS_RMAP_BMBT_BLOCK;
18791683bb3SDarrick J. Wong 	is_attr = irec->rm_flags & XFS_RMAP_ATTR_FORK;
18891683bb3SDarrick J. Wong 	is_unwritten = irec->rm_flags & XFS_RMAP_UNWRITTEN;
18991683bb3SDarrick J. Wong 
19091683bb3SDarrick J. Wong 	/* If this is shared, must be a data fork extent. */
19191683bb3SDarrick J. Wong 	error = xfs_refcount_find_shared(sc->sr.refc_cur, irec->rm_startblock,
19291683bb3SDarrick J. Wong 			irec->rm_blockcount, &fbno, &flen, false);
19391683bb3SDarrick J. Wong 	if (!xchk_should_check_xref(sc, &error, &sc->sr.refc_cur))
19491683bb3SDarrick J. Wong 		return;
19591683bb3SDarrick J. Wong 	if (flen != 0 && (!is_inode || is_attr || is_bmbt || is_unwritten))
19691683bb3SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.refc_cur, 0);
19791683bb3SDarrick J. Wong }
19891683bb3SDarrick J. Wong 
1991ebecab5SDarrick J. Wong /* Cross-reference with other metadata. */
2001ebecab5SDarrick J. Wong STATIC void
xchk_rtrmapbt_xref(struct xfs_scrub * sc,struct xfs_rmap_irec * irec)2011ebecab5SDarrick J. Wong xchk_rtrmapbt_xref(
2021ebecab5SDarrick J. Wong 	struct xfs_scrub	*sc,
2031ebecab5SDarrick J. Wong 	struct xfs_rmap_irec	*irec)
2041ebecab5SDarrick J. Wong {
2051ebecab5SDarrick J. Wong 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
2061ebecab5SDarrick J. Wong 		return;
2071ebecab5SDarrick J. Wong 
2081ebecab5SDarrick J. Wong 	xchk_xref_is_used_rt_space(sc,
2091ebecab5SDarrick J. Wong 			xfs_rgbno_to_rtb(sc->sr.rtg, irec->rm_startblock),
2101ebecab5SDarrick J. Wong 			irec->rm_blockcount);
21191683bb3SDarrick J. Wong 	if (irec->rm_owner == XFS_RMAP_OWN_COW)
21291683bb3SDarrick J. Wong 		xchk_xref_is_cow_staging(sc, irec->rm_startblock,
21391683bb3SDarrick J. Wong 				irec->rm_blockcount);
21491683bb3SDarrick J. Wong 	else
21591683bb3SDarrick J. Wong 		xchk_rtrmapbt_xref_rtrefc(sc, irec);
2161ebecab5SDarrick J. Wong }
2171ebecab5SDarrick J. Wong 
2189a6cc4f6SDarrick J. Wong /* Scrub a realtime rmapbt record. */
2199a6cc4f6SDarrick J. Wong STATIC int
xchk_rtrmapbt_rec(struct xchk_btree * bs,const union xfs_btree_rec * rec)2209a6cc4f6SDarrick J. Wong xchk_rtrmapbt_rec(
2219a6cc4f6SDarrick J. Wong 	struct xchk_btree		*bs,
2229a6cc4f6SDarrick J. Wong 	const union xfs_btree_rec	*rec)
2239a6cc4f6SDarrick J. Wong {
2249a6cc4f6SDarrick J. Wong 	struct xchk_rtrmap		*cr = bs->private;
2259a6cc4f6SDarrick J. Wong 	struct xfs_rmap_irec		irec;
2269a6cc4f6SDarrick J. Wong 
2279a6cc4f6SDarrick J. Wong 	if (xfs_rmap_btrec_to_irec(rec, &irec) != NULL ||
2289a6cc4f6SDarrick J. Wong 	    xfs_rtrmap_check_irec(to_rtg(bs->cur->bc_group), &irec) != NULL) {
2299a6cc4f6SDarrick J. Wong 		xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
2309a6cc4f6SDarrick J. Wong 		return 0;
2319a6cc4f6SDarrick J. Wong 	}
2329a6cc4f6SDarrick J. Wong 
2339a6cc4f6SDarrick J. Wong 	if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
2349a6cc4f6SDarrick J. Wong 		return 0;
2359a6cc4f6SDarrick J. Wong 
2369a6cc4f6SDarrick J. Wong 	xchk_rtrmapbt_check_mergeable(bs, cr, &irec);
2379a6cc4f6SDarrick J. Wong 	xchk_rtrmapbt_check_overlapping(bs, cr, &irec);
2381ebecab5SDarrick J. Wong 	xchk_rtrmapbt_xref(bs->sc, &irec);
2399a6cc4f6SDarrick J. Wong 	return 0;
2409a6cc4f6SDarrick J. Wong }
2419a6cc4f6SDarrick J. Wong 
2429a6cc4f6SDarrick J. Wong /* Scrub the realtime rmap btree. */
2439a6cc4f6SDarrick J. Wong int
xchk_rtrmapbt(struct xfs_scrub * sc)2449a6cc4f6SDarrick J. Wong xchk_rtrmapbt(
2459a6cc4f6SDarrick J. Wong 	struct xfs_scrub	*sc)
2469a6cc4f6SDarrick J. Wong {
2479a6cc4f6SDarrick J. Wong 	struct xfs_inode	*ip = rtg_rmap(sc->sr.rtg);
2489a6cc4f6SDarrick J. Wong 	struct xfs_owner_info	oinfo;
2499a6cc4f6SDarrick J. Wong 	struct xchk_rtrmap	cr = { };
2509a6cc4f6SDarrick J. Wong 	int			error;
2519a6cc4f6SDarrick J. Wong 
2529a6cc4f6SDarrick J. Wong 	error = xchk_metadata_inode_forks(sc);
2539a6cc4f6SDarrick J. Wong 	if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
2549a6cc4f6SDarrick J. Wong 		return error;
2559a6cc4f6SDarrick J. Wong 
2569a6cc4f6SDarrick J. Wong 	xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, XFS_DATA_FORK);
2579a6cc4f6SDarrick J. Wong 	return xchk_btree(sc, sc->sr.rmap_cur, xchk_rtrmapbt_rec, &oinfo, &cr);
2589a6cc4f6SDarrick J. Wong }
259037a44d8SDarrick J. Wong 
260037a44d8SDarrick J. Wong /* xref check that the extent has no realtime reverse mapping at all */
261037a44d8SDarrick J. Wong void
xchk_xref_has_no_rt_owner(struct xfs_scrub * sc,xfs_rgblock_t bno,xfs_extlen_t len)262037a44d8SDarrick J. Wong xchk_xref_has_no_rt_owner(
263037a44d8SDarrick J. Wong 	struct xfs_scrub	*sc,
264037a44d8SDarrick J. Wong 	xfs_rgblock_t		bno,
265037a44d8SDarrick J. Wong 	xfs_extlen_t		len)
266037a44d8SDarrick J. Wong {
267037a44d8SDarrick J. Wong 	enum xbtree_recpacking	outcome;
268037a44d8SDarrick J. Wong 	int			error;
269037a44d8SDarrick J. Wong 
270037a44d8SDarrick J. Wong 	if (!sc->sr.rmap_cur || xchk_skip_xref(sc->sm))
271037a44d8SDarrick J. Wong 		return;
272037a44d8SDarrick J. Wong 
273037a44d8SDarrick J. Wong 	error = xfs_rmap_has_records(sc->sr.rmap_cur, bno, len, &outcome);
274037a44d8SDarrick J. Wong 	if (!xchk_should_check_xref(sc, &error, &sc->sr.rmap_cur))
275037a44d8SDarrick J. Wong 		return;
276037a44d8SDarrick J. Wong 	if (outcome != XBTREE_RECPACKING_EMPTY)
277037a44d8SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
278037a44d8SDarrick J. Wong }
279037a44d8SDarrick J. Wong 
280037a44d8SDarrick J. Wong /* xref check that the extent is completely mapped */
281037a44d8SDarrick J. Wong void
xchk_xref_has_rt_owner(struct xfs_scrub * sc,xfs_rgblock_t bno,xfs_extlen_t len)282037a44d8SDarrick J. Wong xchk_xref_has_rt_owner(
283037a44d8SDarrick J. Wong 	struct xfs_scrub	*sc,
284037a44d8SDarrick J. Wong 	xfs_rgblock_t		bno,
285037a44d8SDarrick J. Wong 	xfs_extlen_t		len)
286037a44d8SDarrick J. Wong {
287037a44d8SDarrick J. Wong 	enum xbtree_recpacking	outcome;
288037a44d8SDarrick J. Wong 	int			error;
289037a44d8SDarrick J. Wong 
290037a44d8SDarrick J. Wong 	if (!sc->sr.rmap_cur || xchk_skip_xref(sc->sm))
291037a44d8SDarrick J. Wong 		return;
292037a44d8SDarrick J. Wong 
293037a44d8SDarrick J. Wong 	error = xfs_rmap_has_records(sc->sr.rmap_cur, bno, len, &outcome);
294037a44d8SDarrick J. Wong 	if (!xchk_should_check_xref(sc, &error, &sc->sr.rmap_cur))
295037a44d8SDarrick J. Wong 		return;
296037a44d8SDarrick J. Wong 	if (outcome != XBTREE_RECPACKING_FULL)
297037a44d8SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
298037a44d8SDarrick J. Wong }
299037a44d8SDarrick J. Wong 
300037a44d8SDarrick J. Wong /* xref check that the extent is only owned by a given owner */
301037a44d8SDarrick J. Wong void
xchk_xref_is_only_rt_owned_by(struct xfs_scrub * sc,xfs_agblock_t bno,xfs_extlen_t len,const struct xfs_owner_info * oinfo)302037a44d8SDarrick J. Wong xchk_xref_is_only_rt_owned_by(
303037a44d8SDarrick J. Wong 	struct xfs_scrub		*sc,
304037a44d8SDarrick J. Wong 	xfs_agblock_t			bno,
305037a44d8SDarrick J. Wong 	xfs_extlen_t			len,
306037a44d8SDarrick J. Wong 	const struct xfs_owner_info	*oinfo)
307037a44d8SDarrick J. Wong {
308037a44d8SDarrick J. Wong 	struct xfs_rmap_matches		res;
309037a44d8SDarrick J. Wong 	int				error;
310037a44d8SDarrick J. Wong 
311037a44d8SDarrick J. Wong 	if (!sc->sr.rmap_cur || xchk_skip_xref(sc->sm))
312037a44d8SDarrick J. Wong 		return;
313037a44d8SDarrick J. Wong 
314037a44d8SDarrick J. Wong 	error = xfs_rmap_count_owners(sc->sr.rmap_cur, bno, len, oinfo, &res);
315037a44d8SDarrick J. Wong 	if (!xchk_should_check_xref(sc, &error, &sc->sr.rmap_cur))
316037a44d8SDarrick J. Wong 		return;
317037a44d8SDarrick J. Wong 	if (res.matches != 1)
318037a44d8SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
319037a44d8SDarrick J. Wong 	if (res.bad_non_owner_matches)
320037a44d8SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
321037a44d8SDarrick J. Wong 	if (res.non_owner_matches)
322037a44d8SDarrick J. Wong 		xchk_btree_xref_set_corrupt(sc, sc->sr.rmap_cur, 0);
323037a44d8SDarrick J. Wong }
324