Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp477528lqz; Sat, 30 Mar 2024 05:11:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1jIr8Kjfoyd+ytTCWWLr+gqld/i/6h2nVMrpffiivIRW4QFPuMRAzTNWnx+Y/Ox/0U385TnxYYKO6HshurNQvZ8ZukZfBRiUK2j+qbg== X-Google-Smtp-Source: AGHT+IHC6l82OPlFXTKd+B5a+CP30kX70RlTSWXGAdKQKSlzEFlmEU2C6b0JvxfkMWrADrD9fQNU X-Received: by 2002:a17:90a:9913:b0:2a0:8ccf:b45a with SMTP id b19-20020a17090a991300b002a08ccfb45amr6799984pjp.4.1711800714945; Sat, 30 Mar 2024 05:11:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711800714; cv=pass; d=google.com; s=arc-20160816; b=gtKxKernkmQtFUnC4DHfIUq3lAGYS+0prsiDgHt3hALo3CJxpIGq3MRra45kZOFwm6 xcHp7bmxAJ3jUj7a7ssOjI77CvRyvCycxQ/pfBzgZMz0CD1tdJ0zmlaSMcAAZVtQRKNt zGVdOm34siKTBdYQnV4a1CYA6X+nnla4EFT+arn9JBpS3tCU+pQ8CMX0Y8C3Gg6BhPPy VpXrlwFkbitnI2LhE4bx4DzVC5Al1JT25D9SjkV7UkoMM8mkFuzvbMUvoY+LSj8fvlW3 R1JVNoz/7KxkWW5eskk2qNNoyzuCaSNyQ+/zzcP7ylY2hXa9wQby3aR4U9vJViHChhr7 90FA== 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=7ayCefXmK5iS2cW3Ga5X5ptpfVnp5TjYr6/01w0rCTc=; fh=dC1DNofMpo0fGa+HNNOiDPPA5M30OdZqJ1HdUJkde1U=; b=UC5Zx6bIOAALjTE3Ko3oej+gSr43P8sBfM+tBWNNkuPFdLxg6JpoEWppH1J0MFDXvY xhsA4LXLucrAExhLceQKPSbXQIXa6vYXRUkzAZicWLTv97gunLuHb5amZuAb+auFEaKY qOPC2khm9XS5FNkS7X/6DEz4anTI1kTrP3XapJqufe87XzY7jQGb9FzCcd7SNGehMbap qDEYpFFh4BZNAk+yGxN8DghdtwEtk3MDFXB/BRGAn7lkIeNvIDnjLs/ml/YiNhB9isEp DyXPkK80Qvj5t60UhXzGBufv2nVrGIB+6woJH6z86B8mBXWFehcBej2MGJPNl2Ed3HLy R+OQ==; 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-1800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1800-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e8-20020a17090ab38800b0029dd816e84fsi7382246pjr.180.2024.03.30.05.11.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 05:11:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1800-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1800-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 82AE2B20EEA for ; Sat, 30 Mar 2024 12:11:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C62D41C60; Sat, 30 Mar 2024 12:10:42 +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 D2291374C3; Sat, 30 Mar 2024 12:10:37 +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=1711800641; cv=none; b=TTlJ6Iw3kDh5150yDi6HRUhSlY2UHv3OY5kA5DlDrggTn4I80cd9txSVAur+zR+q+OOWHrvLpo2D4QNkGaeprGkqDFki7G8woso0aVvWE7BoqP2sVcw3LfXgwsdLGx+QhjBLr50cpxJ1yKl0+xTrUvlTjNCgPkFKpPuKjKYlLUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711800641; c=relaxed/simple; bh=lgK8qWmnAq4sbi27jsO4WAGhjwmtetHmXJmr6z6gpa0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ghMTL1dWhCZTeTGk28Hu1EVQIxeGjPvJXUdnzDi/Rc+zk3hno1uVC6+dWKe4RfZL9VSBXBO31kXPk+Qg3NmMI0y8bse786vdrd+c6XhEmM21V2yfWdq4W56+RJRScfn9MEytOEJraAOqo5k/6O1jeiXPm5yjP/SOSXUyRSWmGc0= 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4V6GLn28HCz4f3mHR; Sat, 30 Mar 2024 20:10:25 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 887891A016E; Sat, 30 Mar 2024 20:10:33 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+REsAQhmkPEjIg--.10652S9; Sat, 30 Mar 2024 20:10:33 +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, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH 5/7] ext4: factor out check for whether a cluster is allocated Date: Sat, 30 Mar 2024 20:02:34 +0800 Message-Id: <20240330120236.3789589-6-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240330120236.3789589-1-yi.zhang@huaweicloud.com> References: <20240330120236.3789589-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:cCh0CgAn+REsAQhmkPEjIg--.10652S9 X-Coremail-Antispam: 1UD129KBjvJXoW7urW7CF45JrWUJw1kAr1UWrg_yoW8trWxpr ZxGF4rJr43Wr97WF4Sqw1DXFyYgay0qrWUJrWa93W8Zr4fJFyrKFn0yF1rXFyrKrW8A3ZI qFWUAryUCF4jka7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOBTYUUUUU 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 429fb99e937a..58bd4ed23cde 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1620,6 +1620,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 @@ -1653,23 +1681,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