Received: by 2002:ab2:687:0:b0:1f4:6588:b3a7 with SMTP id s7csp185927lqe; Tue, 9 Apr 2024 20:51:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbozU3T1h8oGpPUgsC4P/p2r40cvWuiLmsw1cELeRbWNrW8/32GEX8Gib52uSK89mcVbj61GO5oLfR8bwsqSbF8BnVyJUpI2Xm0UzxwA== X-Google-Smtp-Source: AGHT+IFd4mk+Rvb5PIQ7ieq+3VpDNrxnow4d5MB6P8DetsCGhrDHwgfv2ch4W/xy4cavEGKXKuCq X-Received: by 2002:ac8:59c4:0:b0:436:4002:c50f with SMTP id f4-20020ac859c4000000b004364002c50fmr16926qtf.24.1712721064468; Tue, 09 Apr 2024 20:51:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712721064; cv=pass; d=google.com; s=arc-20160816; b=dut3oWkTJwWvMxn2HhKxYS39jsjqZLaXTA1efS69NMSKMtQIJhsxWaQSDtI0kG6QXq 1yw1yOSSZllRabDHMqgMA+d6VdMatQ0oIBrT0C2DedN9et+MYZcAeFy+IHN8Nc5W0yoG Jx2BlVTVn9fRtSVr7mGtEvjYH9wjIKG0W9N2jzwIq9X9wxNk5g82L8Be/y/c3q7oGMBD Drx57oMUeyXFizDrU3IUUbzROVHenjQcpV9iRx3pMjLxHMTknz2Sz346a5f7sEhPKhmf R+vgxbBnizGo4eqvjx5Sr11LdduBrBGoQsoxNb2DhKdZVbfuobvZnFX3qOML18bGtyTS drJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=RuHY6VVKOxj9Xdepnr+9bRSoYO0Xxk07pmy/1ZAaEXY=; fh=dC1DNofMpo0fGa+HNNOiDPPA5M30OdZqJ1HdUJkde1U=; b=ySh515AhreJKcmZVUGOSFovSn17H9G+/BRtCRWbw8nxX8NYZMaRqsQ3FY2u5Q9d0bM xIJ/5JhaRYztKGoj2IBiEEf2RqpnqYlcFSvs1C6E8IqY16GPGUrWBIL3cP+iH938/RQ3 1UHmA9zkjgzkE90iqbK5/C/kTi2WnW2Kl3aLi+3fSYZa8WIlUc4avJbXkj6HMi88ZANd hU/P0a/jXza5S6wGlXDhEYy3WsHpNXUvdj94cJhUCy1vWoC7bUbL+cUtqb9nmowmup4y EW+VCXMiIe+1kbkjiH+redmi0lBPUS3xwzxqbFs+/rZvR9KlO6yUwU6gB3bJ+S1G5RKh y0pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1928-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g15-20020ac85d4f000000b004345e4cb66asi12793925qtx.63.2024.04.09.20.51.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 20:51:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1928-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 37B2F1C21579 for ; Wed, 10 Apr 2024 03:51:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 82778D26D; Wed, 10 Apr 2024 03:50:53 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10F99BA50; Wed, 10 Apr 2024 03:50:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712721053; cv=none; b=X2xDaOvjKxFcy/lU++lpJJ9AUc9TIHgplj3hNyUsx6QYo1afktweL9n9O3yPTYRxT7OSwc0qcpfjyF1feohpsZ6FyMFwj73mf4RZZ2FhesXAwfP0kqCMsTMnpGot1RVvnfu79Zdhlr5nmbl/a9F+HV+o9EqsRDpYOT8GcsHDBjo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712721053; c=relaxed/simple; bh=4aKBF6J1JifebI88IbB+j6VQBFGLK9Ep7hy6nrxj5rE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AzfQ+biX12dMk44t69dL8HJbXSVsuAcSZbLv65aonPhc8dGzanDtUvpuWK/UmB8nbbVLeLnmos29RMgHs2tELMC0wU14gt6qWYdXG89tgxUH9A2LinbRMe59RBTYh6DkP95ws2rkhPmQSbRbRJB8jCuF5y+sDxiw1Bd+oe7k9z4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 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.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VDpl74qV6z4f3kp7; Wed, 10 Apr 2024 11:50:43 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 17A771A038B; Wed, 10 Apr 2024 11:50:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBGADBZmy5ZTJg--.21880S7; Wed, 10 Apr 2024 11:50:47 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v2 3/9] ext4: trim delalloc extent Date: Wed, 10 Apr 2024 11:41:57 +0800 Message-Id: <20240410034203.2188357-4-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410034203.2188357-1-yi.zhang@huaweicloud.com> References: <20240410034203.2188357-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBHGBGADBZmy5ZTJg--.21880S7 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1xWF1Dtr17tF15Aw4Utwb_yoW8CFyUp3 93CFn5Gr4fWw18WayxJF15XF1rK3WUKrW7GrWfKw1rZas8Gw1fKaykAF17tFyUtrZ3Xrs5 XFWDtw18Cw4ftrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUd8n5UUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi The cached delalloc or hole extent should be trimed to the map->map_len if we map delalloc blocks in ext4_da_map_blocks(). But it doesn't trigger any issue now because the map->m_len is always set to one and we always insert one delayed block once a time. Fix this by trim the extent once we get one from the cached extent tree, prearing for mapping a extent with multiple delalloc blocks. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 118b0497a954..e4043ddb07a5 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1734,6 +1734,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1750,10 +1755,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; - retval = es.es_len - (iblock - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es)) @@ -1788,6 +1789,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, * whitout holding i_rwsem and folio lock. */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (!ext4_es_is_hole(&es)) { up_write(&EXT4_I(inode)->i_data_sem); goto found; -- 2.39.2