Skip to content

Commit acfbac7

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: take XFS_MMAPLOCK_EXCL xfs_file_write_zero_eof
xfs_file_write_zero_eof is the only caller of xfs_zero_range that does not take XFS_MMAPLOCK_EXCL (aka the invalidate lock). Currently that is actually the right thing, as an error in the iomap zeroing code will also take the invalidate_lock to clean up, but to fix that deadlock we need a consistent locking pattern first. The only extra thing that XFS_MMAPLOCK_EXCL will lock out are read pagefaults, which isn't really needed here, but also not actively harmful. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent 3c39937 commit acfbac7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

fs/xfs/xfs_file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ xfs_file_write_zero_eof(
364364
{
365365
struct xfs_inode *ip = XFS_I(iocb->ki_filp->f_mapping->host);
366366
loff_t isize;
367+
int error;
367368

368369
/*
369370
* We need to serialise against EOF updates that occur in IO completions
@@ -411,7 +412,12 @@ xfs_file_write_zero_eof(
411412
}
412413

413414
trace_xfs_zero_eof(ip, isize, iocb->ki_pos - isize);
414-
return xfs_zero_range(ip, isize, iocb->ki_pos - isize, NULL);
415+
416+
xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
417+
error = xfs_zero_range(ip, isize, iocb->ki_pos - isize, NULL);
418+
xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
419+
420+
return error;
415421
}
416422

417423
/*

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ xfs_zero_range(
14491449
{
14501450
struct inode *inode = VFS_I(ip);
14511451

1452+
xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL);
1453+
14521454
if (IS_DAX(inode))
14531455
return dax_zero_range(inode, pos, len, did_zero,
14541456
&xfs_dax_write_iomap_ops);

0 commit comments

Comments
 (0)