Commit 90d98a6a authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: convert the rtbitmap block and bit macros to static inline functions

Replace these macros with typechecked helper functions.  Eventually
we're going to add more logic to the helpers and it'll be easier if we
don't have to macro it up.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent ef5a83b7
...@@ -1155,11 +1155,6 @@ static inline bool xfs_dinode_has_large_extent_counts( ...@@ -1155,11 +1155,6 @@ static inline bool xfs_dinode_has_large_extent_counts(
((xfs_suminfo_t *)((bp)->b_addr + \ ((xfs_suminfo_t *)((bp)->b_addr + \
(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp)))) (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
#define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
#define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
#define XFS_BITTOWORD(mp,bi) \
((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
......
...@@ -111,12 +111,12 @@ xfs_rtfind_back( ...@@ -111,12 +111,12 @@ xfs_rtfind_back(
xfs_rtword_t mask; /* mask of relevant bits for value */ xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */ xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */ xfs_rtword_t wdiff; /* difference from wanted value */
int word; /* word number in the buffer */ unsigned int word; /* word number in the buffer */
/* /*
* Compute and read in starting bitmap block for starting block. * Compute and read in starting bitmap block for starting block.
*/ */
block = XFS_BITTOBLOCK(mp, start); block = xfs_rtx_to_rbmblock(mp, start);
error = xfs_rtbuf_get(mp, tp, block, 0, &bp); error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
if (error) { if (error) {
return error; return error;
...@@ -125,7 +125,7 @@ xfs_rtfind_back( ...@@ -125,7 +125,7 @@ xfs_rtfind_back(
/* /*
* Get the first word's index & point to it. * Get the first word's index & point to it.
*/ */
word = XFS_BITTOWORD(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
len = start - limit + 1; len = start - limit + 1;
...@@ -286,12 +286,12 @@ xfs_rtfind_forw( ...@@ -286,12 +286,12 @@ xfs_rtfind_forw(
xfs_rtword_t mask; /* mask of relevant bits for value */ xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t want; /* mask for "good" values */ xfs_rtword_t want; /* mask for "good" values */
xfs_rtword_t wdiff; /* difference from wanted value */ xfs_rtword_t wdiff; /* difference from wanted value */
int word; /* word number in the buffer */ unsigned int word; /* word number in the buffer */
/* /*
* Compute and read in starting bitmap block for starting block. * Compute and read in starting bitmap block for starting block.
*/ */
block = XFS_BITTOBLOCK(mp, start); block = xfs_rtx_to_rbmblock(mp, start);
error = xfs_rtbuf_get(mp, tp, block, 0, &bp); error = xfs_rtbuf_get(mp, tp, block, 0, &bp);
if (error) { if (error) {
return error; return error;
...@@ -300,7 +300,7 @@ xfs_rtfind_forw( ...@@ -300,7 +300,7 @@ xfs_rtfind_forw(
/* /*
* Get the first word's index & point to it. * Get the first word's index & point to it.
*/ */
word = XFS_BITTOWORD(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
len = limit - start + 1; len = limit - start + 1;
...@@ -547,12 +547,12 @@ xfs_rtmodify_range( ...@@ -547,12 +547,12 @@ xfs_rtmodify_range(
int i; /* current bit number rel. to start */ int i; /* current bit number rel. to start */
int lastbit; /* last useful bit in word */ int lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask o frelevant bits for value */ xfs_rtword_t mask; /* mask o frelevant bits for value */
int word; /* word number in the buffer */ unsigned int word; /* word number in the buffer */
/* /*
* Compute starting bitmap block number. * Compute starting bitmap block number.
*/ */
block = XFS_BITTOBLOCK(mp, start); block = xfs_rtx_to_rbmblock(mp, start);
/* /*
* Read the bitmap block, and point to its data. * Read the bitmap block, and point to its data.
*/ */
...@@ -564,7 +564,7 @@ xfs_rtmodify_range( ...@@ -564,7 +564,7 @@ xfs_rtmodify_range(
/* /*
* Compute the starting word's address, and starting bit. * Compute the starting word's address, and starting bit.
*/ */
word = XFS_BITTOWORD(mp, start); word = xfs_rtx_to_rbmword(mp, start);
first = b = &bufp[word]; first = b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
/* /*
...@@ -730,7 +730,7 @@ xfs_rtfree_range( ...@@ -730,7 +730,7 @@ xfs_rtfree_range(
if (preblock < start) { if (preblock < start) {
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(start - preblock), XFS_RTBLOCKLOG(start - preblock),
XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
if (error) { if (error) {
return error; return error;
} }
...@@ -742,7 +742,7 @@ xfs_rtfree_range( ...@@ -742,7 +742,7 @@ xfs_rtfree_range(
if (postblock > end) { if (postblock > end) {
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock - end), XFS_RTBLOCKLOG(postblock - end),
XFS_BITTOBLOCK(mp, end + 1), -1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, end + 1), -1, rbpp, rsb);
if (error) { if (error) {
return error; return error;
} }
...@@ -753,7 +753,7 @@ xfs_rtfree_range( ...@@ -753,7 +753,7 @@ xfs_rtfree_range(
*/ */
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock + 1 - preblock), XFS_RTBLOCKLOG(postblock + 1 - preblock),
XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
return error; return error;
} }
...@@ -781,12 +781,12 @@ xfs_rtcheck_range( ...@@ -781,12 +781,12 @@ xfs_rtcheck_range(
xfs_rtxnum_t lastbit; /* last useful bit in word */ xfs_rtxnum_t lastbit; /* last useful bit in word */
xfs_rtword_t mask; /* mask of relevant bits for value */ xfs_rtword_t mask; /* mask of relevant bits for value */
xfs_rtword_t wdiff; /* difference from wanted value */ xfs_rtword_t wdiff; /* difference from wanted value */
int word; /* word number in the buffer */ unsigned int word; /* word number in the buffer */
/* /*
* Compute starting bitmap block number * Compute starting bitmap block number
*/ */
block = XFS_BITTOBLOCK(mp, start); block = xfs_rtx_to_rbmblock(mp, start);
/* /*
* Read the bitmap block. * Read the bitmap block.
*/ */
...@@ -798,7 +798,7 @@ xfs_rtcheck_range( ...@@ -798,7 +798,7 @@ xfs_rtcheck_range(
/* /*
* Compute the starting word's address, and starting bit. * Compute the starting word's address, and starting bit.
*/ */
word = XFS_BITTOWORD(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = &bufp[word];
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
/* /*
......
...@@ -131,6 +131,33 @@ xfs_rtb_rounddown_rtx( ...@@ -131,6 +131,33 @@ xfs_rtb_rounddown_rtx(
return rounddown_64(rtbno, mp->m_sb.sb_rextsize); return rounddown_64(rtbno, mp->m_sb.sb_rextsize);
} }
/* Convert an rt extent number to a file block offset in the rt bitmap file. */
static inline xfs_fileoff_t
xfs_rtx_to_rbmblock(
struct xfs_mount *mp,
xfs_rtxnum_t rtx)
{
return rtx >> mp->m_blkbit_log;
}
/* Convert an rt extent number to a word offset within an rt bitmap block. */
static inline unsigned int
xfs_rtx_to_rbmword(
struct xfs_mount *mp,
xfs_rtxnum_t rtx)
{
return (rtx >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp);
}
/* Convert a file block offset in the rt bitmap file to an rt extent number. */
static inline xfs_rtxnum_t
xfs_rbmblock_to_rtx(
struct xfs_mount *mp,
xfs_fileoff_t rbmoff)
{
return rbmoff << mp->m_blkbit_log;
}
/* /*
* Functions for walking free space rtextents in the realtime bitmap. * Functions for walking free space rtextents in the realtime bitmap.
*/ */
......
...@@ -130,7 +130,7 @@ xchk_rtsum_record_free( ...@@ -130,7 +130,7 @@ xchk_rtsum_record_free(
return error; return error;
/* Compute the relevant location in the rtsum file. */ /* Compute the relevant location in the rtsum file. */
rbmoff = XFS_BITTOBLOCK(mp, rec->ar_startext); rbmoff = xfs_rtx_to_rbmblock(mp, rec->ar_startext);
lenlog = XFS_RTBLOCKLOG(rec->ar_extcount); lenlog = XFS_RTBLOCKLOG(rec->ar_extcount);
offs = XFS_SUMOFFS(mp, lenlog, rbmoff); offs = XFS_SUMOFFS(mp, lenlog, rbmoff);
......
...@@ -177,7 +177,7 @@ xfs_rtallocate_range( ...@@ -177,7 +177,7 @@ xfs_rtallocate_range(
*/ */
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock + 1 - preblock), XFS_RTBLOCKLOG(postblock + 1 - preblock),
XFS_BITTOBLOCK(mp, preblock), -1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, preblock), -1, rbpp, rsb);
if (error) { if (error) {
return error; return error;
} }
...@@ -188,7 +188,7 @@ xfs_rtallocate_range( ...@@ -188,7 +188,7 @@ xfs_rtallocate_range(
if (preblock < start) { if (preblock < start) {
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(start - preblock), XFS_RTBLOCKLOG(start - preblock),
XFS_BITTOBLOCK(mp, preblock), 1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, preblock), 1, rbpp, rsb);
if (error) { if (error) {
return error; return error;
} }
...@@ -200,7 +200,7 @@ xfs_rtallocate_range( ...@@ -200,7 +200,7 @@ xfs_rtallocate_range(
if (postblock > end) { if (postblock > end) {
error = xfs_rtmodify_summary(mp, tp, error = xfs_rtmodify_summary(mp, tp,
XFS_RTBLOCKLOG(postblock - end), XFS_RTBLOCKLOG(postblock - end),
XFS_BITTOBLOCK(mp, end + 1), 1, rbpp, rsb); xfs_rtx_to_rbmblock(mp, end + 1), 1, rbpp, rsb);
if (error) { if (error) {
return error; return error;
} }
...@@ -261,8 +261,8 @@ xfs_rtallocate_extent_block( ...@@ -261,8 +261,8 @@ xfs_rtallocate_extent_block(
* Loop over all the extents starting in this bitmap block, * Loop over all the extents starting in this bitmap block,
* looking for one that's long enough. * looking for one that's long enough.
*/ */
for (i = XFS_BLOCKTOBIT(mp, bbno), besti = -1, bestlen = 0, for (i = xfs_rbmblock_to_rtx(mp, bbno), besti = -1, bestlen = 0,
end = XFS_BLOCKTOBIT(mp, bbno + 1) - 1; end = xfs_rbmblock_to_rtx(mp, bbno + 1) - 1;
i <= end; i <= end;
i++) { i++) {
/* Make sure we don't scan off the end of the rt volume. */ /* Make sure we don't scan off the end of the rt volume. */
...@@ -489,7 +489,7 @@ xfs_rtallocate_extent_near( ...@@ -489,7 +489,7 @@ xfs_rtallocate_extent_near(
*rtx = r; *rtx = r;
return 0; return 0;
} }
bbno = XFS_BITTOBLOCK(mp, start); bbno = xfs_rtx_to_rbmblock(mp, start);
i = 0; i = 0;
ASSERT(minlen != 0); ASSERT(minlen != 0);
log2len = xfs_highbit32(minlen); log2len = xfs_highbit32(minlen);
...@@ -708,8 +708,8 @@ xfs_rtallocate_extent_size( ...@@ -708,8 +708,8 @@ xfs_rtallocate_extent_size(
* allocator is beyond the next bitmap block, * allocator is beyond the next bitmap block,
* skip to that bitmap block. * skip to that bitmap block.
*/ */
if (XFS_BITTOBLOCK(mp, n) > i + 1) if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
i = XFS_BITTOBLOCK(mp, n) - 1; i = xfs_rtx_to_rbmblock(mp, n) - 1;
} }
} }
/* /*
...@@ -771,8 +771,8 @@ xfs_rtallocate_extent_size( ...@@ -771,8 +771,8 @@ xfs_rtallocate_extent_size(
* allocator is beyond the next bitmap block, * allocator is beyond the next bitmap block,
* skip to that bitmap block. * skip to that bitmap block.
*/ */
if (XFS_BITTOBLOCK(mp, n) > i + 1) if (xfs_rtx_to_rbmblock(mp, n) > i + 1)
i = XFS_BITTOBLOCK(mp, n) - 1; i = xfs_rtx_to_rbmblock(mp, n) - 1;
} }
} }
/* /*
......
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