Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6512539rdb; Tue, 2 Jan 2024 04:43:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6rlND1o1wko3tt1Kq9mT7a2EpBn0n313GX2eA/8myX3qZp4K8Va4Mwdxc7liMGrvONW3n X-Received: by 2002:ad4:5f8e:0:b0:67a:27c4:31f9 with SMTP id jp14-20020ad45f8e000000b0067a27c431f9mr34568828qvb.11.1704199415801; Tue, 02 Jan 2024 04:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704199415; cv=none; d=google.com; s=arc-20160816; b=zJlLaHRDEoUqgnoPPwA0Icu0B5ueJDWgDLmllKRN7vBlyhGEtDFapNmkh9NW3f5yaT HRQ38BdGhr5ij3mnUTpqfkFW16dNEycUiqTXJWmHkzM7M7HdPWvil/BG5wkN8vXkqZza EF1rvJOOvRDIHANzjNs/L4EX5N0PfE9kVmsfBxS0xUtxj51cpUfNaWnBH4BfVsRYCP9C nKv1uxLBvX10XZUkuXnUUC3NLpK5hPlZytQeAd07M7hzi4Ts3NCsZP7iamoDmGe4l2Lz l2VGX7omnhjkL+OIFjuuQHiOqLayuHEau6uoU9iaSa9ic6gSFCdTEBeDyjhsTZxX+3Kb 76GA== ARC-Message-Signature: i=1; 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=ibzvTDQvbHWpuZlSBRam506AV7dGjs5LmZoPW0q5Qsg=; fh=yWWoL3IRufgA/+2kSpO6uyfw9eN3ZOO7zvul0qbDPkA=; b=cETFjZzrcEA5Y+PH3cNZjDe+T9A5FiYvwiDvkI3h5RUYDsOm44niRdMwLq9XoSRfN2 TtPO1lPebqHeGyiThfNZKu20ajWfwZ6xNU5OYQPod0ay4gCV9ecFQxHsOQJmphY/vw3s EhrFnRSxK0MiE4JwCodlCUNxPIXX+h+DHHsOTr3+AS7BeY7ohg6DpV5HXGlonXtdhvxk B+DADBVW6+TZjW7EBDkhrxdBX4ZyqYpgrZPdE+tae8sEAw+05CL/ktTe5yBykN/8mypK AHkS41tfV/8TB5W5cDzZKj+es00+IbRdy0i1I+SGxCgsDnX9IhfAp4lUUgLJVxl2JgvL taRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-603-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h11-20020a05620a244b00b0077fb4eb30d1si28055364qkn.116.2024.01.02.04.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 04:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-603-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-603-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 8D0571C21E6B for ; Tue, 2 Jan 2024 12:43:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5802B12E79; Tue, 2 Jan 2024 12:42:15 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [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 C3D841173B; Tue, 2 Jan 2024 12:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T4CCx19MVz4f3nJx; Tue, 2 Jan 2024 20:42:05 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id C3C241A017F; Tue, 2 Jan 2024 20:42:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgBnwUGUBJRl+EvDFQ--.31823S14; Tue, 02 Jan 2024 20:42:10 +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, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v2 10/25] ext4: correct delalloc extent length Date: Tue, 2 Jan 2024 20:39:03 +0800 Message-Id: <20240102123918.799062-11-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102123918.799062-1-yi.zhang@huaweicloud.com> References: <20240102123918.799062-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:gCh0CgBnwUGUBJRl+E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W8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi When adding a delalloc extent in ext4_da_map_blocks(), the extent length can be incorrect if we found a cached hole extent entry and the hole length is smaller than the origin map->m_len. Fortunately, it should not be able to trigger any issue now because the map->m_len is always 1. Fix this by adjust length before inserting delalloc extent. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index bc29c2e92750..44033828db44 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1712,6 +1712,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; @@ -1727,10 +1732,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)) -- 2.39.2