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: rename and extend ext4_block_truncate_page()

Rename ext4_block_truncate_page() to ext4_block_zero_eof() and extend
its signature to accept an explicit 'end' offset instead of calculating
the block boundary. This helper function now can replace all cases
requiring zeroing of the partial EOF block, including the append
buffered write paths in ext4_*_write_end().

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

authored by

Zhang Yi and committed by
Theodore Ts'o
bd099a05 5447c8b9

+28 -21
+2
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); 3100 3102 extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, 3101 3103 loff_t lstart, loff_t lend); 3102 3104 extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf);
+2 -2
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_zero_partial_blocks(handle, inode, 4658 - old_size, epos - old_size); 4657 + ext4_block_zero_eof(handle, inode, old_size, 4658 + epos); 4659 4659 } 4660 4660 } 4661 4661 ret2 = ext4_mark_inode_dirty(handle, inode);
+24 -19
fs/ext4/inode.c
··· 1468 1468 1469 1469 if (old_size < pos && !verity) { 1470 1470 pagecache_isize_extended(inode, old_size, pos); 1471 - ext4_zero_partial_blocks(handle, inode, old_size, pos - old_size); 1471 + ext4_block_zero_eof(handle, 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_zero_partial_blocks(handle, inode, old_size, pos - old_size); 1589 + ext4_block_zero_eof(handle, 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_zero_partial_blocks(handle, inode, old_size, zero_len); 3285 + ext4_block_zero_eof(handle, inode, old_size, pos); 3286 3286 ext4_mark_inode_dirty(handle, inode); 3287 3287 ext4_journal_stop(handle); 3288 3288 ··· 4162 4162 } 4163 4163 4164 4164 /* 4165 - * ext4_block_truncate_page() zeroes out a mapping from file offset `from' 4166 - * up to the end of the block which corresponds to `from'. 4167 - * This required during truncate. We need to physically zero the tail end 4168 - * of that block so it doesn't yield old data if the file is later grown. 4165 + * Zero out a mapping from file offset 'from' up to the end of the block 4166 + * which corresponds to 'from' or to the given 'end' inside this block. 4167 + * This required during truncate up and performing append writes. We need 4168 + * to physically zero the tail end of that block so it doesn't yield old 4169 + * data if the file is grown. 4169 4170 */ 4170 - static int ext4_block_truncate_page(handle_t *handle, 4171 - struct address_space *mapping, loff_t from) 4171 + int ext4_block_zero_eof(handle_t *handle, struct inode *inode, 4172 + loff_t from, loff_t end) 4172 4173 { 4173 - unsigned length; 4174 - unsigned blocksize; 4175 - struct inode *inode = mapping->host; 4174 + unsigned int blocksize = i_blocksize(inode); 4175 + unsigned int offset; 4176 + loff_t length = end - from; 4176 4177 4178 + offset = from & (blocksize - 1); 4179 + if (!offset || from >= end) 4180 + return 0; 4177 4181 /* If we are processing an encrypted inode during orphan list handling */ 4178 4182 if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode)) 4179 4183 return 0; 4180 4184 4181 - blocksize = i_blocksize(inode); 4182 - length = blocksize - (from & (blocksize - 1)); 4185 + if (length > blocksize - offset) 4186 + length = blocksize - offset; 4183 4187 4184 - return ext4_block_zero_page_range(handle, mapping, from, length, NULL); 4188 + return ext4_block_zero_page_range(handle, inode->i_mapping, from, 4189 + length, NULL); 4185 4190 } 4186 4191 4187 4192 int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, ··· 4540 4535 unsigned int credits; 4541 4536 int err = 0, err2; 4542 4537 handle_t *handle; 4543 - struct address_space *mapping = inode->i_mapping; 4544 4538 4545 4539 /* 4546 4540 * There is a possibility that we're either freeing the inode ··· 4582 4578 goto out_trace; 4583 4579 } 4584 4580 4581 + /* Zero to the end of the block containing i_size */ 4585 4582 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) 4586 - ext4_block_truncate_page(handle, mapping, inode->i_size); 4583 + ext4_block_zero_eof(handle, inode, inode->i_size, LLONG_MAX); 4587 4584 4588 4585 /* 4589 4586 * We add the inode to the orphan list, so that if this ··· 5973 5968 inode_set_mtime_to_ts(inode, 5974 5969 inode_set_ctime_current(inode)); 5975 5970 if (oldsize & (inode->i_sb->s_blocksize - 1)) 5976 - ext4_block_truncate_page(handle, 5977 - inode->i_mapping, oldsize); 5971 + ext4_block_zero_eof(handle, inode, 5972 + oldsize, LLONG_MAX); 5978 5973 } 5979 5974 5980 5975 if (shrink)