@@ -1468,7 +1468,7 @@ static int ext4_write_end(const struct kiocb *iocb,
14681468
14691469 if (old_size < pos && !verity ) {
14701470 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 );
14721472 }
14731473 /*
14741474 * Don't mark the inode dirty under folio lock. First, it unnecessarily
@@ -1586,7 +1586,7 @@ static int ext4_journalled_write_end(const struct kiocb *iocb,
15861586
15871587 if (old_size < pos && !verity ) {
15881588 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 );
15901590 }
15911591
15921592 if (size_changed ) {
@@ -3282,7 +3282,7 @@ static int ext4_da_do_write_end(struct address_space *mapping,
32823282 if (IS_ERR (handle ))
32833283 return PTR_ERR (handle );
32843284 if (zero_len )
3285- ext4_block_zero_eof (handle , inode , old_size , pos );
3285+ ext4_block_zero_eof (inode , old_size , pos );
32863286 ext4_mark_inode_dirty (handle , inode );
32873287 ext4_journal_stop (handle );
32883288
@@ -4131,16 +4131,23 @@ static int ext4_block_do_zero_range(struct inode *inode, loff_t from,
41314131 return 0 ;
41324132}
41334133
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 )
41364136{
41374137 struct buffer_head * bh ;
41384138 struct folio * folio ;
4139+ handle_t * handle ;
41394140 int err ;
41404141
4142+ handle = ext4_journal_start (inode , EXT4_HT_MISC , 1 );
4143+ if (IS_ERR (handle ))
4144+ return PTR_ERR (handle );
4145+
41414146 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+ }
41444151 folio = bh -> b_folio ;
41454152
41464153 BUFFER_TRACE (bh , "get write access" );
@@ -4161,6 +4168,8 @@ static int ext4_block_journalled_zero_range(handle_t *handle,
41614168out :
41624169 folio_unlock (folio );
41634170 folio_put (folio );
4171+ out_handle :
4172+ ext4_journal_stop (handle );
41644173 return err ;
41654174}
41664175
@@ -4170,7 +4179,7 @@ static int ext4_block_journalled_zero_range(handle_t *handle,
41704179 * If the specified range exceeds the end of the block it will be
41714180 * shortened to end of the block that corresponds to 'from'.
41724181 */
4173- static int ext4_block_zero_range (handle_t * handle , struct inode * inode ,
4182+ static int ext4_block_zero_range (struct inode * inode ,
41744183 loff_t from , loff_t length , bool * did_zero ,
41754184 bool * zero_written )
41764185{
@@ -4188,8 +4197,8 @@ static int ext4_block_zero_range(handle_t *handle, struct inode *inode,
41884197 return dax_zero_range (inode , from , length , did_zero ,
41894198 & ext4_iomap_ops );
41904199 } else if (ext4_should_journal_data (inode )) {
4191- return ext4_block_journalled_zero_range (handle , inode , from ,
4192- length , did_zero );
4200+ return ext4_block_journalled_zero_range (inode , from , length ,
4201+ did_zero );
41934202 }
41944203 return ext4_block_do_zero_range (inode , from , length , did_zero ,
41954204 zero_written );
@@ -4202,8 +4211,7 @@ static int ext4_block_zero_range(handle_t *handle, struct inode *inode,
42024211 * to physically zero the tail end of that block so it doesn't yield old
42034212 * data if the file is grown.
42044213 */
4205- int ext4_block_zero_eof (handle_t * handle , struct inode * inode ,
4206- loff_t from , loff_t end )
4214+ int ext4_block_zero_eof (struct inode * inode , loff_t from , loff_t end )
42074215{
42084216 unsigned int blocksize = i_blocksize (inode );
42094217 unsigned int offset ;
@@ -4222,7 +4230,7 @@ int ext4_block_zero_eof(handle_t *handle, struct inode *inode,
42224230 if (length > blocksize - offset )
42234231 length = blocksize - offset ;
42244232
4225- err = ext4_block_zero_range (handle , inode , from , length ,
4233+ err = ext4_block_zero_range (inode , from , length ,
42264234 & did_zero , & zero_written );
42274235 if (err )
42284236 return err ;
@@ -4233,14 +4241,23 @@ int ext4_block_zero_eof(handle_t *handle, struct inode *inode,
42334241 * mmap write during folio writeback.
42344242 */
42354243 if (ext4_should_order_data (inode ) &&
4236- did_zero && zero_written && !IS_DAX (inode ))
4244+ did_zero && zero_written && !IS_DAX (inode )) {
4245+ handle_t * handle ;
4246+
4247+ handle = ext4_journal_start (inode , EXT4_HT_MISC , 1 );
4248+ if (IS_ERR (handle ))
4249+ return PTR_ERR (handle );
4250+
42374251 err = ext4_jbd2_inode_add_write (handle , inode , from , length );
4252+ ext4_journal_stop (handle );
4253+ if (err )
4254+ return err ;
4255+ }
42384256
4239- return err ;
4257+ return 0 ;
42404258}
42414259
4242- int ext4_zero_partial_blocks (handle_t * handle , struct inode * inode ,
4243- loff_t lstart , loff_t length )
4260+ int ext4_zero_partial_blocks (struct inode * inode , loff_t lstart , loff_t length )
42444261{
42454262 struct super_block * sb = inode -> i_sb ;
42464263 unsigned partial_start , partial_end ;
@@ -4257,21 +4274,19 @@ int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
42574274 /* Handle partial zero within the single block */
42584275 if (start == end &&
42594276 (partial_start || (partial_end != sb -> s_blocksize - 1 ))) {
4260- err = ext4_block_zero_range (handle , inode , lstart ,
4261- length , NULL , NULL );
4277+ err = ext4_block_zero_range (inode , lstart , length , NULL , NULL );
42624278 return err ;
42634279 }
42644280 /* Handle partial zero out on the start of the range */
42654281 if (partial_start ) {
4266- err = ext4_block_zero_range (handle , inode , lstart ,
4267- sb -> s_blocksize , NULL , NULL );
4282+ err = ext4_block_zero_range (inode , lstart , sb -> s_blocksize ,
4283+ NULL , NULL );
42684284 if (err )
42694285 return err ;
42704286 }
42714287 /* Handle partial zero out on the end of the range */
42724288 if (partial_end != sb -> s_blocksize - 1 )
4273- err = ext4_block_zero_range (handle , inode ,
4274- byte_end - partial_end ,
4289+ err = ext4_block_zero_range (inode , byte_end - partial_end ,
42754290 partial_end + 1 , NULL , NULL );
42764291 return err ;
42774292}
@@ -4467,7 +4482,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
44674482 return ret ;
44684483 }
44694484
4470- ret = ext4_zero_partial_blocks (handle , inode , offset , length );
4485+ ret = ext4_zero_partial_blocks (inode , offset , length );
44714486 if (ret )
44724487 goto out_handle ;
44734488
@@ -4622,7 +4637,7 @@ int ext4_truncate(struct inode *inode)
46224637
46234638 /* Zero to the end of the block containing i_size */
46244639 if (inode -> i_size & (inode -> i_sb -> s_blocksize - 1 ))
4625- ext4_block_zero_eof (handle , inode , inode -> i_size , LLONG_MAX );
4640+ ext4_block_zero_eof (inode , inode -> i_size , LLONG_MAX );
46264641
46274642 /*
46284643 * We add the inode to the orphan list, so that if this
@@ -6011,8 +6026,8 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
60116026 inode_set_mtime_to_ts (inode ,
60126027 inode_set_ctime_current (inode ));
60136028 if (oldsize & (inode -> i_sb -> s_blocksize - 1 ))
6014- ext4_block_zero_eof (handle , inode ,
6015- oldsize , LLONG_MAX );
6029+ ext4_block_zero_eof (inode , oldsize ,
6030+ LLONG_MAX );
60166031 }
60176032
60186033 if (shrink )
0 commit comments