f2fs: introduce bggc_mode related api
Commit Message
This patch introduces bggc_mode related api and uses it in code.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/f2fs/f2fs.h | 15 +++++++++++++++
fs/f2fs/gc.c | 2 +-
fs/f2fs/super.c | 13 ++++++-------
3 files changed, 22 insertions(+), 8 deletions(-)
@@ -4547,6 +4547,21 @@ static inline bool f2fs_is_readonly(struct f2fs_sb_info *sbi)
return f2fs_sb_has_readonly(sbi) || f2fs_readonly(sbi->sb);
}
+static inline bool bggc_on_mode(struct f2fs_sb_info *sbi)
+{
+ return F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON;
+}
+
+static inline bool bggc_off_mode(struct f2fs_sb_info *sbi)
+{
+ return F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF;
+}
+
+static inline bool bggc_sync_mode(struct f2fs_sb_info *sbi)
+{
+ return F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC;
+}
+
#define EFSBADCRC EBADMSG /* Bad CRC detected */
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
@@ -124,7 +124,7 @@ static int gc_thread_func(void *data)
if (!foreground)
stat_inc_bggc_count(sbi->stat_info);
- sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC;
+ sync_mode = bggc_sync_mode(sbi);
/* foreground GC was been triggered via f2fs_balance_fs() */
if (foreground)
@@ -1897,11 +1897,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
{
struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
- if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
+ if (bggc_sync_mode(sbi))
seq_printf(seq, ",background_gc=%s", "sync");
- else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
+ else if (bggc_on_mode(sbi))
seq_printf(seq, ",background_gc=%s", "on");
- else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
+ else if (bggc_off_mode(sbi))
seq_printf(seq, ",background_gc=%s", "off");
if (test_opt(sbi, GC_MERGE))
@@ -2366,8 +2366,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
* option. Also sync the filesystem.
*/
if ((*flags & SB_RDONLY) ||
- (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
- !test_opt(sbi, GC_MERGE))) {
+ (bggc_off_mode(sbi) && !test_opt(sbi, GC_MERGE))) {
if (sbi->gc_thread) {
f2fs_stop_gc_thread(sbi);
need_restart_gc = true;
@@ -4547,8 +4546,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
* If filesystem is not mounted as read-only then
* do start the gc_thread.
*/
- if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
- test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
+ if ((!bggc_off_mode(sbi) || test_opt(sbi, GC_MERGE)) &&
+ !f2fs_readonly(sb)) {
/* After POR, we can run background GC thread.*/
err = f2fs_start_gc_thread(sbi);
if (err)