From: Darrick J. Wong <djwong@xxxxxxxxxx> Create a pair of functions to round rtblock numbers up or down to the nearest rt extent. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- fs/xfs/libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++++ fs/xfs/xfs_bmap_util.c | 8 +++----- fs/xfs/xfs_rtalloc.c | 4 ++-- fs/xfs/xfs_xchgrange.c | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtbitmap.h b/fs/xfs/libxfs/xfs_rtbitmap.h index bdd4858a794c2..bc51d3bfc7c45 100644 --- a/fs/xfs/libxfs/xfs_rtbitmap.h +++ b/fs/xfs/libxfs/xfs_rtbitmap.h @@ -56,6 +56,24 @@ xfs_rtb_to_rtxt( return div_u64(rtbno, mp->m_sb.sb_rextsize); } +/* Round this rtblock up to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_roundup_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return roundup_64(rtbno, mp->m_sb.sb_rextsize); +} + +/* Round this rtblock down to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_rounddown_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return rounddown_64(rtbno, mp->m_sb.sb_rextsize); +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 8f1e16e49dab2..b17332b84812e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -685,7 +685,7 @@ xfs_can_free_eofblocks( */ end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) - end_fsb = roundup_64(end_fsb, mp->m_sb.sb_rextsize); + end_fsb = xfs_rtb_roundup_rtx(mp, end_fsb); last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); if (last_fsb <= end_fsb) return false; @@ -984,10 +984,8 @@ xfs_free_file_space( /* We can only free complete realtime extents. */ if (xfs_inode_has_bigrtextents(ip)) { - startoffset_fsb = roundup_64(startoffset_fsb, - mp->m_sb.sb_rextsize); - endoffset_fsb = rounddown_64(endoffset_fsb, - mp->m_sb.sb_rextsize); + startoffset_fsb = xfs_rtb_roundup_rtx(mp, startoffset_fsb); + endoffset_fsb = xfs_rtb_rounddown_rtx(mp, endoffset_fsb); } /* diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 8db8f957a683b..e62ca51b995ba 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1633,8 +1633,8 @@ xfs_rtfile_convert_unwritten( if (mp->m_sb.sb_rextsize == 1) return 0; - off = rounddown_64(XFS_B_TO_FSBT(mp, pos), mp->m_sb.sb_rextsize); - endoff = roundup_64(XFS_B_TO_FSB(mp, pos + len), mp->m_sb.sb_rextsize); + off = xfs_rtb_rounddown_rtx(mp, XFS_B_TO_FSBT(mp, pos)); + endoff = xfs_rtb_roundup_rtx(mp, XFS_B_TO_FSB(mp, pos + len)); trace_xfs_rtfile_convert_unwritten(ip, pos, len); diff --git a/fs/xfs/xfs_xchgrange.c b/fs/xfs/xfs_xchgrange.c index befa915089ce6..a4a352e027c97 100644 --- a/fs/xfs/xfs_xchgrange.c +++ b/fs/xfs/xfs_xchgrange.c @@ -28,6 +28,7 @@ #include "xfs_icache.h" #include "xfs_log.h" #include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include <linux/fsnotify.h> /* @@ -1236,8 +1237,7 @@ xfs_xchg_range( * offsets and length in @fxr are safe to round up. */ if (XFS_IS_REALTIME_INODE(ip2)) - req.blockcount = roundup_64(req.blockcount, - mp->m_sb.sb_rextsize); + req.blockcount = xfs_rtb_roundup_rtx(mp, req.blockcount); error = xfs_xchg_range_estimate(&req); if (error)