Skip to content

Commit e147a75

Browse files
author
Darrick J. Wong
committed
xfs: count free space btree blocks when scrubbing pre-lazysbcount fses
Since agf_btreeblks didn't exist before the lazysbcount feature, the fs summary count scrubber needs to walk the free space btrees to determine the amount of space being used by those btrees. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Gao Xiang <[email protected]>
1 parent 6543990 commit e147a75

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

fs/xfs/scrub/fscounters.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "xfs_alloc.h"
1414
#include "xfs_ialloc.h"
1515
#include "xfs_health.h"
16+
#include "xfs_btree.h"
1617
#include "scrub/scrub.h"
1718
#include "scrub/common.h"
1819
#include "scrub/trace.h"
@@ -143,6 +144,35 @@ xchk_setup_fscounters(
143144
return xchk_trans_alloc(sc, 0);
144145
}
145146

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+
146176
/*
147177
* Calculate what the global in-core counters ought to be from the incore
148178
* per-AG structure. Callers can compare this to the actual in-core counters
@@ -182,8 +212,15 @@ xchk_fscount_aggregate_agcounts(
182212
/* Add up the free/freelist/bnobt/cntbt blocks */
183213
fsc->fdblocks += pag->pagf_freeblks;
184214
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)) {
186216
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+
}
187224

188225
/*
189226
* Per-AG reservations are taken out of the incore counters,

0 commit comments

Comments
 (0)