]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: create helpers to convert rt block numbers to rt extent numbers
authorDarrick J. Wong <djwong@kernel.org>
Mon, 16 Oct 2023 16:37:07 +0000 (09:37 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 17 Oct 2023 23:24:22 +0000 (16:24 -0700)
Create helpers to do unit conversions of rt block numbers to rt extent
numbers.  There are three variations -- one to compute the rt extent
number from an rt block number; one to compute the offset of an rt block
within an rt extent; and one to extract both.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_rtbitmap.c
fs/xfs/libxfs/xfs_rtbitmap.h

index 19203699b9925ccb95d83bfaaa191fe2bc2118d6..fc96aa59a691a4eb5031bda06f358993b0daef8d 100644 (file)
@@ -5276,7 +5276,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;
@@ -5371,8 +5370,8 @@ __xfs_bunmapi(
                if (!isrt)
                        goto delete;
 
-               sum = del.br_startblock + del.br_blockcount;
-               div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod);
+               mod = xfs_rtb_to_rtxoff(mp,
+                               del.br_startblock + del.br_blockcount);
                if (mod) {
                        /*
                         * Realtime extent not lined up at the end.
@@ -5419,7 +5418,8 @@ __xfs_bunmapi(
                                goto error0;
                        goto nodelete;
                }
-               div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod);
+
+               mod = xfs_rtb_to_rtxoff(mp, del.br_startblock);
                if (mod) {
                        xfs_extlen_t off = mp->m_sb.sb_rextsize - mod;
 
index f64e4aeb393b5eebcfd0e5abae2b3cb9eb79c841..383c6437e04264535cb57861e86f6e23ca875c74 100644 (file)
@@ -1024,13 +1024,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_rtxrem(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_rtxrem(mp, rtbno, &mod);
        if (mod) {
                ASSERT(mod == 0);
                return -EIO;
index e2a36fc157c4c465f4e1609f620ba8dc4a12fbb1..9df583083407b2f08f81e4a7518212cf6c79eca5 100644 (file)
@@ -39,6 +39,37 @@ xfs_extlen_to_rtxlen(
        return len / mp->m_sb.sb_rextsize;
 }
 
+/* Convert an rt block number into an rt extent number. */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtx(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtbno)
+{
+       return div_u64(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/* Return the offset of an rt block number within an rt extent. */
+static inline xfs_extlen_t
+xfs_rtb_to_rtxoff(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtbno)
+{
+       return do_div(rtbno, mp->m_sb.sb_rextsize);
+}
+
+/*
+ * Crack an rt block number into an rt extent number and an offset within that
+ * rt extent.  Returns the rt extent number directly and the offset in @off.
+ */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtxrem(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtbno,
+       xfs_extlen_t            *off)
+{
+       return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */