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))
......
This diff is collapsed.
...@@ -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