Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5858730rdb; Thu, 14 Dec 2023 01:19:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEu9nxjS+QXPy7yhC1NRO85xThVkmm15tvMuCdj7IsHOuqvucbDLmG6pbK63u2C7zxn/Bsa X-Received: by 2002:a17:90a:4306:b0:286:6cc1:3f0b with SMTP id q6-20020a17090a430600b002866cc13f0bmr7105819pjg.66.1702545544759; Thu, 14 Dec 2023 01:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702545544; cv=none; d=google.com; s=arc-20160816; b=0M5mIVshg9wnpcnVGZkAUUCJdXBiHWTtxlGnH5uCag/T4LoWVg5+hYLAx0Tl976bA1 zy4L5CcoDJgW4lXE+EV4kvoVIVaoIetnnvtlmlpUbf+KjHfLOwCUukVGsSeD8kYXYXpP ubkPyYWiHWMNHBK8CbUE+zkguBApvlIt/zPwnYymbVz97jc2xjg1Ni2m/xQvtrRh7eUW 4HZqDTsuTcY2mPzi20fAn10xXciYp+sEGJ2T5ecmlYSSnCDzDRMqjOU79XLR2nRqJxM2 nlzTHw/UFLZWodsWL17B3TpW//RdNCac453rJlgfPDw2OeBGFoWNQtm72hCoO2i24I3h 0cUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=x1ueXLnOjP9D+weEeFrLwhlSTvwnjVubmUXCyBOiyyI=; fh=O+8nUxKvaRfR85a1ObZm7Cp9koJRMVxj+NtRl2QpAAo=; b=mnPpwmyP+pQtKZua2CYwOEE7UEHz5Usw3DWNjjHSjrPbc4wlCrLFo1j/B1VrgwaxM1 5jgMHRg3b4kV4xyrexaodaHXR5htI4z/aClP4XYe7A7sJdHyVJIpIXDShbYPVWUe7CMP x7yXtre7XeK+W9+w1rhNJHjf2pxxfFMqFIXFv7Yx3ZeHXjwXZOZkhE1SWZ3bSekALWTb eGsYlWc4x+blwrRtanaWCGAbLhvk8Z+AieOjx6ZL8Rq4+tGKxSe0utHOdzEkMpKX1X8d BZEtdBOpU1fGByDrUvuEoJCpGJ03pmqL6czs4u2BghdZKUCrp9HRB4NBVQLzdgB7063/ tFlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-445-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y2-20020a17090a86c200b0028675cb4aeasi12195372pjv.47.2023.12.14.01.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 01:19:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-445-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 567E9B2129D for ; Thu, 14 Dec 2023 09:19:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC1CE2E3F0; Thu, 14 Dec 2023 09:18:55 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CADACB7 for ; Thu, 14 Dec 2023 01:18:50 -0800 (PST) Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SrRc45PGHz4f3kFG for ; Thu, 14 Dec 2023 17:18:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4F01B1A096D for ; Thu, 14 Dec 2023 17:18:47 +0800 (CST) Received: from [10.174.176.34] (unknown [10.174.176.34]) by APP1 (Coremail) with SMTP id cCh0CgDXJg11yHplHsx1Dg--.33268S3; Thu, 14 Dec 2023 17:18:47 +0800 (CST) Subject: Re: [RFC PATCH 3/6] ext4: correct the hole length returned by ext4_map_blocks() To: Jan Kara Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, ritesh.list@gmail.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20231121093429.1827390-1-yi.zhang@huaweicloud.com> <20231121093429.1827390-4-yi.zhang@huaweicloud.com> <20231213182114.tzwsqpeonr5ok3j2@quack3> From: Zhang Yi Message-ID: <52f6786a-b936-9f79-bea0-ed54a57efd62@huaweicloud.com> Date: Thu, 14 Dec 2023 17:18:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20231213182114.tzwsqpeonr5ok3j2@quack3> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:cCh0CgDXJg11yHplHsx1Dg--.33268S3 X-Coremail-Antispam: 1UD129KBjvJXoWxGw4UCF45uF4DZr17WFWxJFb_yoWrXr4x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wrote: >> From: Zhang Yi >> >> In ext4_map_blocks(), if we can't find a range of mapping in the >> extents cache, we are calling ext4_ext_map_blocks() to search the real >> path. But if the querying range was tail overlaped by a delayed extent, >> we can't find it on the real extent path, so the returned hole length >> could be larger than it really is. >> >> | querying map | >> v v >> |----------{-------------}{------|----------------}-----... >> ^ ^ ^^ ^ >> | uncached | hole extent || delayed extent | >> >> We have to adjust the mapping length to the next not hole extent's >> lblk before searching the extent path. >> >> Signed-off-by: Zhang Yi > > So I agree the ext4_ext_determine_hole() does return a hole that does not > reflect possible delalloc extent (it doesn't even need to be straddling the > end of looked up range, does it?). But ext4_ext_put_gap_in_cache() does Yeah. > actually properly trim the hole length in the status tree so I think the > problem rather is that the trimming should happen in > ext4_ext_determine_hole() instead of ext4_ext_put_gap_in_cache() and that > will also make ext4_map_blocks() return proper hole length? And then > there's no need for this special handling? Or am I missing something? > Thanks for your suggestions. Yeah, we can trim the hole length in ext4_ext_determine_hole(), but I'm a little uneasy about the race condition. ext4_da_map_blocks() only hold inode lock and i_data_sem read lock while inserting delay extents, and not all query path of ext4_map_blocks() hold inode lock. I guess the hole/delayed range could be raced by another new delay allocation and changed after we first check in ext4_map_blocks(), the querying range could be overlapped and became all or partial delayed, so we also need to recheck the map type here if the start querying block has became delayed, right? Thanks, Yi. > >> --- >> fs/ext4/inode.c | 24 ++++++++++++++++++++++-- >> 1 file changed, 22 insertions(+), 2 deletions(-) >> >> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c >> index 4ce35f1c8b0a..94e7b8500878 100644 >> --- a/fs/ext4/inode.c >> +++ b/fs/ext4/inode.c >> @@ -479,6 +479,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, >> struct ext4_map_blocks *map, int flags) >> { >> struct extent_status es; >> + ext4_lblk_t next; >> int retval; >> int ret = 0; >> #ifdef ES_AGGRESSIVE_TEST >> @@ -502,8 +503,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, >> return -EFSCORRUPTED; >> >> /* Lookup extent status tree firstly */ >> - if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) && >> - ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { >> + if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) >> + goto uncached; >> + >> + if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { >> if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { >> map->m_pblk = ext4_es_pblock(&es) + >> map->m_lblk - es.es_lblk; >> @@ -532,6 +535,23 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, >> #endif >> goto found; >> } >> + /* >> + * Not found, maybe a hole, need to adjust the map length before >> + * seraching the real extent path. It can prevent incorrect hole >> + * length returned if the following entries have delayed only >> + * ones. >> + */ >> + if (!(flags & EXT4_GET_BLOCKS_CREATE) && es.es_lblk > map->m_lblk) { >> + next = es.es_lblk; >> + if (ext4_es_is_hole(&es)) >> + next = ext4_es_skip_hole_extent(inode, map->m_lblk, >> + map->m_len); >> + retval = next - map->m_lblk; >> + if (map->m_len > retval) >> + map->m_len = retval; >> + } >> + >> +uncached: >> /* >> * In the query cache no-wait mode, nothing we can do more if we >> * cannot find extent in the cache. >> -- >> 2.39.2 >>