Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1027609lqo; Sat, 11 May 2024 04:39:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWidY0ioRKRMxzxnef3YA5Yub1qA56kKZp8v9GGBJ7EcalfnAkjXTAAAhr9e5TwDTNcygb9StIg9dUnMSW1q+aZnTs5kMegI2hyEowxA== X-Google-Smtp-Source: AGHT+IEVYsGXfPOMyfNacsOEpDoKSa2ul3Luz+AWwD+1WT96851mvfjsG53PKK08FC6B29LUf3dE X-Received: by 2002:a05:6358:99a0:b0:192:2e43:927d with SMTP id e5c5f4694b2df-193bb612b17mr582751655d.10.1715427565474; Sat, 11 May 2024 04:39:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715427565; cv=pass; d=google.com; s=arc-20160816; b=0Rddtwr06G5Iv2dUVpicnZyBIqYepfXHHqskfv2EYmZi6MBRw2lm7T491nCPEPyAUg KISBy8YQ5fAd/SbZXK3r82KTgsWvIDGDwlJjHZVq+A+jOc7Ar46YApiUwFzaACz6QD+V DR/nz4grCiGrDau5OB0mQ6ocscazGv7R7ghXz83/z7L+7DXaTleFoVJRzfLN/y25ZTYr fcTAvDI7yhNhoGuMzXEkXz4e7ND8L2vHzbM3DOJVI4g1SsWjd8S1XOmsBTzDvwCQaM3D EW47AOusvq/0hznnKS1+tFNN7klJQmuDnnjBI1Ucu1JhFHD7fT6/TioQkDeFIjIaZ3jk ByKQ== 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=pIBkmmYRsumPf5wYh7y1Ac8DfkorEOiituWOBAESrL0=; fh=/gW0yUFnRcFNkSCPxz8UjBHCGPgiCEguRpLIibqIEzc=; b=ZTaLqjw/u4arwDamZFJNyOllJbbNW7UmwC4E7d5ifPYSZLHOSqCHg0OvmoLwx4fUHM YPtE2m2/0Th+Puw5tlpwXN0mKLhsnn+r+THwq9M3n9Z35Zz0cPFEQPkx8QnPg5dg/RzE /tN4EoydUaZ6cNFZklRhQc7Lk+OhUPBZ3beihxYmL8nA4S233VEZPbaJxKfQMv2E0kbX hKQ0SLZYn/z6VeWKcQqHIYGLycDFLNtvVMH7WHkG2U+CbW2GuZOfClgVs1gZ9qY4B9qm 9qhVKJ8BaUsiXZyNr04DfmVNyrWKwSsO1RYXeYvgdhDB9/foHY3sWtlXRkqSUsdlNkAY 0WNA==; 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-2464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2464-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d72a20si5595145a12.817.2024.05.11.04.39.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 04:39:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2464-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2464-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BF74C282154 for ; Sat, 11 May 2024 11:39:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5E23768EC; Sat, 11 May 2024 11:37:14 +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 0A60C2F26; Sat, 11 May 2024 11:37:10 +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=1715427434; cv=none; b=XjJMKH7EmBZvRtYqdGN9eWTr63FRf6RxUaCJbAN+u3AR6ilWtsaBJy8yPcpOEGGUA/5pv+u7kihoOthXu96abWqy56dpwI0pQ0jjyjFt0zxhb+83x3AS8lj1g4aObqWhndVvlqmnMe6RITUytlmdL+fGzsAFp64Ht9kI2Dr77CQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715427434; c=relaxed/simple; bh=PmdnB6i4fEmZSr9ssaHJqvAaVMFZoMnoNNmu0bwRztI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TMkWd9acS0CHawotaPrUmXFO2hfv9/tLym3yZWJ1lONm6/loKjI2FwmNlEhcQSsVQVWz/pbNSVoR46EbJugYYR09szDmyXVGq7IPUo2I/bb+KH4cDDG/WbhPgwt+stgF9gCu6RE8rRWP6dlBgKyYlNnCMPhATjTWaKTnsrI81lg= 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 4Vc3ct3GDQz4f3jZ8; Sat, 11 May 2024 19:37:02 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id D6D391A0572; Sat, 11 May 2024 19:37:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgDHlxA+WD9mG0B4MQ--.22689S12; Sat, 11 May 2024 19:37:07 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v4 08/10] ext4: factor out check for whether a cluster is allocated Date: Sat, 11 May 2024 19:26:17 +0800 Message-Id: <20240511112619.3656450-9-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240511112619.3656450-1-yi.zhang@huaweicloud.com> References: <20240511112619.3656450-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:cCh0CgDHlxA+WD9mG0B4MQ--.22689S12 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rXr43Wr97WF4Sqw1DXF1Yga18trWUJrWa93W8Zr4fJFy5KF1qyF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUP214x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VU17G YJUUUUU== 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 0c52969654ac..6e418d3f8e87 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