]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: make RT extent numbers relative to the rtgroup
authorChristoph Hellwig <hch@lst.de>
Mon, 5 Aug 2024 17:36:45 +0000 (10:36 -0700)
committerChristoph Hellwig <hch@lst.de>
Tue, 6 Aug 2024 12:53:49 +0000 (05:53 -0700)
Source kernel commit: b8ed01fa4a75b3589000486b3f71568a27aa08f1

To prepare for adding per-rtgroup bitmap files, make the xfs_rtxnum_t
type encode the RT extent number relative to the rtgroup.  The biggest
part of this to clearly distinguish between the relative extent number
that gets masked when converting from a global block number and length
values that just have a factor applied to them when converting from
file system blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_bmap.c
libxfs/xfs_rtbitmap.h

index 5792860f85adf5b439ad924b815db46b117eba06..ae8073ef1e621434f4075901a2eb97b36895c4bb 100644 (file)
@@ -4120,7 +4120,7 @@ retry:
 
        fdblocks = indlen;
        if (XFS_IS_REALTIME_INODE(ip)) {
-               error = xfs_dec_frextents(mp, xfs_rtb_to_rtx(mp, alen));
+               error = xfs_dec_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
                if (error)
                        goto out_unreserve_quota;
        } else {
@@ -4155,7 +4155,7 @@ retry:
 
 out_unreserve_frextents:
        if (XFS_IS_REALTIME_INODE(ip))
-               xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, alen));
+               xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, alen));
 out_unreserve_quota:
        if (XFS_IS_QUOTA_ON(mp))
                xfs_quota_unreserve_blkres(ip, alen);
@@ -5082,7 +5082,7 @@ xfs_bmap_del_extent_delay(
        fdblocks = da_diff;
 
        if (isrt)
-               xfs_add_frextents(mp, xfs_rtb_to_rtx(mp, del->br_blockcount));
+               xfs_add_frextents(mp, xfs_blen_to_rtbxlen(mp, del->br_blockcount));
        else
                fdblocks += del->br_blockcount;
 
index 776cca9e41bf05d737ba151aac572bc3de1ff59f..cf21ae31bfaa474c3906b1658158a36f14b460e9 100644 (file)
@@ -22,13 +22,37 @@ struct xfs_rtalloc_args {
 
 static inline xfs_rtblock_t
 xfs_rtx_to_rtb(
-       struct xfs_mount        *mp,
+       struct xfs_rtgroup      *rtg,
        xfs_rtxnum_t            rtx)
 {
+       struct xfs_mount        *mp = rtg->rtg_mount;
+       xfs_rtblock_t           start = xfs_rgno_start_rtb(mp, rtg->rtg_rgno);
+
        if (mp->m_rtxblklog >= 0)
-               return rtx << mp->m_rtxblklog;
+               return start + (rtx << mp->m_rtxblklog);
+       return start + (rtx * mp->m_sb.sb_rextsize);
+}
 
-       return rtx * mp->m_sb.sb_rextsize;
+/* Convert an rgbno into an rt extent number. */
+static inline xfs_rtxnum_t
+xfs_rgbno_to_rtx(
+       struct xfs_mount        *mp,
+       xfs_rgblock_t           rgbno)
+{
+       if (likely(mp->m_rtxblklog >= 0))
+               return rgbno >> mp->m_rtxblklog;
+       return rgbno / mp->m_sb.sb_rextsize;
+}
+
+static inline uint64_t
+xfs_rtbxlen_to_blen(
+       struct xfs_mount        *mp,
+       xfs_rtbxlen_t           rtbxlen)
+{
+       if (mp->m_rtxblklog >= 0)
+               return rtbxlen << mp->m_rtxblklog;
+
+       return rtbxlen * mp->m_sb.sb_rextsize;
 }
 
 static inline xfs_extlen_t
@@ -65,16 +89,29 @@ xfs_extlen_to_rtxlen(
        return len / mp->m_sb.sb_rextsize;
 }
 
+/* Convert an rt block count into an rt extent count. */
+static inline xfs_rtbxlen_t
+xfs_blen_to_rtbxlen(
+       struct xfs_mount        *mp,
+       uint64_t                blen)
+{
+       if (likely(mp->m_rtxblklog >= 0))
+               return blen >> mp->m_rtxblklog;
+
+       return div_u64(blen, 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)
 {
-       if (likely(mp->m_rtxblklog >= 0))
-               return rtbno >> mp->m_rtxblklog;
+       uint64_t                __rgbno = __xfs_rtb_to_rgbno(mp, rtbno);
 
-       return div_u64(rtbno, mp->m_sb.sb_rextsize);
+       if (likely(mp->m_rtxblklog >= 0))
+               return __rgbno >> mp->m_rtxblklog;
+       return div_u64(__rgbno, mp->m_sb.sb_rextsize);
 }
 
 /* Return the offset of an rt block number within an rt extent. */
@@ -89,26 +126,6 @@ xfs_rtb_to_rtxoff(
        return do_div(rtbno, mp->m_sb.sb_rextsize);
 }
 
-/*
- * 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 (likely(mp->m_rtxblklog >= 0)) {
-               if (rtbno & mp->m_rtxblkmask)
-                       return (rtbno >> mp->m_rtxblklog) + 1;
-               return rtbno >> mp->m_rtxblklog;
-       }
-
-       if (do_div(rtbno, mp->m_sb.sb_rextsize))
-               rtbno++;
-       return rtbno;
-}
-
 /* Round this rtblock up to the nearest rt extent size. */
 static inline xfs_rtblock_t
 xfs_rtb_roundup_rtx(