Lines Matching +full:up +full:- +full:counter

1 // SPDX-License-Identifier: GPL-2.0+
25 * The basics of filesystem summary counter checking are that we iterate the
26 * AGs counting the number of free blocks, free space btree blocks, per-AG
28 * Then we compare what we computed against the in-core counters.
33 * freezing is costly. To get around this, we added a per-cpu counter of the
38 * So the first thing we do is warm up the buffer cache in the setup routine by
39 * walking all the AGs to make sure the incore per-AG structure has been
40 * initialized. The expected value calculation then iterates the incore per-AG
42 * after this operation and use the difference in counter values to guess at
43 * our tolerance for mismatch between expected and actual counter values.
54 * Make sure the per-AG structure has been initialized from the on-disk header
67 struct xfs_mount *mp = sc->mp; in xchk_fscount_warmup()
77 if (pag->pagi_init && pag->pagf_init) in xchk_fscount_warmup()
81 error = xfs_ialloc_read_agi(pag, sc->tp, &agi_bp); in xchk_fscount_warmup()
84 error = xfs_alloc_read_agf(pag, sc->tp, 0, &agf_bp); in xchk_fscount_warmup()
92 if (!pag->pagi_init || !pag->pagf_init) { in xchk_fscount_warmup()
93 error = -EFSCORRUPTED; in xchk_fscount_warmup()
119 sc->buf = kmem_zalloc(sizeof(struct xchk_fscounters), 0); in xchk_setup_fscounters()
120 if (!sc->buf) in xchk_setup_fscounters()
121 return -ENOMEM; in xchk_setup_fscounters()
122 fsc = sc->buf; in xchk_setup_fscounters()
124 xfs_icount_range(sc->mp, &fsc->icount_min, &fsc->icount_max); in xchk_setup_fscounters()
126 /* We must get the incore counters set up before we can proceed. */ in xchk_setup_fscounters()
141 /* Count free space btree blocks manually for pre-lazysbcount filesystems. */
151 error = xchk_ag_init_existing(sc, agno, &sc->sa); in xchk_fscount_btreeblks()
155 error = xfs_btree_count_blocks(sc->sa.bno_cur, &blocks); in xchk_fscount_btreeblks()
158 fsc->fdblocks += blocks - 1; in xchk_fscount_btreeblks()
160 error = xfs_btree_count_blocks(sc->sa.cnt_cur, &blocks); in xchk_fscount_btreeblks()
163 fsc->fdblocks += blocks - 1; in xchk_fscount_btreeblks()
166 xchk_ag_free(sc, &sc->sa); in xchk_fscount_btreeblks()
171 * Calculate what the global in-core counters ought to be from the incore
172 * per-AG structure. Callers can compare this to the actual in-core counters
173 * to estimate by how much both in-core and on-disk counters need to be
181 struct xfs_mount *mp = sc->mp; in xchk_fscount_aggregate_agcounts()
189 fsc->icount = 0; in xchk_fscount_aggregate_agcounts()
190 fsc->ifree = 0; in xchk_fscount_aggregate_agcounts()
191 fsc->fdblocks = 0; in xchk_fscount_aggregate_agcounts()
198 if (!pag->pagi_init || !pag->pagf_init) { in xchk_fscount_aggregate_agcounts()
199 error = -EFSCORRUPTED; in xchk_fscount_aggregate_agcounts()
204 fsc->icount += pag->pagi_count; in xchk_fscount_aggregate_agcounts()
205 fsc->ifree += pag->pagi_freecount; in xchk_fscount_aggregate_agcounts()
207 /* Add up the free/freelist/bnobt/cntbt blocks */ in xchk_fscount_aggregate_agcounts()
208 fsc->fdblocks += pag->pagf_freeblks; in xchk_fscount_aggregate_agcounts()
209 fsc->fdblocks += pag->pagf_flcount; in xchk_fscount_aggregate_agcounts()
210 if (xfs_has_lazysbcount(sc->mp)) { in xchk_fscount_aggregate_agcounts()
211 fsc->fdblocks += pag->pagf_btreeblks; in xchk_fscount_aggregate_agcounts()
219 * Per-AG reservations are taken out of the incore counters, in xchk_fscount_aggregate_agcounts()
222 fsc->fdblocks -= pag->pag_meta_resv.ar_reserved; in xchk_fscount_aggregate_agcounts()
223 fsc->fdblocks -= pag->pag_rmapbt_resv.ar_orig_reserved; in xchk_fscount_aggregate_agcounts()
235 fsc->fdblocks -= mp->m_resblks_avail; in xchk_fscount_aggregate_agcounts()
242 delayed = percpu_counter_sum(&mp->m_delalloc_blks); in xchk_fscount_aggregate_agcounts()
243 fsc->fdblocks -= delayed; in xchk_fscount_aggregate_agcounts()
245 trace_xchk_fscounters_calc(mp, fsc->icount, fsc->ifree, fsc->fdblocks, in xchk_fscount_aggregate_agcounts()
250 if (fsc->icount < fsc->icount_min || fsc->icount > fsc->icount_max || in xchk_fscount_aggregate_agcounts()
251 fsc->fdblocks > mp->m_sb.sb_dblocks || in xchk_fscount_aggregate_agcounts()
252 fsc->ifree > fsc->icount_max) in xchk_fscount_aggregate_agcounts()
253 return -EFSCORRUPTED; in xchk_fscount_aggregate_agcounts()
258 * to maintain ifree <= icount before giving up. in xchk_fscount_aggregate_agcounts()
260 if (fsc->ifree > fsc->icount) { in xchk_fscount_aggregate_agcounts()
261 if (tries--) in xchk_fscount_aggregate_agcounts()
271 * Is the @counter reasonably close to the @expected value?
274 * per-AG data to compute the @expected value, which means that the counter
275 * could have changed. We know the @old_value of the summation of the counter
276 * before the aggregation, and we re-sum the counter now. If the expected
287 struct percpu_counter *counter, in xchk_fscount_within_range() argument
291 int64_t curr_value = percpu_counter_sum(counter); in xchk_fscount_within_range()
293 trace_xchk_fscounters_within_range(sc->mp, expected, curr_value, in xchk_fscount_within_range()
307 /* Within the before-and-after range is ok. */ in xchk_fscount_within_range()
314 * true here so that we don't mark the counter corrupt. in xchk_fscount_within_range()
318 * check should be moved up and the return code changed to signal to in xchk_fscount_within_range()
321 if (max_value - min_value >= XCHK_FSCOUNT_MIN_VARIANCE) { in xchk_fscount_within_range()
334 struct xfs_mount *mp = sc->mp; in xchk_fscounters()
335 struct xchk_fscounters *fsc = sc->buf; in xchk_fscounters()
340 icount = percpu_counter_sum(&mp->m_icount); in xchk_fscounters()
341 ifree = percpu_counter_sum(&mp->m_ifree); in xchk_fscounters()
342 fdblocks = percpu_counter_sum(&mp->m_fdblocks); in xchk_fscounters()
349 if (icount < fsc->icount_min || icount > fsc->icount_max) in xchk_fscounters()
353 if (fdblocks > mp->m_sb.sb_dblocks) in xchk_fscounters()
360 if (ifree > icount && ifree - icount > XCHK_FSCOUNT_MIN_VARIANCE) in xchk_fscounters()
367 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE) in xchk_fscounters()
370 /* Compare the in-core counters with whatever we counted. */ in xchk_fscounters()
371 if (!xchk_fscount_within_range(sc, icount, &mp->m_icount, fsc->icount)) in xchk_fscounters()
374 if (!xchk_fscount_within_range(sc, ifree, &mp->m_ifree, fsc->ifree)) in xchk_fscounters()
377 if (!xchk_fscount_within_range(sc, fdblocks, &mp->m_fdblocks, in xchk_fscounters()
378 fsc->fdblocks)) in xchk_fscounters()