diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2015-04-07 14:48:22 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2015-04-11 22:29:49 -0400 |
commit | e768d7ff7b923a74a019d8782e6ee75dc1de12c1 (patch) | |
tree | df9a6990474ff8c38076819eee0937b826145bde /fs/ext4 | |
parent | 99733fa372eaaa59cfb93fd383cee7b0ff056e1d (diff) |
ext4_file_write_iter: move generic_write_checks() up
simpler that way...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/file.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 1f0afc181b7b..42b1fa33a17a 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c | |||
@@ -99,7 +99,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |||
99 | int overwrite = 0; | 99 | int overwrite = 0; |
100 | size_t length = iov_iter_count(from); | 100 | size_t length = iov_iter_count(from); |
101 | ssize_t ret; | 101 | ssize_t ret; |
102 | loff_t pos = iocb->ki_pos; | 102 | loff_t pos; |
103 | 103 | ||
104 | /* | 104 | /* |
105 | * Unaligned direct AIO must be serialized; see comment above | 105 | * Unaligned direct AIO must be serialized; see comment above |
@@ -109,15 +109,22 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |||
109 | ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) && | 109 | ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) && |
110 | !is_sync_kiocb(iocb) && | 110 | !is_sync_kiocb(iocb) && |
111 | (file->f_flags & O_APPEND || | 111 | (file->f_flags & O_APPEND || |
112 | ext4_unaligned_aio(inode, from, pos))) { | 112 | ext4_unaligned_aio(inode, from, iocb->ki_pos))) { |
113 | aio_mutex = ext4_aio_mutex(inode); | 113 | aio_mutex = ext4_aio_mutex(inode); |
114 | mutex_lock(aio_mutex); | 114 | mutex_lock(aio_mutex); |
115 | ext4_unwritten_wait(inode); | 115 | ext4_unwritten_wait(inode); |
116 | } | 116 | } |
117 | 117 | ||
118 | mutex_lock(&inode->i_mutex); | 118 | mutex_lock(&inode->i_mutex); |
119 | if (file->f_flags & O_APPEND) | 119 | ret = generic_write_checks(file, &iocb->ki_pos, &length); |
120 | iocb->ki_pos = pos = i_size_read(inode); | 120 | if (ret) |
121 | goto out; | ||
122 | |||
123 | if (length == 0) | ||
124 | goto out; | ||
125 | |||
126 | iov_iter_truncate(from, length); | ||
127 | pos = iocb->ki_pos; | ||
121 | 128 | ||
122 | /* | 129 | /* |
123 | * If we have encountered a bitmap-format file, the size limit | 130 | * If we have encountered a bitmap-format file, the size limit |
@@ -126,18 +133,16 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |||
126 | if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { | 133 | if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { |
127 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 134 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
128 | 135 | ||
129 | if ((pos > sbi->s_bitmap_maxbytes) || | 136 | if (pos >= sbi->s_bitmap_maxbytes) { |
130 | (pos == sbi->s_bitmap_maxbytes && length > 0)) { | ||
131 | mutex_unlock(&inode->i_mutex); | ||
132 | ret = -EFBIG; | 137 | ret = -EFBIG; |
133 | goto errout; | 138 | goto out; |
134 | } | 139 | } |
135 | iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos); | 140 | iov_iter_truncate(from, sbi->s_bitmap_maxbytes - pos); |
136 | length = iov_iter_count(from); | ||
137 | } | 141 | } |
138 | 142 | ||
139 | iocb->private = &overwrite; | 143 | iocb->private = &overwrite; |
140 | if (o_direct) { | 144 | if (o_direct) { |
145 | length = iov_iter_count(from); | ||
141 | blk_start_plug(&plug); | 146 | blk_start_plug(&plug); |
142 | 147 | ||
143 | 148 | ||
@@ -171,16 +176,7 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | |||
171 | } | 176 | } |
172 | } | 177 | } |
173 | 178 | ||
174 | ret = generic_write_checks(file, &iocb->ki_pos, &length); | ||
175 | if (ret) | ||
176 | goto out; | ||
177 | |||
178 | if (length == 0) | ||
179 | goto out; | ||
180 | |||
181 | iov_iter_truncate(from, length); | ||
182 | ret = __generic_file_write_iter(iocb, from); | 179 | ret = __generic_file_write_iter(iocb, from); |
183 | out: | ||
184 | mutex_unlock(&inode->i_mutex); | 180 | mutex_unlock(&inode->i_mutex); |
185 | 181 | ||
186 | if (ret > 0) { | 182 | if (ret > 0) { |
@@ -193,7 +189,12 @@ out: | |||
193 | if (o_direct) | 189 | if (o_direct) |
194 | blk_finish_plug(&plug); | 190 | blk_finish_plug(&plug); |
195 | 191 | ||
196 | errout: | 192 | if (aio_mutex) |
193 | mutex_unlock(aio_mutex); | ||
194 | return ret; | ||
195 | |||
196 | out: | ||
197 | mutex_unlock(&inode->i_mutex); | ||
197 | if (aio_mutex) | 198 | if (aio_mutex) |
198 | mutex_unlock(aio_mutex); | 199 | mutex_unlock(aio_mutex); |
199 | return ret; | 200 | return ret; |