From patchwork Wed Apr 10 13:27:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624538 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 2C94FCD1299 for ; Wed, 10 Apr 2024 13:37:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1A426B0092; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C9C06B0093; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8919B6B0095; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6D0376B0092 for ; Wed, 10 Apr 2024 09:36:58 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 32C021A069C for ; Wed, 10 Apr 2024 13:36:58 +0000 (UTC) X-FDA: 81993722916.21.25A1066 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf05.hostedemail.com (Postfix) with ESMTP id C73F210001E for ; Wed, 10 Apr 2024 13:36:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 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=1712756216; 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=hl2GTHN3eWa7fTBXcLa78LLcVq+wXmCFpQfBJ/GP8yKQ30qEsOMlvN7snYQ1SE61M5o3uS wJ24gn67Jfp2aEFAJsLmIi595+DoIs04bez11yFRZ4MQh2mxsz1VoSYNuypbMDEsa+C1oV 78AY1jYVjRFPtacg32OIHfgfXBENL1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756216; a=rsa-sha256; cv=none; b=yHpiQNZ5ccxsTIywP9qbbMydP73sj4UGFHhskmnSUN0UrhqVen7Qbf1m9WSmP517jaJtkJ SmHdA4WMpIxDBjfB7aVlC04VoNl92QJFFEABhhG9JIclIxmNm9F5WymYCpHnDQEh3y18N0 1CRmw/xNh3Diqish1H2kaDpvK72v4cs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF3lM6SFrz4f3jpq for ; Wed, 10 Apr 2024 21:36:47 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 4ACAE1A0568 for ; Wed, 10 Apr 2024 21:36:52 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S11; Wed, 10 Apr 2024 21:36:52 +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, 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 21:27:51 +0800 Message-Id: <20240410132818.2812377-8-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S11 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga10q3yUJrWa93W8Zr4fJFy5KF1qyF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUA rcfUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: C73F210001E X-Rspam-User: X-Stat-Signature: se6sdkpjmimkh7dmmziauqg9ta47eios X-Rspamd-Server: rspam03 X-HE-Tag: 1712756215-874771 X-HE-Meta: U2FsdGVkX18HI+fuqqw7zUcggx/jFlENXTz4gFcPMrBJRByhNzZyNmd/05xxOpD50UMy9g9mkxvXcB6iTy+m6TVkGs6cWfUBB5QzF+DdkipxFlPYe92FHSga7fZMFWpgoEZv1pzdUcByY5fGRwNv0j6SuvHB5AG1fVtqZYRZ+jUsIsnYCw4qDg6DoWxWngcCz3devRHddkEzjRoUNCig2Neej6qvd7UNrT8czfqdHyxEYFXgplOIQ1kjj0FOYtUSkgU/3T9FAgVHLGYtvj1S2J9zonOyTqjv74h05KNpivKOAV/ROZNhN91QwYTTKHTcivvDfOGyAv3VZ8ndE6jbwb4SvE7m5MIXZDVmT4QNAMfzzyI2vkM1El6tK+yBgYNKQ2cnF5/S1KySox4+7eZtlrqqlhR3EiYkhV9fPZWPgOKFCKVcjI27K1OIS5VwJpPAHtbQR7mwuj5HyzUwOfCLQjLKBItyVXUxrTp/1RX25VIvk3yH+UtmIG9BubfE3OsxAzMNx7Nr4724si2u83rOwrAiKClRZfM/xClXPmrDCqSGLba5j7IFeYCR+NyA6LD/xYBv9jNhodiMceN+7r9VPWMvMkCBj9Tlin99zefcgduwGgTC8BX9yzuRc1u8B8gnparmZ9AcgEuSz1BwDuNm3d1XXDiGKFc5aqg/qxNzXcgsoQ3MxRpnYwmCW4RZBWXgc/FliGu/rVR5cQ1Fwj33/pB/LvoMzYfSZa//7+OdrdwB0O6HUNlPPbpAeII2ZwQde0tKYsfzAwJGU4aKidQjpXV0OWKfnMugpavj2AmaY0Tw1GDeEctb5zK0LBCQ0jsCp0f9BGhkCarXovZQ0vnE6znl10NXZBGbzDuXbPHM6bRopb/ZUSU3mNFx26FCN5/BblnSrQdvXJcARAakbbyfIrzbCFsyqizwogMgAsjtQM/i87pVhiORNf6D5T46RxkpX+vSGcVMiUM2vJCTuY+ 0CF7jjT5 SmpgiMf2lZEqkbQb0QQ4IPFHdXkva89I9Qiq1R0j/UFl7iTlG++dQrzxfKFAmXiwUz2LsSBgPxQxOiwdf8pRmzbpm7XeVpr1PzPmU9Euxf4t64YV+zqPxScxhxyCjeXXoy/jbKv//qoKSfluZeTVPMDyO4PHXbaBjwJRa+dex5gFeEKnTFueXpldU9jdhDhyA26hAthfxW3MdV9zM5Y0loCl4/DNUA2yDriKGNAdwY8zp1SlR65z8UYM4SxCooGexgkLZ 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; } }