Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3083227rdb; Wed, 15 Nov 2023 22:26:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHA6jCWLfAgdcYVmdKUXtcnji/2OeFBRrMOLc69WgzoJjTjTjVQgAv6qKN9pGGafvXajhIM X-Received: by 2002:a05:6808:2191:b0:3ae:16b6:6338 with SMTP id be17-20020a056808219100b003ae16b66338mr21219150oib.3.1700115991503; Wed, 15 Nov 2023 22:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700115991; cv=none; d=google.com; s=arc-20160816; b=xkBEPfrYpMnQNSpa/C4ZFmu+dEzUNu3jvpBxO+t+T79nua0osuoQBMgcAGaeRpCKUL gia1G/rLwLqweOiQjKKCndMdixuMA+dhj1sQBW2Vqkup6c/qk2eXj0f/18yKykDBfHc0 y0XHBsFfm9b0cSv9fqkGBZ/GFQrkUhpjfI0N19U/R54R2bmiID3WwCwXo8WhyXJ8ouMz KtlJLgJO/JYoS6GvMHbar95XqxvGg41spjzmS2OWyw6GkqCr8NYy0v0jI+UF1ukjwexT gMqEJirPtkDjiJBz8jjVF6DJdSwMuNtGxc90HrDcvctzNNNB6691L1fv65MAoWXn+leD cFfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5iXeEcEqiRYpmeSIt8aCITFPceGAZWzrZRvTG0xcYrI=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=nnbqrJ8tmVO1goF7AwR+5/ypmV80uVZrt/9//Pln/6s+m+xnRZoxYsScOTgH8R4ROP n+HEXXX+FPbrmwb+3qad98pRkhh2VtDnGw+CUwe/V09LKCwhdHW5oW28vtrXdqMCcC/T uuxjgAN3UpiUvGEGOc+zoL7B7gQTcfLiS0R4RW5ixlNwmTGvNlj2YMuzDNV0hxrNXm5B kybeYhxMJBFBz8nasBJS1c0owkwidZnY4IhL0FgkdMD7YrVRC+EOp1AxzPXBchz7jMIj qGWqMFI/KGT0LRG4wDvobV36/5cYhvDdRyfjk/Bq8l9sVOQFUrpReEc7IioYzMg8NPY3 ZUvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHDeTQZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id s36-20020a056a0017a400b006c3535bfc77si11663326pfg.82.2023.11.15.22.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 22:26:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHDeTQZS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1641C801D828; Wed, 15 Nov 2023 22:26:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230236AbjKPG0M (ORCPT + 99 others); Thu, 16 Nov 2023 01:26:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjKPG0K (ORCPT ); Thu, 16 Nov 2023 01:26:10 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B89F2127 for ; Wed, 15 Nov 2023 22:26:06 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E298C433CA; Thu, 16 Nov 2023 06:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700115966; bh=4ui5+7aVz7Gqv0sQoth9MwnoQqqjL6flt9PtV4MBJnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHDeTQZSCIyaqUr9vYjCrR938zf9P6Ll63wLDGPERCA0VvpwEVjIIG0g0icc4cZLO TTnT/WcHrP2GHjvkhHL+gPcvgoyuuVypIAHkfs4Sj5R1afufTAaJ1rxCgIfAH9oOBq PJCzQdFVSDGtt9mHy59T4+sLSw1pa+CAqjwXze80vBsBJ1pwUjaO5BEDxp3Cje+UXk wYHj0HcvrNTY7iPM8CbPqNQTu59+WLXrvsVoyqmFMnVNVBGKdcS86byQg1img9iYd0 NZmqmjR9LhTa/lcfhJ3NbXUgZPUkuKPOsDIqhRC9Le8sCPORXc+2MGRMOlyGJOVedu Lkc9Lbou9tu7A== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 3/3] f2fs: fix to check return value of f2fs_reserve_new_block() Date: Thu, 16 Nov 2023 14:25:56 +0800 Message-Id: <20231116062556.2451839-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231116062556.2451839-1-chao@kernel.org> References: <20231116062556.2451839-1-chao@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 22:26:25 -0800 (PST) Let's check return value of f2fs_reserve_new_block() in do_recover_data() rather than letting it fails silently. Also refactoring check condition on return value of f2fs_reserve_new_block() as below: - trigger f2fs_bug_on() only for ENOSPC case; - use do-while statement to avoid redundant codes; Signed-off-by: Chao Yu --- fs/f2fs/recovery.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index b56d0f1078a7..16415c770b45 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -712,7 +712,16 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, */ if (dest == NEW_ADDR) { f2fs_truncate_data_blocks_range(&dn, 1); - f2fs_reserve_new_block(&dn); + do { + err = f2fs_reserve_new_block(&dn); + if (err == -ENOSPC) { + f2fs_bug_on(sbi, 1); + break; + } + } while (err && + IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); + if (err) + goto err; continue; } @@ -720,12 +729,14 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { if (src == NULL_ADDR) { - err = f2fs_reserve_new_block(&dn); - while (err && - IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) + do { err = f2fs_reserve_new_block(&dn); - /* We should not get -ENOSPC */ - f2fs_bug_on(sbi, err); + if (err == -ENOSPC) { + f2fs_bug_on(sbi, 1); + break; + } + } while (err && + IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)); if (err) goto err; } -- 2.40.1