Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3268639rwb; Mon, 19 Sep 2022 18:29:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6w8PvebjvWQHIVufARil1tbIxSb2CI8T8emKxSOB5v6NtVGbiHlxgzvQjrjwGZ75bzm7f6 X-Received: by 2002:a63:e906:0:b0:41b:eba0:8b6d with SMTP id i6-20020a63e906000000b0041beba08b6dmr17539410pgh.501.1663637348657; Mon, 19 Sep 2022 18:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663637348; cv=none; d=google.com; s=arc-20160816; b=UIyQoMy4SfUwZLsIgvFkoLPgI0uk8N1pNs/W0qtIji9qXdBFYuw5wnorbU7dP2q6ut +57IwVlryDp3gDTULGuNp5NxfYOPo4I9+QtME+Ok+fFpqxjW+7Zf9d9ezQTRqKpp0DA5 lJgh8j3rv19Y9D8yaMmbwIivDJUfzCFBYQFPGzUxK+s1hHnhWOplYV998k2ab4T9aKh3 sDbsg3bR6lpRKpxf8ZkTpln5vjeroe/97yzpCVnENoGM7mItcjgTwpdNEA4ExXY6JtJ2 KOr8raVYo6YxcR5EEQCjOKBGPqUFPFIXrLUgb5wC4i/PUycDe/RWRcVzUBKtuRGovV9r TX8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fM1GkB3dQR4jBtrrBMpR94yRNW9dtZiKVO31Ty0Eums=; b=HaU1U6CNyA+ucJQAkc+yfdu36nKgGh1NmBmHHtVG1ttgCX2GerNV9LMPHgM3IGjRKD vrsFoHHseRRgucPG0JLsm1yquoN27myBF350t6zGN9MbR+m2sKBGpklP60OtAdafwf0f 3dtKdoVYi6Pn2iKlNzPEXSGRGW33fsgq+NAjmwnvdtzxgPo1u2VIV5CryYMEWtJM2Gun bjhoAWv7MCGfc3+X30fgTERWLUUBFV+NUh+bdmu0ycp6iXOLshK2yzCpSDz4ajE7kncN BbQ7+a77AivY8KHo902j1FfRAj94Mg71L2Beq6Q7iewl6w3Jer5zMUWHLgXP6gCE4Cw4 ZrTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=okg9K9OI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a17090a384900b00202c7eb5e03si302046pjf.30.2022.09.19.18.28.57; Mon, 19 Sep 2022 18:29:08 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=okg9K9OI; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbiITA4w (ORCPT + 99 others); Mon, 19 Sep 2022 20:56:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbiITA4u (ORCPT ); Mon, 19 Sep 2022 20:56:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBC891156 for ; Mon, 19 Sep 2022 17:56:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 673C2B81DF8 for ; Tue, 20 Sep 2022 00:56:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAF58C433C1; Tue, 20 Sep 2022 00:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663635407; bh=3bqIncGQwuSUvaM97RMErCT63FB5S2Jz7uQPJg5tEhc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=okg9K9OIIjb/0dAJrs8Dy+QRQl6/8RlnvFVNBg3+bXeQ/kXEhx92/MJXcfa8ipHYC KY5XPVIxd5Z4FfYpagbLHt4J+qGVxKGUKFj/nD+gp5KrdUflRb8eFhH7PxjtOpfx2t n4AnUYSFT2+9ykX7AhXI0ykmb3HG4vkScfp5wJU6CZO3k1n69U29Df9DvnMVGJHy2r sMToYHTSUQ5IyHCpjHFHV5AAatua4eapar8mSY6qMOocvLgI4KMGm93x+EQhiVT7/Y D4QsPw8QT8FD76pG2h0jOCKaV2U+VQxTrecG9/wk4Xhhz6rpZhOHFjODYsFSH78v7J lHhLuy0T9Nq9Q== Date: Mon, 19 Sep 2022 17:56:45 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2] f2fs: record need_fsck in super_block Message-ID: References: <20220913135919.2445544-1-chao@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220913135919.2445544-1-chao@kernel.org> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On 09/13, Chao Yu wrote: > Once CP_ERROR_FLAG is set, checkpoint is disallowed to be triggered to > persist CP_FSCK_FLAG, fsck won't repair the image due to lack of > CP_FSCK_FLAG. > > This patch proposes to persist newly introduced SB_NEED_FSCK flag into > super block if CP_ERROR_FLAG and SBI_NEED_FSCK is set, later, once fsck > detect this flag, it can check and repair corrupted image in time. > > Signed-off-by: Chao Yu > --- > v2: > - remove unneeded codes. > fs/f2fs/checkpoint.c | 6 +++++- > fs/f2fs/f2fs.h | 1 + > fs/f2fs/super.c | 26 ++++++++++++++++++++++++++ > include/linux/f2fs_fs.h | 5 ++++- > 4 files changed, 36 insertions(+), 2 deletions(-) > > diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c > index c3119e4c890c..0836fce40394 100644 > --- a/fs/f2fs/checkpoint.c > +++ b/fs/f2fs/checkpoint.c > @@ -30,8 +30,12 @@ void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io) > { > f2fs_build_fault_attr(sbi, 0, 0); > set_ckpt_flags(sbi, CP_ERROR_FLAG); > - if (!end_io) > + if (!end_io) { > f2fs_flush_merged_writes(sbi); > + > + if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) > + f2fs_update_sb_flags(sbi, SB_NEED_FSCK); Let's think of putting some more context in superblock, if we want to overwrite it. E.g., a reason to stop checkpoint? > + } > } > > /* > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index dee7b67a17a6..1960a98c7555 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -3556,6 +3556,7 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); > int f2fs_quota_sync(struct super_block *sb, int type); > loff_t max_file_blocks(struct inode *inode); > void f2fs_quota_off_umount(struct super_block *sb); > +void f2fs_update_sb_flags(struct f2fs_sb_info *sbi, unsigned int flag); > int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); > int f2fs_sync_fs(struct super_block *sb, int sync); > int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index b8e5fe244596..c99ba840593d 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -3846,6 +3846,32 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) > return err; > } > > +void f2fs_update_sb_flags(struct f2fs_sb_info *sbi, unsigned int flag) > +{ > + unsigned short s_flags; > + int err; > + > + if (le16_to_cpu(F2FS_RAW_SUPER(sbi)->s_flags) & SB_NEED_FSCK) > + return; > + > + f2fs_down_write(&sbi->sb_lock); > + > + s_flags = le16_to_cpu(F2FS_RAW_SUPER(sbi)->s_flags); > + > + if (s_flags & SB_NEED_FSCK) > + goto out_unlock; > + > + F2FS_RAW_SUPER(sbi)->s_flags = cpu_to_le16(s_flags | SB_NEED_FSCK); > + > + err = f2fs_commit_super(sbi, false); > + if (err) { > + f2fs_warn(sbi, "f2fs_commit_super fails to persist flag: %u, err:%d", flag, err); > + F2FS_RAW_SUPER(sbi)->s_flags = s_flags; > + } > +out_unlock: > + f2fs_up_write(&sbi->sb_lock); > +} > + > static int f2fs_scan_devices(struct f2fs_sb_info *sbi) > { > struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); > diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h > index d445150c5350..124176e2a42c 100644 > --- a/include/linux/f2fs_fs.h > +++ b/include/linux/f2fs_fs.h > @@ -73,6 +73,8 @@ struct f2fs_device { > __le32 total_segments; > } __packed; > > +#define SB_NEED_FSCK 0x00000001 /* need fsck */ > + > struct f2fs_super_block { > __le32 magic; /* Magic Number */ > __le16 major_ver; /* Major Version */ > @@ -116,7 +118,8 @@ struct f2fs_super_block { > __u8 hot_ext_count; /* # of hot file extension */ > __le16 s_encoding; /* Filename charset encoding */ > __le16 s_encoding_flags; /* Filename charset encoding flags */ > - __u8 reserved[306]; /* valid reserved region */ > + __le16 s_flags; /* super block flags */ > + __u8 reserved[304]; /* valid reserved region */ > __le32 crc; /* checksum of superblock */ > } __packed; > > -- > 2.25.1