Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0+
46 * For non-verifier errors (e.g. ENOMEM) we return false to tell the
75 case -EDEADLOCK: in __xchk_process_error()
77 trace_xchk_deadlock_retry(sc->ip, sc->sm, *error); in __xchk_process_error()
79 case -EFSBADCRC: in __xchk_process_error()
80 case -EFSCORRUPTED: in __xchk_process_error()
82 sc->sm->sm_flags |= errflag; in __xchk_process_error()
128 case -EDEADLOCK: in __xchk_fblock_process_error()
130 trace_xchk_deadlock_retry(sc->ip, sc->sm, *error); in __xchk_fblock_process_error()
132 case -EFSBADCRC: in __xchk_fblock_process_error()
133 case -EFSCORRUPTED: in __xchk_fblock_process_error()
135 sc->sm->sm_flags |= errflag; in __xchk_fblock_process_error()
186 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN; in xchk_block_set_preen()
187 trace_xchk_block_preen(sc, bp->b_bn, __return_address); in xchk_block_set_preen()
200 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN; in xchk_ino_set_preen()
209 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT; in xchk_set_corrupt()
219 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT; in xchk_block_set_corrupt()
220 trace_xchk_block_error(sc, bp->b_bn, __return_address); in xchk_block_set_corrupt()
223 /* Record a corruption while cross-referencing. */
229 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT; in xchk_block_xref_set_corrupt()
230 trace_xchk_block_error(sc, bp->b_bn, __return_address); in xchk_block_xref_set_corrupt()
243 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT; in xchk_ino_set_corrupt()
247 /* Record a corruption while cross-referencing with an inode. */
253 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT; in xchk_ino_xref_set_corrupt()
264 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT; in xchk_fblock_set_corrupt()
268 /* Record a corruption while cross-referencing a fork block. */
275 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT; in xchk_fblock_xref_set_corrupt()
288 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING; in xchk_ino_set_warning()
299 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING; in xchk_fblock_set_warning()
308 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_INCOMPLETE; in xchk_set_incomplete()
313 * rmap scrubbing -- compute the number of blocks with a given owner,
319 xfs_filblks_t *blocks; member
332 irec_attr = rec->rm_flags & XFS_RMAP_ATTR_FORK; in xchk_count_rmap_ownedby_irec()
333 oinfo_attr = sroi->oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK; in xchk_count_rmap_ownedby_irec()
335 if (rec->rm_owner != sroi->oinfo->oi_owner) in xchk_count_rmap_ownedby_irec()
338 if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || irec_attr == oinfo_attr) in xchk_count_rmap_ownedby_irec()
339 (*sroi->blocks) += rec->rm_blockcount; in xchk_count_rmap_ownedby_irec()
345 * Calculate the number of blocks the rmap thinks are owned by something.
353 xfs_filblks_t *blocks) in xchk_count_rmap_ownedby_ag() argument
357 .blocks = blocks, in xchk_count_rmap_ownedby_ag()
360 *blocks = 0; in xchk_count_rmap_ownedby_ag()
380 if (sc->sm->sm_type != XFS_SCRUB_TYPE_AGF && in want_ag_read_header_failure()
381 sc->sm->sm_type != XFS_SCRUB_TYPE_AGFL && in want_ag_read_header_failure()
382 sc->sm->sm_type != XFS_SCRUB_TYPE_AGI) in want_ag_read_header_failure()
387 * other headers to cross-check them, but this isn't required. in want_ag_read_header_failure()
389 if (sc->sm->sm_type == type) in want_ag_read_header_failure()
409 struct xfs_mount *mp = sc->mp; in xchk_ag_read_headers()
412 error = xfs_ialloc_read_agi(mp, sc->tp, agno, agi); in xchk_ag_read_headers()
416 error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, agf); in xchk_ag_read_headers()
420 error = xfs_alloc_read_agfl(mp, sc->tp, agno, agfl); in xchk_ag_read_headers()
433 if (sa->refc_cur) in xchk_ag_btcur_free()
434 xfs_btree_del_cursor(sa->refc_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
435 if (sa->rmap_cur) in xchk_ag_btcur_free()
436 xfs_btree_del_cursor(sa->rmap_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
437 if (sa->fino_cur) in xchk_ag_btcur_free()
438 xfs_btree_del_cursor(sa->fino_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
439 if (sa->ino_cur) in xchk_ag_btcur_free()
440 xfs_btree_del_cursor(sa->ino_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
441 if (sa->cnt_cur) in xchk_ag_btcur_free()
442 xfs_btree_del_cursor(sa->cnt_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
443 if (sa->bno_cur) in xchk_ag_btcur_free()
444 xfs_btree_del_cursor(sa->bno_cur, XFS_BTREE_ERROR); in xchk_ag_btcur_free()
446 sa->refc_cur = NULL; in xchk_ag_btcur_free()
447 sa->rmap_cur = NULL; in xchk_ag_btcur_free()
448 sa->fino_cur = NULL; in xchk_ag_btcur_free()
449 sa->ino_cur = NULL; in xchk_ag_btcur_free()
450 sa->bno_cur = NULL; in xchk_ag_btcur_free()
451 sa->cnt_cur = NULL; in xchk_ag_btcur_free()
460 struct xfs_mount *mp = sc->mp; in xchk_ag_btcur_init()
461 xfs_agnumber_t agno = sa->agno; in xchk_ag_btcur_init()
463 xchk_perag_get(sc->mp, sa); in xchk_ag_btcur_init()
464 if (sa->agf_bp && in xchk_ag_btcur_init()
465 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_BNO)) { in xchk_ag_btcur_init()
466 /* Set up a bnobt cursor for cross-referencing. */ in xchk_ag_btcur_init()
467 sa->bno_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp, in xchk_ag_btcur_init()
469 if (!sa->bno_cur) in xchk_ag_btcur_init()
473 if (sa->agf_bp && in xchk_ag_btcur_init()
474 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_CNT)) { in xchk_ag_btcur_init()
475 /* Set up a cntbt cursor for cross-referencing. */ in xchk_ag_btcur_init()
476 sa->cnt_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp, in xchk_ag_btcur_init()
478 if (!sa->cnt_cur) in xchk_ag_btcur_init()
482 /* Set up a inobt cursor for cross-referencing. */ in xchk_ag_btcur_init()
483 if (sa->agi_bp && in xchk_ag_btcur_init()
484 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_INO)) { in xchk_ag_btcur_init()
485 sa->ino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp, in xchk_ag_btcur_init()
487 if (!sa->ino_cur) in xchk_ag_btcur_init()
491 /* Set up a finobt cursor for cross-referencing. */ in xchk_ag_btcur_init()
492 if (sa->agi_bp && xfs_sb_version_hasfinobt(&mp->m_sb) && in xchk_ag_btcur_init()
493 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_FINO)) { in xchk_ag_btcur_init()
494 sa->fino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp, in xchk_ag_btcur_init()
496 if (!sa->fino_cur) in xchk_ag_btcur_init()
500 /* Set up a rmapbt cursor for cross-referencing. */ in xchk_ag_btcur_init()
501 if (sa->agf_bp && xfs_sb_version_hasrmapbt(&mp->m_sb) && in xchk_ag_btcur_init()
502 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_RMAP)) { in xchk_ag_btcur_init()
503 sa->rmap_cur = xfs_rmapbt_init_cursor(mp, sc->tp, sa->agf_bp, in xchk_ag_btcur_init()
505 if (!sa->rmap_cur) in xchk_ag_btcur_init()
509 /* Set up a refcountbt cursor for cross-referencing. */ in xchk_ag_btcur_init()
510 if (sa->agf_bp && xfs_sb_version_hasreflink(&mp->m_sb) && in xchk_ag_btcur_init()
511 xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_REFC)) { in xchk_ag_btcur_init()
512 sa->refc_cur = xfs_refcountbt_init_cursor(mp, sc->tp, in xchk_ag_btcur_init()
513 sa->agf_bp, agno); in xchk_ag_btcur_init()
514 if (!sa->refc_cur) in xchk_ag_btcur_init()
520 return -ENOMEM; in xchk_ag_btcur_init()
530 if (sa->agfl_bp) { in xchk_ag_free()
531 xfs_trans_brelse(sc->tp, sa->agfl_bp); in xchk_ag_free()
532 sa->agfl_bp = NULL; in xchk_ag_free()
534 if (sa->agf_bp) { in xchk_ag_free()
535 xfs_trans_brelse(sc->tp, sa->agf_bp); in xchk_ag_free()
536 sa->agf_bp = NULL; in xchk_ag_free()
538 if (sa->agi_bp) { in xchk_ag_free()
539 xfs_trans_brelse(sc->tp, sa->agi_bp); in xchk_ag_free()
540 sa->agi_bp = NULL; in xchk_ag_free()
542 if (sa->pag) { in xchk_ag_free()
543 xfs_perag_put(sa->pag); in xchk_ag_free()
544 sa->pag = NULL; in xchk_ag_free()
546 sa->agno = NULLAGNUMBER; in xchk_ag_free()
564 sa->agno = agno; in xchk_ag_init()
565 error = xchk_ag_read_headers(sc, agno, &sa->agi_bp, in xchk_ag_init()
566 &sa->agf_bp, &sa->agfl_bp); in xchk_ag_init()
574 * Grab the per-ag structure if we haven't already gotten it. Teardown of the
582 if (!sa->pag) in xchk_perag_get()
583 sa->pag = xfs_perag_get(mp, sa->agno); in xchk_perag_get()
586 /* Per-scrubber setup functions */
589 * Grab an empty transaction so that we can re-grab locked buffers if
595 * blocks in the head transaction as we think we're going to need to rebuild
603 if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) in xchk_trans_alloc()
604 return xfs_trans_alloc(sc->mp, &M_RES(sc->mp)->tr_itruncate, in xchk_trans_alloc()
605 resblks, 0, 0, &sc->tp); in xchk_trans_alloc()
607 return xfs_trans_alloc_empty(sc->mp, &sc->tp); in xchk_trans_alloc()
614 struct xfs_inode *ip) in xchk_setup_fs() argument
626 struct xfs_inode *ip, in xchk_setup_ag_btree() argument
629 struct xfs_mount *mp = sc->mp; in xchk_setup_ag_btree()
644 error = xchk_setup_fs(sc, ip); in xchk_setup_ag_btree()
648 return xchk_ag_init(sc, sc->sm->sm_agno, &sc->sa); in xchk_setup_ag_btree()
661 xfs_ail_push_all_sync(mp->m_ail); in xchk_checkpoint_log()
676 struct xfs_mount *mp = sc->mp; in xchk_get_inode()
677 struct xfs_inode *ip = NULL; in xchk_get_inode() local
681 if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) { in xchk_get_inode()
682 sc->ip = ip_in; in xchk_get_inode()
687 if (xfs_internal_inum(mp, sc->sm->sm_ino)) in xchk_get_inode()
688 return -ENOENT; in xchk_get_inode()
689 error = xfs_iget(mp, NULL, sc->sm->sm_ino, in xchk_get_inode()
690 XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &ip); in xchk_get_inode()
692 case -ENOENT: in xchk_get_inode()
698 case -EINVAL: in xchk_get_inode()
700 * -EINVAL with IGET_UNTRUSTED could mean one of several in xchk_get_inode()
706 * Try just the inode mapping lookup -- if it succeeds, then in xchk_get_inode()
711 error = xfs_imap(sc->mp, sc->tp, sc->sm->sm_ino, &imap, in xchk_get_inode()
714 return -ENOENT; in xchk_get_inode()
715 error = -EFSCORRUPTED; in xchk_get_inode()
719 XFS_INO_TO_AGNO(mp, sc->sm->sm_ino), in xchk_get_inode()
720 XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino), in xchk_get_inode()
724 if (VFS_I(ip)->i_generation != sc->sm->sm_gen) { in xchk_get_inode()
725 xfs_irele(ip); in xchk_get_inode()
726 return -ENOENT; in xchk_get_inode()
729 sc->ip = ip; in xchk_get_inode()
737 struct xfs_inode *ip, in xchk_setup_inode_contents() argument
742 error = xchk_get_inode(sc, ip); in xchk_setup_inode_contents()
747 sc->ilock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL; in xchk_setup_inode_contents()
748 xfs_ilock(sc->ip, sc->ilock_flags); in xchk_setup_inode_contents()
752 sc->ilock_flags |= XFS_ILOCK_EXCL; in xchk_setup_inode_contents()
753 xfs_ilock(sc->ip, XFS_ILOCK_EXCL); in xchk_setup_inode_contents()
761 * Predicate that decides if we need to evaluate the cross-reference check.
762 * If there was an error accessing the cross-reference btree, just delete
772 if (xchk_skip_xref(sc->sm)) in xchk_should_check_xref()
788 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XFAIL; in xchk_should_check_xref()
792 * Errors encountered during cross-referencing with another in xchk_should_check_xref()
799 /* Run the structure verifiers on in-memory buffers to detect bad memory. */
807 if (bp->b_ops == NULL) { in xchk_buffer_recheck()
811 if (bp->b_ops->verify_struct == NULL) { in xchk_buffer_recheck()
815 fa = bp->b_ops->verify_struct(bp); in xchk_buffer_recheck()
818 sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT; in xchk_buffer_recheck()
819 trace_xchk_block_error(sc, bp->b_bn, fa); in xchk_buffer_recheck()
824 * pointed to by sc->ip and the ILOCK must be held.
834 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_metadata_inode_forks()
838 if (sc->ip->i_d.di_flags & XFS_DIFLAG_REALTIME) { in xchk_metadata_inode_forks()
839 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_metadata_inode_forks()
844 if (xfs_is_reflink_inode(sc->ip)) { in xchk_metadata_inode_forks()
845 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_metadata_inode_forks()
850 if (xfs_inode_hasattr(sc->ip)) { in xchk_metadata_inode_forks()
851 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_metadata_inode_forks()
856 smtype = sc->sm->sm_type; in xchk_metadata_inode_forks()
857 sc->sm->sm_type = XFS_SCRUB_TYPE_BMBTD; in xchk_metadata_inode_forks()
859 sc->sm->sm_type = smtype; in xchk_metadata_inode_forks()
860 if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) in xchk_metadata_inode_forks()
863 /* Look for incorrect shared blocks. */ in xchk_metadata_inode_forks()
864 if (xfs_sb_version_hasreflink(&sc->mp->m_sb)) { in xchk_metadata_inode_forks()
865 error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip, in xchk_metadata_inode_forks()
871 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_metadata_inode_forks()
880 * plain breaking AG-order or inode-order inode locking rules. Either way,
886 struct xfs_inode *ip, in xchk_ilock_inverted() argument
892 if (xfs_ilock_nowait(ip, lock_mode)) in xchk_ilock_inverted()
896 return -EDEADLOCK; in xchk_ilock_inverted()
904 sc->flags |= XCHK_REAPING_DISABLED; in xchk_stop_reaping()
905 xfs_stop_block_reaping(sc->mp); in xchk_stop_reaping()
913 xfs_start_block_reaping(sc->mp); in xchk_start_reaping()
914 sc->flags &= ~XCHK_REAPING_DISABLED; in xchk_start_reaping()