xfs: hoist freeing of rt data fork extent mappings
authorDarrick J. Wong <djwong@kernel.org>
Thu, 8 Feb 2024 23:20:36 +0000 (15:20 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Feb 2024 18:10:44 +0000 (19:10 +0100)
commit 6c664484337b37fa0cf6e958f4019623e30d40f7 upstream.

Currently, xfs_bmap_del_extent_real contains a bunch of code to convert
the physical extent of a data fork mapping for a realtime file into rt
extents and pass that to the rt extent freeing function.  Since the
details of this aren't needed when CONFIG_XFS_REALTIME=n, move it to
xfs_rtbitmap.c to reduce code size when realtime isn't enabled.

This will (one day) enable realtime EFIs to reuse the same
unit-converting call with less code duplication.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Acked-by: Chandan Babu R <chandanbabu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_rtbitmap.c
fs/xfs/xfs_rtalloc.h

index 30c931b..26bfa34 100644 (file)
@@ -5057,33 +5057,20 @@ xfs_bmap_del_extent_real(
 
        flags = XFS_ILOG_CORE;
        if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) {
-               xfs_filblks_t   len;
-               xfs_extlen_t    mod;
-
-               len = div_u64_rem(del->br_blockcount, mp->m_sb.sb_rextsize,
-                                 &mod);
-               ASSERT(mod == 0);
-
                if (!(bflags & XFS_BMAPI_REMAP)) {
-                       xfs_fsblock_t   bno;
-
-                       bno = div_u64_rem(del->br_startblock,
-                                       mp->m_sb.sb_rextsize, &mod);
-                       ASSERT(mod == 0);
-
-                       error = xfs_rtfree_extent(tp, bno, (xfs_extlen_t)len);
+                       error = xfs_rtfree_blocks(tp, del->br_startblock,
+                                       del->br_blockcount);
                        if (error)
                                goto done;
                }
 
                do_fx = 0;
-               nblks = len * mp->m_sb.sb_rextsize;
                qfield = XFS_TRANS_DQ_RTBCOUNT;
        } else {
                do_fx = 1;
-               nblks = del->br_blockcount;
                qfield = XFS_TRANS_DQ_BCOUNT;
        }
+       nblks = del->br_blockcount;
 
        del_endblock = del->br_startblock + del->br_blockcount;
        if (cur) {
index fa180ab..655108a 100644 (file)
@@ -1005,6 +1005,39 @@ xfs_rtfree_extent(
        return 0;
 }
 
+/*
+ * Free some blocks in the realtime subvolume.  rtbno and rtlen are in units of
+ * rt blocks, not rt extents; must be aligned to the rt extent size; and rtlen
+ * cannot exceed XFS_MAX_BMBT_EXTLEN.
+ */
+int
+xfs_rtfree_blocks(
+       struct xfs_trans        *tp,
+       xfs_fsblock_t           rtbno,
+       xfs_filblks_t           rtlen)
+{
+       struct xfs_mount        *mp = tp->t_mountp;
+       xfs_rtblock_t           bno;
+       xfs_filblks_t           len;
+       xfs_extlen_t            mod;
+
+       ASSERT(rtlen <= XFS_MAX_BMBT_EXTLEN);
+
+       len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod);
+       if (mod) {
+               ASSERT(mod == 0);
+               return -EIO;
+       }
+
+       bno = div_u64_rem(rtbno, mp->m_sb.sb_rextsize, &mod);
+       if (mod) {
+               ASSERT(mod == 0);
+               return -EIO;
+       }
+
+       return xfs_rtfree_extent(tp, bno, len);
+}
+
 /* Find all the free records within a given range. */
 int
 xfs_rtalloc_query_range(
index 62c7ad7..3b2f1b4 100644 (file)
@@ -58,6 +58,10 @@ xfs_rtfree_extent(
        xfs_rtblock_t           bno,    /* starting block number to free */
        xfs_extlen_t            len);   /* length of extent freed */
 
+/* Same as above, but in units of rt blocks. */
+int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
+               xfs_filblks_t rtlen);
+
 /*
  * Initialize realtime fields in the mount structure.
  */
@@ -139,6 +143,7 @@ int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);
 #else
 # define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb)    (ENOSYS)
 # define xfs_rtfree_extent(t,b,l)                       (ENOSYS)
+# define xfs_rtfree_blocks(t,rb,rl)                    (ENOSYS)
 # define xfs_rtpick_extent(m,t,l,rb)                    (ENOSYS)
 # define xfs_growfs_rt(mp,in)                           (ENOSYS)
 # define xfs_rtalloc_query_range(t,l,h,f,p)             (ENOSYS)