Skip to content

Commit 6a39ec1

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: refactor __xfs_filemap_fault
Split the write fault and DAX fault handling into separate helpers so that the main fault handler is easier to follow. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 9092b1d commit 6a39ec1

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

fs/xfs/xfs_file.c

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ xfs_file_llseek(
12521252
}
12531253

12541254
static inline vm_fault_t
1255-
xfs_dax_fault(
1255+
xfs_dax_fault_locked(
12561256
struct vm_fault *vmf,
12571257
unsigned int order,
12581258
bool write_fault)
@@ -1273,6 +1273,45 @@ xfs_dax_fault(
12731273
return ret;
12741274
}
12751275

1276+
static vm_fault_t
1277+
xfs_dax_read_fault(
1278+
struct vm_fault *vmf,
1279+
unsigned int order)
1280+
{
1281+
struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file));
1282+
unsigned int lock_mode;
1283+
vm_fault_t ret;
1284+
1285+
lock_mode = xfs_ilock_for_write_fault(ip);
1286+
ret = xfs_dax_fault_locked(vmf, order, false);
1287+
xfs_iunlock(ip, lock_mode);
1288+
1289+
return ret;
1290+
}
1291+
1292+
static vm_fault_t
1293+
xfs_write_fault(
1294+
struct vm_fault *vmf,
1295+
unsigned int order)
1296+
{
1297+
struct inode *inode = file_inode(vmf->vma->vm_file);
1298+
unsigned int lock_mode;
1299+
vm_fault_t ret;
1300+
1301+
sb_start_pagefault(inode->i_sb);
1302+
file_update_time(vmf->vma->vm_file);
1303+
1304+
lock_mode = xfs_ilock_for_write_fault(XFS_I(inode));
1305+
if (IS_DAX(inode))
1306+
ret = xfs_dax_fault_locked(vmf, order, true);
1307+
else
1308+
ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops);
1309+
xfs_iunlock(XFS_I(inode), lock_mode);
1310+
1311+
sb_end_pagefault(inode->i_sb);
1312+
return ret;
1313+
}
1314+
12761315
/*
12771316
* Locking for serialisation of IO during page faults. This results in a lock
12781317
* ordering of:
@@ -1290,34 +1329,14 @@ __xfs_filemap_fault(
12901329
bool write_fault)
12911330
{
12921331
struct inode *inode = file_inode(vmf->vma->vm_file);
1293-
struct xfs_inode *ip = XFS_I(inode);
1294-
vm_fault_t ret;
1295-
unsigned int lock_mode = 0;
1296-
1297-
trace_xfs_filemap_fault(ip, order, write_fault);
12981332

1299-
if (write_fault) {
1300-
sb_start_pagefault(inode->i_sb);
1301-
file_update_time(vmf->vma->vm_file);
1302-
}
1303-
1304-
if (IS_DAX(inode) || write_fault)
1305-
lock_mode = xfs_ilock_for_write_fault(XFS_I(inode));
1306-
1307-
if (IS_DAX(inode)) {
1308-
ret = xfs_dax_fault(vmf, order, write_fault);
1309-
} else if (write_fault) {
1310-
ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops);
1311-
} else {
1312-
ret = filemap_fault(vmf);
1313-
}
1314-
1315-
if (lock_mode)
1316-
xfs_iunlock(XFS_I(inode), lock_mode);
1333+
trace_xfs_filemap_fault(XFS_I(inode), order, write_fault);
13171334

13181335
if (write_fault)
1319-
sb_end_pagefault(inode->i_sb);
1320-
return ret;
1336+
return xfs_write_fault(vmf, order);
1337+
if (IS_DAX(inode))
1338+
return xfs_dax_read_fault(vmf, order);
1339+
return filemap_fault(vmf);
13211340
}
13221341

13231342
static inline bool

0 commit comments

Comments
 (0)