f2fs: introduce bggc_mode related api

Message ID 20230425174350.80714-1-frank.li@vivo.com
State New
Headers
Series f2fs: introduce bggc_mode related api |

Commit Message

李扬韬 April 25, 2023, 5:43 p.m. UTC
  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(-)
  

Patch

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d211ee89c158..e507033756f9 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -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 */
 
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 61c5f9d26018..7a35e188c7d4 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -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)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 9f15b03037db..9bdf4d703ad3 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -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)