Lines Matching +full:ip +full:- +full:blocks

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018-2023 Oracle. All Rights Reserved.
44 struct xfs_mount *mp = sc->mp; in xrep_superblock()
50 agno = sc->sm->sm_agno; in xrep_superblock()
52 return -EOPNOTSUPP; in xrep_superblock()
54 error = xfs_sb_get_secondary(mp, sc->tp, agno, &bp); in xrep_superblock()
63 xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); in xrep_superblock()
64 xfs_sb_to_disk(bp->b_addr, &mp->m_sb); in xrep_superblock()
71 struct xfs_dsb *sb = bp->b_addr; in xrep_superblock()
73 sb->sb_features_incompat &= in xrep_superblock()
75 sb->sb_features_log_incompat = 0; in xrep_superblock()
79 xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF); in xrep_superblock()
80 xfs_trans_log_buf(sc->tp, bp, 0, BBTOB(bp->b_length) - 1); in xrep_superblock()
102 if (xchk_should_terminate(raa->sc, &error)) in xrep_agf_walk_allocbt()
105 raa->freeblks += rec->ar_blockcount; in xrep_agf_walk_allocbt()
106 if (rec->ar_blockcount > raa->longest) in xrep_agf_walk_allocbt()
107 raa->longest = rec->ar_blockcount; in xrep_agf_walk_allocbt()
120 if (!xfs_verify_agbno(sc->sa.pag, agbno)) in xrep_agf_check_agfl_block()
121 return -EFSCORRUPTED; in xrep_agf_check_agfl_block()
144 return xfs_verify_agbno(sc->sa.pag, fab->root) && in xrep_check_btree_root()
145 fab->height <= fab->maxlevels; in xrep_check_btree_root()
164 struct xfs_agf *old_agf = agf_bp->b_addr; in xrep_agf_find_btrees()
176 return -EFSCORRUPTED; in xrep_agf_find_btrees()
182 if (fab[XREP_AGF_RMAPBT].root != be32_to_cpu(old_agf->agf_rmap_root)) in xrep_agf_find_btrees()
183 return -EFSCORRUPTED; in xrep_agf_find_btrees()
186 if (xfs_has_reflink(sc->mp) && in xrep_agf_find_btrees()
188 return -EFSCORRUPTED; in xrep_agf_find_btrees()
194 * Reinitialize the AGF header, making an in-core copy of the old contents so
195 * that we know which in-core state needs to be reinitialized.
203 struct xfs_mount *mp = sc->mp; in xrep_agf_init_header()
204 struct xfs_perag *pag = sc->sa.pag; in xrep_agf_init_header()
205 struct xfs_agf *agf = agf_bp->b_addr; in xrep_agf_init_header()
208 memset(agf, 0, BBTOB(agf_bp->b_length)); in xrep_agf_init_header()
209 agf->agf_magicnum = cpu_to_be32(XFS_AGF_MAGIC); in xrep_agf_init_header()
210 agf->agf_versionnum = cpu_to_be32(XFS_AGF_VERSION); in xrep_agf_init_header()
211 agf->agf_seqno = cpu_to_be32(pag->pag_agno); in xrep_agf_init_header()
212 agf->agf_length = cpu_to_be32(pag->block_count); in xrep_agf_init_header()
213 agf->agf_flfirst = old_agf->agf_flfirst; in xrep_agf_init_header()
214 agf->agf_fllast = old_agf->agf_fllast; in xrep_agf_init_header()
215 agf->agf_flcount = old_agf->agf_flcount; in xrep_agf_init_header()
217 uuid_copy(&agf->agf_uuid, &mp->m_sb.sb_meta_uuid); in xrep_agf_init_header()
221 clear_bit(XFS_AGSTATE_AGF_INIT, &pag->pag_opstate); in xrep_agf_init_header()
231 agf->agf_bno_root = cpu_to_be32(fab[XREP_AGF_BNOBT].root); in xrep_agf_set_roots()
232 agf->agf_bno_level = cpu_to_be32(fab[XREP_AGF_BNOBT].height); in xrep_agf_set_roots()
234 agf->agf_cnt_root = cpu_to_be32(fab[XREP_AGF_CNTBT].root); in xrep_agf_set_roots()
235 agf->agf_cnt_level = cpu_to_be32(fab[XREP_AGF_CNTBT].height); in xrep_agf_set_roots()
237 agf->agf_rmap_root = cpu_to_be32(fab[XREP_AGF_RMAPBT].root); in xrep_agf_set_roots()
238 agf->agf_rmap_level = cpu_to_be32(fab[XREP_AGF_RMAPBT].height); in xrep_agf_set_roots()
240 if (xfs_has_reflink(sc->mp)) { in xrep_agf_set_roots()
241 agf->agf_refcount_root = in xrep_agf_set_roots()
243 agf->agf_refcount_level = in xrep_agf_set_roots()
256 struct xfs_agf *agf = agf_bp->b_addr; in xrep_agf_calc_from_btrees()
257 struct xfs_mount *mp = sc->mp; in xrep_agf_calc_from_btrees()
259 xfs_agblock_t blocks; in xrep_agf_calc_from_btrees() local
263 cur = xfs_bnobt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agf_calc_from_btrees()
267 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agf_calc_from_btrees()
271 btreeblks = blocks - 1; in xrep_agf_calc_from_btrees()
272 agf->agf_freeblks = cpu_to_be32(raa.freeblks); in xrep_agf_calc_from_btrees()
273 agf->agf_longest = cpu_to_be32(raa.longest); in xrep_agf_calc_from_btrees()
276 cur = xfs_cntbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agf_calc_from_btrees()
277 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agf_calc_from_btrees()
281 btreeblks += blocks - 1; in xrep_agf_calc_from_btrees()
284 cur = xfs_rmapbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agf_calc_from_btrees()
285 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agf_calc_from_btrees()
289 agf->agf_rmap_blocks = cpu_to_be32(blocks); in xrep_agf_calc_from_btrees()
290 btreeblks += blocks - 1; in xrep_agf_calc_from_btrees()
292 agf->agf_btreeblks = cpu_to_be32(btreeblks); in xrep_agf_calc_from_btrees()
296 cur = xfs_refcountbt_init_cursor(mp, sc->tp, agf_bp, in xrep_agf_calc_from_btrees()
297 sc->sa.pag); in xrep_agf_calc_from_btrees()
298 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agf_calc_from_btrees()
302 agf->agf_refcount_blocks = cpu_to_be32(blocks); in xrep_agf_calc_from_btrees()
318 struct xfs_agf *agf = agf_bp->b_addr; in xrep_agf_commit_new()
321 xfs_force_summary_recalc(sc->mp); in xrep_agf_commit_new()
324 xfs_trans_buf_set_type(sc->tp, agf_bp, XFS_BLFT_AGF_BUF); in xrep_agf_commit_new()
325 xfs_trans_log_buf(sc->tp, agf_bp, 0, BBTOB(agf_bp->b_length) - 1); in xrep_agf_commit_new()
327 /* Now reinitialize the in-core counters we changed. */ in xrep_agf_commit_new()
328 pag = sc->sa.pag; in xrep_agf_commit_new()
329 pag->pagf_btreeblks = be32_to_cpu(agf->agf_btreeblks); in xrep_agf_commit_new()
330 pag->pagf_freeblks = be32_to_cpu(agf->agf_freeblks); in xrep_agf_commit_new()
331 pag->pagf_longest = be32_to_cpu(agf->agf_longest); in xrep_agf_commit_new()
332 pag->pagf_bno_level = be32_to_cpu(agf->agf_bno_level); in xrep_agf_commit_new()
333 pag->pagf_cnt_level = be32_to_cpu(agf->agf_cnt_level); in xrep_agf_commit_new()
334 pag->pagf_rmap_level = be32_to_cpu(agf->agf_rmap_level); in xrep_agf_commit_new()
335 pag->pagf_refcount_level = be32_to_cpu(agf->agf_refcount_level); in xrep_agf_commit_new()
336 set_bit(XFS_AGSTATE_AGF_INIT, &pag->pag_opstate); in xrep_agf_commit_new()
350 .maxlevels = sc->mp->m_alloc_maxlevels, in xrep_agf()
355 .maxlevels = sc->mp->m_alloc_maxlevels, in xrep_agf()
360 .maxlevels = sc->mp->m_rmap_maxlevels, in xrep_agf()
365 .maxlevels = sc->mp->m_refc_maxlevels, in xrep_agf()
372 struct xfs_mount *mp = sc->mp; in xrep_agf()
380 return -EOPNOTSUPP; in xrep_agf()
384 * was corrupt after xfs_alloc_read_agf failed with -EFSCORRUPTED. in xrep_agf()
386 error = xfs_trans_read_buf(mp, sc->tp, mp->m_ddev_targp, in xrep_agf()
387 XFS_AG_DADDR(mp, sc->sa.pag->pag_agno, in xrep_agf()
392 agf_bp->b_ops = &xfs_agf_buf_ops; in xrep_agf()
393 agf = agf_bp->b_addr; in xrep_agf()
396 * Load the AGFL so that we can screen out OWN_AG blocks that are on in xrep_agf()
397 * the AGFL now; these blocks might have once been part of the in xrep_agf()
400 * because we can't do any serious cross-referencing with any of the in xrep_agf()
404 error = xfs_alloc_read_agfl(sc->sa.pag, sc->tp, &agfl_bp); in xrep_agf()
409 * Spot-check the AGFL blocks; if they're obviously corrupt then in xrep_agf()
412 error = xfs_agfl_walk(sc->mp, agf_bp->b_addr, agfl_bp, in xrep_agf()
418 * Find the AGF btree roots. This is also a chicken-and-egg situation; in xrep_agf()
441 clear_bit(XFS_AGSTATE_AGF_INIT, &sc->sa.pag->pag_opstate); in xrep_agf()
449 /* Bitmap of alleged AGFL blocks that we're not going to add. */
452 /* Bitmap of other OWN_AG metadata blocks. */
458 /* rmapbt cursor for finding crosslinked blocks */
474 if (xchk_should_terminate(ra->sc, &error)) in xrep_agfl_walk_rmap()
477 /* Record all the OWN_AG blocks. */ in xrep_agfl_walk_rmap()
478 if (rec->rm_owner == XFS_RMAP_OWN_AG) { in xrep_agfl_walk_rmap()
479 error = xagb_bitmap_set(ra->freesp, rec->rm_startblock, in xrep_agfl_walk_rmap()
480 rec->rm_blockcount); in xrep_agfl_walk_rmap()
485 return xagb_bitmap_set_btcur_path(&ra->agmetablocks, cur); in xrep_agfl_walk_rmap()
488 /* Strike out the blocks that are cross-linked according to the rmapbt. */
496 xfs_agblock_t last_agbno = agbno + len - 1; in xrep_agfl_check_extent()
502 error = xfs_rmap_has_other_keys(ra->rmap_cur, agbno, 1, in xrep_agfl_check_extent()
508 error = xagb_bitmap_set(&ra->crossed, agbno, 1); in xrep_agfl_check_extent()
513 if (xchk_should_terminate(ra->sc, &error)) in xrep_agfl_check_extent()
522 * Map out all the non-AGFL OWN_AG space in this AG so that we can deduce
523 * which blocks belong to the AGFL.
525 * Compute the set of old AGFL blocks by subtracting from the list of OWN_AG
526 * blocks the list of blocks owned by all other OWN_AG metadata (bnobt, cntbt,
527 * rmapbt). These are the old AGFL blocks, so return that list and the number
528 * of blocks we're actually going to put back on the AGFL.
538 struct xfs_mount *mp = sc->mp; in xrep_agfl_collect_blocks()
548 cur = xfs_rmapbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agfl_collect_blocks()
554 /* Find all blocks currently being used by the bnobt. */ in xrep_agfl_collect_blocks()
555 cur = xfs_bnobt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agfl_collect_blocks()
561 /* Find all blocks currently being used by the cntbt. */ in xrep_agfl_collect_blocks()
562 cur = xfs_cntbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agfl_collect_blocks()
569 * Drop the freesp meta blocks that are in use by btrees. in xrep_agfl_collect_blocks()
570 * The remaining blocks /should/ be AGFL blocks. in xrep_agfl_collect_blocks()
576 /* Strike out the blocks that are cross-linked. */ in xrep_agfl_collect_blocks()
577 ra.rmap_cur = xfs_rmapbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.pag); in xrep_agfl_collect_blocks()
587 * Calculate the new AGFL size. If we found more blocks than fit in in xrep_agfl_collect_blocks()
599 /* Update the AGF and reset the in-core state. */
606 struct xfs_agf *agf = agf_bp->b_addr; in xrep_agfl_update_agf()
608 ASSERT(flcount <= xfs_agfl_size(sc->mp)); in xrep_agfl_update_agf()
611 xfs_force_summary_recalc(sc->mp); in xrep_agfl_update_agf()
614 if (xfs_perag_initialised_agf(sc->sa.pag)) { in xrep_agfl_update_agf()
615 sc->sa.pag->pagf_flcount = flcount; in xrep_agfl_update_agf()
617 &sc->sa.pag->pag_opstate); in xrep_agfl_update_agf()
619 agf->agf_flfirst = cpu_to_be32(0); in xrep_agfl_update_agf()
620 agf->agf_flcount = cpu_to_be32(flcount); in xrep_agfl_update_agf()
622 agf->agf_fllast = cpu_to_be32(flcount - 1); in xrep_agfl_update_agf()
624 agf->agf_fllast = cpu_to_be32(xfs_agfl_size(sc->mp) - 1); in xrep_agfl_update_agf()
626 xfs_alloc_log_agf(sc->tp, agf_bp, in xrep_agfl_update_agf()
638 /* Fill the AGFL with whatever blocks are in this extent. */
646 struct xfs_scrub *sc = af->sc; in xrep_agfl_fill()
650 trace_xrep_agfl_insert(sc->sa.pag, agbno, len); in xrep_agfl_fill()
652 while (agbno < start + len && af->fl_off < af->flcount) in xrep_agfl_fill()
653 af->agfl_bno[af->fl_off++] = cpu_to_be32(agbno++); in xrep_agfl_fill()
655 error = xagb_bitmap_set(&af->used_extents, start, agbno - 1); in xrep_agfl_fill()
659 if (af->fl_off == af->flcount) in xrep_agfl_fill()
660 return -ECANCELED; in xrep_agfl_fill()
677 struct xfs_mount *mp = sc->mp; in xrep_agfl_init_header()
688 memset(agfl, 0xFF, BBTOB(agfl_bp->b_length)); in xrep_agfl_init_header()
689 agfl->agfl_magicnum = cpu_to_be32(XFS_AGFL_MAGIC); in xrep_agfl_init_header()
690 agfl->agfl_seqno = cpu_to_be32(sc->sa.pag->pag_agno); in xrep_agfl_init_header()
691 uuid_copy(&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid); in xrep_agfl_init_header()
694 * Fill the AGFL with the remaining blocks. If agfl_extents has more in xrep_agfl_init_header()
695 * blocks than fit in the AGFL, they will be freed in a subsequent in xrep_agfl_init_header()
706 xfs_trans_buf_set_type(sc->tp, agfl_bp, XFS_BLFT_AGFL_BUF); in xrep_agfl_init_header()
707 xfs_trans_log_buf(sc->tp, agfl_bp, 0, BBTOB(agfl_bp->b_length) - 1); in xrep_agfl_init_header()
718 struct xfs_mount *mp = sc->mp; in xrep_agfl()
726 return -EOPNOTSUPP; in xrep_agfl()
733 * have this chicken-and-egg problem. in xrep_agfl()
735 error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp); in xrep_agfl()
741 * was corrupt after xfs_alloc_read_agfl failed with -EFSCORRUPTED. in xrep_agfl()
743 error = xfs_trans_read_buf(mp, sc->tp, mp->m_ddev_targp, in xrep_agfl()
744 XFS_AG_DADDR(mp, sc->sa.pag->pag_agno, in xrep_agfl()
749 agfl_bp->b_ops = &xfs_agfl_buf_ops; in xrep_agfl()
775 sc->sa.agf_bp = agf_bp; in xrep_agfl()
827 /* Map of ino -> next_ino for unlinked inode processing. */
830 /* Map of ino -> prev_ino for unlinked inode processing. */
840 xfarray_destroy(ragi->iunlink_prev); in xrep_agi_buf_cleanup()
841 xfarray_destroy(ragi->iunlink_next); in xrep_agi_buf_cleanup()
842 xagino_bitmap_destroy(&ragi->iunlink_bmp); in xrep_agi_buf_cleanup()
853 struct xfs_scrub *sc = ragi->sc; in xrep_agi_find_btrees()
854 struct xrep_find_ag_btree *fab = ragi->fab; in xrep_agi_find_btrees()
856 struct xfs_mount *mp = sc->mp; in xrep_agi_find_btrees()
860 error = xfs_alloc_read_agf(sc->sa.pag, sc->tp, 0, &agf_bp); in xrep_agi_find_btrees()
871 return -EFSCORRUPTED; in xrep_agi_find_btrees()
876 return -EFSCORRUPTED; in xrep_agi_find_btrees()
882 * Reinitialize the AGI header, making an in-core copy of the old contents so
883 * that we know which in-core state needs to be reinitialized.
889 struct xfs_scrub *sc = ragi->sc; in xrep_agi_init_header()
890 struct xfs_buf *agi_bp = ragi->agi_bp; in xrep_agi_init_header()
891 struct xfs_agi *old_agi = &ragi->old_agi; in xrep_agi_init_header()
892 struct xfs_agi *agi = agi_bp->b_addr; in xrep_agi_init_header()
893 struct xfs_perag *pag = sc->sa.pag; in xrep_agi_init_header()
894 struct xfs_mount *mp = sc->mp; in xrep_agi_init_header()
897 memset(agi, 0, BBTOB(agi_bp->b_length)); in xrep_agi_init_header()
898 agi->agi_magicnum = cpu_to_be32(XFS_AGI_MAGIC); in xrep_agi_init_header()
899 agi->agi_versionnum = cpu_to_be32(XFS_AGI_VERSION); in xrep_agi_init_header()
900 agi->agi_seqno = cpu_to_be32(pag->pag_agno); in xrep_agi_init_header()
901 agi->agi_length = cpu_to_be32(pag->block_count); in xrep_agi_init_header()
902 agi->agi_newino = cpu_to_be32(NULLAGINO); in xrep_agi_init_header()
903 agi->agi_dirino = cpu_to_be32(NULLAGINO); in xrep_agi_init_header()
905 uuid_copy(&agi->agi_uuid, &mp->m_sb.sb_meta_uuid); in xrep_agi_init_header()
909 clear_bit(XFS_AGSTATE_AGI_INIT, &pag->pag_opstate); in xrep_agi_init_header()
917 struct xfs_scrub *sc = ragi->sc; in xrep_agi_set_roots()
918 struct xfs_agi *agi = ragi->agi_bp->b_addr; in xrep_agi_set_roots()
919 struct xrep_find_ag_btree *fab = ragi->fab; in xrep_agi_set_roots()
921 agi->agi_root = cpu_to_be32(fab[XREP_AGI_INOBT].root); in xrep_agi_set_roots()
922 agi->agi_level = cpu_to_be32(fab[XREP_AGI_INOBT].height); in xrep_agi_set_roots()
924 if (xfs_has_finobt(sc->mp)) { in xrep_agi_set_roots()
925 agi->agi_free_root = cpu_to_be32(fab[XREP_AGI_FINOBT].root); in xrep_agi_set_roots()
926 agi->agi_free_level = cpu_to_be32(fab[XREP_AGI_FINOBT].height); in xrep_agi_set_roots()
935 struct xfs_scrub *sc = ragi->sc; in xrep_agi_calc_from_btrees()
936 struct xfs_buf *agi_bp = ragi->agi_bp; in xrep_agi_calc_from_btrees()
938 struct xfs_agi *agi = agi_bp->b_addr; in xrep_agi_calc_from_btrees()
939 struct xfs_mount *mp = sc->mp; in xrep_agi_calc_from_btrees()
944 cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp); in xrep_agi_calc_from_btrees()
949 xfs_agblock_t blocks; in xrep_agi_calc_from_btrees() local
951 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agi_calc_from_btrees()
954 agi->agi_iblocks = cpu_to_be32(blocks); in xrep_agi_calc_from_btrees()
958 agi->agi_count = cpu_to_be32(count); in xrep_agi_calc_from_btrees()
959 agi->agi_freecount = cpu_to_be32(freecount); in xrep_agi_calc_from_btrees()
962 xfs_agblock_t blocks; in xrep_agi_calc_from_btrees() local
964 cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp, agi_bp); in xrep_agi_calc_from_btrees()
965 error = xfs_btree_count_blocks(cur, &blocks); in xrep_agi_calc_from_btrees()
969 agi->agi_fblocks = cpu_to_be32(blocks); in xrep_agi_calc_from_btrees()
979 * Record a forwards unlinked chain pointer from agino -> next_agino in our
990 return xfarray_store(ragi->iunlink_next, agino, &next_agino); in xrep_iunlink_store_next()
994 * Record a backwards unlinked chain pointer from prev_ino <- agino in our
1005 return xfarray_store(ragi->iunlink_prev, agino, &prev_agino); in xrep_iunlink_store_prev()
1011 * like it should be, or a per-AG inode number.
1018 struct xfs_inode *ip; in xrep_iunlink_next() local
1020 ip = xfs_iunlink_lookup(sc->sa.pag, agino); in xrep_iunlink_next()
1021 if (!ip) in xrep_iunlink_next()
1024 return ip->i_next_unlinked; in xrep_iunlink_next()
1031 * per-AG inode number.
1039 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_reload_next()
1040 struct xfs_inode *ip; in xrep_iunlink_reload_next() local
1045 ino = XFS_AGINO_TO_INO(sc->mp, sc->sa.pag->pag_agno, agino); in xrep_iunlink_reload_next()
1046 error = xchk_iget(ragi->sc, ino, &ip); in xrep_iunlink_reload_next()
1050 trace_xrep_iunlink_reload_next(ip, prev_agino); in xrep_iunlink_reload_next()
1053 if (VFS_I(ip)->i_nlink != 0) { in xrep_iunlink_reload_next()
1058 ip->i_prev_unlinked = prev_agino; in xrep_iunlink_reload_next()
1059 ret = ip->i_next_unlinked; in xrep_iunlink_reload_next()
1067 xchk_irele(sc, ip); in xrep_iunlink_reload_next()
1081 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_walk_ondisk_bucket()
1082 struct xfs_agi *agi = sc->sa.agi_bp->b_addr; in xrep_iunlink_walk_ondisk_bucket()
1087 next_agino = be32_to_cpu(agi->agi_unlinked[bucket]); in xrep_iunlink_walk_ondisk_bucket()
1091 if (xchk_should_terminate(ragi->sc, &error)) in xrep_iunlink_walk_ondisk_bucket()
1094 trace_xrep_iunlink_walk_ondisk_bucket(sc->sa.pag, bucket, in xrep_iunlink_walk_ondisk_bucket()
1115 struct xfs_inode *ip) in xrep_iunlink_igrab() argument
1117 struct xfs_mount *mp = pag->pag_mount; in xrep_iunlink_igrab()
1119 if (XFS_INO_TO_AGNO(mp, ip->i_ino) != pag->pag_agno) in xrep_iunlink_igrab()
1122 if (!xfs_inode_on_unlinked_list(ip)) in xrep_iunlink_igrab()
1137 struct xfs_mount *mp = ragi->sc->mp; in xrep_iunlink_visit()
1138 struct xfs_inode *ip = ragi->lookup_batch[batch_idx]; in xrep_iunlink_visit() local
1143 ASSERT(XFS_INO_TO_AGNO(mp, ip->i_ino) == ragi->sc->sa.pag->pag_agno); in xrep_iunlink_visit()
1144 ASSERT(xfs_inode_on_unlinked_list(ip)); in xrep_iunlink_visit()
1146 agino = XFS_INO_TO_AGINO(mp, ip->i_ino); in xrep_iunlink_visit()
1149 trace_xrep_iunlink_visit(ragi->sc->sa.pag, bucket, in xrep_iunlink_visit()
1150 ragi->iunlink_heads[bucket], ip); in xrep_iunlink_visit()
1152 error = xagino_bitmap_set(&ragi->iunlink_bmp, agino, 1); in xrep_iunlink_visit()
1156 if (ip->i_prev_unlinked == NULLAGINO) { in xrep_iunlink_visit()
1157 if (ragi->iunlink_heads[bucket] == NULLAGINO) in xrep_iunlink_visit()
1158 ragi->iunlink_heads[bucket] = agino; in xrep_iunlink_visit()
1173 struct xfs_perag *pag = ragi->sc->sa.pag; in xrep_iunlink_mark_incore()
1174 struct xfs_mount *mp = pag->pag_mount; in xrep_iunlink_mark_incore()
1183 if (xchk_should_terminate(ragi->sc, &error)) in xrep_iunlink_mark_incore()
1188 nr_found = radix_tree_gang_lookup(&pag->pag_ici_root, in xrep_iunlink_mark_incore()
1189 (void **)&ragi->lookup_batch, first_index, in xrep_iunlink_mark_incore()
1197 struct xfs_inode *ip = ragi->lookup_batch[i]; in xrep_iunlink_mark_incore() local
1199 if (done || !xrep_iunlink_igrab(pag, ip)) in xrep_iunlink_mark_incore()
1200 ragi->lookup_batch[i] = NULL; in xrep_iunlink_mark_incore()
1214 if (XFS_INO_TO_AGNO(mp, ip->i_ino) != pag->pag_agno) in xrep_iunlink_mark_incore()
1216 first_index = XFS_INO_TO_AGINO(mp, ip->i_ino + 1); in xrep_iunlink_mark_incore()
1217 if (first_index < XFS_INO_TO_AGINO(mp, ip->i_ino)) in xrep_iunlink_mark_incore()
1225 if (!ragi->lookup_batch[i]) in xrep_iunlink_mark_incore()
1245 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_mark_ondisk_rec()
1246 struct xfs_mount *mp = cur->bc_mp; in xrep_iunlink_mark_ondisk_rec()
1256 struct xfs_inode *ip; in xrep_iunlink_mark_ondisk_rec() local
1263 if (xagino_bitmap_test(&ragi->iunlink_bmp, agino, &len)) in xrep_iunlink_mark_ondisk_rec()
1271 ip = radix_tree_lookup(&sc->sa.pag->pag_ici_root, agino); in xrep_iunlink_mark_ondisk_rec()
1273 if (ip) in xrep_iunlink_mark_ondisk_rec()
1281 error = xchk_iget(ragi->sc, in xrep_iunlink_mark_ondisk_rec()
1282 XFS_AGINO_TO_INO(mp, sc->sa.pag->pag_agno, in xrep_iunlink_mark_ondisk_rec()
1284 &ip); in xrep_iunlink_mark_ondisk_rec()
1288 trace_xrep_iunlink_reload_ondisk(ip); in xrep_iunlink_mark_ondisk_rec()
1290 if (VFS_I(ip)->i_nlink == 0) in xrep_iunlink_mark_ondisk_rec()
1291 error = xagino_bitmap_set(&ragi->iunlink_bmp, agino, 1); in xrep_iunlink_mark_ondisk_rec()
1292 xchk_irele(sc, ip); in xrep_iunlink_mark_ondisk_rec()
1309 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_mark_ondisk()
1310 struct xfs_buf *agi_bp = ragi->agi_bp; in xrep_iunlink_mark_ondisk()
1314 cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp); in xrep_iunlink_mark_ondisk()
1329 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_resolve_bucket()
1330 struct xfs_inode *ip; in xrep_iunlink_resolve_bucket() local
1332 xfs_agino_t next_agino = ragi->iunlink_heads[bucket]; in xrep_iunlink_resolve_bucket()
1336 if (xchk_should_terminate(ragi->sc, &error)) in xrep_iunlink_resolve_bucket()
1340 ip = xfs_iunlink_lookup(sc->sa.pag, next_agino); in xrep_iunlink_resolve_bucket()
1341 if (!ip) { in xrep_iunlink_resolve_bucket()
1343 trace_xrep_iunlink_resolve_uncached(sc->sa.pag, in xrep_iunlink_resolve_bucket()
1355 trace_xrep_iunlink_resolve_wronglist(sc->sa.pag, in xrep_iunlink_resolve_bucket()
1358 next_agino = ip->i_next_unlinked; in xrep_iunlink_resolve_bucket()
1362 if (!xfs_inode_on_unlinked_list(ip)) { in xrep_iunlink_resolve_bucket()
1369 trace_xrep_iunlink_resolve_nolist(sc->sa.pag, in xrep_iunlink_resolve_bucket()
1371 next_agino = ip->i_next_unlinked; in xrep_iunlink_resolve_bucket()
1375 trace_xrep_iunlink_resolve_ok(sc->sa.pag, bucket, prev_agino, in xrep_iunlink_resolve_bucket()
1383 error = xagino_bitmap_clear(&ragi->iunlink_bmp, next_agino, 1); in xrep_iunlink_resolve_bucket()
1402 next_agino = ip->i_next_unlinked; in xrep_iunlink_resolve_bucket()
1428 current_head = ragi->iunlink_heads[bucket]; in xrep_iunlink_add_to_bucket()
1430 trace_xrep_iunlink_add_to_bucket(ragi->sc->sa.pag, bucket, agino, in xrep_iunlink_add_to_bucket()
1444 ragi->iunlink_heads[bucket] = agino; in xrep_iunlink_add_to_bucket()
1458 for (; len > 0; start++, len--) { in xrep_iunlink_add_lost_inodes()
1522 return xagino_bitmap_walk(&ragi->iunlink_bmp, in xrep_iunlink_rebuild_buckets()
1533 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_relink_next()
1534 struct xfs_perag *pag = sc->sa.pag; in xrep_iunlink_relink_next()
1535 struct xfs_inode *ip; in xrep_iunlink_relink_next() local
1536 xfarray_idx_t agino = idx - 1; in xrep_iunlink_relink_next()
1540 ip = xfs_iunlink_lookup(pag, agino); in xrep_iunlink_relink_next()
1541 if (!ip) { in xrep_iunlink_relink_next()
1549 ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino); in xrep_iunlink_relink_next()
1550 error = xchk_iget(sc, ino, &ip); in xrep_iunlink_relink_next()
1552 return -EFSCORRUPTED; in xrep_iunlink_relink_next()
1557 error = xfarray_load(ragi->iunlink_prev, agino, &prev_agino); in xrep_iunlink_relink_next()
1561 trace_xrep_iunlink_relink_prev(ip, prev_agino); in xrep_iunlink_relink_next()
1562 ip->i_prev_unlinked = prev_agino; in xrep_iunlink_relink_next()
1566 if (ip->i_next_unlinked != next_agino) { in xrep_iunlink_relink_next()
1567 error = xfs_iunlink_log_inode(sc->tp, ip, pag, next_agino); in xrep_iunlink_relink_next()
1571 trace_xrep_iunlink_relink_next(ip, next_agino); in xrep_iunlink_relink_next()
1572 ip->i_next_unlinked = next_agino; in xrep_iunlink_relink_next()
1582 xchk_irele(sc, ip); in xrep_iunlink_relink_next()
1593 struct xfs_scrub *sc = ragi->sc; in xrep_iunlink_relink_prev()
1594 struct xfs_perag *pag = sc->sa.pag; in xrep_iunlink_relink_prev()
1595 struct xfs_inode *ip; in xrep_iunlink_relink_prev() local
1596 xfarray_idx_t agino = idx - 1; in xrep_iunlink_relink_prev()
1602 ip = xfs_iunlink_lookup(pag, agino); in xrep_iunlink_relink_prev()
1603 if (!ip) { in xrep_iunlink_relink_prev()
1611 ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino); in xrep_iunlink_relink_prev()
1612 error = xchk_iget(sc, ino, &ip); in xrep_iunlink_relink_prev()
1614 return -EFSCORRUPTED; in xrep_iunlink_relink_prev()
1619 error = xfarray_load(ragi->iunlink_prev, agino, &next_agino); in xrep_iunlink_relink_prev()
1623 error = xfs_iunlink_log_inode(sc->tp, ip, pag, next_agino); in xrep_iunlink_relink_prev()
1627 trace_xrep_iunlink_relink_next(ip, next_agino); in xrep_iunlink_relink_prev()
1628 ip->i_next_unlinked = next_agino; in xrep_iunlink_relink_prev()
1632 if (ip->i_prev_unlinked != prev_agino) { in xrep_iunlink_relink_prev()
1633 trace_xrep_iunlink_relink_prev(ip, prev_agino); in xrep_iunlink_relink_prev()
1634 ip->i_prev_unlinked = prev_agino; in xrep_iunlink_relink_prev()
1644 xchk_irele(sc, ip); in xrep_iunlink_relink_prev()
1653 struct xfs_agi *agi = ragi->agi_bp->b_addr; in xrep_iunlink_commit()
1660 while ((error = xfarray_iter(ragi->iunlink_next, &idx, &agino)) == 1) { in xrep_iunlink_commit()
1668 while ((error = xfarray_iter(ragi->iunlink_prev, &idx, &agino)) == 1) { in xrep_iunlink_commit()
1676 trace_xrep_iunlink_commit_bucket(ragi->sc->sa.pag, i, in xrep_iunlink_commit()
1677 be32_to_cpu(ragi->old_agi.agi_unlinked[i]), in xrep_iunlink_commit()
1678 ragi->iunlink_heads[i]); in xrep_iunlink_commit()
1680 agi->agi_unlinked[i] = cpu_to_be32(ragi->iunlink_heads[i]); in xrep_iunlink_commit()
1686 /* Trigger reinitialization of the in-core data. */
1691 struct xfs_scrub *sc = ragi->sc; in xrep_agi_commit_new()
1692 struct xfs_buf *agi_bp = ragi->agi_bp; in xrep_agi_commit_new()
1694 struct xfs_agi *agi = agi_bp->b_addr; in xrep_agi_commit_new()
1697 xfs_force_summary_recalc(sc->mp); in xrep_agi_commit_new()
1700 xfs_trans_buf_set_type(sc->tp, agi_bp, XFS_BLFT_AGI_BUF); in xrep_agi_commit_new()
1701 xfs_trans_log_buf(sc->tp, agi_bp, 0, BBTOB(agi_bp->b_length) - 1); in xrep_agi_commit_new()
1703 /* Now reinitialize the in-core counters if necessary. */ in xrep_agi_commit_new()
1704 pag = sc->sa.pag; in xrep_agi_commit_new()
1705 pag->pagi_count = be32_to_cpu(agi->agi_count); in xrep_agi_commit_new()
1706 pag->pagi_freecount = be32_to_cpu(agi->agi_freecount); in xrep_agi_commit_new()
1707 set_bit(XFS_AGSTATE_AGI_INIT, &pag->pag_opstate); in xrep_agi_commit_new()
1718 struct xfs_mount *mp = sc->mp; in xrep_agi()
1725 return -EOPNOTSUPP; in xrep_agi()
1727 sc->buf = kzalloc(sizeof(struct xrep_agi), XCHK_GFP_FLAGS); in xrep_agi()
1728 if (!sc->buf) in xrep_agi()
1729 return -ENOMEM; in xrep_agi()
1730 ragi = sc->buf; in xrep_agi()
1731 ragi->sc = sc; in xrep_agi()
1733 ragi->fab[XREP_AGI_INOBT] = (struct xrep_find_ag_btree){ in xrep_agi()
1736 .maxlevels = M_IGEO(sc->mp)->inobt_maxlevels, in xrep_agi()
1738 ragi->fab[XREP_AGI_FINOBT] = (struct xrep_find_ag_btree){ in xrep_agi()
1741 .maxlevels = M_IGEO(sc->mp)->inobt_maxlevels, in xrep_agi()
1743 ragi->fab[XREP_AGI_END] = (struct xrep_find_ag_btree){ in xrep_agi()
1748 ragi->iunlink_heads[i] = NULLAGINO; in xrep_agi()
1750 xagino_bitmap_init(&ragi->iunlink_bmp); in xrep_agi()
1751 sc->buf_cleanup = xrep_agi_buf_cleanup; in xrep_agi()
1755 &ragi->iunlink_next); in xrep_agi()
1762 &ragi->iunlink_prev); in xrep_agi()
1769 * was corrupt after xfs_ialloc_read_agi failed with -EFSCORRUPTED. in xrep_agi()
1771 error = xfs_trans_read_buf(mp, sc->tp, mp->m_ddev_targp, in xrep_agi()
1772 XFS_AG_DADDR(mp, sc->sa.pag->pag_agno, in xrep_agi()
1774 XFS_FSS_TO_BB(mp, 1), 0, &ragi->agi_bp, NULL); in xrep_agi()
1777 ragi->agi_bp->b_ops = &xfs_agi_buf_ops; in xrep_agi()
1802 /* Reinitialize in-core state. */ in xrep_agi()
1807 clear_bit(XFS_AGSTATE_AGI_INIT, &sc->sa.pag->pag_opstate); in xrep_agi()
1808 memcpy(ragi->agi_bp->b_addr, &ragi->old_agi, sizeof(struct xfs_agi)); in xrep_agi()