|
13 | 13 | #include "xfs_alloc.h"
|
14 | 14 | #include "xfs_ialloc.h"
|
15 | 15 | #include "xfs_health.h"
|
| 16 | +#include "xfs_btree.h" |
16 | 17 | #include "scrub/scrub.h"
|
17 | 18 | #include "scrub/common.h"
|
18 | 19 | #include "scrub/trace.h"
|
@@ -143,6 +144,35 @@ xchk_setup_fscounters(
|
143 | 144 | return xchk_trans_alloc(sc, 0);
|
144 | 145 | }
|
145 | 146 |
|
| 147 | +/* Count free space btree blocks manually for pre-lazysbcount filesystems. */ |
| 148 | +static int |
| 149 | +xchk_fscount_btreeblks( |
| 150 | + struct xfs_scrub *sc, |
| 151 | + struct xchk_fscounters *fsc, |
| 152 | + xfs_agnumber_t agno) |
| 153 | +{ |
| 154 | + xfs_extlen_t blocks; |
| 155 | + int error; |
| 156 | + |
| 157 | + error = xchk_ag_init(sc, agno, &sc->sa); |
| 158 | + if (error) |
| 159 | + return error; |
| 160 | + |
| 161 | + error = xfs_btree_count_blocks(sc->sa.bno_cur, &blocks); |
| 162 | + if (error) |
| 163 | + goto out_free; |
| 164 | + fsc->fdblocks += blocks - 1; |
| 165 | + |
| 166 | + error = xfs_btree_count_blocks(sc->sa.cnt_cur, &blocks); |
| 167 | + if (error) |
| 168 | + goto out_free; |
| 169 | + fsc->fdblocks += blocks - 1; |
| 170 | + |
| 171 | +out_free: |
| 172 | + xchk_ag_free(sc, &sc->sa); |
| 173 | + return error; |
| 174 | +} |
| 175 | + |
146 | 176 | /*
|
147 | 177 | * Calculate what the global in-core counters ought to be from the incore
|
148 | 178 | * per-AG structure. Callers can compare this to the actual in-core counters
|
@@ -182,8 +212,15 @@ xchk_fscount_aggregate_agcounts(
|
182 | 212 | /* Add up the free/freelist/bnobt/cntbt blocks */
|
183 | 213 | fsc->fdblocks += pag->pagf_freeblks;
|
184 | 214 | fsc->fdblocks += pag->pagf_flcount;
|
185 |
| - if (xfs_sb_version_haslazysbcount(&sc->mp->m_sb)) |
| 215 | + if (xfs_sb_version_haslazysbcount(&sc->mp->m_sb)) { |
186 | 216 | fsc->fdblocks += pag->pagf_btreeblks;
|
| 217 | + } else { |
| 218 | + error = xchk_fscount_btreeblks(sc, fsc, agno); |
| 219 | + if (error) { |
| 220 | + xfs_perag_put(pag); |
| 221 | + break; |
| 222 | + } |
| 223 | + } |
187 | 224 |
|
188 | 225 | /*
|
189 | 226 | * Per-AG reservations are taken out of the incore counters,
|
|
0 commit comments