Skip to content

Commit d0448fe

Browse files
author
Darrick J. Wong
committed
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: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 097b4b7 commit d0448fe

File tree

5 files changed

+48
-9
lines changed

5 files changed

+48
-9
lines changed

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,3 +1135,30 @@ xfs_rtalloc_extent_is_free(
11351135
*is_free = matches;
11361136
return 0;
11371137
}
1138+
1139+
/*
1140+
* Compute the number of rtbitmap blocks needed to track the given number of rt
1141+
* extents.
1142+
*/
1143+
xfs_filblks_t
1144+
xfs_rtbitmap_blockcount(
1145+
struct xfs_mount *mp,
1146+
xfs_rtbxlen_t rtextents)
1147+
{
1148+
return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
1149+
}
1150+
1151+
/*
1152+
* Compute the number of rtbitmap words needed to populate every block of a
1153+
* bitmap that is large enough to track the given number of rt extents.
1154+
*/
1155+
unsigned long long
1156+
xfs_rtbitmap_wordcount(
1157+
struct xfs_mount *mp,
1158+
xfs_rtbxlen_t rtextents)
1159+
{
1160+
xfs_filblks_t blocks;
1161+
1162+
blocks = xfs_rtbitmap_blockcount(mp, rtextents);
1163+
return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
1164+
}

fs/xfs/libxfs/xfs_rtbitmap.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,25 @@ xfs_rtfree_extent(
280280
/* Same as above, but in units of rt blocks. */
281281
int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
282282
xfs_filblks_t rtlen);
283+
284+
xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
285+
rtextents);
286+
unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
287+
xfs_rtbxlen_t rtextents);
283288
#else /* CONFIG_XFS_RT */
284289
# define xfs_rtfree_extent(t,b,l) (-ENOSYS)
285290
# define xfs_rtfree_blocks(t,rb,rl) (-ENOSYS)
286291
# define xfs_rtalloc_query_range(m,t,l,h,f,p) (-ENOSYS)
287292
# define xfs_rtalloc_query_all(m,t,f,p) (-ENOSYS)
288293
# define xfs_rtbuf_get(m,t,b,i,p) (-ENOSYS)
289294
# define xfs_rtalloc_extent_is_free(m,t,s,l,i) (-ENOSYS)
295+
static inline xfs_filblks_t
296+
xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
297+
{
298+
/* shut up gcc */
299+
return 0;
300+
}
301+
# define xfs_rtbitmap_wordcount(mp, r) (0)
290302
#endif /* CONFIG_XFS_RT */
291303

292304
#endif /* __XFS_RTBITMAP_H__ */

fs/xfs/libxfs/xfs_trans_resv.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,12 @@ xfs_rtalloc_block_count(
218218
struct xfs_mount *mp,
219219
unsigned int num_ops)
220220
{
221-
unsigned int blksz = XFS_FSB_TO_B(mp, 1);
222-
unsigned int rtbmp_bytes;
221+
unsigned int rtbmp_blocks;
222+
xfs_rtxlen_t rtxlen;
223223

224-
rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
225-
return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
224+
rtxlen = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN);
225+
rtbmp_blocks = xfs_rtbitmap_blockcount(mp, rtxlen);
226+
return (rtbmp_blocks + 1) * num_ops;
226227
}
227228

228229
/*

fs/xfs/scrub/rtsummary.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ xchk_rtsum_compute(
160160
struct xfs_scrub *sc)
161161
{
162162
struct xfs_mount *mp = sc->mp;
163-
unsigned long long rtbmp_bytes;
163+
unsigned long long rtbmp_blocks;
164164

165165
/* If the bitmap size doesn't match the computed size, bail. */
166-
rtbmp_bytes = howmany_64(mp->m_sb.sb_rextents, NBBY);
167-
if (roundup_64(rtbmp_bytes, mp->m_sb.sb_blocksize) !=
168-
mp->m_rbmip->i_disk_size)
166+
rtbmp_blocks = xfs_rtbitmap_blockcount(mp, mp->m_sb.sb_rextents);
167+
if (XFS_FSB_TO_B(mp, rtbmp_blocks) != mp->m_rbmip->i_disk_size)
169168
return -EFSCORRUPTED;
170169

171170
return xfs_rtalloc_query_all(sc->mp, sc->tp, xchk_rtsum_record_free,

fs/xfs/xfs_rtalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ xfs_growfs_rt(
998998
*/
999999
nrextents = nrblocks;
10001000
do_div(nrextents, in->extsize);
1001-
nrbmblocks = howmany_64(nrextents, NBBY * sbp->sb_blocksize);
1001+
nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
10021002
nrextslog = xfs_highbit32(nrextents);
10031003
nrsumlevels = nrextslog + 1;
10041004
nrsumsize = (uint)sizeof(xfs_suminfo_t) * nrsumlevels * nrbmblocks;

0 commit comments

Comments
 (0)