Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: remove handle parameters from zero partial block functions

Only journal data mode requires an active journal handle when zeroing
partial blocks. Stop passing handle_t *handle to
ext4_zero_partial_blocks() and related functions, and make
ext4_block_journalled_zero_range() start a handle independently.

This change has no practical impact now because all callers invoke these
functions within the context of an active handle. It prepares for moving
ext4_block_zero_eof() out of an active handle in the next patch, which
is a prerequisite for converting block zero range operations to iomap
infrastructure.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20260327102939.1095257-7-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Zhang Yi and committed by
Theodore Ts'o
d3609a71 69e2d5c1

+48 -35
+3 -4
fs/ext4/ext4.h
··· 3097 3097 extern int ext4_chunk_trans_extent(struct inode *inode, int nrblocks); 3098 3098 extern int ext4_meta_trans_blocks(struct inode *inode, int lblocks, 3099 3099 int pextents); 3100 - extern int ext4_block_zero_eof(handle_t *handle, struct inode *inode, 3101 - loff_t from, loff_t end); 3102 - extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 3103 - loff_t lstart, loff_t lend); 3100 + extern int ext4_block_zero_eof(struct inode *inode, loff_t from, loff_t end); 3101 + extern int ext4_zero_partial_blocks(struct inode *inode, loff_t lstart, 3102 + loff_t length); 3104 3103 extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); 3105 3104 extern qsize_t *ext4_get_reserved_space(struct inode *inode); 3106 3105 extern int ext4_get_projid(struct inode *inode, kprojid_t *projid);
+2 -3
fs/ext4/extents.c
··· 4654 4654 inode_get_ctime(inode)); 4655 4655 if (epos > old_size) { 4656 4656 pagecache_isize_extended(inode, old_size, epos); 4657 - ext4_block_zero_eof(handle, inode, old_size, 4658 - epos); 4657 + ext4_block_zero_eof(inode, old_size, epos); 4659 4658 } 4660 4659 } 4661 4660 ret2 = ext4_mark_inode_dirty(handle, inode); ··· 4772 4773 } 4773 4774 4774 4775 /* Zero out partial block at the edges of the range */ 4775 - ret = ext4_zero_partial_blocks(handle, inode, offset, len); 4776 + ret = ext4_zero_partial_blocks(inode, offset, len); 4776 4777 if (ret) 4777 4778 goto out_handle; 4778 4779
+43 -28
fs/ext4/inode.c
··· 1468 1468 1469 1469 if (old_size < pos && !verity) { 1470 1470 pagecache_isize_extended(inode, old_size, pos); 1471 - ext4_block_zero_eof(handle, inode, old_size, pos); 1471 + ext4_block_zero_eof(inode, old_size, pos); 1472 1472 } 1473 1473 /* 1474 1474 * Don't mark the inode dirty under folio lock. First, it unnecessarily ··· 1586 1586 1587 1587 if (old_size < pos && !verity) { 1588 1588 pagecache_isize_extended(inode, old_size, pos); 1589 - ext4_block_zero_eof(handle, inode, old_size, pos); 1589 + ext4_block_zero_eof(inode, old_size, pos); 1590 1590 } 1591 1591 1592 1592 if (size_changed) { ··· 3282 3282 if (IS_ERR(handle)) 3283 3283 return PTR_ERR(handle); 3284 3284 if (zero_len) 3285 - ext4_block_zero_eof(handle, inode, old_size, pos); 3285 + ext4_block_zero_eof(inode, old_size, pos); 3286 3286 ext4_mark_inode_dirty(handle, inode); 3287 3287 ext4_journal_stop(handle); 3288 3288 ··· 4131 4131 return 0; 4132 4132 } 4133 4133 4134 - static int ext4_block_journalled_zero_range(handle_t *handle, 4135 - struct inode *inode, loff_t from, loff_t length, bool *did_zero) 4134 + static int ext4_block_journalled_zero_range(struct inode *inode, loff_t from, 4135 + loff_t length, bool *did_zero) 4136 4136 { 4137 4137 struct buffer_head *bh; 4138 4138 struct folio *folio; 4139 + handle_t *handle; 4139 4140 int err; 4140 4141 4142 + handle = ext4_journal_start(inode, EXT4_HT_MISC, 1); 4143 + if (IS_ERR(handle)) 4144 + return PTR_ERR(handle); 4145 + 4141 4146 bh = ext4_load_tail_bh(inode, from); 4142 - if (IS_ERR_OR_NULL(bh)) 4143 - return PTR_ERR_OR_ZERO(bh); 4147 + if (IS_ERR_OR_NULL(bh)) { 4148 + err = PTR_ERR_OR_ZERO(bh); 4149 + goto out_handle; 4150 + } 4144 4151 folio = bh->b_folio; 4145 4152 4146 4153 BUFFER_TRACE(bh, "get write access"); ··· 4168 4161 out: 4169 4162 folio_unlock(folio); 4170 4163 folio_put(folio); 4164 + out_handle: 4165 + ext4_journal_stop(handle); 4171 4166 return err; 4172 4167 } 4173 4168 ··· 4179 4170 * If the specified range exceeds the end of the block it will be 4180 4171 * shortened to end of the block that corresponds to 'from'. 4181 4172 */ 4182 - static int ext4_block_zero_range(handle_t *handle, struct inode *inode, 4173 + static int ext4_block_zero_range(struct inode *inode, 4183 4174 loff_t from, loff_t length, bool *did_zero, 4184 4175 bool *zero_written) 4185 4176 { ··· 4197 4188 return dax_zero_range(inode, from, length, did_zero, 4198 4189 &ext4_iomap_ops); 4199 4190 } else if (ext4_should_journal_data(inode)) { 4200 - return ext4_block_journalled_zero_range(handle, inode, from, 4201 - length, did_zero); 4191 + return ext4_block_journalled_zero_range(inode, from, length, 4192 + did_zero); 4202 4193 } 4203 4194 return ext4_block_do_zero_range(inode, from, length, did_zero, 4204 4195 zero_written); ··· 4211 4202 * to physically zero the tail end of that block so it doesn't yield old 4212 4203 * data if the file is grown. 4213 4204 */ 4214 - int ext4_block_zero_eof(handle_t *handle, struct inode *inode, 4215 - loff_t from, loff_t end) 4205 + int ext4_block_zero_eof(struct inode *inode, loff_t from, loff_t end) 4216 4206 { 4217 4207 unsigned int blocksize = i_blocksize(inode); 4218 4208 unsigned int offset; ··· 4230 4222 if (length > blocksize - offset) 4231 4223 length = blocksize - offset; 4232 4224 4233 - err = ext4_block_zero_range(handle, inode, from, length, 4225 + err = ext4_block_zero_range(inode, from, length, 4234 4226 &did_zero, &zero_written); 4235 4227 if (err) 4236 4228 return err; ··· 4241 4233 * mmap write during folio writeback. 4242 4234 */ 4243 4235 if (ext4_should_order_data(inode) && 4244 - did_zero && zero_written && !IS_DAX(inode)) 4245 - err = ext4_jbd2_inode_add_write(handle, inode, from, length); 4236 + did_zero && zero_written && !IS_DAX(inode)) { 4237 + handle_t *handle; 4246 4238 4247 - return err; 4239 + handle = ext4_journal_start(inode, EXT4_HT_MISC, 1); 4240 + if (IS_ERR(handle)) 4241 + return PTR_ERR(handle); 4242 + 4243 + err = ext4_jbd2_inode_add_write(handle, inode, from, length); 4244 + ext4_journal_stop(handle); 4245 + if (err) 4246 + return err; 4247 + } 4248 + 4249 + return 0; 4248 4250 } 4249 4251 4250 - int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 4251 - loff_t lstart, loff_t length) 4252 + int ext4_zero_partial_blocks(struct inode *inode, loff_t lstart, loff_t length) 4252 4253 { 4253 4254 struct super_block *sb = inode->i_sb; 4254 4255 unsigned partial_start, partial_end; ··· 4274 4257 /* Handle partial zero within the single block */ 4275 4258 if (start == end && 4276 4259 (partial_start || (partial_end != sb->s_blocksize - 1))) { 4277 - err = ext4_block_zero_range(handle, inode, lstart, 4278 - length, NULL, NULL); 4260 + err = ext4_block_zero_range(inode, lstart, length, NULL, NULL); 4279 4261 return err; 4280 4262 } 4281 4263 /* Handle partial zero out on the start of the range */ 4282 4264 if (partial_start) { 4283 - err = ext4_block_zero_range(handle, inode, lstart, 4284 - sb->s_blocksize, NULL, NULL); 4265 + err = ext4_block_zero_range(inode, lstart, sb->s_blocksize, 4266 + NULL, NULL); 4285 4267 if (err) 4286 4268 return err; 4287 4269 } 4288 4270 /* Handle partial zero out on the end of the range */ 4289 4271 if (partial_end != sb->s_blocksize - 1) 4290 - err = ext4_block_zero_range(handle, inode, 4291 - byte_end - partial_end, 4272 + err = ext4_block_zero_range(inode, byte_end - partial_end, 4292 4273 partial_end + 1, NULL, NULL); 4293 4274 return err; 4294 4275 } ··· 4482 4467 return ret; 4483 4468 } 4484 4469 4485 - ret = ext4_zero_partial_blocks(handle, inode, offset, length); 4470 + ret = ext4_zero_partial_blocks(inode, offset, length); 4486 4471 if (ret) 4487 4472 goto out_handle; 4488 4473 ··· 4637 4622 4638 4623 /* Zero to the end of the block containing i_size */ 4639 4624 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) 4640 - ext4_block_zero_eof(handle, inode, inode->i_size, LLONG_MAX); 4625 + ext4_block_zero_eof(inode, inode->i_size, LLONG_MAX); 4641 4626 4642 4627 /* 4643 4628 * We add the inode to the orphan list, so that if this ··· 6026 6011 inode_set_mtime_to_ts(inode, 6027 6012 inode_set_ctime_current(inode)); 6028 6013 if (oldsize & (inode->i_sb->s_blocksize - 1)) 6029 - ext4_block_zero_eof(handle, inode, 6030 - oldsize, LLONG_MAX); 6014 + ext4_block_zero_eof(inode, oldsize, 6015 + LLONG_MAX); 6031 6016 } 6032 6017 6033 6018 if (shrink)