]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
authorDarrick J. Wong <djwong@kernel.org>
Mon, 16 Oct 2023 16:37:47 +0000 (09:37 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 17 Oct 2023 23:25:55 +0000 (16:25 -0700)
Convert these calls to use the helpers, and clean up all these places
where the same variable can have different units depending on where it
is in the function.

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.h
fs/xfs/scrub/rtbitmap.c
fs/xfs/xfs_bmap_util.c
fs/xfs/xfs_fsmap.c
fs/xfs/xfs_rtalloc.c

index fc96aa59a691a4eb5031bda06f358993b0daef8d..be62acffad6ccdfb31748987cc507e03f08afb81 100644 (file)
@@ -4826,12 +4826,8 @@ xfs_bmap_del_extent_delay(
        ASSERT(got->br_startoff <= del->br_startoff);
        ASSERT(got_endoff >= del_endoff);
 
-       if (isrt) {
-               uint64_t        rtexts = del->br_blockcount;
-
-               do_div(rtexts, mp->m_sb.sb_rextsize);
-               xfs_mod_frextents(mp, rtexts);
-       }
+       if (isrt)
+               xfs_mod_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
 
        /*
         * Update the inode delalloc counter now and wait to update the
index 9df583083407b2f08f81e4a7518212cf6c79eca5..ff901bf3d1ee51f5e60910e15f683e998177d2aa 100644 (file)
@@ -70,6 +70,20 @@ xfs_rtb_to_rtxrem(
        return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off);
 }
 
+/*
+ * Convert an rt block number into an rt extent number, rounding up to the next
+ * rt extent if the rt block is not aligned to an rt extent boundary.
+ */
+static inline xfs_rtxnum_t
+xfs_rtb_to_rtxup(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtbno)
+{
+       if (do_div(rtbno, mp->m_sb.sb_rextsize))
+               rtbno++;
+       return rtbno;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
index 584a2b8badac2631c6bd46db63447b9bb791af3d..41a1d89ae8e6cdce6e465ea68d7fc77a02c189ba 100644 (file)
@@ -128,26 +128,22 @@ out:
 void
 xchk_xref_is_used_rt_space(
        struct xfs_scrub        *sc,
-       xfs_rtblock_t           fsbno,
+       xfs_rtblock_t           rtbno,
        xfs_extlen_t            len)
 {
        xfs_rtxnum_t            startext;
        xfs_rtxnum_t            endext;
-       xfs_rtxlen_t            extcount;
        bool                    is_free;
        int                     error;
 
        if (xchk_skip_xref(sc->sm))
                return;
 
-       startext = fsbno;
-       endext = fsbno + len - 1;
-       do_div(startext, sc->mp->m_sb.sb_rextsize);
-       do_div(endext, sc->mp->m_sb.sb_rextsize);
-       extcount = endext - startext + 1;
+       startext = xfs_rtb_to_rtx(sc->mp, rtbno);
+       endext = xfs_rtb_to_rtx(sc->mp, rtbno + len - 1);
        xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
-       error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount,
-                       &is_free);
+       error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext,
+                       endext - startext + 1, &is_free);
        if (!xchk_should_check_xref(sc, &error, NULL))
                goto out_unlock;
        if (is_free)
index 4f53f784f06d774444e3188699caea7431bb6ff9..25a03c1276e37e9db2d1d2a543d9e95bd268b7b8 100644 (file)
@@ -156,14 +156,12 @@ retry:
         * Realtime allocation, done through xfs_rtallocate_extent.
         */
        if (ignore_locality)
-               ap->blkno = 0;
+               rtx = 0;
        else
-               do_div(ap->blkno, mp->m_sb.sb_rextsize);
-       rtx = ap->blkno;
-       ap->length = ralen;
+               rtx = xfs_rtb_to_rtx(mp, ap->blkno);
        raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
-       error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length,
-                       &ralen, ap->wasdel, prod, &rtx);
+       error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
+                       ap->wasdel, prod, &rtx);
        if (error)
                return error;
 
index 1a187bc9da3de04130575448e00b6cb029414285..5a72217f5feb9b990ff3a41d1cb79519cf2b3091 100644 (file)
@@ -539,11 +539,8 @@ xfs_getfsmap_rtdev_rtbitmap(
         * Set up query parameters to return free rtextents covering the range
         * we want.
         */
-       alow.ar_startext = start_rtb;
-       ahigh.ar_startext = end_rtb;
-       do_div(alow.ar_startext, mp->m_sb.sb_rextsize);
-       if (do_div(ahigh.ar_startext, mp->m_sb.sb_rextsize))
-               ahigh.ar_startext++;
+       alow.ar_startext = xfs_rtb_to_rtx(mp, start_rtb);
+       ahigh.ar_startext = xfs_rtb_to_rtxup(mp, end_rtb);
        error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh,
                        xfs_getfsmap_rtdev_rtbitmap_helper, info);
        if (error)
index 62faec195040b8c173d872bc90c35aca13b85c14..ac7c269ad547581d1c1f3a2d20959e393d7ef81d 100644 (file)
@@ -1058,8 +1058,7 @@ xfs_growfs_rt(
                nrblocks_step = (bmbno + 1) * NBBY * nsbp->sb_blocksize *
                                nsbp->sb_rextsize;
                nsbp->sb_rblocks = min(nrblocks, nrblocks_step);
-               nsbp->sb_rextents = nsbp->sb_rblocks;
-               do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
+               nsbp->sb_rextents = xfs_rtb_to_rtx(nmp, nsbp->sb_rblocks);
                ASSERT(nsbp->sb_rextents != 0);
                nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
                nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;