Skip to content

Commit 4818fd6

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: fold xfs_ilock_for_write_fault into xfs_write_fault
Now that the page fault handler has been refactored, the only caller of xfs_ilock_for_write_fault is simple enough and calls it unconditionally. Fold the logic and expand the comments explaining it. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 4e82fa1 commit 4818fd6

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

fs/xfs/xfs_file.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,6 @@ xfs_ilock_iocb_for_write(
227227
return 0;
228228
}
229229

230-
static unsigned int
231-
xfs_ilock_for_write_fault(
232-
struct xfs_inode *ip)
233-
{
234-
/* get a shared lock if no remapping in progress */
235-
xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
236-
if (!xfs_iflags_test(ip, XFS_IREMAPPING))
237-
return XFS_MMAPLOCK_SHARED;
238-
239-
/* wait for remapping to complete */
240-
xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
241-
xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
242-
return XFS_MMAPLOCK_EXCL;
243-
}
244-
245230
STATIC ssize_t
246231
xfs_file_dio_read(
247232
struct kiocb *iocb,
@@ -1294,18 +1279,30 @@ xfs_write_fault(
12941279
unsigned int order)
12951280
{
12961281
struct inode *inode = file_inode(vmf->vma->vm_file);
1297-
unsigned int lock_mode;
1282+
struct xfs_inode *ip = XFS_I(inode);
1283+
unsigned int lock_mode = XFS_MMAPLOCK_SHARED;
12981284
vm_fault_t ret;
12991285

13001286
sb_start_pagefault(inode->i_sb);
13011287
file_update_time(vmf->vma->vm_file);
13021288

1303-
lock_mode = xfs_ilock_for_write_fault(XFS_I(inode));
1289+
/*
1290+
* Normally we only need the shared mmaplock, but if a reflink remap is
1291+
* in progress we take the exclusive lock to wait for the remap to
1292+
* finish before taking a write fault.
1293+
*/
1294+
xfs_ilock(ip, XFS_MMAPLOCK_SHARED);
1295+
if (xfs_iflags_test(ip, XFS_IREMAPPING)) {
1296+
xfs_iunlock(ip, XFS_MMAPLOCK_SHARED);
1297+
xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
1298+
lock_mode = XFS_MMAPLOCK_EXCL;
1299+
}
1300+
13041301
if (IS_DAX(inode))
13051302
ret = xfs_dax_fault_locked(vmf, order, true);
13061303
else
13071304
ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops);
1308-
xfs_iunlock(XFS_I(inode), lock_mode);
1305+
xfs_iunlock(ip, lock_mode);
13091306

13101307
sb_end_pagefault(inode->i_sb);
13111308
return ret;

0 commit comments

Comments
 (0)