summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-05-21 17:07:21 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2019-08-10 09:57:57 -0700
commit5978cec37a357067de1b4226242ce917b6d1ed6b (patch)
tree3c8a17f94c2d61b85e8eeb24358d2b957f2f25eb /fs/xfs/libxfs
parentfbf147609ac4125e0dd8266458cc8de939da32f9 (diff)
xfs: create a new inode fork block unmap helper
Create a new helper to unmap blocks from an inode's fork. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs/xfs/libxfs')
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c43
-rw-r--r--fs/xfs/libxfs/xfs_bmap.h3
2 files changed, 46 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 39dbc93374dc..5be389bfaf3f 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -6227,3 +6227,46 @@ 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,
+ int whichfork,
+ xfs_fileoff_t startoff,
+ xfs_filblks_t unmap_len,
+ int bunmapi_flags)
+{
+ int error = 0;
+
+ ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+
+ bunmapi_flags |= xfs_bmapi_aflag(whichfork);
+ while (unmap_len > 0) {
+ ASSERT((*tpp)->t_firstblock == NULLFSBLOCK);
+ error = __xfs_bunmapi(*tpp, ip, startoff, &unmap_len,
+ bunmapi_flags, XFS_ITRUNC_MAX_EXTENTS);
+ if (error)
+ goto out;
+
+ /*
+ * Duplicate the transaction that has the permanent
+ * reservation and commit the old transaction.
+ */
+ error = xfs_defer_finish(tpp);
+ if (error)
+ goto out;
+ }
+out:
+ return error;
+}
diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h
index b857762fac55..cf460d3654b5 100644
--- a/fs/xfs/libxfs/xfs_bmap.h
+++ b/fs/xfs/libxfs/xfs_bmap.h
@@ -279,5 +279,8 @@ xfs_failaddr_t xfs_bmap_validate_extent(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,
int flags);
+int xfs_bunmapi_range(struct xfs_trans **tpp, struct xfs_inode *ip,
+ int whichfork, xfs_fileoff_t startoff, xfs_filblks_t unmap_len,
+ int bunmapi_flags);
#endif /* __XFS_BMAP_H__ */