Lines Matching +full:summation +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2019-2023 Oracle. All Rights Reserved.
33 * AGs counting the number of free blocks, free space btree blocks, per-AG
35 * Then we compare what we computed against the in-core counters.
40 * freezing is costly. To get around this, we added a per-cpu counter of the
46 * walking all the AGs to make sure the incore per-AG structure has been
47 * initialized. The expected value calculation then iterates the incore per-AG
61 * Make sure the per-AG structure has been initialized from the on-disk header
74 struct xfs_mount *mp = sc->mp; in xchk_fscount_warmup()
88 error = xfs_ialloc_read_agi(pag, sc->tp, 0, &agi_bp); in xchk_fscount_warmup()
91 error = xfs_alloc_read_agf(pag, sc->tp, 0, &agf_bp); in xchk_fscount_warmup()
101 error = -EFSCORRUPTED; in xchk_fscount_warmup()
126 error = freeze_super(sc->mp->m_super, FREEZE_HOLDER_KERNEL); in xchk_fsfreeze()
138 error = thaw_super(sc->mp->m_super, FREEZE_HOLDER_KERNEL); in xchk_fsthaw()
146 * We need to disable all writer threads, which means taking the first two
155 struct xchk_fscounters *fsc = sc->buf; in xchk_fscounters_freeze()
158 if (sc->flags & XCHK_HAVE_FREEZE_PROT) { in xchk_fscounters_freeze()
159 sc->flags &= ~XCHK_HAVE_FREEZE_PROT; in xchk_fscounters_freeze()
160 mnt_drop_write_file(sc->file); in xchk_fscounters_freeze()
164 while ((error = xchk_fsfreeze(sc)) == -EBUSY) { in xchk_fscounters_freeze()
173 fsc->frozen = true; in xchk_fscounters_freeze()
183 struct xfs_scrub *sc = fsc->sc; in xchk_fscounters_cleanup()
186 if (!fsc->frozen) in xchk_fscounters_cleanup()
191 xfs_emerg(sc->mp, "still frozen after scrub, err=%d", error); in xchk_fscounters_cleanup()
193 fsc->frozen = false; in xchk_fscounters_cleanup()
207 if (!xfs_has_lazysbcount(sc->mp)) in xchk_setup_fscounters()
210 sc->buf = kzalloc(sizeof(struct xchk_fscounters), XCHK_GFP_FLAGS); in xchk_setup_fscounters()
211 if (!sc->buf) in xchk_setup_fscounters()
212 return -ENOMEM; in xchk_setup_fscounters()
213 sc->buf_cleanup = xchk_fscounters_cleanup; in xchk_setup_fscounters()
214 fsc = sc->buf; in xchk_setup_fscounters()
215 fsc->sc = sc; in xchk_setup_fscounters()
217 xfs_icount_range(sc->mp, &fsc->icount_min, &fsc->icount_max); in xchk_setup_fscounters()
231 * This requires the fs to be frozen, which will disable background in xchk_setup_fscounters()
234 if ((sc->flags & XCHK_TRY_HARDER) || xchk_could_repair(sc)) { in xchk_setup_fscounters()
257 /* Count free space btree blocks manually for pre-lazysbcount filesystems. */
267 error = xchk_ag_init_existing(sc, agno, &sc->sa); in xchk_fscount_btreeblks()
271 error = xfs_btree_count_blocks(sc->sa.bno_cur, &blocks); in xchk_fscount_btreeblks()
274 fsc->fdblocks += blocks - 1; in xchk_fscount_btreeblks()
276 error = xfs_btree_count_blocks(sc->sa.cnt_cur, &blocks); in xchk_fscount_btreeblks()
279 fsc->fdblocks += blocks - 1; in xchk_fscount_btreeblks()
282 xchk_ag_free(sc, &sc->sa); in xchk_fscount_btreeblks()
287 * Calculate what the global in-core counters ought to be from the incore
288 * per-AG structure. Callers can compare this to the actual in-core counters
289 * to estimate by how much both in-core and on-disk counters need to be
297 struct xfs_mount *mp = sc->mp; in xchk_fscount_aggregate_agcounts()
304 fsc->icount = 0; in xchk_fscount_aggregate_agcounts()
305 fsc->ifree = 0; in xchk_fscount_aggregate_agcounts()
306 fsc->fdblocks = 0; in xchk_fscount_aggregate_agcounts()
315 error = -EFSCORRUPTED; in xchk_fscount_aggregate_agcounts()
320 fsc->icount += pag->pagi_count; in xchk_fscount_aggregate_agcounts()
321 fsc->ifree += pag->pagi_freecount; in xchk_fscount_aggregate_agcounts()
324 fsc->fdblocks += pag->pagf_freeblks; in xchk_fscount_aggregate_agcounts()
325 fsc->fdblocks += pag->pagf_flcount; in xchk_fscount_aggregate_agcounts()
326 if (xfs_has_lazysbcount(sc->mp)) { in xchk_fscount_aggregate_agcounts()
327 fsc->fdblocks += pag->pagf_btreeblks; in xchk_fscount_aggregate_agcounts()
335 * Per-AG reservations are taken out of the incore counters, in xchk_fscount_aggregate_agcounts()
338 fsc->fdblocks -= pag->pag_meta_resv.ar_reserved; in xchk_fscount_aggregate_agcounts()
339 fsc->fdblocks -= pag->pag_rmapbt_resv.ar_orig_reserved; in xchk_fscount_aggregate_agcounts()
353 fsc->fdblocks -= mp->m_resblks_avail; in xchk_fscount_aggregate_agcounts()
360 delayed = percpu_counter_sum(&mp->m_delalloc_blks); in xchk_fscount_aggregate_agcounts()
361 fsc->fdblocks -= delayed; in xchk_fscount_aggregate_agcounts()
363 trace_xchk_fscounters_calc(mp, fsc->icount, fsc->ifree, fsc->fdblocks, in xchk_fscount_aggregate_agcounts()
368 if (fsc->icount < fsc->icount_min || fsc->icount > fsc->icount_max || in xchk_fscount_aggregate_agcounts()
369 fsc->fdblocks > mp->m_sb.sb_dblocks || in xchk_fscount_aggregate_agcounts()
370 fsc->ifree > fsc->icount_max) in xchk_fscount_aggregate_agcounts()
371 return -EFSCORRUPTED; in xchk_fscount_aggregate_agcounts()
378 if (fsc->ifree > fsc->icount) { in xchk_fscount_aggregate_agcounts()
379 if (tries--) in xchk_fscount_aggregate_agcounts()
381 return -EDEADLOCK; in xchk_fscount_aggregate_agcounts()
398 fsc->frextents += rec->ar_extcount; in xchk_fscount_add_frextent()
400 xchk_should_terminate(fsc->sc, &error); in xchk_fscount_add_frextent()
410 struct xfs_mount *mp = sc->mp; in xchk_fscount_count_frextents()
414 fsc->frextents = 0; in xchk_fscount_count_frextents()
415 fsc->frextents_delayed = 0; in xchk_fscount_count_frextents()
421 error = xfs_rtalloc_query_all(rtg, sc->tp, in xchk_fscount_count_frextents()
431 fsc->frextents_delayed = percpu_counter_sum(&mp->m_delalloc_rtextents); in xchk_fscount_count_frextents()
440 fsc->frextents = 0; in xchk_fscount_count_frextents()
441 fsc->frextents_delayed = 0; in xchk_fscount_count_frextents()
455 * per-AG data to compute the @expected value, which means that the counter
456 * could have changed. We know the @old_value of the summation of the counter
457 * before the aggregation, and we re-sum the counter now. If the expected
476 trace_xchk_fscounters_within_range(sc->mp, expected, curr_value, in xchk_fscount_within_range()
488 if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) in xchk_fscount_within_range()
494 /* Within the before-and-after range is ok. */ in xchk_fscount_within_range()
507 struct xfs_mount *mp = sc->mp; in xchk_fscounters()
508 struct xchk_fscounters *fsc = sc->buf; in xchk_fscounters()
514 icount = percpu_counter_sum(&mp->m_icount); in xchk_fscounters()
515 ifree = percpu_counter_sum(&mp->m_ifree); in xchk_fscounters()
516 fdblocks = percpu_counter_sum(&mp->m_fdblocks); in xchk_fscounters()
517 frextents = percpu_counter_sum(&mp->m_frextents); in xchk_fscounters()
524 * If the filesystem is not frozen, the counter summation calls above in xchk_fscounters()
533 if (!fsc->frozen) in xchk_fscounters()
534 return -EDEADLOCK; in xchk_fscounters()
541 if (icount < fsc->icount_min || icount > fsc->icount_max) in xchk_fscounters()
545 if (fdblocks > mp->m_sb.sb_dblocks) in xchk_fscounters()
549 if (frextents > mp->m_sb.sb_rextents) in xchk_fscounters()
556 if (ifree > icount && ifree - icount > XCHK_FSCOUNT_MIN_VARIANCE) in xchk_fscounters()
568 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE) in xchk_fscounters()
572 * Compare the in-core counters with whatever we counted. If the fs is in xchk_fscounters()
577 if (!xchk_fscount_within_range(sc, icount, &mp->m_icount, in xchk_fscounters()
578 fsc->icount)) { in xchk_fscounters()
579 if (fsc->frozen) in xchk_fscounters()
585 if (!xchk_fscount_within_range(sc, ifree, &mp->m_ifree, fsc->ifree)) { in xchk_fscounters()
586 if (fsc->frozen) in xchk_fscounters()
592 if (!xchk_fscount_within_range(sc, fdblocks, &mp->m_fdblocks, in xchk_fscounters()
593 fsc->fdblocks)) { in xchk_fscounters()
594 if (fsc->frozen) in xchk_fscounters()
600 if (!xchk_fscount_within_range(sc, frextents, &mp->m_frextents, in xchk_fscounters()
601 fsc->frextents - fsc->frextents_delayed)) { in xchk_fscounters()
602 if (fsc->frozen) in xchk_fscounters()
609 return -EDEADLOCK; in xchk_fscounters()