xfs: call xfs_flush_unmap_range from xfs_free_file_space
authorChristoph Hellwig <hch@lst.de>
Tue, 27 Aug 2024 06:50:48 +0000 (08:50 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 28 Aug 2024 14:53:58 +0000 (16:53 +0200)
Call xfs_flush_unmap_range from xfs_free_file_space so that
xfs_file_fallocate doesn't have to predict which mode will call it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20240827065123.1762168-5-hch@lst.de
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/xfs/xfs_bmap_util.c
fs/xfs/xfs_file.c

index fe2e2c930975501b447ca5b36109de998275dd3f..187a0dbda24fc4a4f905ffa73d9d20fc43feff2f 100644 (file)
@@ -848,6 +848,14 @@ xfs_free_file_space(
        if (len <= 0)   /* if nothing being freed */
                return 0;
 
+       /*
+        * Now AIO and DIO has drained we flush and (if necessary) invalidate
+        * the cached range over the first operation we are about to run.
+        */
+       error = xfs_flush_unmap_range(ip, offset, len);
+       if (error)
+               return error;
+
        startoffset_fsb = XFS_B_TO_FSB(mp, offset);
        endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len);
 
index 4cdc54dc96862e2af50a5dbd5951be2588d3a282..5b9e49da06013c66a859f662d303bf0cabb59c20 100644 (file)
@@ -890,27 +890,6 @@ xfs_file_fallocate(
         */
        inode_dio_wait(inode);
 
-       /*
-        * Now AIO and DIO has drained we flush and (if necessary) invalidate
-        * the cached range over the first operation we are about to run.
-        *
-        * We care about zero and collapse here because they both run a hole
-        * punch over the range first. Because that can zero data, and the range
-        * of invalidation for the shift operations is much larger, we still do
-        * the required flush for collapse in xfs_prepare_shift().
-        *
-        * Insert has the same range requirements as collapse, and we extend the
-        * file first which can zero data. Hence insert has the same
-        * flush/invalidate requirements as collapse and so they are both
-        * handled at the right time by xfs_prepare_shift().
-        */
-       if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE |
-                   FALLOC_FL_COLLAPSE_RANGE)) {
-               error = xfs_flush_unmap_range(ip, offset, len);
-               if (error)
-                       goto out_unlock;
-       }
-
        error = file_modified(file);
        if (error)
                goto out_unlock;