Skip to content

Commit 3fd9735

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix error path of f2fs_remount()
In error path of f2fs_remount(), it missed to restart/stop kernel thread or enable/disable checkpoint, then mount option status may not be consistent with real condition of filesystem, so let's reorder remount flow a bit as below and do recovery correctly in error path: 1) handle gc thread 2) handle ckpt thread 3) handle flush thread 4) handle checkpoint disabling Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent f3e367d commit 3fd9735

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

‎fs/f2fs/super.c‎

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,8 +1927,9 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
19271927
struct f2fs_mount_info org_mount_opt;
19281928
unsigned long old_sb_flags;
19291929
int err;
1930-
bool need_restart_gc = false;
1931-
bool need_stop_gc = false;
1930+
bool need_restart_gc = false, need_stop_gc = false;
1931+
bool need_restart_ckpt = false, need_stop_ckpt = false;
1932+
bool need_restart_flush = false, need_stop_flush = false;
19321933
bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
19331934
bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT);
19341935
bool no_io_align = !F2FS_IO_ALIGNED(sbi);
@@ -2059,19 +2060,10 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
20592060
clear_sbi_flag(sbi, SBI_IS_CLOSE);
20602061
}
20612062

2062-
if (checkpoint_changed) {
2063-
if (test_opt(sbi, DISABLE_CHECKPOINT)) {
2064-
err = f2fs_disable_checkpoint(sbi);
2065-
if (err)
2066-
goto restore_gc;
2067-
} else {
2068-
f2fs_enable_checkpoint(sbi);
2069-
}
2070-
}
2071-
20722063
if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) ||
20732064
!test_opt(sbi, MERGE_CHECKPOINT)) {
20742065
f2fs_stop_ckpt_thread(sbi);
2066+
need_restart_ckpt = true;
20752067
} else {
20762068
err = f2fs_start_ckpt_thread(sbi);
20772069
if (err) {
@@ -2080,6 +2072,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
20802072
err);
20812073
goto restore_gc;
20822074
}
2075+
need_stop_ckpt = true;
20832076
}
20842077

20852078
/*
@@ -2089,11 +2082,24 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
20892082
if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
20902083
clear_opt(sbi, FLUSH_MERGE);
20912084
f2fs_destroy_flush_cmd_control(sbi, false);
2085+
need_restart_flush = true;
20922086
} else {
20932087
err = f2fs_create_flush_cmd_control(sbi);
20942088
if (err)
2095-
goto restore_gc;
2089+
goto restore_ckpt;
2090+
need_stop_flush = true;
20962091
}
2092+
2093+
if (checkpoint_changed) {
2094+
if (test_opt(sbi, DISABLE_CHECKPOINT)) {
2095+
err = f2fs_disable_checkpoint(sbi);
2096+
if (err)
2097+
goto restore_flush;
2098+
} else {
2099+
f2fs_enable_checkpoint(sbi);
2100+
}
2101+
}
2102+
20972103
skip:
20982104
#ifdef CONFIG_QUOTA
20992105
/* Release old quota file names */
@@ -2108,6 +2114,21 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
21082114
adjust_unusable_cap_perc(sbi);
21092115
*flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
21102116
return 0;
2117+
restore_flush:
2118+
if (need_restart_flush) {
2119+
if (f2fs_create_flush_cmd_control(sbi))
2120+
f2fs_warn(sbi, "background flush thread has stopped");
2121+
} else if (need_stop_flush) {
2122+
clear_opt(sbi, FLUSH_MERGE);
2123+
f2fs_destroy_flush_cmd_control(sbi, false);
2124+
}
2125+
restore_ckpt:
2126+
if (need_restart_ckpt) {
2127+
if (f2fs_start_ckpt_thread(sbi))
2128+
f2fs_warn(sbi, "background ckpt thread has stopped");
2129+
} else if (need_stop_ckpt) {
2130+
f2fs_stop_ckpt_thread(sbi);
2131+
}
21112132
restore_gc:
21122133
if (need_restart_gc) {
21132134
if (f2fs_start_gc_thread(sbi))

0 commit comments

Comments
 (0)