Check in Jan Kara's v3 DAX iomap patches
[ext4-patch-queue.git] / rip-out-DAX-handling-from-direct-IO-path
blob1f2dda7fbcd311468b1ea30029ea78e21cf78b0c
1 ext4: rip out DAX handling from direct IO path
3 From: Jan Kara <jack@suse.cz>
5 Reads and writes for DAX inodes should no longer end up in direct IO
6 code. Rip out the support and add a warning.
8 Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
9 Signed-off-by: Jan Kara <jack@suse.cz>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/ext4.h  |  2 --
13  fs/ext4/inode.c | 97 +++++++++------------------------------------------------
14  2 files changed, 15 insertions(+), 84 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index 098b39910001..8b763113a1b8 100644
18 --- a/fs/ext4/ext4.h
19 +++ b/fs/ext4/ext4.h
20 @@ -2457,8 +2457,6 @@ struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
21  struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
22  int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
23                              struct buffer_head *bh_result, int create);
24 -int ext4_dax_get_block(struct inode *inode, sector_t iblock,
25 -                      struct buffer_head *bh_result, int create);
26  int ext4_get_block(struct inode *inode, sector_t iblock,
27                    struct buffer_head *bh_result, int create);
28  int ext4_dio_get_block(struct inode *inode, sector_t iblock,
29 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
30 index 4d71c7bc3524..d13f7cb6b1d5 100644
31 --- a/fs/ext4/inode.c
32 +++ b/fs/ext4/inode.c
33 @@ -3272,46 +3272,6 @@ static int ext4_releasepage(struct page *page, gfp_t wait)
34  }
36  #ifdef CONFIG_FS_DAX
37 -/*
38 - * Get block function for DAX IO and mmap faults. It takes care of converting
39 - * unwritten extents to written ones and initializes new / converted blocks
40 - * to zeros.
41 - */
42 -int ext4_dax_get_block(struct inode *inode, sector_t iblock,
43 -                      struct buffer_head *bh_result, int create)
45 -       int ret;
47 -       ext4_debug("inode %lu, create flag %d\n", inode->i_ino, create);
48 -       if (!create)
49 -               return _ext4_get_block(inode, iblock, bh_result, 0);
51 -       ret = ext4_get_block_trans(inode, iblock, bh_result,
52 -                                  EXT4_GET_BLOCKS_PRE_IO |
53 -                                  EXT4_GET_BLOCKS_CREATE_ZERO);
54 -       if (ret < 0)
55 -               return ret;
57 -       if (buffer_unwritten(bh_result)) {
58 -               /*
59 -                * We are protected by i_mmap_sem or i_mutex so we know block
60 -                * cannot go away from under us even though we dropped
61 -                * i_data_sem. Convert extent to written and write zeros there.
62 -                */
63 -               ret = ext4_get_block_trans(inode, iblock, bh_result,
64 -                                          EXT4_GET_BLOCKS_CONVERT |
65 -                                          EXT4_GET_BLOCKS_CREATE_ZERO);
66 -               if (ret < 0)
67 -                       return ret;
68 -       }
69 -       /*
70 -        * At least for now we have to clear BH_New so that DAX code
71 -        * doesn't attempt to zero blocks again in a racy way.
72 -        */
73 -       clear_buffer_new(bh_result);
74 -       return 0;
77  static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
78                             unsigned flags, struct iomap *iomap)
79  {
80 @@ -3465,14 +3425,6 @@ struct iomap_ops ext4_iomap_ops = {
81         .iomap_end              = ext4_iomap_end,
82  };
84 -#else
85 -/* Just define empty function, it will never get called. */
86 -int ext4_dax_get_block(struct inode *inode, sector_t iblock,
87 -                      struct buffer_head *bh_result, int create)
89 -       BUG();
90 -       return 0;
92  #endif
94  static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
95 @@ -3594,19 +3546,7 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
96         iocb->private = NULL;
97         if (overwrite)
98                 get_block_func = ext4_dio_get_block_overwrite;
99 -       else if (IS_DAX(inode)) {
100 -               /*
101 -                * We can avoid zeroing for aligned DAX writes beyond EOF. Other
102 -                * writes need zeroing either because they can race with page
103 -                * faults or because they use partial blocks.
104 -                */
105 -               if (round_down(offset, 1<<inode->i_blkbits) >= inode->i_size &&
106 -                   ext4_aligned_io(inode, offset, count))
107 -                       get_block_func = ext4_dio_get_block;
108 -               else
109 -                       get_block_func = ext4_dax_get_block;
110 -               dio_flags = DIO_LOCKING;
111 -       } else if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) ||
112 +       else if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) ||
113                    round_down(offset, 1 << inode->i_blkbits) >= inode->i_size) {
114                 get_block_func = ext4_dio_get_block;
115                 dio_flags = DIO_LOCKING | DIO_SKIP_HOLES;
116 @@ -3620,14 +3560,9 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
117  #ifdef CONFIG_EXT4_FS_ENCRYPTION
118         BUG_ON(ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode));
119  #endif
120 -       if (IS_DAX(inode)) {
121 -               ret = dax_do_io(iocb, inode, iter, get_block_func,
122 -                               ext4_end_io_dio, dio_flags);
123 -       } else
124 -               ret = __blockdev_direct_IO(iocb, inode,
125 -                                          inode->i_sb->s_bdev, iter,
126 -                                          get_block_func,
127 -                                          ext4_end_io_dio, NULL, dio_flags);
128 +       ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev, iter,
129 +                                  get_block_func, ext4_end_io_dio, NULL,
130 +                                  dio_flags);
132         if (ret > 0 && !overwrite && ext4_test_inode_state(inode,
133                                                 EXT4_STATE_DIO_UNWRITTEN)) {
134 @@ -3696,6 +3631,7 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter)
136         struct address_space *mapping = iocb->ki_filp->f_mapping;
137         struct inode *inode = mapping->host;
138 +       size_t count = iov_iter_count(iter);
139         ssize_t ret;
141         /*
142 @@ -3704,19 +3640,12 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter)
143          * we are protected against page writeback as well.
144          */
145         inode_lock_shared(inode);
146 -       if (IS_DAX(inode)) {
147 -               ret = dax_do_io(iocb, inode, iter, ext4_dio_get_block, NULL, 0);
148 -       } else {
149 -               size_t count = iov_iter_count(iter);
151 -               ret = filemap_write_and_wait_range(mapping, iocb->ki_pos,
152 -                                                  iocb->ki_pos + count);
153 -               if (ret)
154 -                       goto out_unlock;
155 -               ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
156 -                                          iter, ext4_dio_get_block,
157 -                                          NULL, NULL, 0);
158 -       }
159 +       ret = filemap_write_and_wait_range(mapping, iocb->ki_pos,
160 +                                          iocb->ki_pos + count);
161 +       if (ret)
162 +               goto out_unlock;
163 +       ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
164 +                                  iter, ext4_dio_get_block, NULL, NULL, 0);
165  out_unlock:
166         inode_unlock_shared(inode);
167         return ret;
168 @@ -3745,6 +3674,10 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
169         if (ext4_has_inline_data(inode))
170                 return 0;
172 +       /* DAX uses iomap path now */
173 +       if (WARN_ON_ONCE(IS_DAX(inode)))
174 +               return 0;
176         trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
177         if (iov_iter_rw(iter) == READ)
178                 ret = ext4_direct_IO_read(iocb, iter);
179 -- 
180 2.6.6