1 ext4: convert DAX faults to iomap infrastructure
3 From: Jan Kara <jack@suse.cz>
5 Convert DAX faults to use iomap infrastructure. We would not have to start
6 transaction in ext4_dax_fault() anymore since ext4_iomap_begin takes
7 care of that but so far we do that to avoid lock inversion of
8 transaction start with DAX entry lock which gets acquired in
9 dax_iomap_fault() before calling ->iomap_begin handler.
11 Signed-off-by: Jan Kara <jack@suse.cz>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 fs/ext4/file.c | 9 +++++----
15 fs/ext4/inode.c | 14 +++++++++-----
16 2 files changed, 14 insertions(+), 9 deletions(-)
18 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
19 index 1953fe34f9fe..b5f184493c57 100644
22 @@ -275,7 +275,7 @@ static int ext4_dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
24 result = VM_FAULT_SIGBUS;
26 - result = dax_fault(vma, vmf, ext4_dax_get_block);
27 + result = dax_iomap_fault(vma, vmf, &ext4_iomap_ops);
31 @@ -309,9 +309,10 @@ static int ext4_dax_pmd_fault(struct vm_area_struct *vma, unsigned long addr,
34 result = VM_FAULT_SIGBUS;
36 - result = dax_pmd_fault(vma, addr, pmd, flags,
37 - ext4_dax_get_block);
39 + result = dax_iomap_pmd_fault(vma, addr, pmd, flags,
45 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
46 index 3192ec0768d4..4d71c7bc3524 100644
49 @@ -3361,12 +3361,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
53 - * If we added blocks beyond i_size we need to make sure they
54 + * If we added blocks beyond i_size, we need to make sure they
55 * will get truncated if we crash before updating i_size in
57 + * ext4_iomap_end(). For faults we don't need to do that (and
58 + * even cannot because for orphan list operations inode_lock is
59 + * required) - if we happen to instantiate block beyond i_size,
60 + * it is because we race with truncate which has already added
61 + * the inode to the orphan list.
63 - if (first_block + map.m_len >
64 - (inode->i_size + (1 << blkbits) - 1) >> blkbits) {
65 + if (!(flags & IOMAP_FAULT) && first_block + map.m_len >
66 + (i_size_read(inode) + (1 << blkbits) - 1) >> blkbits) {
69 err = ext4_orphan_add(handle, inode);
70 @@ -3412,7 +3416,7 @@ static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length,
71 int blkbits = inode->i_blkbits;
72 bool truncate = false;
74 - if (!(flags & IOMAP_WRITE))
75 + if (!(flags & IOMAP_WRITE) || (flags & IOMAP_FAULT))
78 handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);