]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: hoist freeing of rt data fork extent mappings
authorDarrick J. Wong <djwong@kernel.org>
Mon, 12 Feb 2024 14:01:33 +0000 (15:01 +0100)
committerCarlos Maiolino <cem@kernel.org>
Thu, 15 Feb 2024 11:56:43 +0000 (12:56 +0100)
Source kernel commit: 6c664484337b37fa0cf6e958f4019623e30d40f7

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: Carlos Maiolino <cem@kernel.org>
libxfs/libxfs_api_defs.h
libxfs/libxfs_priv.h
libxfs/xfs_bmap.c
libxfs/xfs_rtbitmap.c

index 04277c00955b7f1e7fe6a3db9275f558fe35abea..a16efa00757247d1fd7e9ce6a120f49ce45b2fb1 100644 (file)
 #define xfs_rmap_query_range           libxfs_rmap_query_range
 
 #define xfs_rtfree_extent              libxfs_rtfree_extent
+#define xfs_rtfree_blocks              libxfs_rtfree_blocks
 #define xfs_sb_from_disk               libxfs_sb_from_disk
 #define xfs_sb_quota_from_disk         libxfs_sb_quota_from_disk
 #define xfs_sb_read_secondary          libxfs_sb_read_secondary
index 5a7decf970ecebb58434d674af458cf049f774c0..21d772cf4d76752040566c80280b829e92f1278e 100644 (file)
@@ -497,6 +497,7 @@ xfs_buf_corruption_error(struct xfs_buf *bp, xfs_failaddr_t fa);
 /* XXX: this is clearly a bug - a shared header needs to export this */
 /* xfs_rtalloc.c */
 int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
+int libxfs_rtfree_blocks(struct xfs_trans *, xfs_fsblock_t, xfs_filblks_t);
 bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
 
 struct xfs_rtalloc_rec {
index 2bd23d40e7431d2bd5cf9fc81c8117fff06c451b..5744b882ba90e3f2ba3dd06487b90e5e31d25b6a 100644 (file)
@@ -5050,33 +5050,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 bc8312caf54b1e0a2444142b3e07af6521307b5d..2c20c6538917e379c4942f1447564776c182e5d3 100644 (file)
@@ -1003,6 +1003,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(