Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3291974rwb; Mon, 19 Sep 2022 19:03:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ZqV3pl3i6MXlA7xSRnXJVAarwShldg6D1pwKcsBlG7Anr6Wtluz3rO0pPv47BWZjwDbak X-Received: by 2002:a05:6402:51c7:b0:452:981:872a with SMTP id r7-20020a05640251c700b004520981872amr18368699edd.388.1663639407967; Mon, 19 Sep 2022 19:03:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663639407; cv=none; d=google.com; s=arc-20160816; b=dazwIkfen+nivcVoGlgVGuQMX1UgXDcE33DBdF3ZXp2TmblJ3O0VOetqWmDa8nNmOG EwcF85PmR1GRI37bE+eVcNmxT5Ql2mXMVr2J4fIh4rnMyrIJ1PoUhnepCmb7aawyqx+V 72AXSVuzztZTRT+t7tUlT2PhxsHab+vvnZbNPVd/f7qUE/wTHsahEN4LekYz/NzNGyWY Ch6Kc/kisjqCidVZTXGjt3c5AIfTH3n4MngeRkOWhmFNfPb1AFiyLOiX9P0DHv6Ur9+3 K9dW6YpjJcm4J6QcSwW5c4txg8VHsDx3unxE8FndpcZG8Nc20GUKRKXidaOB95y02T9G NUAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=QDFa4Gho6RZKEcxIJ/jOiwQKq/3e3Vy7e76hSWaq6DQ=; b=ugftM5Hbw11NPovbHInKa01iSho5rNZhGPX83GJ6Nn0pvZIbGpCCnQAuPTYBUwxg4s TGl4jDvq71aG2tH82ujMLvPn5SmAxb8drms0r/3ieqg0kl8bGrWNFx6C3h++bR4mGEfb LZCqrKO2CbxXHiUPBRM28MVHfPAxcPAGA98tHRXjBh5zQ8xlh0VHfWVvvm93vFLbdeP/ blEx9BHZ3WLkWIEejO2OL+si3lxnsUFi3X5tSzF/E8nCrcg7lVMOQjbsXHKbM3RTmx8C bKiPVcx4HH/MEEz1nEZXCk6XUk8PKRbMZecZZzbIkfF05eLSdFJgH2jNzwtuwr8MUybU I3Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz3-20020a1709072ce300b0077b6e408450si77330ejc.46.2022.09.19.19.03.00; Mon, 19 Sep 2022 19:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbiITB2i (ORCPT + 99 others); Mon, 19 Sep 2022 21:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiITB2f (ORCPT ); Mon, 19 Sep 2022 21:28:35 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01C634F67A for ; Mon, 19 Sep 2022 18:28:31 -0700 (PDT) Received: from SHSend.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by SHSQR01.spreadtrum.com with ESMTPS id 28K1Rjia027661 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Tue, 20 Sep 2022 09:27:45 +0800 (CST) (envelope-from Zhiguo.Niu@unisoc.com) Received: from bj08434pcu.spreadtrum.com (10.0.74.109) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 20 Sep 2022 09:27:44 +0800 From: "zhiguo.niu" To: , , , CC: , , Subject: [PATCH V3] f2fs: fix some error handling case in gc Date: Tue, 20 Sep 2022 09:27:38 +0800 Message-ID: <1663637258-21987-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.74.109] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 28K1Rjia027661 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During GC, if segment type stored in SSA and SIT is inconsistent, we set SBI_NEED_FSCK first and then stop checkpoint, this will cause the following issues: 1. SBI_NEED_FSCK can not be set to flash truly because of checkpoint has been stopped. 2. Will cause more EIO error if user use f2fs because of CP_ERROR_FLAG has been set in f2fs_stop_checkpoint, this is not reasonable. So we fix this error handling case by recording current victim segment as invalid for gc and do not stop checkpoint. 1. SBI_NEED_FSCK will still be set but not do f2fs_stop_checkpoint for f2fs.fsck to have opportunity to fix the inconsistent segment type in SSA and SIT. 2. Let user can still use fs, avoid EIO error for some operations such as read and write,etc. 3. If current segment has inconsistent segment type in SSA and SIT, we add this segment segno in SIT_I(sbi)->invalid_segmap to skip this segment to avoid deadloop in gc,similar as commit bbf9f7d90f21 ("f2fs: Fix indefinite loop in f2fs_gc()") Fixes: 793ab1c8a792 ("f2fs: fix to avoid deadloop in foreground GC") Signed-off-by: zhiguo.niu --- changes of v3: keep "set SBI_NEED_FSCK and f2fs_err()" as before and do not depend on CONFIG_F2FS_CHECK_FS as Chao's suggestion. --- --- fs/f2fs/gc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index d5fb426e0747..f354883872f6 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1703,7 +1703,10 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT", segno, type, GET_SUM_TYPE((&sum->footer))); set_sbi_flag(sbi, SBI_NEED_FSCK); - f2fs_stop_checkpoint(sbi, false); +#ifdef CONFIG_F2FS_CHECK_FS + if (!test_bit(segno, SIT_I(sbi)->invalid_segmap)) + set_bit(segno, SIT_I(sbi)->invalid_segmap); +#endif goto skip; } -- 2.17.1