UPSTREAM: f2fs: skip GC if possible when checkpoint disabling

If the number of unusable blocks is not larger than
unusable capacity, we can skip GC when checkpoint
disabling.

Bug: 298174040
Bug: 298709750
Signed-off-by: Weichao Guo <guoweichao@oppo.com>
Signed-off-by: Chao Yu <chao@kernel.org>
[Jaegeuk Kim: Fix missing gc_mode assignment]
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit a7d44c3873e942b4a5f1c8e815d92a207d0f2c36)
Change-Id: I4559ec453ef1f3370d2b053515068b96710e4229
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index c6f13e5..3470da8 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -2114,7 +2114,7 @@
 {
 	unsigned int s_flags = sbi->sb->s_flags;
 	struct cp_control cpc;
-	unsigned int gc_mode;
+	unsigned int gc_mode = sbi->gc_mode;
 	int err = 0;
 	int ret;
 	block_t unusable;
@@ -2125,9 +2125,13 @@
 	}
 	sbi->sb->s_flags |= SB_ACTIVE;
 
+	/* check if we need more GC first */
+	unusable = f2fs_get_unusable_blocks(sbi);
+	if (!f2fs_disable_cp_again(sbi, unusable))
+		goto skip_gc;
+
 	f2fs_update_time(sbi, DISABLE_TIME);
 
-	gc_mode = sbi->gc_mode;
 	sbi->gc_mode = GC_URGENT_HIGH;
 
 	while (!f2fs_time_over(sbi, DISABLE_TIME)) {
@@ -2153,6 +2157,7 @@
 		goto restore_flag;
 	}
 
+skip_gc:
 	f2fs_down_write(&sbi->gc_lock);
 	cpc.reason = CP_PAUSE;
 	set_sbi_flag(sbi, SBI_CP_DISABLED);