Merge tag 'xfs-5.13-merge-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-2.6-microblaze.git] / fs / f2fs / super.c
index 82592b1..7d325bf 100644 (file)
@@ -151,6 +151,8 @@ enum {
        Opt_compress_chksum,
        Opt_compress_mode,
        Opt_atgc,
+       Opt_gc_merge,
+       Opt_nogc_merge,
        Opt_err,
 };
 
@@ -223,6 +225,8 @@ static match_table_t f2fs_tokens = {
        {Opt_compress_chksum, "compress_chksum"},
        {Opt_compress_mode, "compress_mode=%s"},
        {Opt_atgc, "atgc"},
+       {Opt_gc_merge, "gc_merge"},
+       {Opt_nogc_merge, "nogc_merge"},
        {Opt_err, NULL},
 };
 
@@ -555,6 +559,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 
        while ((p = strsep(&options, ",")) != NULL) {
                int token;
+
                if (!*p)
                        continue;
                /*
@@ -1073,6 +1078,12 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
                case Opt_atgc:
                        set_opt(sbi, ATGC);
                        break;
+               case Opt_gc_merge:
+                       set_opt(sbi, GC_MERGE);
+                       break;
+               case Opt_nogc_merge:
+                       clear_opt(sbi, GC_MERGE);
+                       break;
                default:
                        f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
                                 p);
@@ -1616,6 +1627,7 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
 #endif
 }
 
+#ifdef CONFIG_F2FS_FS_COMPRESSION
 static inline void f2fs_show_compress_options(struct seq_file *seq,
                                                        struct super_block *sb)
 {
@@ -1661,6 +1673,7 @@ static inline void f2fs_show_compress_options(struct seq_file *seq,
        else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER)
                seq_printf(seq, ",compress_mode=%s", "user");
 }
+#endif
 
 static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 {
@@ -1673,6 +1686,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
        else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
                seq_printf(seq, ",background_gc=%s", "off");
 
+       if (test_opt(sbi, GC_MERGE))
+               seq_puts(seq, ",gc_merge");
+
        if (test_opt(sbi, DISABLE_ROLL_FORWARD))
                seq_puts(seq, ",disable_roll_forward");
        if (test_opt(sbi, NORECOVERY))
@@ -1824,6 +1840,7 @@ static void default_options(struct f2fs_sb_info *sbi)
        set_opt(sbi, EXTENT_CACHE);
        set_opt(sbi, NOHEAP);
        clear_opt(sbi, DISABLE_CHECKPOINT);
+       set_opt(sbi, MERGE_CHECKPOINT);
        F2FS_OPTION(sbi).unusable_cap = 0;
        sbi->sb->s_flags |= SB_LAZYTIME;
        set_opt(sbi, FLUSH_MERGE);
@@ -1865,7 +1882,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
 
        while (!f2fs_time_over(sbi, DISABLE_TIME)) {
                down_write(&sbi->gc_lock);
-               err = f2fs_gc(sbi, true, false, NULL_SEGNO);
+               err = f2fs_gc(sbi, true, false, false, NULL_SEGNO);
                if (err == -ENODATA) {
                        err = 0;
                        break;
@@ -1876,7 +1893,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
 
        ret = sync_filesystem(sbi->sb);
        if (ret || err) {
-               err = ret ? ret: err;
+               err = ret ? ret : err;
                goto restore_flag;
        }
 
@@ -1925,8 +1942,9 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        struct f2fs_mount_info org_mount_opt;
        unsigned long old_sb_flags;
        int err;
-       bool need_restart_gc = false;
-       bool need_stop_gc = false;
+       bool need_restart_gc = false, need_stop_gc = false;
+       bool need_restart_ckpt = false, need_stop_ckpt = false;
+       bool need_restart_flush = false, need_stop_flush = false;
        bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
        bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT);
        bool no_io_align = !F2FS_IO_ALIGNED(sbi);
@@ -2035,7 +2053,8 @@ 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) {
+                       (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
+                       !test_opt(sbi, GC_MERGE))) {
                if (sbi->gc_thread) {
                        f2fs_stop_gc_thread(sbi);
                        need_restart_gc = true;
@@ -2057,18 +2076,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
                clear_sbi_flag(sbi, SBI_IS_CLOSE);
        }
 
-       if (checkpoint_changed) {
-               if (test_opt(sbi, DISABLE_CHECKPOINT)) {
-                       err = f2fs_disable_checkpoint(sbi);
-                       if (err)
-                               goto restore_gc;
-               } else {
-                       f2fs_enable_checkpoint(sbi);
-               }
-       }
-
-       if (!test_opt(sbi, DISABLE_CHECKPOINT) &&
-                       test_opt(sbi, MERGE_CHECKPOINT)) {
+       if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) ||
+                       !test_opt(sbi, MERGE_CHECKPOINT)) {
+               f2fs_stop_ckpt_thread(sbi);
+               need_restart_ckpt = true;
+       } else {
                err = f2fs_start_ckpt_thread(sbi);
                if (err) {
                        f2fs_err(sbi,
@@ -2076,8 +2088,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
                            err);
                        goto restore_gc;
                }
-       } else {
-               f2fs_stop_ckpt_thread(sbi);
+               need_stop_ckpt = true;
        }
 
        /*
@@ -2087,11 +2098,24 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
                clear_opt(sbi, FLUSH_MERGE);
                f2fs_destroy_flush_cmd_control(sbi, false);
+               need_restart_flush = true;
        } else {
                err = f2fs_create_flush_cmd_control(sbi);
                if (err)
-                       goto restore_gc;
+                       goto restore_ckpt;
+               need_stop_flush = true;
        }
+
+       if (checkpoint_changed) {
+               if (test_opt(sbi, DISABLE_CHECKPOINT)) {
+                       err = f2fs_disable_checkpoint(sbi);
+                       if (err)
+                               goto restore_flush;
+               } else {
+                       f2fs_enable_checkpoint(sbi);
+               }
+       }
+
 skip:
 #ifdef CONFIG_QUOTA
        /* Release old quota file names */
@@ -2106,6 +2130,21 @@ skip:
        adjust_unusable_cap_perc(sbi);
        *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
        return 0;
+restore_flush:
+       if (need_restart_flush) {
+               if (f2fs_create_flush_cmd_control(sbi))
+                       f2fs_warn(sbi, "background flush thread has stopped");
+       } else if (need_stop_flush) {
+               clear_opt(sbi, FLUSH_MERGE);
+               f2fs_destroy_flush_cmd_control(sbi, false);
+       }
+restore_ckpt:
+       if (need_restart_ckpt) {
+               if (f2fs_start_ckpt_thread(sbi))
+                       f2fs_warn(sbi, "background ckpt thread has stopped");
+       } else if (need_stop_ckpt) {
+               f2fs_stop_ckpt_thread(sbi);
+       }
 restore_gc:
        if (need_restart_gc) {
                if (f2fs_start_gc_thread(sbi))
@@ -3719,7 +3758,7 @@ try_onemore:
        sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS;
 
        for (i = 0; i < NR_PAGE_TYPE; i++) {
-               int n = (i == META) ? 1: NR_TEMP_TYPE;
+               int n = (i == META) ? 1 : NR_TEMP_TYPE;
                int j;
 
                sbi->write_io[i] =
@@ -3833,7 +3872,7 @@ try_onemore:
 
        /* setup checkpoint request control and start checkpoint issue thread */
        f2fs_init_ckpt_req_control(sbi);
-       if (!test_opt(sbi, DISABLE_CHECKPOINT) &&
+       if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) &&
                        test_opt(sbi, MERGE_CHECKPOINT)) {
                err = f2fs_start_ckpt_thread(sbi);
                if (err) {
@@ -3929,10 +3968,18 @@ try_onemore:
                 * previous checkpoint was not done by clean system shutdown.
                 */
                if (f2fs_hw_is_readonly(sbi)) {
-                       if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))
-                               f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");
-                       else
-                               f2fs_info(sbi, "write access unavailable, skipping recovery");
+                       if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
+                               err = f2fs_recover_fsync_data(sbi, true);
+                               if (err > 0) {
+                                       err = -EROFS;
+                                       f2fs_err(sbi, "Need to recover fsync data, but "
+                                               "write access unavailable, please try "
+                                               "mount w/ disable_roll_forward or norecovery");
+                               }
+                               if (err < 0)
+                                       goto free_meta;
+                       }
+                       f2fs_info(sbi, "write access unavailable, skipping recovery");
                        goto reset_checkpoint;
                }
 
@@ -3989,7 +4036,8 @@ reset_checkpoint:
         * If filesystem is not mounted as read-only then
         * do start the gc_thread.
         */
-       if (F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF && !f2fs_readonly(sb)) {
+       if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
+               test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
                /* After POR, we can run background GC thread.*/
                err = f2fs_start_gc_thread(sbi);
                if (err)