Skip to content

Commit 1df1d3b

Browse files
Christoph Hellwigbrauner
authored andcommitted
xfs: call xfs_flush_unmap_range from xfs_free_file_space
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>
1 parent 57413d8 commit 1df1d3b

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,14 @@ xfs_free_file_space(
848848
if (len <= 0) /* if nothing being freed */
849849
return 0;
850850

851+
/*
852+
* Now AIO and DIO has drained we flush and (if necessary) invalidate
853+
* the cached range over the first operation we are about to run.
854+
*/
855+
error = xfs_flush_unmap_range(ip, offset, len);
856+
if (error)
857+
return error;
858+
851859
startoffset_fsb = XFS_B_TO_FSB(mp, offset);
852860
endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len);
853861

fs/xfs/xfs_file.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -890,27 +890,6 @@ xfs_file_fallocate(
890890
*/
891891
inode_dio_wait(inode);
892892

893-
/*
894-
* Now AIO and DIO has drained we flush and (if necessary) invalidate
895-
* the cached range over the first operation we are about to run.
896-
*
897-
* We care about zero and collapse here because they both run a hole
898-
* punch over the range first. Because that can zero data, and the range
899-
* of invalidation for the shift operations is much larger, we still do
900-
* the required flush for collapse in xfs_prepare_shift().
901-
*
902-
* Insert has the same range requirements as collapse, and we extend the
903-
* file first which can zero data. Hence insert has the same
904-
* flush/invalidate requirements as collapse and so they are both
905-
* handled at the right time by xfs_prepare_shift().
906-
*/
907-
if (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE |
908-
FALLOC_FL_COLLAPSE_RANGE)) {
909-
error = xfs_flush_unmap_range(ip, offset, len);
910-
if (error)
911-
goto out_unlock;
912-
}
913-
914893
error = file_modified(file);
915894
if (error)
916895
goto out_unlock;

0 commit comments

Comments
 (0)