Skip to content

Commit a39e596

Browse files
Christoph Hellwigdjbw
authored andcommitted
xfs: support for synchronous DAX faults
Return IOMAP_F_DIRTY from xfs_file_iomap_begin() when asked to prepare blocks for writing and the inode is pinned, and has dirty fields other than the timestamps. In __xfs_filemap_fault() we then detect this case and call dax_finish_sync_fault() to make sure all metadata is committed, and to insert the page table entry. Note that this will also dirty corresponding radix tree entry which is what we want - fsync(2) will still provide data integrity guarantees for applications not using userspace flushing. And applications using userspace flushing can avoid calling fsync(2) and thus avoid the performance overhead. [JK: Added VM_SYNC flag handling] Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 7b565c9 commit a39e596

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

fs/xfs/xfs_file.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <linux/falloc.h>
4545
#include <linux/pagevec.h>
4646
#include <linux/backing-dev.h>
47+
#include <linux/mman.h>
4748

4849
static const struct vm_operations_struct xfs_file_vm_ops;
4950

@@ -1040,7 +1041,11 @@ __xfs_filemap_fault(
10401041

10411042
xfs_ilock(XFS_I(inode), XFS_MMAPLOCK_SHARED);
10421043
if (IS_DAX(inode)) {
1043-
ret = dax_iomap_fault(vmf, pe_size, NULL, &xfs_iomap_ops);
1044+
pfn_t pfn;
1045+
1046+
ret = dax_iomap_fault(vmf, pe_size, &pfn, &xfs_iomap_ops);
1047+
if (ret & VM_FAULT_NEEDDSYNC)
1048+
ret = dax_finish_sync_fault(vmf, pe_size, pfn);
10441049
} else {
10451050
if (write_fault)
10461051
ret = iomap_page_mkwrite(vmf, &xfs_iomap_ops);
@@ -1110,6 +1115,13 @@ xfs_file_mmap(
11101115
struct file *filp,
11111116
struct vm_area_struct *vma)
11121117
{
1118+
/*
1119+
* We don't support synchronous mappings for non-DAX files. At least
1120+
* until someone comes with a sensible use case.
1121+
*/
1122+
if (!IS_DAX(file_inode(filp)) && (vma->vm_flags & VM_SYNC))
1123+
return -EOPNOTSUPP;
1124+
11131125
file_accessed(filp);
11141126
vma->vm_ops = &xfs_file_vm_ops;
11151127
if (IS_DAX(file_inode(filp)))
@@ -1128,6 +1140,7 @@ const struct file_operations xfs_file_operations = {
11281140
.compat_ioctl = xfs_file_compat_ioctl,
11291141
#endif
11301142
.mmap = xfs_file_mmap,
1143+
.mmap_supported_flags = MAP_SYNC,
11311144
.open = xfs_file_open,
11321145
.release = xfs_file_release,
11331146
.fsync = xfs_file_fsync,

fs/xfs/xfs_iomap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "xfs_error.h"
3434
#include "xfs_trans.h"
3535
#include "xfs_trans_space.h"
36+
#include "xfs_inode_item.h"
3637
#include "xfs_iomap.h"
3738
#include "xfs_trace.h"
3839
#include "xfs_icache.h"
@@ -1086,6 +1087,10 @@ xfs_file_iomap_begin(
10861087
trace_xfs_iomap_found(ip, offset, length, 0, &imap);
10871088
}
10881089

1090+
if ((flags & IOMAP_WRITE) && xfs_ipincount(ip) &&
1091+
(ip->i_itemp->ili_fsync_fields & ~XFS_ILOG_TIMESTAMP))
1092+
iomap->flags |= IOMAP_F_DIRTY;
1093+
10891094
xfs_bmbt_to_iomap(ip, iomap, &imap);
10901095

10911096
if (shared)

0 commit comments

Comments
 (0)