Commit 035e32f7 authored by Chandan Babu R's avatar Chandan Babu R

Merge tag 'refactor-rtbitmap-macros-6.7_2023-10-19' of...

Merge tag 'refactor-rtbitmap-macros-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.7-mergeA

xfs: refactor rtbitmap/summary macros [v1.1]

In preparation for adding block headers and enforcing endian order in
rtbitmap and rtsummary blocks, replace open-coded geometry computations
and fugly macros with proper helper functions that can be typechecked.
Soon we'll be needing to add more complex logic to the helpers.

v1.1: various cleanups suggested by hch

With a bit of luck, this should all go splendidly.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>

* tag 'refactor-rtbitmap-macros-6.7_2023-10-19' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: create helpers for rtbitmap block/wordcount computations
  xfs: convert rt summary macros to helpers
  xfs: convert open-coded xfs_rtword_t pointer accesses to helper
  xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
  xfs: convert the rtbitmap block and bit macros to static inline functions
parents 9d4ca5af d0448fe7
...@@ -1142,24 +1142,10 @@ static inline bool xfs_dinode_has_large_extent_counts( ...@@ -1142,24 +1142,10 @@ static inline bool xfs_dinode_has_large_extent_counts(
#define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize) #define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize)
#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask) #define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
#define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize)
#define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask)
/* /*
* RT Summary and bit manipulation macros. * RT bit manipulation macros.
*/ */
#define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
#define XFS_SUMOFFSTOBLOCK(mp,s) \
(((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
#define XFS_SUMPTR(mp,bp,so) \
((xfs_suminfo_t *)((bp)->b_addr + \
(((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))
......
...@@ -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 */
...@@ -111,22 +110,22 @@ xfs_rtfind_back( ...@@ -111,22 +110,22 @@ 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;
} }
bufp = bp->b_addr;
/* /*
* 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 = 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 = XFS_BLOCKWMASK(mp); 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 = XFS_BLOCKWMASK(mp); 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 */
...@@ -286,22 +284,22 @@ xfs_rtfind_forw( ...@@ -286,22 +284,22 @@ 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;
} }
bufp = bp->b_addr;
/* /*
* 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 = 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;
/* /*
...@@ -338,7 +336,7 @@ xfs_rtfind_forw( ...@@ -338,7 +336,7 @@ xfs_rtfind_forw(
* Go on to next block if that's where the next word is * Go on to next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* If done with this block, get the previous one. * If done with this block, get the previous one.
*/ */
...@@ -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.
...@@ -383,7 +382,7 @@ xfs_rtfind_forw( ...@@ -383,7 +382,7 @@ xfs_rtfind_forw(
* Go on to next block if that's where the next word is * Go on to next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* If done with this block, get the next one. * If done with this block, get the next one.
*/ */
...@@ -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.
...@@ -455,17 +455,18 @@ xfs_rtmodify_summary_int( ...@@ -455,17 +455,18 @@ xfs_rtmodify_summary_int(
struct xfs_buf *bp; /* buffer for the summary block */ struct xfs_buf *bp; /* buffer for the summary block */
int error; /* error value */ int error; /* error value */
xfs_fileoff_t sb; /* summary fsblock */ xfs_fileoff_t sb; /* summary fsblock */
int so; /* index into the summary file */ xfs_rtsumoff_t so; /* index into the summary file */
xfs_suminfo_t *sp; /* pointer to returned data */ xfs_suminfo_t *sp; /* pointer to returned data */
unsigned int infoword;
/* /*
* Compute entry number in the summary file. * Compute entry number in the summary file.
*/ */
so = XFS_SUMOFFS(mp, log, bbno); so = xfs_rtsumoffs(mp, log, bbno);
/* /*
* Compute the block number in the summary file. * Compute the block number in the summary file.
*/ */
sb = XFS_SUMOFFSTOBLOCK(mp, so); sb = xfs_rtsumoffs_to_block(mp, so);
/* /*
* If we have an old buffer, and the block number matches, use that. * If we have an old buffer, and the block number matches, use that.
*/ */
...@@ -493,7 +494,8 @@ xfs_rtmodify_summary_int( ...@@ -493,7 +494,8 @@ xfs_rtmodify_summary_int(
/* /*
* Point to the summary information, modify/log it, and/or copy it out. * Point to the summary information, modify/log it, and/or copy it out.
*/ */
sp = XFS_SUMPTR(mp, bp, so); infoword = xfs_rtsumoffs_to_infoword(mp, so);
sp = xfs_rsumblock_infoptr(bp, infoword);
if (delta) { if (delta) {
uint first = (uint)((char *)sp - (char *)bp->b_addr); uint first = (uint)((char *)sp - (char *)bp->b_addr);
...@@ -541,18 +543,17 @@ xfs_rtmodify_range( ...@@ -541,18 +543,17 @@ 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 */
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.
*/ */
...@@ -560,12 +561,12 @@ xfs_rtmodify_range( ...@@ -560,12 +561,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_BITTOWORD(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.
...@@ -593,20 +594,21 @@ xfs_rtmodify_range( ...@@ -593,20 +594,21 @@ xfs_rtmodify_range(
* Go on to the next block if that's where the next word is * Go on to the next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* Log the changed part of this block. * Log the changed part of this block.
* 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
...@@ -633,20 +635,21 @@ xfs_rtmodify_range( ...@@ -633,20 +635,21 @@ xfs_rtmodify_range(
* Go on to the next block if that's where the next word is * Go on to the next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* Log the changed part of this block. * Log the changed part of this block.
* 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 +679,9 @@ xfs_rtmodify_range( ...@@ -676,8 +679,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;
} }
...@@ -730,7 +734,7 @@ xfs_rtfree_range( ...@@ -730,7 +734,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 +746,7 @@ xfs_rtfree_range( ...@@ -742,7 +746,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 +757,7 @@ xfs_rtfree_range( ...@@ -753,7 +757,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;
} }
...@@ -775,18 +779,17 @@ xfs_rtcheck_range( ...@@ -775,18 +779,17 @@ 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 */
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.
*/ */
...@@ -794,12 +797,12 @@ xfs_rtcheck_range( ...@@ -794,12 +797,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_BITTOWORD(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.
...@@ -836,7 +839,7 @@ xfs_rtcheck_range( ...@@ -836,7 +839,7 @@ xfs_rtcheck_range(
* Go on to next block if that's where the next word is * Go on to next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* If done with this block, get the next one. * If done with this block, get the next one.
*/ */
...@@ -845,8 +848,9 @@ xfs_rtcheck_range( ...@@ -845,8 +848,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.
...@@ -882,7 +886,7 @@ xfs_rtcheck_range( ...@@ -882,7 +886,7 @@ xfs_rtcheck_range(
* Go on to next block if that's where the next word is * Go on to next block if that's where the next word is
* and we need the next word. * and we need the next word.
*/ */
if (++word == XFS_BLOCKWSIZE(mp) && i < len) { if (++word == mp->m_blockwsize && i < len) {
/* /*
* If done with this block, get the next one. * If done with this block, get the next one.
*/ */
...@@ -891,8 +895,9 @@ xfs_rtcheck_range( ...@@ -891,8 +895,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.
...@@ -1130,3 +1135,30 @@ xfs_rtalloc_extent_is_free( ...@@ -1130,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;
}
...@@ -131,6 +131,94 @@ xfs_rtb_rounddown_rtx( ...@@ -131,6 +131,94 @@ 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) & (mp->m_blockwsize - 1);
}
/* 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;
}
/* 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;
}
/*
* Convert a rt extent length and rt bitmap block number to a xfs_suminfo_t
* offset within the rt summary file.
*/
static inline xfs_rtsumoff_t
xfs_rtsumoffs(
struct xfs_mount *mp,
int log2_len,
xfs_fileoff_t rbmoff)
{
return log2_len * mp->m_sb.sb_rbmblocks + rbmoff;
}
/*
* Convert an xfs_suminfo_t offset to a file block offset within the rt summary
* file.
*/
static inline xfs_fileoff_t
xfs_rtsumoffs_to_block(
struct xfs_mount *mp,
xfs_rtsumoff_t rsumoff)
{
return XFS_B_TO_FSBT(mp, rsumoff * sizeof(xfs_suminfo_t));
}
/*
* Convert an xfs_suminfo_t offset to an info word offset within an rt summary
* block.
*/
static inline unsigned int
xfs_rtsumoffs_to_infoword(
struct xfs_mount *mp,
xfs_rtsumoff_t rsumoff)
{
unsigned int mask = mp->m_blockmask >> XFS_SUMINFOLOG;
return rsumoff & mask;
}
/* Return a pointer to a summary info word within a rt summary block. */
static inline xfs_suminfo_t *
xfs_rsumblock_infoptr(
struct xfs_buf *bp,
unsigned int index)
{
xfs_suminfo_t *info = bp->b_addr;
return info + index;
}
/* /*
* Functions for walking free space rtextents in the realtime bitmap. * Functions for walking free space rtextents in the realtime bitmap.
*/ */
...@@ -192,6 +280,11 @@ xfs_rtfree_extent( ...@@ -192,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)
...@@ -199,6 +292,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno, ...@@ -199,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;
} }
/* /*
......
...@@ -19,6 +19,7 @@ typedef int64_t xfs_fsize_t; /* bytes in a file */ ...@@ -19,6 +19,7 @@ typedef int64_t xfs_fsize_t; /* bytes in a file */
typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */ typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */
typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */ typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */
typedef uint32_t xfs_rtsumoff_t; /* offset of an rtsummary info word */
typedef uint32_t xfs_rtword_t; /* word type for bitmap manipulations */ typedef uint32_t xfs_rtword_t; /* word type for bitmap manipulations */
typedef int64_t xfs_lsn_t; /* log sequence number */ typedef int64_t xfs_lsn_t; /* log sequence number */
...@@ -149,6 +150,7 @@ typedef uint32_t xfs_dqid_t; ...@@ -149,6 +150,7 @@ typedef uint32_t xfs_dqid_t;
*/ */
#define XFS_NBBYLOG 3 /* log2(NBBY) */ #define XFS_NBBYLOG 3 /* log2(NBBY) */
#define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */ #define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
#define XFS_SUMINFOLOG 2 /* log2(sizeof(xfs_suminfo_t)) */
#define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG) #define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
#define XFS_NBWORD (1 << XFS_NBWORDLOG) #define XFS_NBWORD (1 << XFS_NBWORDLOG)
#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1) #define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
......
...@@ -81,7 +81,7 @@ typedef unsigned int xchk_rtsumoff_t; ...@@ -81,7 +81,7 @@ typedef unsigned int xchk_rtsumoff_t;
static inline int static inline int
xfsum_load( xfsum_load(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xchk_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
xfs_suminfo_t *info) xfs_suminfo_t *info)
{ {
return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t), return xfile_obj_load(sc->xfile, info, sizeof(xfs_suminfo_t),
...@@ -91,7 +91,7 @@ xfsum_load( ...@@ -91,7 +91,7 @@ xfsum_load(
static inline int static inline int
xfsum_store( xfsum_store(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xchk_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
const xfs_suminfo_t info) const xfs_suminfo_t info)
{ {
return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t), return xfile_obj_store(sc->xfile, &info, sizeof(xfs_suminfo_t),
...@@ -101,7 +101,7 @@ xfsum_store( ...@@ -101,7 +101,7 @@ xfsum_store(
static inline int static inline int
xfsum_copyout( xfsum_copyout(
struct xfs_scrub *sc, struct xfs_scrub *sc,
xchk_rtsumoff_t sumoff, xfs_rtsumoff_t sumoff,
xfs_suminfo_t *info, xfs_suminfo_t *info,
unsigned int nr_words) unsigned int nr_words)
{ {
...@@ -121,7 +121,7 @@ xchk_rtsum_record_free( ...@@ -121,7 +121,7 @@ xchk_rtsum_record_free(
xfs_fileoff_t rbmoff; xfs_fileoff_t rbmoff;
xfs_rtblock_t rtbno; xfs_rtblock_t rtbno;
xfs_filblks_t rtlen; xfs_filblks_t rtlen;
xchk_rtsumoff_t offs; xfs_rtsumoff_t offs;
unsigned int lenlog; unsigned int lenlog;
xfs_suminfo_t v = 0; xfs_suminfo_t v = 0;
int error = 0; int error = 0;
...@@ -130,9 +130,9 @@ xchk_rtsum_record_free( ...@@ -130,9 +130,9 @@ 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_rtsumoffs(mp, lenlog, rbmoff);
rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext); rtbno = xfs_rtx_to_rtb(mp, rec->ar_startext);
rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount); rtlen = xfs_rtx_to_rtb(mp, rec->ar_extcount);
...@@ -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,
...@@ -185,6 +184,7 @@ xchk_rtsum_compare( ...@@ -185,6 +184,7 @@ xchk_rtsum_compare(
int nmap; int nmap;
for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) { for (off = 0; off < XFS_B_TO_FSB(mp, mp->m_rsumsize); off++) {
xfs_suminfo_t *ondisk_info;
int error = 0; int error = 0;
if (xchk_should_terminate(sc, &error)) if (xchk_should_terminate(sc, &error))
...@@ -216,7 +216,8 @@ xchk_rtsum_compare( ...@@ -216,7 +216,8 @@ xchk_rtsum_compare(
return error; return error;
} }
if (memcmp(bp->b_addr, sc->buf, ondisk_info = xfs_rsumblock_infoptr(bp, 0);
if (memcmp(ondisk_info, sc->buf,
mp->m_blockwsize << XFS_WORDLOG) != 0) mp->m_blockwsize << XFS_WORDLOG) != 0)
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off); xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off);
......
...@@ -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;
} }
} }
/* /*
...@@ -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