0001
0002
0003
0004
0005
0006 #include "xfs.h"
0007 #include "xfs_fs.h"
0008 #include "xfs_shared.h"
0009 #include "xfs_format.h"
0010 #include "xfs_trans_resv.h"
0011 #include "xfs_mount.h"
0012 #include "xfs_btree.h"
0013 #include "xfs_alloc.h"
0014 #include "xfs_rmap.h"
0015 #include "scrub/scrub.h"
0016 #include "scrub/common.h"
0017 #include "scrub/btree.h"
0018 #include "xfs_ag.h"
0019
0020
0021
0022
0023 int
0024 xchk_setup_ag_allocbt(
0025 struct xfs_scrub *sc)
0026 {
0027 return xchk_setup_ag_btree(sc, false);
0028 }
0029
0030
0031
0032
0033
0034
0035 STATIC void
0036 xchk_allocbt_xref_other(
0037 struct xfs_scrub *sc,
0038 xfs_agblock_t agbno,
0039 xfs_extlen_t len)
0040 {
0041 struct xfs_btree_cur **pcur;
0042 xfs_agblock_t fbno;
0043 xfs_extlen_t flen;
0044 int has_otherrec;
0045 int error;
0046
0047 if (sc->sm->sm_type == XFS_SCRUB_TYPE_BNOBT)
0048 pcur = &sc->sa.cnt_cur;
0049 else
0050 pcur = &sc->sa.bno_cur;
0051 if (!*pcur || xchk_skip_xref(sc->sm))
0052 return;
0053
0054 error = xfs_alloc_lookup_le(*pcur, agbno, len, &has_otherrec);
0055 if (!xchk_should_check_xref(sc, &error, pcur))
0056 return;
0057 if (!has_otherrec) {
0058 xchk_btree_xref_set_corrupt(sc, *pcur, 0);
0059 return;
0060 }
0061
0062 error = xfs_alloc_get_rec(*pcur, &fbno, &flen, &has_otherrec);
0063 if (!xchk_should_check_xref(sc, &error, pcur))
0064 return;
0065 if (!has_otherrec) {
0066 xchk_btree_xref_set_corrupt(sc, *pcur, 0);
0067 return;
0068 }
0069
0070 if (fbno != agbno || flen != len)
0071 xchk_btree_xref_set_corrupt(sc, *pcur, 0);
0072 }
0073
0074
0075 STATIC void
0076 xchk_allocbt_xref(
0077 struct xfs_scrub *sc,
0078 xfs_agblock_t agbno,
0079 xfs_extlen_t len)
0080 {
0081 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
0082 return;
0083
0084 xchk_allocbt_xref_other(sc, agbno, len);
0085 xchk_xref_is_not_inode_chunk(sc, agbno, len);
0086 xchk_xref_has_no_owner(sc, agbno, len);
0087 xchk_xref_is_not_shared(sc, agbno, len);
0088 }
0089
0090
0091 STATIC int
0092 xchk_allocbt_rec(
0093 struct xchk_btree *bs,
0094 const union xfs_btree_rec *rec)
0095 {
0096 struct xfs_perag *pag = bs->cur->bc_ag.pag;
0097 xfs_agblock_t bno;
0098 xfs_extlen_t len;
0099
0100 bno = be32_to_cpu(rec->alloc.ar_startblock);
0101 len = be32_to_cpu(rec->alloc.ar_blockcount);
0102
0103 if (bno + len <= bno ||
0104 !xfs_verify_agbno(pag, bno) ||
0105 !xfs_verify_agbno(pag, bno + len - 1))
0106 xchk_btree_set_corrupt(bs->sc, bs->cur, 0);
0107
0108 xchk_allocbt_xref(bs->sc, bno, len);
0109
0110 return 0;
0111 }
0112
0113
0114 STATIC int
0115 xchk_allocbt(
0116 struct xfs_scrub *sc,
0117 xfs_btnum_t which)
0118 {
0119 struct xfs_btree_cur *cur;
0120
0121 cur = which == XFS_BTNUM_BNO ? sc->sa.bno_cur : sc->sa.cnt_cur;
0122 return xchk_btree(sc, cur, xchk_allocbt_rec, &XFS_RMAP_OINFO_AG, NULL);
0123 }
0124
0125 int
0126 xchk_bnobt(
0127 struct xfs_scrub *sc)
0128 {
0129 return xchk_allocbt(sc, XFS_BTNUM_BNO);
0130 }
0131
0132 int
0133 xchk_cntbt(
0134 struct xfs_scrub *sc)
0135 {
0136 return xchk_allocbt(sc, XFS_BTNUM_CNT);
0137 }
0138
0139
0140 void
0141 xchk_xref_is_used_space(
0142 struct xfs_scrub *sc,
0143 xfs_agblock_t agbno,
0144 xfs_extlen_t len)
0145 {
0146 bool is_freesp;
0147 int error;
0148
0149 if (!sc->sa.bno_cur || xchk_skip_xref(sc->sm))
0150 return;
0151
0152 error = xfs_alloc_has_record(sc->sa.bno_cur, agbno, len, &is_freesp);
0153 if (!xchk_should_check_xref(sc, &error, &sc->sa.bno_cur))
0154 return;
0155 if (is_freesp)
0156 xchk_btree_xref_set_corrupt(sc, sc->sa.bno_cur, 0);
0157 }