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 04/13] ext4: add es helper to convert unwrit to convert pending without changing i_es_seq
Date: Fri, 27 Nov 2026 20:40:51 +0530 [thread overview]
Message-ID: <20261127-ext4-endio-zero-bug-v2-4-4106968e4d15@linux.ibm.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com>
Upcoming codepaths would often want to convert an existing unwritten extent
to convert pending in extent status cache. This is essentially not an
operation that needs to bump the i_es_seq because both of these types mean
the same thing for most of the code paths that care about the sequence
counter. Hence, introduce a new helper to change the extent status without
having to bump the extent status cache.
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/extents_status.c | 45 ++++++++++++++++++++++++++++++++++++---------
fs/ext4/extents_status.h | 2 ++
fs/ext4/inode.c | 23 +++++++++++++++++++++++
3 files changed, 61 insertions(+), 9 deletions(-)
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 75dd065106e4..244cc0f62196 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -907,14 +907,10 @@ static int __es_insert_extent(struct inode *inode, struct extent_status *newes,
return 0;
}
-/*
- * ext4_es_insert_extent() adds information to an inode's extent
- * status tree. This interface is used for modifying extents. To cache
- * on-disk extents, use ext4_es_cache_extent() instead.
- */
-void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
- ext4_lblk_t len, ext4_fsblk_t pblk,
- unsigned int status, bool delalloc_reserve_used)
+static void __ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk,
+ unsigned int status,
+ bool delalloc_reserve_used, bool inc_seq)
{
struct extent_status newes;
ext4_lblk_t end = lblk + len - 1;
@@ -1004,7 +1000,8 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
}
pending = err3;
}
- ext4_es_inc_seq(inode);
+ if (inc_seq)
+ ext4_es_inc_seq(inode);
error:
write_unlock(&EXT4_I(inode)->i_es_lock);
/*
@@ -1036,6 +1033,35 @@ void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
return;
}
+/*
+ * ext4_es_insert_extent() adds information to an inode's extent
+ * status tree. This interface is used for modifying extents. To cache
+ * on-disk extents, use ext4_es_cache_extent() instead.
+ */
+void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk,
+ unsigned int status, bool delalloc_reserve_used)
+{
+ __ext4_es_insert_extent(inode, lblk, len, pblk, status,
+ delalloc_reserve_used, true);
+}
+
+/*
+ * ext4_es_mark_convert_pending() marks an already unwritten range as
+ * CONVERT_PENDING. For most of the codepaths CONVERT_PENDING is treated as
+ * unwritten everywhere (except the endio zeroout path, which is already
+ * serialized with i_data_sem) hence we don't bump the i_es_seq here.
+ *
+ * The caller must hold i_data_sem in shared (at least) and must have made sure
+ * that the range is unwritten.
+ */
+void ext4_es_mark_convert_pending(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk)
+{
+ __ext4_es_insert_extent(inode, lblk, len, pblk,
+ EXTENT_STATUS_CONVERT_PENDING, false, false);
+}
+
/*
* ext4_es_cache_extent() inserts information into the extent status tree
* only if there is no existing information about the specified range or
@@ -2488,6 +2514,7 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk,
#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_mark_convert_pending);
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_cache_extent);
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_remove_extent);
EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_find_extent_range);
diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
index 2247f811f6c3..b1bc34af786f 100644
--- a/fs/ext4/extents_status.h
+++ b/fs/ext4/extents_status.h
@@ -140,6 +140,8 @@ extern void ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
ext4_lblk_t len, ext4_fsblk_t pblk,
unsigned int status,
bool delalloc_reserve_used);
+extern void ext4_es_mark_convert_pending(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk);
extern void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
ext4_lblk_t len, ext4_fsblk_t pblk,
unsigned int status);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9368a68db289..f7fc5fb7e819 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -757,6 +757,29 @@ int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
return retval;
}
+/*
+ * Mark the unwritten range in @map as convert pending in the extent status
+ * tree. This is used by the zeroout code to ensure we don't write zeroes on
+ * such unwritten ranges and hence must be serialized against endio conversion /
+ * extent zeroout, which hold i_data_sem excl.
+ *
+ * Returns false if the extent status tree changed since @map was looked up, in
+ * which case the caller must redo the lookup.
+ */
+static bool ext4_map_mark_convert_pending(struct inode *inode,
+ struct ext4_map_blocks *map)
+{
+ bool ok;
+
+ down_read(&EXT4_I(inode)->i_data_sem);
+ ok = map->m_seq == READ_ONCE(EXT4_I(inode)->i_es_seq);
+ if (ok)
+ ext4_es_mark_convert_pending(inode, map->m_lblk, map->m_len,
+ map->m_pblk);
+ up_read(&EXT4_I(inode)->i_data_sem);
+ return ok;
+}
+
/*
* The ext4_map_blocks() function tries to look up the requested blocks,
* and returns if the blocks are already mapped.
--
2.55.0
next prev parent reply other threads:[~2026-11-27 15:11 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 ` Ojaswin Mujoo [this message]
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 ` [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-4-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®