diff options
author | Weichao Guo <guoweichao@oppo.com> | 2022-08-31 16:38:26 +0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2022-09-07 19:07:38 -0700 |
commit | 0d6acbe2ec4ca7de7f3f9e647cbdd6ae8adc6316 (patch) | |
tree | 3fcea9f5ccb0ba9b923033790d943d6778fa753e | |
parent | 9b7a4c5d4f62407ff997a6c00d81369f9dc15c09 (diff) | |
download | f2fs-tools-0d6acbe2ec4ca7de7f3f9e647cbdd6ae8adc6316.tar.gz |
fsck.f2fs: use elapsed_time in checkpoint for period check
We now use walltime for monthly period check. However the walltime is:
* unstable(timestamp register reset) and settable(modified by user)
* unreasonable(e.g: device power-off for one month, no data changed)
When the walltime changes to the past before one month or the future
after one month, the period check in next fsck will fail to skip or
start a full scan. So, let's use the elapsed_time in checkpoint as
current time for period check.
Signed-off-by: Weichao Guo <guoweichao@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fsck/mount.c | 85 |
1 files changed, 42 insertions, 43 deletions
diff --git a/fsck/mount.c b/fsck/mount.c index e2caac0..af24484 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -969,49 +969,6 @@ int validate_super_block(struct f2fs_sb_info *sbi, enum SB_ADDR sb_addr) MSG(0, "Info: MKFS version\n \"%s\"\n", c.init_version); MSG(0, "Info: FSCK version\n from \"%s\"\n to \"%s\"\n", c.sb_version, c.version); -#if defined(__APPLE__) - if (!c.no_kernel_check && - memcmp(c.sb_version, c.version, VERSION_NAME_LEN)) { - c.auto_fix = 0; - c.fix_on = 1; - memcpy(sbi->raw_super->version, - c.version, VERSION_NAME_LEN); - update_superblock(sbi->raw_super, SB_MASK(sb_addr)); - } -#else - if (!c.no_kernel_check) { - struct timespec t; - u32 prev_time, cur_time, time_diff; - __le32 *ver_ts_ptr = (__le32 *)(sbi->raw_super->version - + VERSION_NAME_LEN); - - t.tv_sec = t.tv_nsec = 0; - clock_gettime(CLOCK_REALTIME, &t); - cur_time = (u32)t.tv_sec; - prev_time = le32_to_cpu(*ver_ts_ptr); - - MSG(0, "Info: version timestamp cur: %u, prev: %u\n", - cur_time, prev_time); - if (!memcmp(c.sb_version, c.version, - VERSION_NAME_LEN)) { - /* valid prev_time */ - if (prev_time != 0 && cur_time > prev_time) { - time_diff = cur_time - prev_time; - if (time_diff < CHECK_PERIOD) - goto out; - c.auto_fix = 0; - c.fix_on = 1; - } - } else { - memcpy(sbi->raw_super->version, - c.version, VERSION_NAME_LEN); - } - - *ver_ts_ptr = cpu_to_le32(cur_time); - update_superblock(sbi->raw_super, SB_MASK(sb_addr)); - } -out: -#endif print_sb_state(sbi->raw_super); return 0; } @@ -3582,6 +3539,48 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi) return -1; } + if (c.func == FSCK) { +#if defined(__APPLE__) + if (!c.no_kernel_check && + memcmp(c.sb_version, c.version, VERSION_NAME_LEN)) { + c.auto_fix = 0; + c.fix_on = 1; + memcpy(sbi->raw_super->version, + c.version, VERSION_NAME_LEN); + update_superblock(sbi->raw_super, SB_MASK_ALL); + } +#else + if (!c.no_kernel_check) { + u32 prev_time, cur_time, time_diff; + __le32 *ver_ts_ptr = (__le32 *)(sbi->raw_super->version + + VERSION_NAME_LEN); + + cur_time = (u32)get_cp(elapsed_time); + prev_time = le32_to_cpu(*ver_ts_ptr); + + MSG(0, "Info: version timestamp cur: %u, prev: %u\n", + cur_time, prev_time); + if (!memcmp(c.sb_version, c.version, + VERSION_NAME_LEN)) { + /* valid prev_time */ + if (prev_time != 0 && cur_time > prev_time) { + time_diff = cur_time - prev_time; + if (time_diff < CHECK_PERIOD) + goto out; + c.auto_fix = 0; + c.fix_on = 1; + } + } else { + memcpy(sbi->raw_super->version, + c.version, VERSION_NAME_LEN); + } + + *ver_ts_ptr = cpu_to_le32(cur_time); + update_superblock(sbi->raw_super, SB_MASK_ALL); + } +#endif + } +out: print_ckpt_info(sbi); if (c.quota_fix) { |