From patchwork Mon Feb 19 06:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Niu X-Patchwork-Id: 13562178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 61DAEC48260 for ; Mon, 19 Feb 2024 06:07:03 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rbwnt-0004Gm-7V; Mon, 19 Feb 2024 06:07:01 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rbwnr-0004GY-CJ for linux-f2fs-devel@lists.sourceforge.net; Mon, 19 Feb 2024 06:06:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=VjKnYAUrVx3Ki5CL6XKIjEzACQo+j6qELWT75/S1DDk=; b=SbXOhLT1xscsJR8fEvve1d0bH4 oN1fNtZ/9K/AsyiTqT2sjRhF9XcOSPKbslc8m2BsL8dBLisOV9T3Qdoz1lHl8UZVEIbbLHsXzzO+n XFP7lJDWvqTrZMonDXb5gP34HkZMqYKNGwXqtuXql/O6JUqg8ThHcgR+aFP37VIpQOIo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=VjKnYAUrVx3Ki5CL6XKIjEzACQo+j6qELWT75/S1DDk=; b=c cdNB5wozgbnwOAvNZlCEikUxL1uVwn6yrMSe23iQhYXCB1MztTXYZ5/dLva0Ran9ACmIPN2T9ISI2 Sk6iZ7ClnEV5kVstUZuw67XW/UjnzMgebUYFUEmhYwZV026VbnCnuYm8+5fwLGprp+AMxPDicL1y+ BPyzss4NKpiX5hMk=; Received: from mx1.unisoc.com ([222.66.158.135] helo=SHSQR01.spreadtrum.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rbwno-0004bm-FO for linux-f2fs-devel@lists.sourceforge.net; Mon, 19 Feb 2024 06:06:59 +0000 Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 41J66QAm087442; Mon, 19 Feb 2024 14:06:26 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TdX8g1Q9Gz2KG46m; Mon, 19 Feb 2024 14:05:55 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 19 Feb 2024 14:06:24 +0800 From: Zhiguo Niu To: , Date: Mon, 19 Feb 2024 14:05:41 +0800 Message-ID: <1708322741-14849-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.87] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 41J66QAm087442 X-Headers-End: 1rbwno-0004bm-FO Subject: [f2fs-dev] [PATCH v3 4/4] f2fs: stop checkpoint when get a out-of-bounds segment X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ke.wang@unisoc.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, hongyu.jin@unisoc.com, zhiguo.niu@unisoc.com, niuzhiguo84@gmail.com Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net There is low probability that an out-of-bounds segment will be got on a small-capacity device. In order to prevent subsequent write requests allocating block address from this invalid segment, which may cause unexpected issue, stop checkpoint should be performed. Also introduce a new stop cp reason: STOP_CP_REASON_OUT_OF_RANGE. Signed-off-by: Zhiguo Niu --- changes of v3: correct MACRO spelling and update based on the lastes code --- --- fs/f2fs/segment.c | 7 ++++++- include/linux/f2fs_fs.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c25aaec..8f7ac49 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2665,7 +2665,12 @@ static void get_new_segment(struct f2fs_sb_info *sbi, if (secno >= MAIN_SECS(sbi)) { secno = find_first_zero_bit(free_i->free_secmap, MAIN_SECS(sbi)); - f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi)); + if (secno >= MAIN_SECS(sbi)) { + f2fs_stop_checkpoint(sbi, false, + STOP_CP_REASON_OUT_OF_RANGE); + f2fs_bug_on(sbi, 1); + } + } segno = GET_SEG_FROM_SEC(sbi, secno); zoneno = GET_ZONE_FROM_SEC(sbi, secno); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 9b69c50..56e260c 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -75,6 +75,7 @@ enum stop_cp_reason { STOP_CP_REASON_CORRUPTED_SUMMARY, STOP_CP_REASON_UPDATE_INODE, STOP_CP_REASON_FLUSH_FAIL, + STOP_CP_REASON_OUT_OF_RANGE, STOP_CP_REASON_MAX, };