refcount.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2017-2023 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <djwong@kernel.org>
  5. */
  6. #include "xfs.h"
  7. #include "xfs_fs.h"
  8. #include "xfs_shared.h"
  9. #include "xfs_format.h"
  10. #include "xfs_log_format.h"
  11. #include "xfs_trans_resv.h"
  12. #include "xfs_mount.h"
  13. #include "xfs_trans.h"
  14. #include "xfs_ag.h"
  15. #include "xfs_btree.h"
  16. #include "xfs_rmap.h"
  17. #include "xfs_refcount.h"
  18. #include "scrub/scrub.h"
  19. #include "scrub/common.h"
  20. #include "scrub/btree.h"
  21. #include "scrub/trace.h"
  22. #include "scrub/repair.h"
  23. /*
  24. * Set us up to scrub reference count btrees.
  25. */
  26. int
  27. xchk_setup_ag_refcountbt(
  28. struct xfs_scrub *sc)
  29. {
  30. if (xchk_need_intent_drain(sc))
  31. xchk_fsgates_enable(sc, XCHK_FSGATES_DRAIN);
  32. if (xchk_could_repair(sc)) {
  33. int error;
  34. error = xrep_setup_ag_refcountbt(sc);
  35. if (error)
  36. return error;
  37. }
  38. return xchk_setup_ag_btree(sc, false);
  39. }
  40. /* Reference count btree scrubber. */
  41. /*
  42. * Confirming Reference Counts via Reverse Mappings
  43. *
  44. * We want to count the reverse mappings overlapping a refcount record
  45. * (bno, len, refcount), allowing for the possibility that some of the
  46. * overlap may come from smaller adjoining reverse mappings, while some
  47. * comes from single extents which overlap the range entirely. The
  48. * outer loop is as follows:
  49. *
  50. * 1. For all reverse mappings overlapping the refcount extent,
  51. * a. If a given rmap completely overlaps, mark it as seen.
  52. * b. Otherwise, record the fragment (in agbno order) for later
  53. * processing.
  54. *
  55. * Once we've seen all the rmaps, we know that for all blocks in the
  56. * refcount record we want to find $refcount owners and we've already
  57. * visited $seen extents that overlap all the blocks. Therefore, we
  58. * need to find ($refcount - $seen) owners for every block in the
  59. * extent; call that quantity $target_nr. Proceed as follows:
  60. *
  61. * 2. Pull the first $target_nr fragments from the list; all of them
  62. * should start at or before the start of the extent.
  63. * Call this subset of fragments the working set.
  64. * 3. Until there are no more unprocessed fragments,
  65. * a. Find the shortest fragments in the set and remove them.
  66. * b. Note the block number of the end of these fragments.
  67. * c. Pull the same number of fragments from the list. All of these
  68. * fragments should start at the block number recorded in the
  69. * previous step.
  70. * d. Put those fragments in the set.
  71. * 4. Check that there are $target_nr fragments remaining in the list,
  72. * and that they all end at or beyond the end of the refcount extent.
  73. *
  74. * If the refcount is correct, all the check conditions in the algorithm
  75. * should always hold true. If not, the refcount is incorrect.
  76. */
  77. struct xchk_refcnt_frag {
  78. struct list_head list;
  79. struct xfs_rmap_irec rm;
  80. };
  81. struct xchk_refcnt_check {
  82. struct xfs_scrub *sc;
  83. struct list_head fragments;
  84. /* refcount extent we're examining */
  85. xfs_agblock_t bno;
  86. xfs_extlen_t len;
  87. xfs_nlink_t refcount;
  88. /* number of owners seen */
  89. xfs_nlink_t seen;
  90. };
  91. /*
  92. * Decide if the given rmap is large enough that we can redeem it
  93. * towards refcount verification now, or if it's a fragment, in
  94. * which case we'll hang onto it in the hopes that we'll later
  95. * discover that we've collected exactly the correct number of
  96. * fragments as the refcountbt says we should have.
  97. */
  98. STATIC int
  99. xchk_refcountbt_rmap_check(
  100. struct xfs_btree_cur *cur,
  101. const struct xfs_rmap_irec *rec,
  102. void *priv)
  103. {
  104. struct xchk_refcnt_check *refchk = priv;
  105. struct xchk_refcnt_frag *frag;
  106. xfs_agblock_t rm_last;
  107. xfs_agblock_t rc_last;
  108. int error = 0;
  109. if (xchk_should_terminate(refchk->sc, &error))
  110. return error;
  111. rm_last = rec->rm_startblock + rec->rm_blockcount - 1;
  112. rc_last = refchk->bno + refchk->len - 1;
  113. /* Confirm that a single-owner refc extent is a CoW stage. */
  114. if (refchk->refcount == 1 && rec->rm_owner != XFS_RMAP_OWN_COW) {
  115. xchk_btree_xref_set_corrupt(refchk->sc, cur, 0);
  116. return 0;
  117. }
  118. if (rec->rm_startblock <= refchk->bno && rm_last >= rc_last) {
  119. /*
  120. * The rmap overlaps the refcount record, so we can confirm
  121. * one refcount owner seen.
  122. */
  123. refchk->seen++;
  124. } else {
  125. /*
  126. * This rmap covers only part of the refcount record, so
  127. * save the fragment for later processing. If the rmapbt
  128. * is healthy each rmap_irec we see will be in agbno order
  129. * so we don't need insertion sort here.
  130. */
  131. frag = kmalloc(sizeof(struct xchk_refcnt_frag),
  132. XCHK_GFP_FLAGS);
  133. if (!frag)
  134. return -ENOMEM;
  135. memcpy(&frag->rm, rec, sizeof(frag->rm));
  136. list_add_tail(&frag->list, &refchk->fragments);
  137. }
  138. return 0;
  139. }
  140. /*
  141. * Given a bunch of rmap fragments, iterate through them, keeping
  142. * a running tally of the refcount. If this ever deviates from
  143. * what we expect (which is the refcountbt's refcount minus the
  144. * number of extents that totally covered the refcountbt extent),
  145. * we have a refcountbt error.
  146. */
  147. STATIC void
  148. xchk_refcountbt_process_rmap_fragments(
  149. struct xchk_refcnt_check *refchk)
  150. {
  151. struct list_head worklist;
  152. struct xchk_refcnt_frag *frag;
  153. struct xchk_refcnt_frag *n;
  154. xfs_agblock_t bno;
  155. xfs_agblock_t rbno;
  156. xfs_agblock_t next_rbno;
  157. xfs_nlink_t nr;
  158. xfs_nlink_t target_nr;
  159. target_nr = refchk->refcount - refchk->seen;
  160. if (target_nr == 0)
  161. return;
  162. /*
  163. * There are (refchk->rc.rc_refcount - refchk->nr refcount)
  164. * references we haven't found yet. Pull that many off the
  165. * fragment list and figure out where the smallest rmap ends
  166. * (and therefore the next rmap should start). All the rmaps
  167. * we pull off should start at or before the beginning of the
  168. * refcount record's range.
  169. */
  170. INIT_LIST_HEAD(&worklist);
  171. rbno = NULLAGBLOCK;
  172. /* Make sure the fragments actually /are/ in agbno order. */
  173. bno = 0;
  174. list_for_each_entry(frag, &refchk->fragments, list) {
  175. if (frag->rm.rm_startblock < bno)
  176. goto done;
  177. bno = frag->rm.rm_startblock;
  178. }
  179. /*
  180. * Find all the rmaps that start at or before the refc extent,
  181. * and put them on the worklist.
  182. */
  183. nr = 0;
  184. list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
  185. if (frag->rm.rm_startblock > refchk->bno || nr > target_nr)
  186. break;
  187. bno = frag->rm.rm_startblock + frag->rm.rm_blockcount;
  188. if (bno < rbno)
  189. rbno = bno;
  190. list_move_tail(&frag->list, &worklist);
  191. nr++;
  192. }
  193. /*
  194. * We should have found exactly $target_nr rmap fragments starting
  195. * at or before the refcount extent.
  196. */
  197. if (nr != target_nr)
  198. goto done;
  199. while (!list_empty(&refchk->fragments)) {
  200. /* Discard any fragments ending at rbno from the worklist. */
  201. nr = 0;
  202. next_rbno = NULLAGBLOCK;
  203. list_for_each_entry_safe(frag, n, &worklist, list) {
  204. bno = frag->rm.rm_startblock + frag->rm.rm_blockcount;
  205. if (bno != rbno) {
  206. if (bno < next_rbno)
  207. next_rbno = bno;
  208. continue;
  209. }
  210. list_del(&frag->list);
  211. kfree(frag);
  212. nr++;
  213. }
  214. /* Try to add nr rmaps starting at rbno to the worklist. */
  215. list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
  216. bno = frag->rm.rm_startblock + frag->rm.rm_blockcount;
  217. if (frag->rm.rm_startblock != rbno)
  218. goto done;
  219. list_move_tail(&frag->list, &worklist);
  220. if (next_rbno > bno)
  221. next_rbno = bno;
  222. nr--;
  223. if (nr == 0)
  224. break;
  225. }
  226. /*
  227. * If we get here and nr > 0, this means that we added fewer
  228. * items to the worklist than we discarded because the fragment
  229. * list ran out of items. Therefore, we cannot maintain the
  230. * required refcount. Something is wrong, so we're done.
  231. */
  232. if (nr)
  233. goto done;
  234. rbno = next_rbno;
  235. }
  236. /*
  237. * Make sure the last extent we processed ends at or beyond
  238. * the end of the refcount extent.
  239. */
  240. if (rbno < refchk->bno + refchk->len)
  241. goto done;
  242. /* Actually record us having seen the remaining refcount. */
  243. refchk->seen = refchk->refcount;
  244. done:
  245. /* Delete fragments and work list. */
  246. list_for_each_entry_safe(frag, n, &worklist, list) {
  247. list_del(&frag->list);
  248. kfree(frag);
  249. }
  250. list_for_each_entry_safe(frag, n, &refchk->fragments, list) {
  251. list_del(&frag->list);
  252. kfree(frag);
  253. }
  254. }
  255. /* Use the rmap entries covering this extent to verify the refcount. */
  256. STATIC void
  257. xchk_refcountbt_xref_rmap(
  258. struct xfs_scrub *sc,
  259. const struct xfs_refcount_irec *irec)
  260. {
  261. struct xchk_refcnt_check refchk = {
  262. .sc = sc,
  263. .bno = irec->rc_startblock,
  264. .len = irec->rc_blockcount,
  265. .refcount = irec->rc_refcount,
  266. .seen = 0,
  267. };
  268. struct xfs_rmap_irec low;
  269. struct xfs_rmap_irec high;
  270. struct xchk_refcnt_frag *frag;
  271. struct xchk_refcnt_frag *n;
  272. int error;
  273. if (!sc->sa.rmap_cur || xchk_skip_xref(sc->sm))
  274. return;
  275. /* Cross-reference with the rmapbt to confirm the refcount. */
  276. memset(&low, 0, sizeof(low));
  277. low.rm_startblock = irec->rc_startblock;
  278. memset(&high, 0xFF, sizeof(high));
  279. high.rm_startblock = irec->rc_startblock + irec->rc_blockcount - 1;
  280. INIT_LIST_HEAD(&refchk.fragments);
  281. error = xfs_rmap_query_range(sc->sa.rmap_cur, &low, &high,
  282. &xchk_refcountbt_rmap_check, &refchk);
  283. if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
  284. goto out_free;
  285. xchk_refcountbt_process_rmap_fragments(&refchk);
  286. if (irec->rc_refcount != refchk.seen) {
  287. trace_xchk_refcount_incorrect(sc->sa.pag, irec, refchk.seen);
  288. xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
  289. }
  290. out_free:
  291. list_for_each_entry_safe(frag, n, &refchk.fragments, list) {
  292. list_del(&frag->list);
  293. kfree(frag);
  294. }
  295. }
  296. /* Cross-reference with the other btrees. */
  297. STATIC void
  298. xchk_refcountbt_xref(
  299. struct xfs_scrub *sc,
  300. const struct xfs_refcount_irec *irec)
  301. {
  302. if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
  303. return;
  304. xchk_xref_is_used_space(sc, irec->rc_startblock, irec->rc_blockcount);
  305. xchk_xref_is_not_inode_chunk(sc, irec->rc_startblock,
  306. irec->rc_blockcount);
  307. xchk_refcountbt_xref_rmap(sc, irec);
  308. }
  309. struct xchk_refcbt_records {
  310. /* Previous refcount record. */
  311. struct xfs_refcount_irec prev_rec;
  312. /* The next AG block where we aren't expecting shared extents. */
  313. xfs_agblock_t next_unshared_agbno;
  314. /* Number of CoW blocks we expect. */
  315. xfs_agblock_t cow_blocks;
  316. /* Was the last record a shared or CoW staging extent? */
  317. enum xfs_refc_domain prev_domain;
  318. };
  319. STATIC int
  320. xchk_refcountbt_rmap_check_gap(
  321. struct xfs_btree_cur *cur,
  322. const struct xfs_rmap_irec *rec,
  323. void *priv)
  324. {
  325. xfs_agblock_t *next_bno = priv;
  326. if (*next_bno != NULLAGBLOCK && rec->rm_startblock < *next_bno)
  327. return -ECANCELED;
  328. *next_bno = rec->rm_startblock + rec->rm_blockcount;
  329. return 0;
  330. }
  331. /*
  332. * Make sure that a gap in the reference count records does not correspond to
  333. * overlapping records (i.e. shared extents) in the reverse mappings.
  334. */
  335. static inline void
  336. xchk_refcountbt_xref_gaps(
  337. struct xfs_scrub *sc,
  338. struct xchk_refcbt_records *rrc,
  339. xfs_agblock_t bno)
  340. {
  341. struct xfs_rmap_irec low;
  342. struct xfs_rmap_irec high;
  343. xfs_agblock_t next_bno = NULLAGBLOCK;
  344. int error;
  345. if (bno <= rrc->next_unshared_agbno || !sc->sa.rmap_cur ||
  346. xchk_skip_xref(sc->sm))
  347. return;
  348. memset(&low, 0, sizeof(low));
  349. low.rm_startblock = rrc->next_unshared_agbno;
  350. memset(&high, 0xFF, sizeof(high));
  351. high.rm_startblock = bno - 1;
  352. error = xfs_rmap_query_range(sc->sa.rmap_cur, &low, &high,
  353. xchk_refcountbt_rmap_check_gap, &next_bno);
  354. if (error == -ECANCELED)
  355. xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
  356. else
  357. xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur);
  358. }
  359. static inline bool
  360. xchk_refcount_mergeable(
  361. struct xchk_refcbt_records *rrc,
  362. const struct xfs_refcount_irec *r2)
  363. {
  364. const struct xfs_refcount_irec *r1 = &rrc->prev_rec;
  365. /* Ignore if prev_rec is not yet initialized. */
  366. if (r1->rc_blockcount > 0)
  367. return false;
  368. if (r1->rc_domain != r2->rc_domain)
  369. return false;
  370. if (r1->rc_startblock + r1->rc_blockcount != r2->rc_startblock)
  371. return false;
  372. if (r1->rc_refcount != r2->rc_refcount)
  373. return false;
  374. if ((unsigned long long)r1->rc_blockcount + r2->rc_blockcount >
  375. MAXREFCEXTLEN)
  376. return false;
  377. return true;
  378. }
  379. /* Flag failures for records that could be merged. */
  380. STATIC void
  381. xchk_refcountbt_check_mergeable(
  382. struct xchk_btree *bs,
  383. struct xchk_refcbt_records *rrc,
  384. const struct xfs_refcount_irec *irec)
  385. {
  386. if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
  387. return;
  388. if (xchk_refcount_mergeable(rrc, irec))
  389. xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
  390. memcpy(&rrc->prev_rec, irec, sizeof(struct xfs_refcount_irec));
  391. }
  392. /* Scrub a refcountbt record. */
  393. STATIC int
  394. xchk_refcountbt_rec(
  395. struct xchk_btree *bs,
  396. const union xfs_btree_rec *rec)
  397. {
  398. struct xfs_refcount_irec irec;
  399. struct xchk_refcbt_records *rrc = bs->private;
  400. xfs_refcount_btrec_to_irec(rec, &irec);
  401. if (xfs_refcount_check_irec(bs->cur->bc_ag.pag, &irec) != NULL) {
  402. xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
  403. return 0;
  404. }
  405. if (irec.rc_domain == XFS_REFC_DOMAIN_COW)
  406. rrc->cow_blocks += irec.rc_blockcount;
  407. /* Shared records always come before CoW records. */
  408. if (irec.rc_domain == XFS_REFC_DOMAIN_SHARED &&
  409. rrc->prev_domain == XFS_REFC_DOMAIN_COW)
  410. xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
  411. rrc->prev_domain = irec.rc_domain;
  412. xchk_refcountbt_check_mergeable(bs, rrc, &irec);
  413. xchk_refcountbt_xref(bs->sc, &irec);
  414. /*
  415. * If this is a record for a shared extent, check that all blocks
  416. * between the previous record and this one have at most one reverse
  417. * mapping.
  418. */
  419. if (irec.rc_domain == XFS_REFC_DOMAIN_SHARED) {
  420. xchk_refcountbt_xref_gaps(bs->sc, rrc, irec.rc_startblock);
  421. rrc->next_unshared_agbno = irec.rc_startblock +
  422. irec.rc_blockcount;
  423. }
  424. return 0;
  425. }
  426. /* Make sure we have as many refc blocks as the rmap says. */
  427. STATIC void
  428. xchk_refcount_xref_rmap(
  429. struct xfs_scrub *sc,
  430. xfs_filblks_t cow_blocks)
  431. {
  432. xfs_filblks_t refcbt_blocks = 0;
  433. xfs_filblks_t blocks;
  434. int error;
  435. if (!sc->sa.rmap_cur || xchk_skip_xref(sc->sm))
  436. return;
  437. /* Check that we saw as many refcbt blocks as the rmap knows about. */
  438. error = xfs_btree_count_blocks(sc->sa.refc_cur, &refcbt_blocks);
  439. if (!xchk_btree_process_error(sc, sc->sa.refc_cur, 0, &error))
  440. return;
  441. error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
  442. &XFS_RMAP_OINFO_REFC, &blocks);
  443. if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
  444. return;
  445. if (blocks != refcbt_blocks)
  446. xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
  447. /* Check that we saw as many cow blocks as the rmap knows about. */
  448. error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur,
  449. &XFS_RMAP_OINFO_COW, &blocks);
  450. if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
  451. return;
  452. if (blocks != cow_blocks)
  453. xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0);
  454. }
  455. /* Scrub the refcount btree for some AG. */
  456. int
  457. xchk_refcountbt(
  458. struct xfs_scrub *sc)
  459. {
  460. struct xchk_refcbt_records rrc = {
  461. .cow_blocks = 0,
  462. .next_unshared_agbno = 0,
  463. .prev_domain = XFS_REFC_DOMAIN_SHARED,
  464. };
  465. int error;
  466. error = xchk_btree(sc, sc->sa.refc_cur, xchk_refcountbt_rec,
  467. &XFS_RMAP_OINFO_REFC, &rrc);
  468. if (error)
  469. return error;
  470. /*
  471. * Check that all blocks between the last refcount > 1 record and the
  472. * end of the AG have at most one reverse mapping.
  473. */
  474. xchk_refcountbt_xref_gaps(sc, &rrc, sc->mp->m_sb.sb_agblocks);
  475. xchk_refcount_xref_rmap(sc, rrc.cow_blocks);
  476. return 0;
  477. }
  478. /* xref check that a cow staging extent is marked in the refcountbt. */
  479. void
  480. xchk_xref_is_cow_staging(
  481. struct xfs_scrub *sc,
  482. xfs_agblock_t agbno,
  483. xfs_extlen_t len)
  484. {
  485. struct xfs_refcount_irec rc;
  486. int has_refcount;
  487. int error;
  488. if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm))
  489. return;
  490. /* Find the CoW staging extent. */
  491. error = xfs_refcount_lookup_le(sc->sa.refc_cur, XFS_REFC_DOMAIN_COW,
  492. agbno, &has_refcount);
  493. if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
  494. return;
  495. if (!has_refcount) {
  496. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  497. return;
  498. }
  499. error = xfs_refcount_get_rec(sc->sa.refc_cur, &rc, &has_refcount);
  500. if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
  501. return;
  502. if (!has_refcount) {
  503. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  504. return;
  505. }
  506. /* CoW lookup returned a shared extent record? */
  507. if (rc.rc_domain != XFS_REFC_DOMAIN_COW)
  508. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  509. /* Must be at least as long as what was passed in */
  510. if (rc.rc_blockcount < len)
  511. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  512. }
  513. /*
  514. * xref check that the extent is not shared. Only file data blocks
  515. * can have multiple owners.
  516. */
  517. void
  518. xchk_xref_is_not_shared(
  519. struct xfs_scrub *sc,
  520. xfs_agblock_t agbno,
  521. xfs_extlen_t len)
  522. {
  523. enum xbtree_recpacking outcome;
  524. int error;
  525. if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm))
  526. return;
  527. error = xfs_refcount_has_records(sc->sa.refc_cur,
  528. XFS_REFC_DOMAIN_SHARED, agbno, len, &outcome);
  529. if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
  530. return;
  531. if (outcome != XBTREE_RECPACKING_EMPTY)
  532. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  533. }
  534. /* xref check that the extent is not being used for CoW staging. */
  535. void
  536. xchk_xref_is_not_cow_staging(
  537. struct xfs_scrub *sc,
  538. xfs_agblock_t agbno,
  539. xfs_extlen_t len)
  540. {
  541. enum xbtree_recpacking outcome;
  542. int error;
  543. if (!sc->sa.refc_cur || xchk_skip_xref(sc->sm))
  544. return;
  545. error = xfs_refcount_has_records(sc->sa.refc_cur, XFS_REFC_DOMAIN_COW,
  546. agbno, len, &outcome);
  547. if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
  548. return;
  549. if (outcome != XBTREE_RECPACKING_EMPTY)
  550. xchk_btree_xref_set_corrupt(sc, sc->sa.refc_cur, 0);
  551. }