1 ext4: rename and split get blocks functions
3 From: Jan Kara <jack@suse.cz>
5 Rename ext4_get_blocks_write() to ext4_get_blocks_unwritten() to better
6 describe what it does. Also split out get blocks functions for direct
7 IO. Later we move functionality from _ext4_get_blocks() there. There's no
8 functional change in this patch.
10 Signed-off-by: Jan Kara <jack@suse.cz>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 fs/ext4/ext4.h | 8 +++--
14 fs/ext4/indirect.c | 10 +++---
15 fs/ext4/inline.c | 7 ++--
16 fs/ext4/inode.c | 96 ++++++++++++++++++++++++++++++++++--------------------
17 4 files changed, 74 insertions(+), 47 deletions(-)
19 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
20 index b02b2e58805a..80cc3914b6ad 100644
23 @@ -2505,12 +2505,14 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
24 int ext4_inode_is_fast_symlink(struct inode *inode);
25 struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
26 struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
27 -int ext4_get_block_write(struct inode *inode, sector_t iblock,
28 - struct buffer_head *bh_result, int create);
29 +int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
30 + struct buffer_head *bh_result, int create);
31 int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
32 struct buffer_head *bh_result, int create);
33 int ext4_get_block(struct inode *inode, sector_t iblock,
34 - struct buffer_head *bh_result, int create);
35 + struct buffer_head *bh_result, int create);
36 +int ext4_dio_get_block(struct inode *inode, sector_t iblock,
37 + struct buffer_head *bh_result, int create);
38 int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
39 struct buffer_head *bh, int create);
40 int ext4_walk_page_buffers(handle_t *handle,
41 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
42 index 355ef9c36c87..1655ff195e0e 100644
43 --- a/fs/ext4/indirect.c
44 +++ b/fs/ext4/indirect.c
45 @@ -693,21 +693,21 @@ retry:
48 ret = dax_do_io(iocb, inode, iter, offset,
49 - ext4_get_block, NULL, 0);
50 + ext4_dio_get_block, NULL, 0);
52 ret = __blockdev_direct_IO(iocb, inode,
53 inode->i_sb->s_bdev, iter,
54 - offset, ext4_get_block, NULL,
56 + offset, ext4_dio_get_block,
62 ret = dax_do_io(iocb, inode, iter, offset,
63 - ext4_get_block, NULL, DIO_LOCKING);
64 + ext4_dio_get_block, NULL, DIO_LOCKING);
66 ret = blockdev_direct_IO(iocb, inode, iter, offset,
68 + ext4_dio_get_block);
70 if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
71 loff_t isize = i_size_read(inode);
72 diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
73 index dfe3b9bafc0d..36d8cc9327f5 100644
74 --- a/fs/ext4/inline.c
75 +++ b/fs/ext4/inline.c
76 @@ -581,9 +581,10 @@ retry:
80 - if (ext4_should_dioread_nolock(inode))
81 - ret = __block_write_begin(page, from, to, ext4_get_block_write);
83 + if (ext4_should_dioread_nolock(inode)) {
84 + ret = __block_write_begin(page, from, to,
85 + ext4_get_block_unwritten);
87 ret = __block_write_begin(page, from, to, ext4_get_block);
89 if (!ret && ext4_should_journal_data(inode)) {
90 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
91 index ee8ca1ff4023..47b11fbd1417 100644
94 @@ -741,6 +741,60 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
98 + * Get block function used when preparing for buffered write if we require
99 + * creating an unwritten extent if blocks haven't been allocated. The extent
100 + * will be converted to written after the IO is complete.
102 +int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
103 + struct buffer_head *bh_result, int create)
105 + ext4_debug("ext4_get_block_unwritten: inode %lu, create flag %d\n",
106 + inode->i_ino, create);
107 + return _ext4_get_block(inode, iblock, bh_result,
108 + EXT4_GET_BLOCKS_IO_CREATE_EXT);
111 +/* Get block function for DIO reads and writes to inodes without extents */
112 +int ext4_dio_get_block(struct inode *inode, sector_t iblock,
113 + struct buffer_head *bh, int create)
115 + return _ext4_get_block(inode, iblock, bh,
116 + create ? EXT4_GET_BLOCKS_CREATE : 0);
120 + * Get block function for DIO writes when we create unwritten extent if
121 + * blocks are not allocated yet. The extent will be converted to written
122 + * after IO is complete.
124 +static int ext4_dio_get_block_unwritten(struct inode *inode, sector_t iblock,
125 + struct buffer_head *bh_result, int create)
127 + ext4_debug("ext4_dio_get_block_unwritten: inode %lu, create flag %d\n",
128 + inode->i_ino, create);
129 + return _ext4_get_block(inode, iblock, bh_result,
130 + EXT4_GET_BLOCKS_IO_CREATE_EXT);
133 +static int ext4_dio_get_block_overwrite(struct inode *inode, sector_t iblock,
134 + struct buffer_head *bh_result, int create)
138 + ext4_debug("ext4_dio_get_block_overwrite: inode %lu, create flag %d\n",
139 + inode->i_ino, create);
140 + ret = _ext4_get_block(inode, iblock, bh_result, 0);
142 + * Blocks should have been preallocated! ext4_file_write_iter() checks
145 + WARN_ON_ONCE(!buffer_mapped(bh_result));
152 * `handle' can be NULL if create is zero
154 struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
155 @@ -1051,13 +1105,14 @@ retry_journal:
156 #ifdef CONFIG_EXT4_FS_ENCRYPTION
157 if (ext4_should_dioread_nolock(inode))
158 ret = ext4_block_write_begin(page, pos, len,
159 - ext4_get_block_write);
160 + ext4_get_block_unwritten);
162 ret = ext4_block_write_begin(page, pos, len,
165 if (ext4_should_dioread_nolock(inode))
166 - ret = __block_write_begin(page, pos, len, ext4_get_block_write);
167 + ret = __block_write_begin(page, pos, len,
168 + ext4_get_block_unwritten);
170 ret = __block_write_begin(page, pos, len, ext4_get_block);
172 @@ -3056,37 +3111,6 @@ static int ext4_releasepage(struct page *page, gfp_t wait)
173 return try_to_free_buffers(page);
177 - * ext4_get_block used when preparing for a DIO write or buffer write.
178 - * We allocate an uinitialized extent if blocks haven't been allocated.
179 - * The extent will be converted to initialized after the IO is complete.
181 -int ext4_get_block_write(struct inode *inode, sector_t iblock,
182 - struct buffer_head *bh_result, int create)
184 - ext4_debug("ext4_get_block_write: inode %lu, create flag %d\n",
185 - inode->i_ino, create);
186 - return _ext4_get_block(inode, iblock, bh_result,
187 - EXT4_GET_BLOCKS_IO_CREATE_EXT);
190 -static int ext4_get_block_overwrite(struct inode *inode, sector_t iblock,
191 - struct buffer_head *bh_result, int create)
195 - ext4_debug("ext4_get_block_overwrite: inode %lu, create flag %d\n",
196 - inode->i_ino, create);
197 - ret = _ext4_get_block(inode, iblock, bh_result, 0);
199 - * Blocks should have been preallocated! ext4_file_write_iter() checks
202 - WARN_ON_ONCE(!buffer_mapped(bh_result));
208 int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
209 struct buffer_head *bh_result, int create)
210 @@ -3254,7 +3278,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
212 iocb->private = NULL;
214 - get_block_func = ext4_get_block_overwrite;
215 + get_block_func = ext4_dio_get_block_overwrite;
217 ext4_inode_aio_set(inode, NULL);
218 if (!is_sync_kiocb(iocb)) {
219 @@ -3276,7 +3300,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
221 ext4_inode_aio_set(inode, io_end);
223 - get_block_func = ext4_get_block_write;
224 + get_block_func = ext4_dio_get_block_unwritten;
225 dio_flags = DIO_LOCKING;
227 #ifdef CONFIG_EXT4_FS_ENCRYPTION
228 @@ -5470,7 +5494,7 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
230 /* OK, we need to fill the hole... */
231 if (ext4_should_dioread_nolock(inode))
232 - get_block = ext4_get_block_write;
233 + get_block = ext4_get_block_unwritten;
235 get_block = ext4_get_block;