Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2142822rwb; Sun, 18 Sep 2022 23:32:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4olJZiO29KM8HcU5NRDBh9r+5OSud06mf9OAvzv5rCxEMxIgnT0l4KZJaBvJPdGmwfIpEi X-Received: by 2002:a05:6402:914:b0:451:22c5:2e28 with SMTP id g20-20020a056402091400b0045122c52e28mr14161362edz.294.1663569125144; Sun, 18 Sep 2022 23:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663569125; cv=none; d=google.com; s=arc-20160816; b=k0R0SYHU0xk3WcBXE/Cojls6az5nQdk9zvBKch0h+yd4DRt/qQXXtwdmNaC9xa9BuV Mh0q+dUpHJhwZyrdHuCvR9dRl0x3D5EwLsSgToY12EDSYa/mlytSvQxGOoHUx9toP4E0 Yef5iTZ3hDFyqTZlIfMoeXk6iw/9wbhc0kg5I8DlB5hAPeZaTVC71yFmVFHhcd/AZaTY ontKEQi9vGEf0+Ew1INUQF6+TrVPh/BDypWHRRJHhLTXPdeg8rzDWqhL1uWU3uGWgmBj Khdjy4fgHp49fYN8MYA9FyqEduHKsBp5vW41gMyzOLPCm9bSuTGoY+abFoMGpwq7t0nI RIPw== 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=uUNrUwW6aGTkNv5R8wz2RoH/jwcu8ORGkBQQOXM7XrY=; b=skVqGMa1jzYEcak301GNeLjfH87tPpxbP3GuxWm8LwktcIB98Bo7GBsxcbDEOwXUun UmmjYD1dmmhnFGLGxS3TpbYhB+oHLmb2bf36AERUL3PMhWbVnrXH1nztLekNv5Gsn4aq 7FnOQrgokyKc8dKw/scBrG+QktISHbZR6xZvn9GAwT1V40ksPi8ylHKVArzkFLQKT9qQ ThdVV5NDDr7Tny+hC3IcFyYaH1Ew0QHo7DkifZP+CUnGTcXfmq+MPPT/a/TfnU3zdhOV qBQfwdJnm9WLtljzwQGLJTLVDl3SJ2DKNuDy3rF7Q4P1QojZsmtejU06iBaJKumIgmrM ZLvg== 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 qw38-20020a1709066a2600b0077b4248b138si25582330ejc.127.2022.09.18.23.31.39; Sun, 18 Sep 2022 23:32:05 -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 S229509AbiISGCK (ORCPT + 99 others); Mon, 19 Sep 2022 02:02:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiISGCG (ORCPT ); Mon, 19 Sep 2022 02:02:06 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E01714D0F for ; Sun, 18 Sep 2022 23:02:03 -0700 (PDT) Received: from SHSend.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by SHSQR01.spreadtrum.com with ESMTPS id 28J611ob064546 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Mon, 19 Sep 2022 14:01:01 +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; Mon, 19 Sep 2022 14:01:00 +0800 From: "zhiguo.niu" To: , , , CC: , , Subject: [PATCH V2] f2fs: fix some error handling case in gc Date: Mon, 19 Sep 2022 14:00:54 +0800 Message-ID: <1663567254-12338-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 28J611ob064546 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 --- fs/f2fs/gc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index d5fb426e0747..66bdf2678b5e 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1700,10 +1700,13 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, sum = page_address(sum_page); if (type != GET_SUM_TYPE((&sum->footer))) { - 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_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { + 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); + } +#endif goto skip; } -- 2.17.1