Skip to content

Commit 1cac233

Browse files
committed
xfs: refactor agfl length computation function
Refactor xfs_alloc_min_freelist to accept a NULL @pag argument, in which case it returns the largest possible minimum length. This will be used in an upcoming patch to compute the length of the AGFL at mkfs time. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]>
1 parent af952ae commit 1cac233

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,24 +2248,32 @@ xfs_alloc_longest_free_extent(
22482248
return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
22492249
}
22502250

2251+
/*
2252+
* Compute the minimum length of the AGFL in the given AG. If @pag is NULL,
2253+
* return the largest possible minimum length.
2254+
*/
22512255
unsigned int
22522256
xfs_alloc_min_freelist(
22532257
struct xfs_mount *mp,
22542258
struct xfs_perag *pag)
22552259
{
2260+
/* AG btrees have at least 1 level. */
2261+
static const uint8_t fake_levels[XFS_BTNUM_AGF] = {1, 1, 1};
2262+
const uint8_t *levels = pag ? pag->pagf_levels : fake_levels;
22562263
unsigned int min_free;
22572264

2265+
ASSERT(mp->m_ag_maxlevels > 0);
2266+
22582267
/* space needed by-bno freespace btree */
2259-
min_free = min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_BNOi] + 1,
2268+
min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
22602269
mp->m_ag_maxlevels);
22612270
/* space needed by-size freespace btree */
2262-
min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_CNTi] + 1,
2271+
min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
22632272
mp->m_ag_maxlevels);
22642273
/* space needed reverse mapping used space btree */
22652274
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
2266-
min_free += min_t(unsigned int,
2267-
pag->pagf_levels[XFS_BTNUM_RMAPi] + 1,
2268-
mp->m_rmap_maxlevels);
2275+
min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
2276+
mp->m_rmap_maxlevels);
22692277

22702278
return min_free;
22712279
}

0 commit comments

Comments
 (0)