Commit aaa422c4 authored by Dan Williams's avatar Dan Williams

fs, dax: unify IOMAP_F_DIRTY read vs write handling policy in the dax core

While reviewing whether MAP_SYNC should strengthen its current guarantee
of syncing writes from the initiating process to also include
third-party readers observing dirty metadata, Dave pointed out that the
check of IOMAP_WRITE is misplaced.

The policy of what to with IOMAP_F_DIRTY should be separated from the
generic filesystem mechanism of reporting dirty metadata. Move this
policy to the fs-dax core to simplify the per-filesystem iomap handlers,
and further centralize code that implements the MAP_SYNC policy. This
otherwise should not change behavior, it just makes it easier to change
behavior in the future.
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Reported-by: default avatarDave Chinner <david@fromorbit.com>
Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent a39e596b
...@@ -1079,6 +1079,17 @@ static int dax_fault_return(int error) ...@@ -1079,6 +1079,17 @@ static int dax_fault_return(int error)
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
} }
/*
* MAP_SYNC on a dax mapping guarantees dirty metadata is
* flushed on write-faults (non-cow), but not read-faults.
*/
static bool dax_fault_is_synchronous(unsigned long flags,
struct vm_area_struct *vma, struct iomap *iomap)
{
return (flags & IOMAP_WRITE) && (vma->vm_flags & VM_SYNC)
&& (iomap->flags & IOMAP_F_DIRTY);
}
static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
const struct iomap_ops *ops) const struct iomap_ops *ops)
{ {
...@@ -1170,7 +1181,7 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp, ...@@ -1170,7 +1181,7 @@ static int dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
goto finish_iomap; goto finish_iomap;
} }
sync = (vma->vm_flags & VM_SYNC) && (iomap.flags & IOMAP_F_DIRTY); sync = dax_fault_is_synchronous(flags, vma, &iomap);
switch (iomap.type) { switch (iomap.type) {
case IOMAP_MAPPED: case IOMAP_MAPPED:
...@@ -1390,7 +1401,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp, ...@@ -1390,7 +1401,7 @@ static int dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
if (iomap.offset + iomap.length < pos + PMD_SIZE) if (iomap.offset + iomap.length < pos + PMD_SIZE)
goto finish_iomap; goto finish_iomap;
sync = (vma->vm_flags & VM_SYNC) && (iomap.flags & IOMAP_F_DIRTY); sync = dax_fault_is_synchronous(iomap_flags, vma, &iomap);
switch (iomap.type) { switch (iomap.type) {
case IOMAP_MAPPED: case IOMAP_MAPPED:
......
...@@ -3479,7 +3479,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, ...@@ -3479,7 +3479,7 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
} }
iomap->flags = 0; iomap->flags = 0;
if ((flags & IOMAP_WRITE) && ext4_inode_datasync_dirty(inode)) if (ext4_inode_datasync_dirty(inode))
iomap->flags |= IOMAP_F_DIRTY; iomap->flags |= IOMAP_F_DIRTY;
iomap->bdev = inode->i_sb->s_bdev; iomap->bdev = inode->i_sb->s_bdev;
iomap->dax_dev = sbi->s_daxdev; iomap->dax_dev = sbi->s_daxdev;
......
...@@ -1087,8 +1087,8 @@ xfs_file_iomap_begin( ...@@ -1087,8 +1087,8 @@ xfs_file_iomap_begin(
trace_xfs_iomap_found(ip, offset, length, 0, &imap); trace_xfs_iomap_found(ip, offset, length, 0, &imap);
} }
if ((flags & IOMAP_WRITE) && xfs_ipincount(ip) && if (xfs_ipincount(ip) && (ip->i_itemp->ili_fsync_fields
(ip->i_itemp->ili_fsync_fields & ~XFS_ILOG_TIMESTAMP)) & ~XFS_ILOG_TIMESTAMP))
iomap->flags |= IOMAP_F_DIRTY; iomap->flags |= IOMAP_F_DIRTY;
xfs_bmbt_to_iomap(ip, iomap, &imap); xfs_bmbt_to_iomap(ip, iomap, &imap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment