f2fs: record need_fsck in super_block
Chao Yu
maintainerRFC PATCH v3 1/1 f2fs: record need_fsck in super_block
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.
---
v3:
- fix to add missing cpu_to_le16()
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(-)
fs/f2fs/checkpoint.c +5 -1
@@ -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 ); + } }/*
fs/f2fs/f2fs.h +1 -0
@@ -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);
fs/f2fs/super.c +26 -0
@@ -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 =cpu_to_le16 (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);
include/linux/f2fs_fs.h +4 -1
@@ -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;
Signature · 8 lines
2.25.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerJaegeuk,
Any thoughts about this patch?
Quoted 99 lines · Chao Yu
Once
CP_ERROR_FLAGis set, checkpoint is disallowed to be triggered to persistCP_FSCK_FLAG, fsck won't repair the image due to lack ofCP_FSCK_FLAG.This patch proposes to persist newly introduced
SB_NEED_FSCKflag into super block ifCP_ERROR_FLAGandSBI_NEED_FSCKis set, later, once fsck detect this flag, it can check and repair corrupted image in time.Signed-off-by Chao Yu <[email protected]>---
v3:
- fix to add missingcpu_to_le16()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(-)fs/f2fs/checkpoint.c +5
-1@@ -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 ); + } }/* fs/f2fs/f2fs.h +1
-0@@ -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);fs/f2fs/super.c +26
-0@@ -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 =cpu_to_le16 (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);include/linux/f2fs_fs.h +2
-0@@ -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 */
include/linux/f2fs_fs.h struct f2fs_super_block { · line 125
Quoted 9 lines
include/linux/f2fs_fs.h +2
-1@@ -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;
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel