Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp185344lqj; Wed, 10 Apr 2024 07:42:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmtJMXWgCz3fWlaLVdSwV+1pqM+H9ys6ptIMyJmjVClMRtCHbBEbDFQHpVqNmixC4qUOyDIVxdk3qTGMR5CLQ5yg9ZTncAdZSjZXciiA== X-Google-Smtp-Source: AGHT+IH6hRrYCy2fbRRFe/Ffj9hyMCL4wfmYw8eW2kBEXPlb8xx7gtE4HU9FNY5LbVXrVTRwo6Qo X-Received: by 2002:ac2:47ed:0:b0:515:bfaa:fa12 with SMTP id b13-20020ac247ed000000b00515bfaafa12mr2341547lfp.22.1712760162625; Wed, 10 Apr 2024 07:42:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760162; cv=pass; d=google.com; s=arc-20160816; b=ZvI92RMgtiJ3UNbZUKLf6xqAoadIs9rG97Dx/++HzJugvYSoXpauJwicPGGCaHNR7j 9eJjOz8sj9c+LXUVPr0Ip2pSoaHkj4salnXSCRMtIfZT/qBbaLa52oMne6HfBzjGbNhh t4pWyyCWWHaQrVs1lPnvHbLexRwgG9LJNruWEt9BehnmVY3IxptOZSBYumVucKn6nBKt zTMvRbNsDI8B9QT4f7eFv3Epcw4TdcyHfLapNGCKFrsG60JLh1bNEiUaYaoyfe67HO2P mWwwpipa/Gvv4wDcxnJ+snqG+/SG1G9d2VkkDucWrDDLfesMdOUBHpvjSU1PZHjby/pN pT/Q== 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=1B4ngafH1j/H0v6adJNVq5qXwTB2PXDJPpcTLBN4hv4=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=zs4QR/HJ9fD1nFw7HBgg5TwdoRRJX6/xIg7NCFc3mNWOYL4Jr1VsBcf22j9xIuOGUz FYaKEYqRxcciwhSiJSIVhe1ud7hBW0WL8dYTOdfmhRTXuBKJJjxpm0oreUMMvm28qruN VWayGJC8jUu8mM10TZPiApAgrSa7NDASidyuqWn8Dl4pwuyYct7GasPUkAXVNC119vAb IJxUJMNRhsSaf4OgQIRKeIM4n3X/L5+j15tdXA46Whj8A5Vi/5Ic8F8e1yqiyZtW1mYF PREQ60S+wQyHKvXc5Og2+s9JnfqzxJL3Ph9/2uC1awpWGBbBySgGtmdh4HY24L2bYmIv DOCQ==; 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-1979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1979-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e6-20020a17090681c600b00a51d83c1af7si2967571ejx.633.2024.04.10.07.42.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:42:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1979-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4C0221F21789 for ; Wed, 10 Apr 2024 14:42:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9EF0178CF0; Wed, 10 Apr 2024 14:38:36 +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 2E0AE17277C; Wed, 10 Apr 2024 14:38:33 +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=1712759916; cv=none; b=DDcyOZ9TWdH+8DSQclu6Vr6UaEK7Oy3g57TqQ7kL38S2Pa4AVdH524LSp1SSdqKc2LSX5neWslxhiPq7tbQ1RptcX8Go/OAWXOmljGLEkXQyLPwZ5Kmrvl2DJw0EHBYYV65wAWCSgujwLGAqSff9Xoj/hfKj1TKhIfZB5ak7WNg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759916; c=relaxed/simple; bh=zp8Y8W3yQMUZGx/zUI8wawzP1c/idPCnssYAOGv/w4c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dxjT33mlTKI4DOSQzADFf3YVP52pbm/BPDpWcn4wIzLBIWpEgU5HAtAdrasAnyxzGTU/YF4tyb5sqwhZTVenQClGeDuzDhi7TxFFZaT15JOn4Mzcaaz/4UmRu2P13JD+HibuZPt/D3Jj+32O4jcdDaCZHzUow7b4azOPMJ6rwO4= 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.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56P4qpWz4f3m7R; Wed, 10 Apr 2024 22:38:21 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 525141A0568; 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> 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:cCh0CgAX6RFSpBZmcwR8Jg--.63000S11 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga10q3yUJrWa93W8Zr4fJFy5KF1qyF1rXFyrK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U== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ 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; } } -- 2.39.2