mirror of https://lore.kernel.org/lkml/
 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 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks()
Date: Fri, 27 Nov 2026 20:40:52 +0530	[thread overview]
Message-ID: <20261127-ext4-endio-zero-bug-v2-5-4106968e4d15@linux.ibm.com> (raw)
In-Reply-To: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com>

Introduce a new get block flag to indicate that the caller is about to
issue IO over unwritten ranges and hence wants them to be marked as
convert pending. This allows upcoming changes to query such ranges before
trying to zero them out in endio.

We need to be careful to always add the CONVERT_PENDING extent status entry
under i_data_sem because the upcoming changes will use that sem to
serialize with the endio zeroout path.

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
 fs/ext4/ext4.h              |  9 ++++++++-
 fs/ext4/inode.c             | 23 +++++++++++++++++++++--
 include/trace/events/ext4.h |  1 +
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 646c017dda1c..8cce99d68978 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -748,6 +748,12 @@ struct ext4_new_flex_group_data {
  */
 #define EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF	0x1000
 
+/*
+ * This range will get converted from unwritten to written soon due to endio
+ * conversion.
+ */
+#define EXT4_GET_BLOCKS_CONVERT_PENDING	0x2000
+
 /*
  * The bit position of these flags must not overlap with any of the
  * EXT4_GET_BLOCKS_*.  They are used by ext4_find_extent(),
@@ -766,7 +772,8 @@ struct ext4_new_flex_group_data {
  */
 #define EXT4_EX_QUERY_FILTER	(EXT4_EX_NOCACHE | EXT4_EX_FORCE_CACHE |\
 				 EXT4_EX_NOFAIL |\
-				 EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF)
+				 EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF |\
+				 EXT4_GET_BLOCKS_CONVERT_PENDING)
 
 /*
  * Flags used by ext4_free_blocks
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index f7fc5fb7e819..3e4c0e1396ab 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -750,6 +750,9 @@ int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 
 	status = map->m_flags & EXT4_MAP_UNWRITTEN ?
 			EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
+	if (status == EXTENT_STATUS_UNWRITTEN &&
+	    flags & EXT4_GET_BLOCKS_CONVERT_PENDING)
+		status = EXTENT_STATUS_CONVERT_PENDING;
 	ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk,
 			      status, flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE);
 	map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq);
@@ -911,8 +914,17 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
 	}
 
 	/* If it is only a block(s) look up */
-	if ((flags & EXT4_GET_BLOCKS_CREATE) == 0)
+	if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
+		if (map->m_flags & EXT4_MAP_UNWRITTEN &&
+		    flags & EXT4_GET_BLOCKS_CONVERT_PENDING &&
+		    !ext4_map_mark_convert_pending(inode, map)) {
+			map->m_flags = 0;
+			map->m_len = orig_mlen;
+			goto create_retry;
+		}
+
 		return retval;
+	}
 
 	/*
 	 * Returns if the blocks have already allocated
@@ -934,8 +946,15 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
 		    !(flags & EXT4_GET_BLOCKS_CONVERT)) {
 			/* Contains EXT4_GET_BLOCKS_CREATE - mark mapped. */
 			ret = check_block_validity(inode, map);
-			if (!ret)
+			if (!ret) {
+				if (flags & EXT4_GET_BLOCKS_CONVERT_PENDING &&
+				    !ext4_map_mark_convert_pending(inode, map)) {
+					map->m_flags = 0;
+					map->m_len = orig_mlen;
+					goto create_retry;
+				}
 				map->m_flags |= EXT4_MAP_MAPPED;
+			}
 			goto out;
 		}
 	} else if (retval == 0) {
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 4313694cd4e9..fb18fdcb3003 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -46,6 +46,7 @@ struct partial_cluster;
 	{ EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,	"CONVERT_UNWRITTEN" },  \
 	{ EXT4_GET_BLOCKS_ZERO,			"ZERO" },		\
 	{ EXT4_GET_BLOCKS_IO_SUBMIT,		"IO_SUBMIT" },		\
+	{ EXT4_GET_BLOCKS_CONVERT_PENDING,	"CONV_PENDING" },		\
 	{ EXT4_EX_NOCACHE,			"EX_NOCACHE" })
 
 /*

-- 
2.55.0


  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 ` [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 ` Ojaswin Mujoo [this message]
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-5-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®