From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=124.71.94.104 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796209391; b=qfryG/Fwut6vLWVA+A1uGE4GVID89xB1fcyOGJjCrFnkV6vZmPjdDRO8UvhOyGUbmoHd 4pWp6TIWVt4Wp0a3Hztcy8JOIT223p8duytwHpH6eozUi6tlNL/NYI8CdDB+PYXh8atYe SzFAqULXx/Gv3yNIKF6O5xCNIkfkCyaW6pQXBoANNDZuyFDSgtpBUDYZjOR+ZpmsJKFtk HLBcdgfiZ+xLE5BDQ86qKDHOQlcb+5CmIRQcfmj6AKRbb8TYjm4lwL2DviohY2QpMlspy 70LK/nJ1XVwLIJqlyFJmvBCNCjijk0tFG+uBpuRiXFfcq+p6CoSRve2UBIVoMeyUCVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796209391; h=DMARC-Filter:Received:Received:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:X-CM-SenderInfo; bh=wr84VbQPiKic4p59nYIMq5NSuJL3GZxC8BwArFAF+AE=; b=i9qbR854VbpTQcKwE7saC8whjDhRCoq0XSxDregbuHuK9+kp4P4yy9wR6+s7f8I8c+TS KaK24Ki10F66qPtQ2LraIpXuTaTHBIi8DDCerI4w770S2kkw5UrTlQWUwzDgrGfyy/MZ8 R8366QKnNVorfgq4VaelpfHAu5IEZyV0EeFCT5+1RVEwCdioP/NuE6g6ldcg55Mw2CL3o GqWNjvI3jdONiWfjz9CBTdME8RxyfSUG8pUgTwn4dGgpFJ95WYk+5E+jNfvwwuavkOy0Y KJubFy3VJMAp4ZAz+2tgbnzy5iJQbSkc+DQyJNK8Tx81JI/YUt4vQiLhuXailH+wZog== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.remote-ip=124.71.94.104 Received: from dggmsgout13.his.huawei.com (dggmsgout13.his.huawei.com [124.71.94.104]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28837606A335; Wed, 2 Dec 2026 11:03:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28837606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.177]) by dggmsgout13.his.huawei.com (SkyGuard) with ESMTP id 4jfZbs4xhKz1rqvs; Wed, 2 Dec 2026 19:02:49 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 78CF7405EC; Wed, 2 Dec 2026 19:03:05 +0800 (CST) Received: from [10.174.179.19] (unknown [10.174.179.19]) by APP4 (Coremail) with UTF8SMTPSA id gCh0CgAnZvXn+g9rObGdGg--.28744S3; Wed, 02 Dec 2026 19:03:05 +0800 (CST) Message-ID: <3e5119b7-38d0-4ed7-a3d6-64fd8fccc468@huaweicloud.com> Date: Wed, 2 Dec 2026 19:03:03 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 05/13] ext4: add support to track convert pending ranges in ext4_map_blocks() To: Ojaswin Mujoo Cc: Theodore Ts'o , Andreas Dilger , Baokun Li , Jan Kara , "Ritesh Harjani (IBM)" , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261127-ext4-endio-zero-bug-v2-0-4106968e4d15@linux.ibm.com> <20261127-ext4-endio-zero-bug-v2-5-4106968e4d15@linux.ibm.com> Content-Language: en-US From: Zhang Yi In-Reply-To: <20261127-ext4-endio-zero-bug-v2-5-4106968e4d15@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CM-TRANSID:gCh0CgAnZvXn+g9rObGdGg--.28744S3 X-Coremail-Antispam: 1UD129KBjvJXoWxKr4UWF1DtF47XF1fuF47XFb_yoW3Jr4UpF WvyF1ruF4jgw45urWxCF4jvF1Sgw1rKFWDCa1xWrW5u342yr1SyF1FyF1fCFW3trWfZw4Y qFW5G348Cws3G37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyGb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1veHDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ On 11/27/2026 11:10 PM, Ojaswin Mujoo wrote: > 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 > --- > 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) { Hi Ojaswin, Regarding the change in ext4_map_blocks(), maybe we can clean it up a bit further. The current logic feels a little convoluted. For example, something like the following, it would also let us drop the ext4_map_mark_convert_pending() helper added in patch 4. What do you think? diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 041b7d872604..5d0ba049dabe 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -796,7 +796,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, KUNIT_STATIC_STUB_REDIRECT(ext4_map_blocks, handle, inode, map, flags); - map->m_flags = 0; ext_debug(inode, "flag 0x%x, max_blocks %u, logical block %lu\n", flags, map->m_len, (unsigned long) map->m_lblk); @@ -821,7 +820,9 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, else ext4_check_map_extents_env(inode); -create_retry: +retry: + map->m_flags = 0; + map->m_len = orig_mlen; /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, &map->m_seq)) { if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { @@ -882,36 +883,53 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, goto out; } - /* If it is only a block(s) look up */ - if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) + /* It is only a block(s) look up */ + if (!(flags & (EXT4_GET_BLOCKS_CREATE | + EXT4_GET_BLOCKS_CONVERT_PENDING))) return retval; - /* - * Returns if the blocks have already allocated - * - * Note that if blocks have been preallocated - * ext4_ext_map_blocks() returns with buffer head unmapped - */ + /* Got a written or unwritten extent. */ if (retval > 0) { - /* - * If we need to convert written extent to unwritten or - * convert unwritten extent to written, continue and do - * the actual work in ext4_ext_map_blocks(). - */ - if (map->m_flags & EXT4_MAP_MAPPED && - !(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) - goto out; - if (map->m_flags & EXT4_MAP_UNWRITTEN && - (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) && + if (map->m_flags & EXT4_MAP_MAPPED) { + /* Return if we don't convert blocks to unwritten. */ + if (!(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) + goto out; + goto create; + } + + /* The caller accepts the unwritten mapping as-is. */ + if ((flags & (EXT4_GET_BLOCKS_UNWRIT_EXT | + EXT4_GET_BLOCKS_CONVERT_PENDING)) && !(flags & (EXT4_GET_BLOCKS_CONVERT | EXT4_GET_BLOCKS_SPLIT_NOMERGE))) { - /* Contains EXT4_GET_BLOCKS_CREATE - mark mapped. */ ret = check_block_validity(inode, map); - if (!ret) + if (ret) + goto out; + + /* + * If the tree changed since the lookup, the mapping + * is stale and must be looked up again. + */ + if (flags & EXT4_GET_BLOCKS_CONVERT_PENDING) { + down_read(&EXT4_I(inode)->i_data_sem); + if (map->m_seq != + READ_ONCE(EXT4_I(inode)->i_es_seq)) { + up_read(&EXT4_I(inode)->i_data_sem); + goto retry; + } + ext4_es_mark_convert_pending(inode, map->m_lblk, + map->m_len, map->m_pblk); + up_read(&EXT4_I(inode)->i_data_sem); + } + + if (flags & EXT4_GET_BLOCKS_CREATE) map->m_flags |= EXT4_MAP_MAPPED; goto out; } + /* Got a hole or delalloc extent. */ } else if (retval == 0) { + if (!(flags & EXT4_GET_BLOCKS_CREATE)) + goto out; /* * Do not allocate blocks for holes in the context of * data submission path. @@ -920,6 +938,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, goto out; } +create: if (!handle) { handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, ext4_chunk_trans_blocks(inode, orig_mlen)); @@ -949,9 +968,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, */ if (map->m_seq != READ_ONCE(EXT4_I(inode)->i_es_seq)) { up_write(&EXT4_I(inode)->i_data_sem); - map->m_flags = 0; - map->m_len = orig_mlen; - goto create_retry; + goto retry; } retval = ext4_map_create_blocks(handle, inode, map, flags); up_write((&EXT4_I(inode)->i_data_sem));