add patch fix-inode-checksum-calculation-if-i_extra_size-is-too-small
[ext4-patch-queue.git] / convert-DAX-faults-to-iomap-infrastructure
blob211a750169c220cb5f788458c5ddf7d80eccbd43
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>
13 ---
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
20 --- a/fs/ext4/file.c
21 +++ b/fs/ext4/file.c
22 @@ -275,7 +275,7 @@ static int ext4_dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
23         if (IS_ERR(handle))
24                 result = VM_FAULT_SIGBUS;
25         else
26 -               result = dax_fault(vma, vmf, ext4_dax_get_block);
27 +               result = dax_iomap_fault(vma, vmf, &ext4_iomap_ops);
29         if (write) {
30                 if (!IS_ERR(handle))
31 @@ -309,9 +309,10 @@ static int ext4_dax_pmd_fault(struct vm_area_struct *vma, unsigned long addr,
33         if (IS_ERR(handle))
34                 result = VM_FAULT_SIGBUS;
35 -       else
36 -               result = dax_pmd_fault(vma, addr, pmd, flags,
37 -                                        ext4_dax_get_block);
38 +       else {
39 +               result = dax_iomap_pmd_fault(vma, addr, pmd, flags,
40 +                                            &ext4_iomap_ops);
41 +       }
43         if (write) {
44                 if (!IS_ERR(handle))
45 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
46 index 3192ec0768d4..4d71c7bc3524 100644
47 --- a/fs/ext4/inode.c
48 +++ b/fs/ext4/inode.c
49 @@ -3361,12 +3361,16 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
50                 }
52                 /*
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
56 -                * ext4_iomap_end().
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.
62                  */
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) {
67                         int err;
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))
76                 return 0;
78         handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
79 -- 
80 2.6.6