From patchwork Wed Apr 10 14:29:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CB96CD11C2 for ; Wed, 10 Apr 2024 14:38:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 953166B0092; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0E46B0093; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 581696B0096; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 334426B0093 for ; Wed, 10 Apr 2024 10:38:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DC79A1A07B9 for ; Wed, 10 Apr 2024 14:38:36 +0000 (UTC) X-FDA: 81993878232.25.D0B6F69 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 75A5520002 for ; Wed, 10 Apr 2024 14:38:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712759915; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1B4ngafH1j/H0v6adJNVq5qXwTB2PXDJPpcTLBN4hv4=; b=yhvrzesHWqonp4t0HG/5L2RfnweU1S5vqM7K9l12gFpuxGP5b9Gegit130XzFtafafEewl u+Heh5SWZb7Z1UVlJTLBCOnMUiBe00lIXGTMYpJRHVCopZBzZGAyWBXkCDbmoK8lT+hZzf rk3kaFhfw+T2XT43jEnG95hKagtPLqI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712759915; a=rsa-sha256; cv=none; b=ujOsVGGsR3RSrGAlny7ffeAKZzUdsZMfKakKJDw/soOIZ06Rah2yVUEkfghjXtZQrdf6U4 w/+BQ0BcCVAaPEU9h2AHT4Je4sXzMxmMvcapSAgUkxqAtb31Ig3GnA3HWmPhZ9dVlCBaWt /TKHpXb0t2v1pqEbb1N/tXnAO0P/1UE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF56R2y7kz4f3khr for ; Wed, 10 Apr 2024 22:38:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 45CD01A0C72 for ; Wed, 10 Apr 2024 22:38:30 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S11; Wed, 10 Apr 2024 22:38:30 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v4 07/34] ext4: factor out check for whether a cluster is allocated Date: Wed, 10 Apr 2024 22:29:21 +0800 Message-Id: <20240410142948.2817554-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX6RFSpBZmcwR8Jg--.63000S11 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga10q3yUJrWa93W8Zr4fJFy5KF1qyF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUHS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I 8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCF s4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFI xGxcIEc7CjxVA2Y2ka0xkIwI1lc7CjxVAaw2AFwI0_GFv_Wryl42xK82IYc2Ij64vIr41l 4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxV WUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI 7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Ar0_tr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWx Jr1lIxAIcVC2z280aVCY1x0267AKxVWxJr0_GcJvcSsGvfC2KfnxnUUI43ZEXa7sRibyCP UUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 75A5520002 X-Rspam-User: X-Stat-Signature: rqj897bycdfc9yj69ykesbjhzbxdejyi X-Rspamd-Server: rspam03 X-HE-Tag: 1712759914-733652 X-HE-Meta: U2FsdGVkX1+Quz6bFLemKYetoxtCpV+YfOEguSM67clun/Nb2xs6OaT/mikXfzKRg1+kWs60SwtmRaFU2YTaXussq2GDMVa2/3yeCg1xfNln3ZEX7eNkbFSKxLjF9pIzXFXeEvaNPelCk0j7XPHTKfaXbaFMuiQ1DB+lhS65lgHl0I6n3/MdTV/6I2uCW9oWoslecM4WM55RpPQPbRroU7WmIKfFl8iG77AcF3mdNl2Qv35qZbDJOoqP4bPKVDQQrM8IA1DNPADPpmnEAU7fZPtxdpkaiJqT3N6XiFehEUvnCTc60dKM2StiEQeDt5OSzK/L2yi/bRxbrlRkBZzuKwQvCOekxA89NcVu9G0tcxuHKoocnPYDHbCwU8clKyoPw+moSJnp/1IRIkSByirNQoiXvQ94NqdrKk2fVagiK4RIgyvsj1ka2LcGZsb4k9nqe9N8sU0HcPfWpRWrK5K39qoeW16j5SgVEj72QZkepOxGL64imlOojDEbZ7aB7zSGZKdNljr81gVEh89+hVrVeEEEh9NCXeq7L31tfpN652TMmKqJ5lwBJMidO0dK2GDH25bm81Z0EGw4oYf+SOsTIsE0iFMHTyDS/BrfhG0NvXaOM8O1d68Kxb1l9XGKStDWVL9bPYAR6XUeIEgw2PGG8zBlfFmYNrfXrZyfbbUwnsmUnDcNrr+ou+YGVXXkzYstZZlnCsPJGHX5ClFFGZoZkEHRIpW7jjiZjuLDvXFqi+mItO/kppKolUipfYwSfACgcOXwb+dDkSivJmJdTnjL99N3V6khV9Y8ygupxAS/1l44khK8vmiW5dq2odVYpckHdbp8pR3pr0l4te+EgqQ4LfbaeTceYgf3HpwmJBYC3ySaDP+u3wsYwR5Tga6hfVsZu8y0+QUSFCGAmCm4l+MRWlUTTN/BwN8QDZW6sZfpRg01gTw63QImvG3XIg5FjCYvOlJWzdN01th+i181ufk iplOquSI EJsyyYAFgtgdXIhAL/EHV0K0G2Qh4VhbfjJ291eMiBYrtbVqiJxEsEwiLPHc2UAzdaDsBvVNCFhn3YwwoNUgKDsdgUhhFteNd/1tT9OINBlpihwTdDs75EfSU3AjKHLcwyH1FW8qcXD0uFlPdayD7OOfVlaAVKqXAR367ZeFQTVmJOPbo+VoN/yaZ5m+buZi0oDi6Y7OJyqgLyP+HbhKTJdUBuwVyJ5LAS8NAU7nQ78fBIhRZShkVc+MQcIRfxXswS8C1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Factor out a common helper ext4_da_check_clu_allocated(), check whether the cluster containing a delalloc block to be added has been delayed or allocated, no logic changes. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 52 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 1180a9eb4362..46c34baa848a 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1649,6 +1649,34 @@ static void ext4_print_free_blocks(struct inode *inode) return; } +/* + * Check whether the cluster containing lblk has been delayed or allocated, + * if not, it means we should reserve a cluster when add delalloc, return 1, + * otherwise return 0 or error code. + */ +static int ext4_da_check_clu_allocated(struct inode *inode, ext4_lblk_t lblk, + bool *allocated) +{ + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); + int ret; + + *allocated = false; + if (ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) + return 0; + + if (ext4_es_scan_clu(inode, &ext4_es_is_mapped, lblk)) + goto allocated; + + ret = ext4_clu_mapped(inode, EXT4_B2C(sbi, lblk)); + if (ret < 0) + return ret; + if (ret == 0) + return 1; +allocated: + *allocated = true; + return 0; +} + /* * ext4_insert_delayed_block - adds a delayed block to the extents status * tree, incrementing the reserved cluster/block @@ -1682,23 +1710,13 @@ static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) if (ret != 0) /* ENOSPC */ return ret; } else { /* bigalloc */ - if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { - if (!ext4_es_scan_clu(inode, - &ext4_es_is_mapped, lblk)) { - ret = ext4_clu_mapped(inode, - EXT4_B2C(sbi, lblk)); - if (ret < 0) - return ret; - if (ret == 0) { - ret = ext4_da_reserve_space(inode, 1); - if (ret != 0) /* ENOSPC */ - return ret; - } else { - allocated = true; - } - } else { - allocated = true; - } + ret = ext4_da_check_clu_allocated(inode, lblk, &allocated); + if (ret < 0) + return ret; + if (ret > 0) { + ret = ext4_da_reserve_space(inode, 1); + if (ret != 0) /* ENOSPC */ + return ret; } }