Skip to content

Commit 91b8ca8

Browse files
jankaratytso
authored andcommitted
ext4: Make sure BH_New bit is cleared in ->write_end handler
Currently we clear BH_New bit in case of error and also in the standard ext4_write_end() handler (in block_commit_write()). However ext4_journalled_write_end() misses this clearing and thus we are leaving stale BH_New bits behind. Generally ext4_block_write_begin() clears these bits before any harm can be done but in case blocksize < pagesize and we hit some error when processing a page with these stale bits, we'll try to zero buffers with these stale BH_New bits and jbd2 will complain (as buffers were not prepared for writing in this transaction). Fix the problem by clearing BH_New bits in ext4_journalled_write_end() and WARN if ext4_block_write_begin() sees stale BH_New bits. Reported-by: Baolin Liu <liubaolin12138@163.com> Reported-by: Zhi Long <longzhi@sangfor.com.cn> Fixes: 3910b51 ("ext4: persist the new uptodate buffers in ext4_journalled_zero_new_buffers") Signed-off-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20250709084831.23876-2-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent c678bdc commit 91b8ca8

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

fs/ext4/inline.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
612612
} else
613613
ret = ext4_block_write_begin(handle, folio, from, to,
614614
ext4_get_block);
615+
clear_buffer_new(folio_buffers(folio));
615616

616617
if (!ret && ext4_should_journal_data(inode)) {
617618
ret = ext4_walk_page_buffers(handle, inode,
@@ -891,6 +892,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
891892
return ret;
892893
}
893894

895+
clear_buffer_new(folio_buffers(folio));
894896
folio_mark_dirty(folio);
895897
folio_mark_uptodate(folio);
896898
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);

fs/ext4/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio,
11891189
}
11901190
continue;
11911191
}
1192-
if (buffer_new(bh))
1192+
if (WARN_ON_ONCE(buffer_new(bh)))
11931193
clear_buffer_new(bh);
11941194
if (!buffer_mapped(bh)) {
11951195
WARN_ON(bh->b_size != blocksize);
@@ -1417,6 +1417,7 @@ static int write_end_fn(handle_t *handle, struct inode *inode,
14171417
ret = ext4_dirty_journalled_data(handle, bh);
14181418
clear_buffer_meta(bh);
14191419
clear_buffer_prio(bh);
1420+
clear_buffer_new(bh);
14201421
return ret;
14211422
}
14221423

0 commit comments

Comments
 (0)