ext4: Make sure BH_New bit is cleared in ->write_end handler
Jan Kara
reviewerPATCH v4 1/1 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.
--- fs/ext4/inline.c | 2 ++ fs/ext4/inode.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
Changes since v3 (https://lore.kernel.org/all/[email protected]):
* Clear stale BH_New flags resulting from inline->extent data conversion
fs/ext4/inline.c +2 -0
@@ -606,6 +606,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, }else ret =ext4_block_write_begin (handle, folio, from, to, ext4_get_block); +clear_buffer_new (folio_buffers (folio));if (!ret &&ext4_should_journal_data (inode)) { ret = ext4_walk_page_buffers(handle, inode,
@@ -867,6 +868,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,return ret; } +clear_buffer_new (folio_buffers (folio));folio_mark_dirty (folio);folio_mark_uptodate (folio);ext4_clear_inode_state (inode,EXT4_STATE_MAY_INLINE_DATA );
fs/ext4/inode.c +2 -1
@@ -1049,7 +1049,7 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio, }continue ; } -if (buffer_new (bh)) +if (WARN_ON_ONCE (buffer_new (bh)))clear_buffer_new (bh);if (!buffer_mapped (bh)) {WARN_ON (bh->b_size != blocksize);
@@ -1265,6 +1265,7 @@ static int write_end_fn(handle_t *handle, struct inode *inode, ret =ext4_dirty_journalled_data (handle, bh);clear_buffer_meta (bh);clear_buffer_prio (bh); +clear_buffer_new (bh);return ret; }
Signature · 1 line
2.35.3