From: Darrick J. Wong <djwong@xxxxxxxxxx> Create helpers to do unit conversions of rt block numbers to rt extent numbers. There are two variations -- the suffix "t" denotes the one that returns only the truncated extent number; the other one also returns the misalignment. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- include/libxfs.h | 1 + libxfs/xfs_bmap.c | 7 +++---- libxfs/xfs_rtbitmap.c | 4 ++-- libxfs/xfs_rtbitmap.h | 17 +++++++++++++++++ libxfs/xfs_swapext.c | 7 ++++--- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/include/libxfs.h b/include/libxfs.h index 661964b8a1e..26202dede67 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -20,6 +20,7 @@ #include "bitops.h" #include "kmem.h" #include "libfrog/radix-tree.h" +#include "libfrog/div64.h" #include "atomic.h" #include "spinlock.h" diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 025298db1e8..5fbfc5372c9 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -5365,7 +5365,6 @@ __xfs_bunmapi( int tmp_logflags; /* partial logging flags */ int wasdel; /* was a delayed alloc extent */ int whichfork; /* data or attribute fork */ - xfs_fsblock_t sum; xfs_filblks_t len = *rlen; /* length to unmap in file */ xfs_fileoff_t end; struct xfs_iext_cursor icur; @@ -5462,8 +5461,7 @@ __xfs_bunmapi( if (!isrt || (flags & XFS_BMAPI_REMAP)) goto delete; - sum = del.br_startblock + del.br_blockcount; - div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, del.br_startblock + del.br_blockcount, &mod); if (mod) { /* * Realtime extent not lined up at the end. @@ -5510,7 +5508,8 @@ __xfs_bunmapi( goto error0; goto nodelete; } - div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod); + + xfs_rtb_to_rtx(mp, del.br_startblock, &mod); if (mod) { xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index 70424ffb7d3..f74618323b4 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1029,13 +1029,13 @@ xfs_rtfree_blocks( ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN); - len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod); + len = xfs_rtb_to_rtx(mp, rtlen, &mod); if (mod) { ASSERT(mod == 0); return -EIO; } - start = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod); + start = xfs_rtb_to_rtx(mp, rtbno, &mod); if (mod) { ASSERT(mod == 0); return -EIO; diff --git a/libxfs/xfs_rtbitmap.h b/libxfs/xfs_rtbitmap.h index e2a36fc157c..bdd4858a794 100644 --- a/libxfs/xfs_rtbitmap.h +++ b/libxfs/xfs_rtbitmap.h @@ -39,6 +39,23 @@ xfs_extlen_to_rtxlen( return len / mp->m_sb.sb_rextsize; } +static inline xfs_rtxnum_t +xfs_rtb_to_rtx( + struct xfs_mount *mp, + xfs_rtblock_t rtbno, + xfs_extlen_t *mod) +{ + return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, mod); +} + +static inline xfs_rtxnum_t +xfs_rtb_to_rtxt( + struct xfs_mount *mp, + xfs_rtblock_t rtbno) +{ + return div_u64(rtbno, mp->m_sb.sb_rextsize); +} + /* * Functions for walking free space rtextents in the realtime bitmap. */ diff --git a/libxfs/xfs_swapext.c b/libxfs/xfs_swapext.c index d2f0c89571d..718600019a7 100644 --- a/libxfs/xfs_swapext.c +++ b/libxfs/xfs_swapext.c @@ -28,6 +28,7 @@ #include "xfs_dir2_priv.h" #include "xfs_dir2.h" #include "xfs_symlink_remote.h" +#include "xfs_rtbitmap.h" struct kmem_cache *xfs_swapext_intent_cache; @@ -213,19 +214,19 @@ xfs_swapext_check_rt_extents( irec2.br_blockcount); /* Both mappings must be aligned to the realtime extent size. */ - div_u64_rem(irec1.br_startoff, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL; } - div_u64_rem(irec2.br_startoff, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_startoff, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL; } - div_u64_rem(irec1.br_blockcount, mp->m_sb.sb_rextsize, &mod); + xfs_rtb_to_rtx(mp, irec1.br_blockcount, &mod); if (mod) { ASSERT(mod == 0); return -EINVAL;