Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Ojaswin Mujoo <ojaswin@linux.ibm.com>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>
Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 07/13] ext4: add tracking for unwritten to-be-converted ranges in non iomap buffered path
Date: Fri, 27 Nov 2026 20:40:54 +0530	[thread overview]
Message-ID: <20261127-ext4-endio-zero-bug-v2-7-4106968e4d15@linux.ibm.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com>

Make sure non iomap buffered write paths pass the
EXT4_GET_BLOCKS_CONVERT_PENDING flag to track unwritten ranges that are
about to be converted. This enables tracking such ranges in extent status.
This avoid data corruption by allowing endio extent zeroout code to avoid
zeroing over such ranges.

Note that CONVERT_PENDING and folio writeback state will always exist
together (serialised by folio_lock()). This ensures paths like
ext4_move_extents() won't silently drop CONVERT_PENDING state (as it drops
es cache).

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 fs/ext4/inode.c   |  3 ++-
 fs/ext4/page-io.c | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 4aafd0aaea69..2031b1dd7069 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2633,7 +2633,8 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd)
 
 	dioread_nolock = ext4_should_dioread_nolock(inode);
 	if (dioread_nolock)
-		get_blocks_flags |= EXT4_GET_BLOCKS_UNWRIT_EXT;
+		get_blocks_flags |= EXT4_GET_BLOCKS_UNWRIT_EXT |
+				    EXT4_GET_BLOCKS_CONVERT_PENDING;
 
 	err = ext4_map_blocks(handle, inode, map, get_blocks_flags);
 	if (err < 0)
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 059827b961ec..6753b35311b4 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -158,6 +158,24 @@ static void ext4_release_io_end(ext4_io_end_t *io_end)
 	kmem_cache_free(io_end_cachep, io_end);
 }
 
+/*
+ * The unwritten ranges of a failed io_end were marked convert pending in
+ * mpage_map_one_extent() before the IO was submitted but will not be
+ * converted, so drop the cached state.
+ */
+static void ext4_io_end_clear_convert_pending(ext4_io_end_t *io_end)
+{
+	struct inode *inode = io_end->inode;
+	u8 blkbits = inode->i_blkbits;
+	struct ext4_io_end_vec *io_end_vec;
+
+	list_for_each_entry(io_end_vec, &io_end->list_vec, list)
+		ext4_clear_convert_pending(inode,
+				io_end_vec->offset >> blkbits,
+				EXT4_MAX_BLOCKS(io_end_vec->size,
+						io_end_vec->offset, blkbits));
+}
+
 /*
  * On successful IO, check a range of space and convert unwritten extents to
  * written. On IO failure, check if journal abort is needed. Note that
@@ -195,6 +213,8 @@ static int ext4_end_io_end(ext4_io_end_t *io_end)
 		if (ret < 0)
 			mapping_set_error(inode->i_mapping, ret);
 	}
+	if (ret < 0 && io_end->flag & EXT4_IO_END_UNWRITTEN)
+		ext4_io_end_clear_convert_pending(io_end);
 	if (ret < 0 && !ext4_emergency_state(sb) &&
 	    io_end->flag & EXT4_IO_END_UNWRITTEN) {
 		ext4_msg(sb, KERN_EMERG,

-- 
2.55.0


  parent reply	other threads:[~2026-11-27 15:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:10 [PATCH v2 00/13] ext4: fix endio zeroout corruption by tracking to-be-converted unwritten IOs Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 01/13] ext4: disable zeroout fallback in ext4_split_extent() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 02/13] ext4: introduce CONVERT_PENDING extent status type Ojaswin Mujoo
2026-11-27 15:58   ` sashiko-bot
2026-11-27 15:10 ` [PATCH v2 03/13] ext4: preserve convert pending extents when adding unwrit extents to es cache Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 04/13] ext4: add es helper to convert unwrit to convert pending without changing i_es_seq Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks() Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 06/13] ext4: add tracking for unwritten to-be-converted ranges in dio write path Ojaswin Mujoo
2026-11-27 15:10 ` Ojaswin Mujoo [this message]
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in iomap buffered path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 09/13] ext4: don't zeroout if conv pending ranges are present Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 10/13] ext4: add tracepoints for extent split and convert Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 11/13] ext4: update extent status cache when zeroing extents Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 12/13] ext4: don't drop the extents in case extent split fails Ojaswin Mujoo
2026-11-27 15:11 ` [PATCH v2 13/13] ext4: re-enable zeroout fallback Ojaswin Mujoo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127-ext4-endio-zero-bug-v2-7-4106968e4d15@linux.ibm.com \
    --to=ojaswin@linux.ibm.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox