* [f2fs-dev] [RFC PATCH] fsck.f2fs: trigger fix if SB_NEED_FSCK is set in auto/preen mode
@ 2022-09-13 12:12 Chao Yu
0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2022-09-13 12:12 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
SB_NEED_FSCK can be set once image may be corrupted, detect this flag
and try to check/repair the image in auto/preen mode.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fsck/fsck.c | 8 ++++++++
fsck/mount.c | 13 +++++++++++++
include/f2fs_fs.h | 5 ++++-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/fsck/fsck.c b/fsck/fsck.c
index b1b6722..70678c0 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -3344,6 +3344,8 @@ int fsck_verify(struct f2fs_sb_info *sbi)
/* fix global metadata */
if (force || (c.fix_on && f2fs_dev_is_writable())) {
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
+ struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
+ unsigned short s_flags;
if (force || c.bug_on || c.bug_nat_bits || c.quota_fixed) {
/* flush nats to write_nit_bits below */
@@ -3359,6 +3361,12 @@ int fsck_verify(struct f2fs_sb_info *sbi)
is_set_ckpt_flags(cp, CP_QUOTA_NEED_FSCK_FLAG)) {
write_checkpoints(sbi);
}
+
+ s_flags = le16_to_cpu(sb->s_flags);
+ if (s_flags & SB_NEED_FSCK) {
+ sb->s_flags = cpu_to_le16(s_flags & ~SB_NEED_FSCK);
+ update_superblock(sb, SB_MASK_ALL);
+ }
/* to return FSCK_ERROR_CORRECTED */
ret = 0;
}
diff --git a/fsck/mount.c b/fsck/mount.c
index af24484..234955a 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -424,6 +424,7 @@ printout:
DISP_u32(sb, node_ino);
DISP_u32(sb, meta_ino);
DISP_u32(sb, cp_payload);
+ DISP_u16(sb, s_flags);
DISP_u32(sb, crc);
DISP("%-.252s", sb, version);
printf("\n");
@@ -583,6 +584,16 @@ void print_sb_state(struct f2fs_super_block *sb)
MSG(0, "\n");
}
+void print_sb_flags(struct f2fs_super_block *sb)
+{
+ unsigned short f = le16_to_cpu(sb->s_flags);
+
+ MSG(0, "Info: superblock flags = %x : ", f);
+ if (f & SB_NEED_FSCK)
+ MSG(0, "%s", " need_fsck");
+ MSG(0, "\n");
+}
+
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
block_t blkaddr, int type)
{
@@ -970,6 +981,7 @@ int validate_super_block(struct f2fs_sb_info *sbi, enum SB_ADDR sb_addr)
MSG(0, "Info: FSCK version\n from \"%s\"\n to \"%s\"\n",
c.sb_version, c.version);
print_sb_state(sbi->raw_super);
+ print_sb_flags(sbi->raw_super);
return 0;
}
@@ -1210,6 +1222,7 @@ static int f2fs_should_proceed(struct f2fs_super_block *sb, u32 flag)
if (!c.fix_on && (c.auto_fix || c.preen_mode)) {
if (flag & CP_FSCK_FLAG ||
flag & CP_QUOTA_NEED_FSCK_FLAG ||
+ get_sb(s_flags) & SB_NEED_FSCK ||
(exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
c.fix_on = 1;
} else if (!c.preen_mode) {
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 509d75a..ed93f9c 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -758,6 +758,8 @@ struct f2fs_device {
static_assert(sizeof(struct f2fs_device) == 68, "");
+#define SB_NEED_FSCK 0x00000001 /* need fsck */
+
struct f2fs_super_block {
__le32 magic; /* Magic Number */
__le16 major_ver; /* Major Version */
@@ -802,7 +804,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 */
};
--
2.25.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-09-13 12:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 12:12 [f2fs-dev] [RFC PATCH] fsck.f2fs: trigger fix if SB_NEED_FSCK is set in auto/preen mode Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).