[RFC PATCH v4 01/12] xfs: reexpand iter to original count when upgrading to excl ILOCK
From: Ojaswin Mujoo
Date: Mon Sep 28 2026 - 08:25:16 EST
In xfs_file_write_checks() when we upgrade to an exclusive lock, we
correctly redo the write checks, but we should also reexpand the iter to
the original count incase it was trimmed. This is because a parallel
truncation/expansion, in the window where inode was unlocked, could have
changed the isize so its good to recalculate limits based on the original
count.
Also, s/count/orig_count/ while we are at it to better indicate its purpose
Signed-off-by: Ojaswin Mujoo <ojaswin@xxxxxxxxxxxxx>
---
fs/xfs/xfs_file.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index d8202da15aca..d53a329b6a58 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -450,7 +450,7 @@ xfs_file_write_checks(
struct xfs_zone_alloc_ctx *ac)
{
struct inode *inode = iocb->ki_filp->f_mapping->host;
- size_t count = iov_iter_count(from);
+ size_t orig_count = iov_iter_count(from);
bool drained_dio = false;
ssize_t error;
@@ -482,6 +482,7 @@ xfs_file_write_checks(
*iolock = 0;
return error;
}
+ iov_iter_reexpand(from, orig_count);
goto restart;
}
@@ -496,7 +497,7 @@ xfs_file_write_checks(
* the slow path when we are at or beyond the current EOF.
*/
if (iocb->ki_pos > i_size_read(inode)) {
- error = xfs_file_write_zero_eof(iocb, from, iolock, count,
+ error = xfs_file_write_zero_eof(iocb, from, iolock, orig_count,
&drained_dio, ac);
if (error == 1)
goto restart;
--
2.55.0