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 06/13] ext4: add tracking for unwritten to-be-converted ranges in dio write path
Date: Fri, 27 Nov 2026 20:40:53 +0530 [thread overview]
Message-ID: <20261127-ext4-endio-zero-bug-v2-6-4106968e4d15@linux.ibm.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com>
Make sure dio 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.
Error note:
Ideally, on an IO error we should clear the CONVERT_PENDING bits since they
will not be converted, however, this is not straigh forward in dio. This is
because nothing stops parallel overlapping dios to mark the same range as
CONVERT_PENDING. If one of those fails, clearing CONVERT_PENDING would be
wrong because the other dio is still depending on it.
For simplicitly, we just don't clear it at all on dio errors because:
1. Clearing unconditionally exposes the range for zeroout corruption that
CONVERT_PENDING was designed to solve. Not clearning it is much more
forgiving because it just disables zeroout fallback on such ranges.
2. One sideeffect is that we would end up leaving these stale unreclaimable
CONVERT_PENDING es entries but this would be rare and hopefully future IOs
would consume the stale CONVERT_PENDING ranges if this happens.
3. Solving it would require much more intrusive changes to refcount track
each CONVERT_PENDING extent status.
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/ext4.h | 2 ++
fs/ext4/inode.c | 39 +++++++++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 8cce99d68978..72de06efb4b2 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -4221,6 +4221,8 @@ extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
+extern void ext4_clear_convert_pending(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len);
extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
struct ext4_map_blocks *map, int flags);
extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3e4c0e1396ab..4aafd0aaea69 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -783,6 +783,37 @@ static bool ext4_map_mark_convert_pending(struct inode *inode,
return ok;
}
+/*
+ * Drop the convert pending extents in the given range from the extent status
+ * tree. Convert pending is set when we map an unwritten extent which is
+ * expected to be converted to written for endio soon. If the IO fails, nobody
+ * will do that, so just drop the cache.
+ */
+void ext4_clear_convert_pending(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len)
+{
+ ext4_lblk_t end = lblk + len - 1;
+ struct extent_status es;
+
+ if (!len)
+ return;
+
+ while (lblk <= end) {
+ ext4_lblk_t start, stop;
+
+ ext4_es_find_extent_range(inode, ext4_es_is_convert_pending,
+ lblk, end, &es);
+ if (!es.es_len || es.es_lblk > end)
+ break;
+ start = max(lblk, es.es_lblk);
+ stop = min(end, es.es_lblk + es.es_len - 1);
+ ext4_es_remove_extent(inode, start, stop - start + 1);
+ if (stop == end)
+ break;
+ lblk = stop + 1;
+ }
+}
+
/*
* The ext4_map_blocks() function tries to look up the requested blocks,
* and returns if the blocks are already mapped.
@@ -4012,7 +4043,8 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
else if (EXT4_LBLK_TO_B(inode, map->m_lblk) >= i_size_read(inode))
m_flags = EXT4_GET_BLOCKS_CREATE;
else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
- m_flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT;
+ m_flags = EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT |
+ EXT4_GET_BLOCKS_CONVERT_PENDING;
if (flags & IOMAP_ATOMIC)
ret = ext4_map_blocks_atomic_write(handle, inode, map, m_flags,
@@ -4082,7 +4114,10 @@ int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
* especially in multi-threaded overwrite requests.
*/
if (offset + length <= i_size_read(inode)) {
- ret = ext4_map_blocks(NULL, inode, &map, 0);
+ ret = ext4_map_blocks(NULL, inode, &map,
+ (flags & IOMAP_DAX) ?
+ 0 :
+ EXT4_GET_BLOCKS_CONVERT_PENDING);
/*
* For DAX we convert extents to initialized ones before
* copying the data, otherwise we do it after I/O so
--
2.55.0
next prev parent reply other threads:[~2026-11-27 15:12 UTC|newest]
Thread overview: 14+ 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: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 ` Ojaswin Mujoo [this message]
2026-11-27 15:10 ` [PATCH v2 07/13] ext4: add tracking for unwritten to-be-converted ranges in non iomap buffered path Ojaswin Mujoo
2026-11-27 15:10 ` [PATCH v2 08/13] ext4: add tracking for unwritten to-be-converted ranges in " 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-6-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
all inboxes | Powered by JetHome®