/* Make sure the fragments actually /are/ in agbno order. */
bno = 0;
list_for_each_entry(frag, &refchk->fragments, list) { if (frag->rm.rm_startblock < bno) goto done;
bno = frag->rm.rm_startblock;
}
/* *Findallthermapsthatstartatorbeforetherefcextent, *andputthemontheworklist.
*/
nr = 0;
list_for_each_entry_safe(frag, n, &refchk->fragments, list) { if (frag->rm.rm_startblock > refchk->bno || nr > target_nr) break;
bno = frag->rm.rm_startblock + frag->rm.rm_blockcount; if (bno < rbno)
rbno = bno;
list_move_tail(&frag->list, &worklist);
nr++;
}
/* *Weshouldhavefoundexactly$target_nrrmapfragmentsstarting *atorbeforetherefcountextent.
*/ if (nr != target_nr) goto done;
while (!list_empty(&refchk->fragments)) { /* Discard any fragments ending at rbno from the worklist. */
nr = 0;
next_rbno = NULLAGBLOCK;
list_for_each_entry_safe(frag, n, &worklist, list) {
bno = frag->rm.rm_startblock + frag->rm.rm_blockcount; if (bno != rbno) { if (bno < next_rbno)
next_rbno = bno; continue;
}
list_del(&frag->list);
kfree(frag);
nr++;
}
/* Try to add nr rmaps starting at rbno to the worklist. */
list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
bno = frag->rm.rm_startblock + frag->rm.rm_blockcount; if (frag->rm.rm_startblock != rbno) goto done;
list_move_tail(&frag->list, &worklist); if (next_rbno > bno)
next_rbno = bno;
nr--; if (nr == 0) break;
}
/* *Ifwegethereandnr>0,thismeansthatweaddedfewer *itemstotheworklistthanwediscardedbecausethefragment *listranoutofitems.Therefore,wecannotmaintainthe *requiredrefcount.Somethingiswrong,sowe'redone.
*/ if (nr) goto done;
/* Actually record us having seen the remaining refcount. */
refchk->seen = refchk->refcount;
done: /* Delete fragments and work list. */
list_for_each_entry_safe(frag, n, &worklist, list) {
list_del(&frag->list);
kfree(frag);
}
list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
list_del(&frag->list);
kfree(frag);
}
}
/* Use the rmap entries covering this extent to verify the refcount. */ STATICvoid
xchk_refcountbt_xref_rmap( struct xfs_scrub *sc, conststruct xfs_refcount_irec *irec)
{ struct xchk_refcnt_check refchk = {
.sc = sc,
.bno = irec->rc_startblock,
.len = irec->rc_blockcount,
.refcount = irec->rc_refcount,
.seen = 0,
}; struct xfs_rmap_irec low; struct xfs_rmap_irec high; struct xchk_refcnt_frag *frag; struct xchk_refcnt_frag *n; int error;
if (!sc->sa.rmap_cur || xchk_skip_xref(sc->sm)) return;
/* Cross-reference with the rmapbt to confirm the refcount. */
memset(&low, 0, sizeof(low));
low.rm_startblock = irec->rc_startblock;
memset(&high, 0xFF, sizeof(high));
high.rm_startblock = irec->rc_startblock + irec->rc_blockcount - 1;
/* Ignore if prev_rec is not yet initialized. */ if (r1->rc_blockcount > 0) returnfalse;
if (r1->rc_domain != r2->rc_domain) returnfalse; if (r1->rc_startblock + r1->rc_blockcount != r2->rc_startblock) returnfalse; if (r1->rc_refcount != r2->rc_refcount) returnfalse; if ((unsignedlonglong)r1->rc_blockcount + r2->rc_blockcount >
XFS_REFC_LEN_MAX) returnfalse;
returntrue;
}
/* Flag failures for records that could be merged. */ STATICvoid
xchk_refcountbt_check_mergeable( struct xchk_btree *bs, struct xchk_refcbt_records *rrc, conststruct xfs_refcount_irec *irec)
{ if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) return;
if (xchk_refcount_mergeable(rrc, irec))
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
if (irec.rc_domain == XFS_REFC_DOMAIN_COW)
rrc->cow_blocks += irec.rc_blockcount;
/* Shared records always come before CoW records. */ if (irec.rc_domain == XFS_REFC_DOMAIN_SHARED &&
rrc->prev_domain == XFS_REFC_DOMAIN_COW)
xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
rrc->prev_domain = irec.rc_domain;
/* Make sure we have as many refc blocks as the rmap says. */ STATICvoid
xchk_refcount_xref_rmap( struct xfs_scrub *sc,
xfs_filblks_t cow_blocks)
{
xfs_filblks_t refcbt_blocks = 0;
xfs_filblks_t blocks; int error;
if (!sc->sa.rmap_cur || xchk_skip_xref(sc->sm)) return;
/* Check that we saw as many refcbt blocks as the rmap knows about. */
error = xfs_btree_count_blocks(sc->sa.refc_cur, &refcbt_blocks); if (!xchk_btree_process_error(sc, sc->sa.refc_cur, 0, &error)) return;
error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
&XFS_RMAP_OINFO_REFC, &blocks); if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur)) return; if (blocks != refcbt_blocks)
xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
/* Check that we saw as many cow blocks as the rmap knows about. */
error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
&XFS_RMAP_OINFO_COW, &blocks); if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur)) return; if (blocks != cow_blocks)
xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
}
/* Scrub the refcount btree for some AG. */ int
xchk_refcountbt( struct xfs_scrub *sc)
{ struct xchk_refcbt_records rrc = {
.cow_blocks = 0,
.next_unshared_agbno = 0,
.prev_domain = XFS_REFC_DOMAIN_SHARED,
}; int error;
/* xref check that a cow staging extent is marked in the refcountbt. */ void
xchk_xref_is_cow_staging( struct xfs_scrub *sc,
xfs_agblock_t agbno,
xfs_extlen_t len)
{ struct xfs_refcount_irec rc; int has_refcount; int error;
if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm)) return;
/* Find the CoW staging extent. */
error = xfs_refcount_lookup_le(sc->sa.refc_cur, XFS_REFC_DOMAIN_COW,
agbno, &has_refcount); if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur)) return; if (!has_refcount) {
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0); return;
}
error = xfs_refcount_get_rec(sc->sa.refc_cur, &rc, &has_refcount); if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur)) return; if (!has_refcount) {
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0); return;
}
/* CoW lookup returned a shared extent record? */ if (rc.rc_domain != XFS_REFC_DOMAIN_COW)
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
/* Must be at least as long as what was passed in */ if (rc.rc_blockcount < len)
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
}
if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm)) return;
error = xfs_refcount_has_records(sc->sa.refc_cur,
XFS_REFC_DOMAIN_SHARED, agbno, len, &outcome); if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur)) return; if (outcome != XBTREE_RECPACKING_EMPTY)
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
}
/* xref check that the extent is not being used for CoW staging. */ void
xchk_xref_is_not_cow_staging( struct xfs_scrub *sc,
xfs_agblock_t agbno,
xfs_extlen_t len)
{ enum xbtree_recpacking outcome; int error;
if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm)) return;
error = xfs_refcount_has_records(sc->sa.refc_cur, XFS_REFC_DOMAIN_COW,
agbno, len, &outcome); if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur)) return; if (outcome != XBTREE_RECPACKING_EMPTY)
xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.