Commit d0448fe7 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: create helpers for rtbitmap block/wordcount computations

Create helper functions that compute the number of blocks or words
necessary to store the rt bitmap.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 097b4b7b
...@@ -1135,3 +1135,30 @@ xfs_rtalloc_extent_is_free( ...@@ -1135,3 +1135,30 @@ xfs_rtalloc_extent_is_free(
*is_free = matches; *is_free = matches;
return 0; return 0;
} }
/*
* Compute the number of rtbitmap blocks needed to track the given number of rt
* extents.
*/
xfs_filblks_t
xfs_rtbitmap_blockcount(
struct xfs_mount *mp,
xfs_rtbxlen_t rtextents)
{
return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
}
/*
* Compute the number of rtbitmap words needed to populate every block of a
* bitmap that is large enough to track the given number of rt extents.
*/
unsigned long long
xfs_rtbitmap_wordcount(
struct xfs_mount *mp,
xfs_rtbxlen_t rtextents)
{
xfs_filblks_t blocks;
blocks = xfs_rtbitmap_blockcount(mp, rtextents);
return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
}
...@@ -280,6 +280,11 @@ xfs_rtfree_extent( ...@@ -280,6 +280,11 @@ xfs_rtfree_extent(
/* Same as above, but in units of rt blocks. */ /* Same as above, but in units of rt blocks. */
int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
xfs_filblks_t rtlen); xfs_filblks_t rtlen);
xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
rtextents);
unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
xfs_rtbxlen_t rtextents);
#else /* CONFIG_XFS_RT */ #else /* CONFIG_XFS_RT */
# define xfs_rtfree_extent(t,b,l) (-ENOSYS) # define xfs_rtfree_extent(t,b,l) (-ENOSYS)
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS) # define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
...@@ -287,6 +292,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, ...@@ -287,6 +292,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS) # define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS) # define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS) # define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
static inline xfs_filblks_t
xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
{
/* shut up gcc */
return 0;
}
# define xfs_rtbitmap_wordcount(mp, r) (0)
#endif /* CONFIG_XFS_RT */ #endif /* CONFIG_XFS_RT */
#endif /* __XFS_RTBITMAP_H__ */ #endif /* __XFS_RTBITMAP_H__ */
...@@ -218,11 +218,12 @@ xfs_rtalloc_block_count( ...@@ -218,11 +218,12 @@ xfs_rtalloc_block_count(
struct xfs_mount *mp, struct xfs_mount *mp,
unsigned int num_ops) unsigned int num_ops)
{ {
unsigned int blksz = XFS_FSB_TO_B(mp, 1); unsigned int rtbmp_blocks;
unsigned int rtbmp_bytes; xfs_rtxlen_t rtxlen;
rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY; rtxlen = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN);
return (howmany(rtbmp_bytes, blksz) + 1) * num_ops; rtbmp_blocks = xfs_rtbitmap_blockcount(mp, rtxlen);
return (rtbmp_blocks + 1) * num_ops;
} }
/* /*
......
...@@ -160,12 +160,11 @@ xchk_rtsum_compute( ...@@ -160,12 +160,11 @@ xchk_rtsum_compute(
struct xfs_scrub *sc) struct xfs_scrub *sc)
{ {
struct xfs_mount *mp = sc->mp; struct xfs_mount *mp = sc->mp;
unsigned long long rtbmp_bytes; unsigned long long rtbmp_blocks;
/* If the bitmap size doesn't match the computed size, bail. */ /* If the bitmap size doesn't match the computed size, bail. */
rtbmp_bytes = howmany_64(mp->m_sb.sb_rextents, NBBY); rtbmp_blocks = xfs_rtbitmap_blockcount(mp, mp->m_sb.sb_rextents);
if (roundup_64(rtbmp_bytes, mp->m_sb.sb_blocksize) != if (XFS_FSB_TO_B(mp, rtbmp_blocks) != mp->m_rbmip->i_disk_size)
mp->m_rbmip->i_disk_size)
return -EFSCORRUPTED; return -EFSCORRUPTED;
return xfs_rtalloc_query_all(sc->mp, sc->tp, xchk_rtsum_record_free, return xfs_rtalloc_query_all(sc->mp, sc->tp, xchk_rtsum_record_free,
......
...@@ -998,7 +998,7 @@ xfs_growfs_rt( ...@@ -998,7 +998,7 @@ xfs_growfs_rt(
*/ */
nrextents = nrblocks; nrextents = nrblocks;
do_div(nrextents, in->extsize); do_div(nrextents, in->extsize);
nrbmblocks = howmany_64(nrextents, NBBY * sbp->sb_blocksize); nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
nrextslog = xfs_highbit32(nrextents); nrextslog = xfs_highbit32(nrextents);
nrsumlevels = nrextslog + 1; nrsumlevels = nrextslog + 1;
nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks; nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment