1 ext4: move ext4_file_dio_write() into ext4_file_write()
3 This commit doesn't actually change anything; it just moves code
4 around in preparation for some code simplification work.
6 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
7 Reviewed-by: Jan Kara <jack@suse.cz>
9 fs/ext4/file.c | 138 ++++++++++++++++++++++++++-------------------------------
10 1 file changed, 64 insertions(+), 74 deletions(-)
12 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
13 index 79b77a5..20f1c03 100644
16 @@ -92,82 +92,15 @@ ext4_unaligned_aio(struct inode *inode, const struct iovec *iov,
20 -ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov,
21 - unsigned long nr_segs, loff_t pos)
22 +ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
23 + unsigned long nr_segs, loff_t pos)
25 struct file *file = iocb->ki_filp;
26 - struct inode *inode = file->f_mapping->host;
27 + struct inode *inode = file_inode(iocb->ki_filp);
29 int unaligned_aio = 0;
32 size_t length = iov_length(iov, nr_segs);
34 - if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
35 - !is_sync_kiocb(iocb))
36 - unaligned_aio = ext4_unaligned_aio(inode, iov, nr_segs, pos);
38 - /* Unaligned direct AIO must be serialized; see comment above */
39 - if (unaligned_aio) {
40 - mutex_lock(ext4_aio_mutex(inode));
41 - ext4_unwritten_wait(inode);
44 - mutex_lock(&inode->i_mutex);
45 - blk_start_plug(&plug);
47 - iocb->private = &overwrite;
49 - /* check whether we do a DIO overwrite or not */
50 - if (ext4_should_dioread_nolock(inode) && !unaligned_aio &&
51 - !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
52 - struct ext4_map_blocks map;
53 - unsigned int blkbits = inode->i_blkbits;
56 - map.m_lblk = pos >> blkbits;
57 - map.m_len = (EXT4_BLOCK_ALIGN(pos + length, blkbits) >> blkbits)
61 - err = ext4_map_blocks(NULL, inode, &map, 0);
63 - * 'err==len' means that all of blocks has been preallocated no
64 - * matter they are initialized or not. For excluding
65 - * unwritten extents, we need to check m_flags. There are
66 - * two conditions that indicate for initialized extents.
67 - * 1) If we hit extent cache, EXT4_MAP_MAPPED flag is returned;
68 - * 2) If we do a real lookup, non-flags are returned.
69 - * So we should check these two conditions.
71 - if (err == len && (map.m_flags & EXT4_MAP_MAPPED))
75 - ret = __generic_file_aio_write(iocb, iov, nr_segs);
76 - mutex_unlock(&inode->i_mutex);
81 - err = generic_write_sync(file, iocb->ki_pos - ret, ret);
85 - blk_finish_plug(&plug);
88 - mutex_unlock(ext4_aio_mutex(inode));
94 -ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
95 - unsigned long nr_segs, loff_t pos)
97 - struct file *file = iocb->ki_filp;
98 - struct inode *inode = file_inode(iocb->ki_filp);
101 BUG_ON(iocb->ki_pos != pos);
102 @@ -179,7 +112,6 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
104 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
105 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
106 - size_t length = iov_length(iov, nr_segs);
108 if ((pos > sbi->s_bitmap_maxbytes ||
109 (pos == sbi->s_bitmap_maxbytes && length > 0)))
110 @@ -191,9 +123,67 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
114 - if (unlikely(iocb->ki_filp->f_flags & O_DIRECT))
115 - ret = ext4_file_dio_write(iocb, iov, nr_segs, pos);
117 + if (unlikely(iocb->ki_filp->f_flags & O_DIRECT)) {
118 + if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) &&
119 + !is_sync_kiocb(iocb))
120 + unaligned_aio = ext4_unaligned_aio(inode, iov,
123 + /* Unaligned direct AIO must be serialized; see comment above */
124 + if (unaligned_aio) {
125 + mutex_lock(ext4_aio_mutex(inode));
126 + ext4_unwritten_wait(inode);
129 + mutex_lock(&inode->i_mutex);
130 + blk_start_plug(&plug);
132 + iocb->private = &overwrite;
134 + /* check whether we do a DIO overwrite or not */
135 + if (ext4_should_dioread_nolock(inode) && !unaligned_aio &&
136 + !file->f_mapping->nrpages && pos + length <= i_size_read(inode)) {
137 + struct ext4_map_blocks map;
138 + unsigned int blkbits = inode->i_blkbits;
141 + map.m_lblk = pos >> blkbits;
142 + map.m_len = (EXT4_BLOCK_ALIGN(pos + length, blkbits) >> blkbits)
146 + err = ext4_map_blocks(NULL, inode, &map, 0);
148 + * 'err==len' means that all of blocks has
149 + * been preallocated no matter they are
150 + * initialized or not. For excluding
151 + * unwritten extents, we need to check
152 + * m_flags. There are two conditions that
153 + * indicate for initialized extents. 1) If we
154 + * hit extent cache, EXT4_MAP_MAPPED flag is
155 + * returned; 2) If we do a real lookup,
156 + * non-flags are returned. So we should check
157 + * these two conditions.
159 + if (err == len && (map.m_flags & EXT4_MAP_MAPPED))
163 + ret = __generic_file_aio_write(iocb, iov, nr_segs);
164 + mutex_unlock(&inode->i_mutex);
169 + err = generic_write_sync(file, iocb->ki_pos - ret, ret);
173 + blk_finish_plug(&plug);
176 + mutex_unlock(ext4_aio_mutex(inode));
178 mutex_lock(&inode->i_mutex);
179 ret = __generic_file_aio_write(iocb, iov, nr_segs);
180 mutex_unlock(&inode->i_mutex);