]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: create a new inode fork block unmap helper
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 23:07:39 +0000 (16:07 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 17 Apr 2024 21:06:25 +0000 (14:06 -0700)
Source kernel commit: a59eb5fc21b2a6dc160ee6cdf77f20bc186a88fd

Create a new helper to unmap blocks from an inode's fork.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
libxfs/xfs_bmap.c
libxfs/xfs_bmap.h

index 534a516b59bad72b50cd8696ac4f23c57727ce86..3520235b58afbd76254fabfe17c0d0486c2fdf36 100644 (file)
@@ -5233,7 +5233,7 @@ xfs_bmap_del_extent_real(
  * that value.  If not all extents in the block range can be removed then
  * *done is set.
  */
-int                                            /* error */
+static int
 __xfs_bunmapi(
        struct xfs_trans        *tp,            /* transaction pointer */
        struct xfs_inode        *ip,            /* incore inode */
@@ -6214,3 +6214,42 @@ xfs_bmap_validate_extent(
        return xfs_bmap_validate_extent_raw(ip->i_mount,
                        XFS_IS_REALTIME_INODE(ip), whichfork, irec);
 }
+
+/*
+ * Used in xfs_itruncate_extents().  This is the maximum number of extents
+ * freed from a file in a single transaction.
+ */
+#define        XFS_ITRUNC_MAX_EXTENTS  2
+
+/*
+ * Unmap every extent in part of an inode's fork.  We don't do any higher level
+ * invalidation work at all.
+ */
+int
+xfs_bunmapi_range(
+       struct xfs_trans        **tpp,
+       struct xfs_inode        *ip,
+       uint32_t                flags,
+       xfs_fileoff_t           startoff,
+       xfs_fileoff_t           endoff)
+{
+       xfs_filblks_t           unmap_len = endoff - startoff + 1;
+       int                     error = 0;
+
+       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+
+       while (unmap_len > 0) {
+               ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER);
+               error = __xfs_bunmapi(*tpp, ip, startoff, &unmap_len, flags,
+                               XFS_ITRUNC_MAX_EXTENTS);
+               if (error)
+                       goto out;
+
+               /* free the just unmapped extents */
+               error = xfs_defer_finish(tpp);
+               if (error)
+                       goto out;
+       }
+out:
+       return error;
+}
index 8518324db2855631b0e4d87a08b0c487b47300b9..4b83f6148e0071c00c9d88744c2d60261c991fd4 100644 (file)
@@ -190,9 +190,6 @@ int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno,
 int    xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip,
                xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags,
                xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap);
-int    __xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
-               xfs_fileoff_t bno, xfs_filblks_t *rlen, uint32_t flags,
-               xfs_extnum_t nexts);
 int    xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
                xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags,
                xfs_extnum_t nexts, int *done);
@@ -273,6 +270,8 @@ int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork,
 int    xfs_bmapi_remap(struct xfs_trans *tp, struct xfs_inode *ip,
                xfs_fileoff_t bno, xfs_filblks_t len, xfs_fsblock_t startblock,
                uint32_t flags);
+int    xfs_bunmapi_range(struct xfs_trans **tpp, struct xfs_inode *ip,
+               uint32_t flags, xfs_fileoff_t startoff, xfs_fileoff_t endoff);
 
 extern struct kmem_cache       *xfs_bmap_intent_cache;