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

xfs: convert open-coded xfs_rtword_t pointer accesses to helper

There are a bunch of places where we use open-coded logic to find a
pointer to an xfs_rtword_t within a rt bitmap buffer.  Convert all that
to helper functions for better type safety.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent add3cdda
...@@ -103,7 +103,6 @@ xfs_rtfind_back( ...@@ -103,7 +103,6 @@ xfs_rtfind_back(
int bit; /* bit number in the word */ int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */ struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */ int error; /* error value */
xfs_rtxnum_t firstbit; /* first useful bit in the word */ xfs_rtxnum_t firstbit; /* first useful bit in the word */
xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t i; /* current bit number rel. to start */
...@@ -121,12 +120,12 @@ xfs_rtfind_back( ...@@ -121,12 +120,12 @@ xfs_rtfind_back(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
/* /*
* Get the first word's index & point to it. * Get the first word's index & point to it.
*/ */
word = xfs_rtx_to_rbmword(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
len = start - limit + 1; len = start - limit + 1;
/* /*
...@@ -173,9 +172,9 @@ xfs_rtfind_back( ...@@ -173,9 +172,9 @@ xfs_rtfind_back(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
word = mp->m_blockwsize - 1; word = mp->m_blockwsize - 1;
b = &bufp[word]; b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the previous word in the buffer. * Go on to the previous word in the buffer.
...@@ -219,9 +218,9 @@ xfs_rtfind_back( ...@@ -219,9 +218,9 @@ xfs_rtfind_back(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
word = mp->m_blockwsize - 1; word = mp->m_blockwsize - 1;
b = &bufp[word]; b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the previous word in the buffer. * Go on to the previous word in the buffer.
...@@ -278,7 +277,6 @@ xfs_rtfind_forw( ...@@ -278,7 +277,6 @@ xfs_rtfind_forw(
int bit; /* bit number in the word */ int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */ struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */ int error; /* error value */
xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit; /* last useful bit in the word */ xfs_rtxnum_t lastbit; /* last useful bit in the word */
...@@ -296,12 +294,12 @@ xfs_rtfind_forw( ...@@ -296,12 +294,12 @@ xfs_rtfind_forw(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
/* /*
* Get the first word's index & point to it. * Get the first word's index & point to it.
*/ */
word = xfs_rtx_to_rbmword(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
len = limit - start + 1; len = limit - start + 1;
/* /*
...@@ -347,8 +345,9 @@ xfs_rtfind_forw( ...@@ -347,8 +345,9 @@ xfs_rtfind_forw(
if (error) { if (error) {
return error; return error;
} }
b = bufp = bp->b_addr;
word = 0; word = 0;
b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the previous word in the buffer. * Go on to the previous word in the buffer.
...@@ -392,8 +391,9 @@ xfs_rtfind_forw( ...@@ -392,8 +391,9 @@ xfs_rtfind_forw(
if (error) { if (error) {
return error; return error;
} }
b = bufp = bp->b_addr;
word = 0; word = 0;
b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the next word in the buffer. * Go on to the next word in the buffer.
...@@ -541,7 +541,6 @@ xfs_rtmodify_range( ...@@ -541,7 +541,6 @@ xfs_rtmodify_range(
int bit; /* bit number in the word */ int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */ struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */ int error; /* error value */
xfs_rtword_t *first; /* first used word in the buffer */ xfs_rtword_t *first; /* first used word in the buffer */
int i; /* current bit number rel. to start */ int i; /* current bit number rel. to start */
...@@ -560,12 +559,12 @@ xfs_rtmodify_range( ...@@ -560,12 +559,12 @@ xfs_rtmodify_range(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
/* /*
* Compute the starting word's address, and starting bit. * Compute the starting word's address, and starting bit.
*/ */
word = xfs_rtx_to_rbmword(mp, start); word = xfs_rtx_to_rbmword(mp, start);
first = b = &bufp[word]; first = b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
/* /*
* 0 (allocated) => all zeroes; 1 (free) => all ones. * 0 (allocated) => all zeroes; 1 (free) => all ones.
...@@ -599,14 +598,15 @@ xfs_rtmodify_range( ...@@ -599,14 +598,15 @@ xfs_rtmodify_range(
* Get the next one. * Get the next one.
*/ */
xfs_trans_log_buf(tp, bp, xfs_trans_log_buf(tp, bp,
(uint)((char *)first - (char *)bufp), (uint)((char *)first - (char *)bp->b_addr),
(uint)((char *)b - (char *)bufp)); (uint)((char *)b - (char *)bp->b_addr));
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;
} }
first = b = bufp = bp->b_addr;
word = 0; word = 0;
first = b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the next word in the buffer * Go on to the next word in the buffer
...@@ -639,14 +639,15 @@ xfs_rtmodify_range( ...@@ -639,14 +639,15 @@ xfs_rtmodify_range(
* Get the next one. * Get the next one.
*/ */
xfs_trans_log_buf(tp, bp, xfs_trans_log_buf(tp, bp,
(uint)((char *)first - (char *)bufp), (uint)((char *)first - (char *)bp->b_addr),
(uint)((char *)b - (char *)bufp)); (uint)((char *)b - (char *)bp->b_addr));
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;
} }
first = b = bufp = bp->b_addr;
word = 0; word = 0;
first = b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the next word in the buffer * Go on to the next word in the buffer
...@@ -676,8 +677,9 @@ xfs_rtmodify_range( ...@@ -676,8 +677,9 @@ xfs_rtmodify_range(
* Log any remaining changed bytes. * Log any remaining changed bytes.
*/ */
if (b > first) if (b > first)
xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp), xfs_trans_log_buf(tp, bp,
(uint)((char *)b - (char *)bufp - 1)); (uint)((char *)first - (char *)bp->b_addr),
(uint)((char *)b - (char *)bp->b_addr - 1));
return 0; return 0;
} }
...@@ -775,7 +777,6 @@ xfs_rtcheck_range( ...@@ -775,7 +777,6 @@ xfs_rtcheck_range(
int bit; /* bit number in the word */ int bit; /* bit number in the word */
xfs_fileoff_t block; /* bitmap block number */ xfs_fileoff_t block; /* bitmap block number */
struct xfs_buf *bp; /* buf for the block */ struct xfs_buf *bp; /* buf for the block */
xfs_rtword_t *bufp; /* starting word in buffer */
int error; /* error value */ int error; /* error value */
xfs_rtxnum_t i; /* current bit number rel. to start */ xfs_rtxnum_t i; /* current bit number rel. to start */
xfs_rtxnum_t lastbit; /* last useful bit in word */ xfs_rtxnum_t lastbit; /* last useful bit in word */
...@@ -794,12 +795,12 @@ xfs_rtcheck_range( ...@@ -794,12 +795,12 @@ xfs_rtcheck_range(
if (error) { if (error) {
return error; return error;
} }
bufp = bp->b_addr;
/* /*
* Compute the starting word's address, and starting bit. * Compute the starting word's address, and starting bit.
*/ */
word = xfs_rtx_to_rbmword(mp, start); word = xfs_rtx_to_rbmword(mp, start);
b = &bufp[word]; b = xfs_rbmblock_wordptr(bp, word);
bit = (int)(start & (XFS_NBWORD - 1)); bit = (int)(start & (XFS_NBWORD - 1));
/* /*
* 0 (allocated) => all zero's; 1 (free) => all one's. * 0 (allocated) => all zero's; 1 (free) => all one's.
...@@ -845,8 +846,9 @@ xfs_rtcheck_range( ...@@ -845,8 +846,9 @@ xfs_rtcheck_range(
if (error) { if (error) {
return error; return error;
} }
b = bufp = bp->b_addr;
word = 0; word = 0;
b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the next word in the buffer. * Go on to the next word in the buffer.
...@@ -891,8 +893,9 @@ xfs_rtcheck_range( ...@@ -891,8 +893,9 @@ xfs_rtcheck_range(
if (error) { if (error) {
return error; return error;
} }
b = bufp = bp->b_addr;
word = 0; word = 0;
b = xfs_rbmblock_wordptr(bp, word);
} else { } else {
/* /*
* Go on to the next word in the buffer. * Go on to the next word in the buffer.
......
...@@ -158,6 +158,17 @@ xfs_rbmblock_to_rtx( ...@@ -158,6 +158,17 @@ xfs_rbmblock_to_rtx(
return rbmoff << mp->m_blkbit_log; return rbmoff << mp->m_blkbit_log;
} }
/* Return a pointer to a bitmap word within a rt bitmap block. */
static inline xfs_rtword_t *
xfs_rbmblock_wordptr(
struct xfs_buf *bp,
unsigned int index)
{
xfs_rtword_t *words = bp->b_addr;
return words + index;
}
/* /*
* Functions for walking free space rtextents in the realtime bitmap. * Functions for walking free space rtextents in the realtime bitmap.
*/ */
......
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