Merge tag 'for-linus-20190715' of git://git.kernel.dk/linux-block
[sfrench/cifs-2.6.git] / fs / f2fs / super.c
index 4e91ba6c8a2e7b11760cb6a6fbbbacf3f9d426f2..6de6cda440315d68b4055f0c428a6ed302624b30 100644 (file)
@@ -136,7 +136,10 @@ enum {
        Opt_alloc,
        Opt_fsync,
        Opt_test_dummy_encryption,
-       Opt_checkpoint,
+       Opt_checkpoint_disable,
+       Opt_checkpoint_disable_cap,
+       Opt_checkpoint_disable_cap_perc,
+       Opt_checkpoint_enable,
        Opt_err,
 };
 
@@ -195,45 +198,52 @@ static match_table_t f2fs_tokens = {
        {Opt_alloc, "alloc_mode=%s"},
        {Opt_fsync, "fsync_mode=%s"},
        {Opt_test_dummy_encryption, "test_dummy_encryption"},
-       {Opt_checkpoint, "checkpoint=%s"},
+       {Opt_checkpoint_disable, "checkpoint=disable"},
+       {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"},
+       {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
+       {Opt_checkpoint_enable, "checkpoint=enable"},
        {Opt_err, NULL},
 };
 
-void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
+void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
 {
        struct va_format vaf;
        va_list args;
+       int level;
 
        va_start(args, fmt);
-       vaf.fmt = fmt;
+
+       level = printk_get_level(fmt);
+       vaf.fmt = printk_skip_level(fmt);
        vaf.va = &args;
-       printk("%sF2FS-fs (%s): %pV\n", level, sb->s_id, &vaf);
+       printk("%c%cF2FS-fs (%s): %pV\n",
+              KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
+
        va_end(args);
 }
 
 static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
 {
-       block_t limit = (sbi->user_block_count << 1) / 1000;
+       block_t limit = min((sbi->user_block_count << 1) / 1000,
+                       sbi->user_block_count - sbi->reserved_blocks);
 
        /* limit is 0.2% */
        if (test_opt(sbi, RESERVE_ROOT) &&
                        F2FS_OPTION(sbi).root_reserved_blocks > limit) {
                F2FS_OPTION(sbi).root_reserved_blocks = limit;
-               f2fs_msg(sbi->sb, KERN_INFO,
-                       "Reduce reserved blocks for root = %u",
-                       F2FS_OPTION(sbi).root_reserved_blocks);
+               f2fs_info(sbi, "Reduce reserved blocks for root = %u",
+                         F2FS_OPTION(sbi).root_reserved_blocks);
        }
        if (!test_opt(sbi, RESERVE_ROOT) &&
                (!uid_eq(F2FS_OPTION(sbi).s_resuid,
                                make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
                !gid_eq(F2FS_OPTION(sbi).s_resgid,
                                make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
-               f2fs_msg(sbi->sb, KERN_INFO,
-                       "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
-                               from_kuid_munged(&init_user_ns,
-                                       F2FS_OPTION(sbi).s_resuid),
-                               from_kgid_munged(&init_user_ns,
-                                       F2FS_OPTION(sbi).s_resgid));
+               f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
+                         from_kuid_munged(&init_user_ns,
+                                          F2FS_OPTION(sbi).s_resuid),
+                         from_kgid_munged(&init_user_ns,
+                                          F2FS_OPTION(sbi).s_resgid));
 }
 
 static void init_once(void *foo)
@@ -254,35 +264,29 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
        int ret = -EINVAL;
 
        if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Cannot change journaled "
-                       "quota options when quota turned on");
+               f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
                return -EINVAL;
        }
        if (f2fs_sb_has_quota_ino(sbi)) {
-               f2fs_msg(sb, KERN_INFO,
-                       "QUOTA feature is enabled, so ignore qf_name");
+               f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
                return 0;
        }
 
        qname = match_strdup(args);
        if (!qname) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Not enough memory for storing quotafile name");
+               f2fs_err(sbi, "Not enough memory for storing quotafile name");
                return -ENOMEM;
        }
        if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
                if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
                        ret = 0;
                else
-                       f2fs_msg(sb, KERN_ERR,
-                                "%s quota file already specified",
+                       f2fs_err(sbi, "%s quota file already specified",
                                 QTYPE2NAME(qtype));
                goto errout;
        }
        if (strchr(qname, '/')) {
-               f2fs_msg(sb, KERN_ERR,
-                       "quotafile must be on filesystem root");
+               f2fs_err(sbi, "quotafile must be on filesystem root");
                goto errout;
        }
        F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
@@ -298,8 +302,7 @@ static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
        struct f2fs_sb_info *sbi = F2FS_SB(sb);
 
        if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
-               f2fs_msg(sb, KERN_ERR, "Cannot change journaled quota options"
-                       " when quota turned on");
+               f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
                return -EINVAL;
        }
        kvfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
@@ -315,8 +318,7 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
         * to support legacy quotas in quota files.
         */
        if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
-               f2fs_msg(sbi->sb, KERN_ERR, "Project quota feature not enabled. "
-                        "Cannot enable project quota enforcement.");
+               f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
                return -1;
        }
        if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
@@ -336,21 +338,18 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
 
                if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
                                test_opt(sbi, PRJQUOTA)) {
-                       f2fs_msg(sbi->sb, KERN_ERR, "old and new quota "
-                                       "format mixing");
+                       f2fs_err(sbi, "old and new quota format mixing");
                        return -1;
                }
 
                if (!F2FS_OPTION(sbi).s_jquota_fmt) {
-                       f2fs_msg(sbi->sb, KERN_ERR, "journaled quota format "
-                                       "not specified");
+                       f2fs_err(sbi, "journaled quota format not specified");
                        return -1;
                }
        }
 
        if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
-               f2fs_msg(sbi->sb, KERN_INFO,
-                       "QUOTA feature is enabled, so ignore jquota_fmt");
+               f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
                F2FS_OPTION(sbi).s_jquota_fmt = 0;
        }
        return 0;
@@ -418,8 +417,7 @@ static int parse_options(struct super_block *sb, char *options)
                        break;
                case Opt_nodiscard:
                        if (f2fs_sb_has_blkzoned(sbi)) {
-                               f2fs_msg(sb, KERN_WARNING,
-                                       "discard is required for zoned block devices");
+                               f2fs_warn(sbi, "discard is required for zoned block devices");
                                return -EINVAL;
                        }
                        clear_opt(sbi, DISCARD);
@@ -451,20 +449,16 @@ static int parse_options(struct super_block *sb, char *options)
                        break;
 #else
                case Opt_user_xattr:
-                       f2fs_msg(sb, KERN_INFO,
-                               "user_xattr options not supported");
+                       f2fs_info(sbi, "user_xattr options not supported");
                        break;
                case Opt_nouser_xattr:
-                       f2fs_msg(sb, KERN_INFO,
-                               "nouser_xattr options not supported");
+                       f2fs_info(sbi, "nouser_xattr options not supported");
                        break;
                case Opt_inline_xattr:
-                       f2fs_msg(sb, KERN_INFO,
-                               "inline_xattr options not supported");
+                       f2fs_info(sbi, "inline_xattr options not supported");
                        break;
                case Opt_noinline_xattr:
-                       f2fs_msg(sb, KERN_INFO,
-                               "noinline_xattr options not supported");
+                       f2fs_info(sbi, "noinline_xattr options not supported");
                        break;
 #endif
 #ifdef CONFIG_F2FS_FS_POSIX_ACL
@@ -476,10 +470,10 @@ static int parse_options(struct super_block *sb, char *options)
                        break;
 #else
                case Opt_acl:
-                       f2fs_msg(sb, KERN_INFO, "acl options not supported");
+                       f2fs_info(sbi, "acl options not supported");
                        break;
                case Opt_noacl:
-                       f2fs_msg(sb, KERN_INFO, "noacl options not supported");
+                       f2fs_info(sbi, "noacl options not supported");
                        break;
 #endif
                case Opt_active_logs:
@@ -529,9 +523,8 @@ static int parse_options(struct super_block *sb, char *options)
                        if (args->from && match_int(args, &arg))
                                return -EINVAL;
                        if (test_opt(sbi, RESERVE_ROOT)) {
-                               f2fs_msg(sb, KERN_INFO,
-                                       "Preserve previous reserve_root=%u",
-                                       F2FS_OPTION(sbi).root_reserved_blocks);
+                               f2fs_info(sbi, "Preserve previous reserve_root=%u",
+                                         F2FS_OPTION(sbi).root_reserved_blocks);
                        } else {
                                F2FS_OPTION(sbi).root_reserved_blocks = arg;
                                set_opt(sbi, RESERVE_ROOT);
@@ -542,8 +535,7 @@ static int parse_options(struct super_block *sb, char *options)
                                return -EINVAL;
                        uid = make_kuid(current_user_ns(), arg);
                        if (!uid_valid(uid)) {
-                               f2fs_msg(sb, KERN_ERR,
-                                       "Invalid uid value %d", arg);
+                               f2fs_err(sbi, "Invalid uid value %d", arg);
                                return -EINVAL;
                        }
                        F2FS_OPTION(sbi).s_resuid = uid;
@@ -553,8 +545,7 @@ static int parse_options(struct super_block *sb, char *options)
                                return -EINVAL;
                        gid = make_kgid(current_user_ns(), arg);
                        if (!gid_valid(gid)) {
-                               f2fs_msg(sb, KERN_ERR,
-                                       "Invalid gid value %d", arg);
+                               f2fs_err(sbi, "Invalid gid value %d", arg);
                                return -EINVAL;
                        }
                        F2FS_OPTION(sbi).s_resgid = gid;
@@ -567,9 +558,7 @@ static int parse_options(struct super_block *sb, char *options)
                        if (strlen(name) == 8 &&
                                        !strncmp(name, "adaptive", 8)) {
                                if (f2fs_sb_has_blkzoned(sbi)) {
-                                       f2fs_msg(sb, KERN_WARNING,
-                                                "adaptive mode is not allowed with "
-                                                "zoned block device feature");
+                                       f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
                                        kvfree(name);
                                        return -EINVAL;
                                }
@@ -587,9 +576,8 @@ static int parse_options(struct super_block *sb, char *options)
                        if (args->from && match_int(args, &arg))
                                return -EINVAL;
                        if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_PAGES)) {
-                               f2fs_msg(sb, KERN_WARNING,
-                                       "Not support %d, larger than %d",
-                                       1 << arg, BIO_MAX_PAGES);
+                               f2fs_warn(sbi, "Not support %d, larger than %d",
+                                         1 << arg, BIO_MAX_PAGES);
                                return -EINVAL;
                        }
                        F2FS_OPTION(sbi).write_io_size_bits = arg;
@@ -610,13 +598,11 @@ static int parse_options(struct super_block *sb, char *options)
                        break;
 #else
                case Opt_fault_injection:
-                       f2fs_msg(sb, KERN_INFO,
-                               "fault_injection options not supported");
+                       f2fs_info(sbi, "fault_injection options not supported");
                        break;
 
                case Opt_fault_type:
-                       f2fs_msg(sb, KERN_INFO,
-                               "fault_type options not supported");
+                       f2fs_info(sbi, "fault_type options not supported");
                        break;
 #endif
                case Opt_lazytime:
@@ -696,8 +682,7 @@ static int parse_options(struct super_block *sb, char *options)
                case Opt_jqfmt_vfsv0:
                case Opt_jqfmt_vfsv1:
                case Opt_noquota:
-                       f2fs_msg(sb, KERN_INFO,
-                                       "quota operations not supported");
+                       f2fs_info(sbi, "quota operations not supported");
                        break;
 #endif
                case Opt_whint:
@@ -759,39 +744,44 @@ static int parse_options(struct super_block *sb, char *options)
                case Opt_test_dummy_encryption:
 #ifdef CONFIG_FS_ENCRYPTION
                        if (!f2fs_sb_has_encrypt(sbi)) {
-                               f2fs_msg(sb, KERN_ERR, "Encrypt feature is off");
+                               f2fs_err(sbi, "Encrypt feature is off");
                                return -EINVAL;
                        }
 
                        F2FS_OPTION(sbi).test_dummy_encryption = true;
-                       f2fs_msg(sb, KERN_INFO,
-                                       "Test dummy encryption mode enabled");
+                       f2fs_info(sbi, "Test dummy encryption mode enabled");
 #else
-                       f2fs_msg(sb, KERN_INFO,
-                                       "Test dummy encryption mount option ignored");
+                       f2fs_info(sbi, "Test dummy encryption mount option ignored");
 #endif
                        break;
-               case Opt_checkpoint:
-                       name = match_strdup(&args[0]);
-                       if (!name)
-                               return -ENOMEM;
-
-                       if (strlen(name) == 6 &&
-                                       !strncmp(name, "enable", 6)) {
-                               clear_opt(sbi, DISABLE_CHECKPOINT);
-                       } else if (strlen(name) == 7 &&
-                                       !strncmp(name, "disable", 7)) {
-                               set_opt(sbi, DISABLE_CHECKPOINT);
-                       } else {
-                               kvfree(name);
+               case Opt_checkpoint_disable_cap_perc:
+                       if (args->from && match_int(args, &arg))
                                return -EINVAL;
-                       }
-                       kvfree(name);
+                       if (arg < 0 || arg > 100)
+                               return -EINVAL;
+                       if (arg == 100)
+                               F2FS_OPTION(sbi).unusable_cap =
+                                       sbi->user_block_count;
+                       else
+                               F2FS_OPTION(sbi).unusable_cap =
+                                       (sbi->user_block_count / 100) * arg;
+                       set_opt(sbi, DISABLE_CHECKPOINT);
+                       break;
+               case Opt_checkpoint_disable_cap:
+                       if (args->from && match_int(args, &arg))
+                               return -EINVAL;
+                       F2FS_OPTION(sbi).unusable_cap = arg;
+                       set_opt(sbi, DISABLE_CHECKPOINT);
+                       break;
+               case Opt_checkpoint_disable:
+                       set_opt(sbi, DISABLE_CHECKPOINT);
+                       break;
+               case Opt_checkpoint_enable:
+                       clear_opt(sbi, DISABLE_CHECKPOINT);
                        break;
                default:
-                       f2fs_msg(sb, KERN_ERR,
-                               "Unrecognized mount option \"%s\" or missing value",
-                               p);
+                       f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
+                                p);
                        return -EINVAL;
                }
        }
@@ -800,23 +790,18 @@ static int parse_options(struct super_block *sb, char *options)
                return -EINVAL;
 #else
        if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
-               f2fs_msg(sbi->sb, KERN_INFO,
-                        "Filesystem with quota feature cannot be mounted RDWR "
-                        "without CONFIG_QUOTA");
+               f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
                return -EINVAL;
        }
        if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Filesystem with project quota feature cannot be "
-                       "mounted RDWR without CONFIG_QUOTA");
+               f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
                return -EINVAL;
        }
 #endif
 
        if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) {
-               f2fs_msg(sb, KERN_ERR,
-                               "Should set mode=lfs with %uKB-sized IO",
-                               F2FS_IO_SIZE_KB(sbi));
+               f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
+                        F2FS_IO_SIZE_KB(sbi));
                return -EINVAL;
        }
 
@@ -825,15 +810,11 @@ static int parse_options(struct super_block *sb, char *options)
 
                if (!f2fs_sb_has_extra_attr(sbi) ||
                        !f2fs_sb_has_flexible_inline_xattr(sbi)) {
-                       f2fs_msg(sb, KERN_ERR,
-                                       "extra_attr or flexible_inline_xattr "
-                                       "feature is off");
+                       f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
                        return -EINVAL;
                }
                if (!test_opt(sbi, INLINE_XATTR)) {
-                       f2fs_msg(sb, KERN_ERR,
-                                       "inline_xattr_size option should be "
-                                       "set with inline_xattr option");
+                       f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
                        return -EINVAL;
                }
 
@@ -842,16 +823,14 @@ static int parse_options(struct super_block *sb, char *options)
 
                if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
                                F2FS_OPTION(sbi).inline_xattr_size > max_size) {
-                       f2fs_msg(sb, KERN_ERR,
-                               "inline xattr size is out of range: %d ~ %d",
-                               min_size, max_size);
+                       f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
+                                min_size, max_size);
                        return -EINVAL;
                }
        }
 
        if (test_opt(sbi, DISABLE_CHECKPOINT) && test_opt(sbi, LFS)) {
-               f2fs_msg(sb, KERN_ERR,
-                               "LFS not compatible with checkpoint=disable\n");
+               f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
                return -EINVAL;
        }
 
@@ -1313,6 +1292,8 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
                seq_puts(seq, ",disable_roll_forward");
        if (test_opt(sbi, DISCARD))
                seq_puts(seq, ",discard");
+       else
+               seq_puts(seq, ",nodiscard");
        if (test_opt(sbi, NOHEAP))
                seq_puts(seq, ",no_heap");
        else
@@ -1409,8 +1390,8 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
                seq_printf(seq, ",alloc_mode=%s", "reuse");
 
        if (test_opt(sbi, DISABLE_CHECKPOINT))
-               seq_puts(seq, ",checkpoint=disable");
-
+               seq_printf(seq, ",checkpoint=disable:%u",
+                               F2FS_OPTION(sbi).unusable_cap);
        if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
                seq_printf(seq, ",fsync_mode=%s", "posix");
        else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
@@ -1439,6 +1420,7 @@ static void default_options(struct f2fs_sb_info *sbi)
        set_opt(sbi, EXTENT_CACHE);
        set_opt(sbi, NOHEAP);
        clear_opt(sbi, DISABLE_CHECKPOINT);
+       F2FS_OPTION(sbi).unusable_cap = 0;
        sbi->sb->s_flags |= SB_LAZYTIME;
        set_opt(sbi, FLUSH_MERGE);
        set_opt(sbi, DISCARD);
@@ -1467,10 +1449,10 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
        struct cp_control cpc;
        int err = 0;
        int ret;
+       block_t unusable;
 
        if (s_flags & SB_RDONLY) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                               "checkpoint=disable on readonly fs");
+               f2fs_err(sbi, "checkpoint=disable on readonly fs");
                return -EINVAL;
        }
        sbi->sb->s_flags |= SB_ACTIVE;
@@ -1494,7 +1476,8 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
                goto restore_flag;
        }
 
-       if (f2fs_disable_cp_again(sbi)) {
+       unusable = f2fs_get_unusable_blocks(sbi);
+       if (f2fs_disable_cp_again(sbi, unusable)) {
                err = -EAGAIN;
                goto restore_flag;
        }
@@ -1507,7 +1490,7 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
                goto out_unlock;
 
        spin_lock(&sbi->stat_lock);
-       sbi->unusable_block_count = 0;
+       sbi->unusable_block_count = unusable;
        spin_unlock(&sbi->stat_lock);
 
 out_unlock:
@@ -1572,8 +1555,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        /* recover superblocks we couldn't write due to previous RO mount */
        if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
                err = f2fs_commit_super(sbi, false);
-               f2fs_msg(sb, KERN_INFO,
-                       "Try to recover all the superblocks, ret: %d", err);
+               f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
+                         err);
                if (!err)
                        clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
        }
@@ -1614,15 +1597,13 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        /* disallow enable/disable extent_cache dynamically */
        if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
                err = -EINVAL;
-               f2fs_msg(sbi->sb, KERN_WARNING,
-                               "switch extent_cache option is not allowed");
+               f2fs_warn(sbi, "switch extent_cache option is not allowed");
                goto restore_opts;
        }
 
        if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
                err = -EINVAL;
-               f2fs_msg(sbi->sb, KERN_WARNING,
-                       "disabling checkpoint not compatible with read-only");
+               f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
                goto restore_opts;
        }
 
@@ -1692,8 +1673,7 @@ skip:
 restore_gc:
        if (need_restart_gc) {
                if (f2fs_start_gc_thread(sbi))
-                       f2fs_msg(sbi->sb, KERN_WARNING,
-                               "background gc thread has stopped");
+                       f2fs_warn(sbi, "background gc thread has stopped");
        } else if (need_stop_gc) {
                f2fs_stop_gc_thread(sbi);
        }
@@ -1832,8 +1812,7 @@ static qsize_t *f2fs_get_reserved_space(struct inode *inode)
 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
 {
        if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "quota sysfile may be corrupted, skip loading it");
+               f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
                return 0;
        }
 
@@ -1849,8 +1828,7 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
        if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
                err = f2fs_enable_quotas(sbi->sb);
                if (err) {
-                       f2fs_msg(sbi->sb, KERN_ERR,
-                                       "Cannot turn on quota_ino: %d", err);
+                       f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
                        return 0;
                }
                return 1;
@@ -1863,8 +1841,8 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
                                enabled = 1;
                                continue;
                        }
-                       f2fs_msg(sbi->sb, KERN_ERR,
-                               "Cannot turn on quotas: %d on %d", err, i);
+                       f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
+                                err, i);
                }
        }
        return enabled;
@@ -1885,8 +1863,7 @@ static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
 
        qf_inode = f2fs_iget(sb, qf_inum);
        if (IS_ERR(qf_inode)) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Bad quota inode %u:%lu", type, qf_inum);
+               f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
                return PTR_ERR(qf_inode);
        }
 
@@ -1899,17 +1876,17 @@ static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
 
 static int f2fs_enable_quotas(struct super_block *sb)
 {
+       struct f2fs_sb_info *sbi = F2FS_SB(sb);
        int type, err = 0;
        unsigned long qf_inum;
        bool quota_mopt[MAXQUOTAS] = {
-               test_opt(F2FS_SB(sb), USRQUOTA),
-               test_opt(F2FS_SB(sb), GRPQUOTA),
-               test_opt(F2FS_SB(sb), PRJQUOTA),
+               test_opt(sbi, USRQUOTA),
+               test_opt(sbi, GRPQUOTA),
+               test_opt(sbi, PRJQUOTA),
        };
 
        if (is_set_ckpt_flags(F2FS_SB(sb), CP_QUOTA_NEED_FSCK_FLAG)) {
-               f2fs_msg(sb, KERN_ERR,
-                       "quota file may be corrupted, skip loading it");
+               f2fs_err(sbi, "quota file may be corrupted, skip loading it");
                return 0;
        }
 
@@ -1922,10 +1899,8 @@ static int f2fs_enable_quotas(struct super_block *sb)
                                DQUOT_USAGE_ENABLED |
                                (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
                        if (err) {
-                               f2fs_msg(sb, KERN_ERR,
-                                       "Failed to enable quota tracking "
-                                       "(type=%d, err=%d). Please run "
-                                       "fsck to fix.", type, err);
+                               f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
+                                        type, err);
                                for (type--; type >= 0; type--)
                                        dquot_quota_off(sb, type);
                                set_sbi_flag(F2FS_SB(sb),
@@ -1944,6 +1919,18 @@ int f2fs_quota_sync(struct super_block *sb, int type)
        int cnt;
        int ret;
 
+       /*
+        * do_quotactl
+        *  f2fs_quota_sync
+        *  down_read(quota_sem)
+        *  dquot_writeback_dquots()
+        *  f2fs_dquot_commit
+        *                            block_operation
+        *                            down_read(quota_sem)
+        */
+       f2fs_lock_op(sbi);
+
+       down_read(&sbi->quota_sem);
        ret = dquot_writeback_dquots(sb, type);
        if (ret)
                goto out;
@@ -1981,6 +1968,8 @@ int f2fs_quota_sync(struct super_block *sb, int type)
 out:
        if (ret)
                set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
+       up_read(&sbi->quota_sem);
+       f2fs_unlock_op(sbi);
        return ret;
 }
 
@@ -2045,10 +2034,8 @@ void f2fs_quota_off_umount(struct super_block *sb)
                if (err) {
                        int ret = dquot_quota_off(sb, type);
 
-                       f2fs_msg(sb, KERN_ERR,
-                               "Fail to turn off disk quota "
-                               "(type: %d, err: %d, ret:%d), Please "
-                               "run fsck to fix it.", type, err, ret);
+                       f2fs_err(F2FS_SB(sb), "Fail to turn off disk quota (type: %d, err: %d, ret:%d), Please run fsck to fix it.",
+                                type, err, ret);
                        set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
                }
        }
@@ -2074,32 +2061,40 @@ static void f2fs_truncate_quota_inode_pages(struct super_block *sb)
 
 static int f2fs_dquot_commit(struct dquot *dquot)
 {
+       struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
        int ret;
 
+       down_read(&sbi->quota_sem);
        ret = dquot_commit(dquot);
        if (ret < 0)
-               set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR);
+               set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
+       up_read(&sbi->quota_sem);
        return ret;
 }
 
 static int f2fs_dquot_acquire(struct dquot *dquot)
 {
+       struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
        int ret;
 
+       down_read(&sbi->quota_sem);
        ret = dquot_acquire(dquot);
        if (ret < 0)
-               set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR);
-
+               set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
+       up_read(&sbi->quota_sem);
        return ret;
 }
 
 static int f2fs_dquot_release(struct dquot *dquot)
 {
+       struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
        int ret;
 
+       down_read(&sbi->quota_sem);
        ret = dquot_release(dquot);
        if (ret < 0)
-               set_sbi_flag(F2FS_SB(dquot->dq_sb), SBI_QUOTA_NEED_REPAIR);
+               set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
+       up_read(&sbi->quota_sem);
        return ret;
 }
 
@@ -2109,22 +2104,27 @@ static int f2fs_dquot_mark_dquot_dirty(struct dquot *dquot)
        struct f2fs_sb_info *sbi = F2FS_SB(sb);
        int ret;
 
+       down_read(&sbi->quota_sem);
        ret = dquot_mark_dquot_dirty(dquot);
 
        /* if we are using journalled quota */
        if (is_journalled_quota(sbi))
                set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
 
+       up_read(&sbi->quota_sem);
        return ret;
 }
 
 static int f2fs_dquot_commit_info(struct super_block *sb, int type)
 {
+       struct f2fs_sb_info *sbi = F2FS_SB(sb);
        int ret;
 
+       down_read(&sbi->quota_sem);
        ret = dquot_commit_info(sb, type);
        if (ret < 0)
-               set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
+               set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
+       up_read(&sbi->quota_sem);
        return ret;
 }
 
@@ -2341,55 +2341,49 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
                                (segment_count << log_blocks_per_seg);
 
        if (segment0_blkaddr != cp_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
-                       segment0_blkaddr, cp_blkaddr);
+               f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
+                         segment0_blkaddr, cp_blkaddr);
                return true;
        }
 
        if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) !=
                                                        sit_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
-                       cp_blkaddr, sit_blkaddr,
-                       segment_count_ckpt << log_blocks_per_seg);
+               f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
+                         cp_blkaddr, sit_blkaddr,
+                         segment_count_ckpt << log_blocks_per_seg);
                return true;
        }
 
        if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) !=
                                                        nat_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
-                       sit_blkaddr, nat_blkaddr,
-                       segment_count_sit << log_blocks_per_seg);
+               f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
+                         sit_blkaddr, nat_blkaddr,
+                         segment_count_sit << log_blocks_per_seg);
                return true;
        }
 
        if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) !=
                                                        ssa_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
-                       nat_blkaddr, ssa_blkaddr,
-                       segment_count_nat << log_blocks_per_seg);
+               f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
+                         nat_blkaddr, ssa_blkaddr,
+                         segment_count_nat << log_blocks_per_seg);
                return true;
        }
 
        if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) !=
                                                        main_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
-                       ssa_blkaddr, main_blkaddr,
-                       segment_count_ssa << log_blocks_per_seg);
+               f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
+                         ssa_blkaddr, main_blkaddr,
+                         segment_count_ssa << log_blocks_per_seg);
                return true;
        }
 
        if (main_end_blkaddr > seg_end_blkaddr) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)",
-                       main_blkaddr,
-                       segment0_blkaddr +
-                               (segment_count << log_blocks_per_seg),
-                       segment_count_main << log_blocks_per_seg);
+               f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%u) block(%u)",
+                         main_blkaddr,
+                         segment0_blkaddr +
+                         (segment_count << log_blocks_per_seg),
+                         segment_count_main << log_blocks_per_seg);
                return true;
        } else if (main_end_blkaddr < seg_end_blkaddr) {
                int err = 0;
@@ -2406,12 +2400,11 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
                        err = __f2fs_commit_super(bh, NULL);
                        res = err ? "failed" : "done";
                }
-               f2fs_msg(sb, KERN_INFO,
-                       "Fix alignment : %s, start(%u) end(%u) block(%u)",
-                       res, main_blkaddr,
-                       segment0_blkaddr +
-                               (segment_count << log_blocks_per_seg),
-                       segment_count_main << log_blocks_per_seg);
+               f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%u) block(%u)",
+                         res, main_blkaddr,
+                         segment0_blkaddr +
+                         (segment_count << log_blocks_per_seg),
+                         segment_count_main << log_blocks_per_seg);
                if (err)
                        return true;
        }
@@ -2425,7 +2418,6 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
        block_t total_sections, blocks_per_seg;
        struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
                                        (bh->b_data + F2FS_SUPER_OFFSET);
-       struct super_block *sb = sbi->sb;
        unsigned int blocksize;
        size_t crc_offset = 0;
        __u32 crc = 0;
@@ -2435,48 +2427,42 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
                crc_offset = le32_to_cpu(raw_super->checksum_offset);
                if (crc_offset !=
                        offsetof(struct f2fs_super_block, crc)) {
-                       f2fs_msg(sb, KERN_INFO,
-                               "Invalid SB checksum offset: %zu",
-                               crc_offset);
+                       f2fs_info(sbi, "Invalid SB checksum offset: %zu",
+                                 crc_offset);
                        return 1;
                }
                crc = le32_to_cpu(raw_super->crc);
                if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
-                       f2fs_msg(sb, KERN_INFO,
-                               "Invalid SB checksum value: %u", crc);
+                       f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
                        return 1;
                }
        }
 
        if (F2FS_SUPER_MAGIC != le32_to_cpu(raw_super->magic)) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Magic Mismatch, valid(0x%x) - read(0x%x)",
-                       F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
+               f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
+                         F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
                return 1;
        }
 
        /* Currently, support only 4KB page cache size */
        if (F2FS_BLKSIZE != PAGE_SIZE) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid page_cache_size (%lu), supports only 4KB",
-                       PAGE_SIZE);
+               f2fs_info(sbi, "Invalid page_cache_size (%lu), supports only 4KB",
+                         PAGE_SIZE);
                return 1;
        }
 
        /* Currently, support only 4KB block size */
        blocksize = 1 << le32_to_cpu(raw_super->log_blocksize);
        if (blocksize != F2FS_BLKSIZE) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid blocksize (%u), supports only 4KB",
-                       blocksize);
+               f2fs_info(sbi, "Invalid blocksize (%u), supports only 4KB",
+                         blocksize);
                return 1;
        }
 
        /* check log blocks per segment */
        if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid log blocks per segment (%u)",
-                       le32_to_cpu(raw_super->log_blocks_per_seg));
+               f2fs_info(sbi, "Invalid log blocks per segment (%u)",
+                         le32_to_cpu(raw_super->log_blocks_per_seg));
                return 1;
        }
 
@@ -2485,17 +2471,16 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
                                F2FS_MAX_LOG_SECTOR_SIZE ||
                le32_to_cpu(raw_super->log_sectorsize) <
                                F2FS_MIN_LOG_SECTOR_SIZE) {
-               f2fs_msg(sb, KERN_INFO, "Invalid log sectorsize (%u)",
-                       le32_to_cpu(raw_super->log_sectorsize));
+               f2fs_info(sbi, "Invalid log sectorsize (%u)",
+                         le32_to_cpu(raw_super->log_sectorsize));
                return 1;
        }
        if (le32_to_cpu(raw_super->log_sectors_per_block) +
                le32_to_cpu(raw_super->log_sectorsize) !=
                        F2FS_MAX_LOG_SECTOR_SIZE) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid log sectors per block(%u) log sectorsize(%u)",
-                       le32_to_cpu(raw_super->log_sectors_per_block),
-                       le32_to_cpu(raw_super->log_sectorsize));
+               f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
+                         le32_to_cpu(raw_super->log_sectors_per_block),
+                         le32_to_cpu(raw_super->log_sectorsize));
                return 1;
        }
 
@@ -2509,59 +2494,51 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
 
        if (segment_count > F2FS_MAX_SEGMENT ||
                                segment_count < F2FS_MIN_SEGMENTS) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid segment count (%u)",
-                       segment_count);
+               f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
                return 1;
        }
 
        if (total_sections > segment_count ||
                        total_sections < F2FS_MIN_SEGMENTS ||
                        segs_per_sec > segment_count || !segs_per_sec) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid segment/section count (%u, %u x %u)",
-                       segment_count, total_sections, segs_per_sec);
+               f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
+                         segment_count, total_sections, segs_per_sec);
                return 1;
        }
 
        if ((segment_count / segs_per_sec) < total_sections) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Small segment_count (%u < %u * %u)",
-                       segment_count, segs_per_sec, total_sections);
+               f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
+                         segment_count, segs_per_sec, total_sections);
                return 1;
        }
 
        if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong segment_count / block_count (%u > %llu)",
-                       segment_count, le64_to_cpu(raw_super->block_count));
+               f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
+                         segment_count, le64_to_cpu(raw_super->block_count));
                return 1;
        }
 
        if (secs_per_zone > total_sections || !secs_per_zone) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Wrong secs_per_zone / total_sections (%u, %u)",
-                       secs_per_zone, total_sections);
+               f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
+                         secs_per_zone, total_sections);
                return 1;
        }
        if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION ||
                        raw_super->hot_ext_count > F2FS_MAX_EXTENSION ||
                        (le32_to_cpu(raw_super->extension_count) +
                        raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Corrupted extension count (%u + %u > %u)",
-                       le32_to_cpu(raw_super->extension_count),
-                       raw_super->hot_ext_count,
-                       F2FS_MAX_EXTENSION);
+               f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
+                         le32_to_cpu(raw_super->extension_count),
+                         raw_super->hot_ext_count,
+                         F2FS_MAX_EXTENSION);
                return 1;
        }
 
        if (le32_to_cpu(raw_super->cp_payload) >
                                (blocks_per_seg - F2FS_CP_PACKS)) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Insane cp_payload (%u > %u)",
-                       le32_to_cpu(raw_super->cp_payload),
-                       blocks_per_seg - F2FS_CP_PACKS);
+               f2fs_info(sbi, "Insane cp_payload (%u > %u)",
+                         le32_to_cpu(raw_super->cp_payload),
+                         blocks_per_seg - F2FS_CP_PACKS);
                return 1;
        }
 
@@ -2569,11 +2546,10 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
        if (le32_to_cpu(raw_super->node_ino) != 1 ||
                le32_to_cpu(raw_super->meta_ino) != 2 ||
                le32_to_cpu(raw_super->root_ino) != 3) {
-               f2fs_msg(sb, KERN_INFO,
-                       "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
-                       le32_to_cpu(raw_super->node_ino),
-                       le32_to_cpu(raw_super->meta_ino),
-                       le32_to_cpu(raw_super->root_ino));
+               f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
+                         le32_to_cpu(raw_super->node_ino),
+                         le32_to_cpu(raw_super->meta_ino),
+                         le32_to_cpu(raw_super->root_ino));
                return 1;
        }
 
@@ -2617,8 +2593,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 
        if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||
                        ovp_segments == 0 || reserved_segments == 0)) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong layout: check mkfs.f2fs version");
+               f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
                return 1;
        }
 
@@ -2627,16 +2602,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
        log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
        if (!user_block_count || user_block_count >=
                        segment_count_main << log_blocks_per_seg) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong user_block_count: %u", user_block_count);
+               f2fs_err(sbi, "Wrong user_block_count: %u",
+                        user_block_count);
                return 1;
        }
 
        valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
        if (valid_user_blocks > user_block_count) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong valid_user_blocks: %u, user_block_count: %u",
-                       valid_user_blocks, user_block_count);
+               f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
+                        valid_user_blocks, user_block_count);
                return 1;
        }
 
@@ -2644,9 +2618,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
        avail_node_count = sbi->total_node_count - sbi->nquota_files -
                                                F2FS_RESERVED_NODE_NUM;
        if (valid_node_count > avail_node_count) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong valid_node_count: %u, avail_node_count: %u",
-                       valid_node_count, avail_node_count);
+               f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
+                        valid_node_count, avail_node_count);
                return 1;
        }
 
@@ -2660,10 +2633,9 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
                for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
                        if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
                                le32_to_cpu(ckpt->cur_node_segno[j])) {
-                               f2fs_msg(sbi->sb, KERN_ERR,
-                                       "Node segment (%u, %u) has the same "
-                                       "segno: %u", i, j,
-                                       le32_to_cpu(ckpt->cur_node_segno[i]));
+                               f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
+                                        i, j,
+                                        le32_to_cpu(ckpt->cur_node_segno[i]));
                                return 1;
                        }
                }
@@ -2675,10 +2647,9 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
                for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
                        if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
                                le32_to_cpu(ckpt->cur_data_segno[j])) {
-                               f2fs_msg(sbi->sb, KERN_ERR,
-                                       "Data segment (%u, %u) has the same "
-                                       "segno: %u", i, j,
-                                       le32_to_cpu(ckpt->cur_data_segno[i]));
+                               f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
+                                        i, j,
+                                        le32_to_cpu(ckpt->cur_data_segno[i]));
                                return 1;
                        }
                }
@@ -2687,10 +2658,9 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
                for (j = i; j < NR_CURSEG_DATA_TYPE; j++) {
                        if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
                                le32_to_cpu(ckpt->cur_data_segno[j])) {
-                               f2fs_msg(sbi->sb, KERN_ERR,
-                                       "Data segment (%u) and Data segment (%u)"
-                                       " has the same segno: %u", i, j,
-                                       le32_to_cpu(ckpt->cur_node_segno[i]));
+                               f2fs_err(sbi, "Data segment (%u) and Data segment (%u) has the same segno: %u",
+                                        i, j,
+                                        le32_to_cpu(ckpt->cur_node_segno[i]));
                                return 1;
                        }
                }
@@ -2701,9 +2671,8 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
 
        if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 ||
                nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong bitmap size: sit: %u, nat:%u",
-                       sit_bitmap_size, nat_bitmap_size);
+               f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
+                        sit_bitmap_size, nat_bitmap_size);
                return 1;
        }
 
@@ -2712,14 +2681,22 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
        if (cp_pack_start_sum < cp_payload + 1 ||
                cp_pack_start_sum > blocks_per_seg - 1 -
                        NR_CURSEG_TYPE) {
-               f2fs_msg(sbi->sb, KERN_ERR,
-                       "Wrong cp_pack_start_sum: %u",
-                       cp_pack_start_sum);
+               f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
+                        cp_pack_start_sum);
+               return 1;
+       }
+
+       if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) &&
+               le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) {
+               f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
+                         "please run fsck v1.13.0 or higher to repair, chksum_offset: %u, "
+                         "fixed with patch: \"f2fs-tools: relocate chksum_offset for large_nat_bitmap feature\"",
+                         le32_to_cpu(ckpt->checksum_offset));
                return 1;
        }
 
        if (unlikely(f2fs_cp_error(sbi))) {
-               f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
+               f2fs_err(sbi, "A bug case: need to run fsck");
                return 1;
        }
        return 0;
@@ -2886,18 +2863,17 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
        for (block = 0; block < 2; block++) {
                bh = sb_bread(sb, block);
                if (!bh) {
-                       f2fs_msg(sb, KERN_ERR, "Unable to read %dth superblock",
-                               block + 1);
+                       f2fs_err(sbi, "Unable to read %dth superblock",
+                                block + 1);
                        err = -EIO;
                        continue;
                }
 
                /* sanity checking of raw super */
                if (sanity_check_raw_super(sbi, bh)) {
-                       f2fs_msg(sb, KERN_ERR,
-                               "Can't find valid F2FS filesystem in %dth superblock",
-                               block + 1);
-                       err = -EINVAL;
+                       f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
+                                block + 1);
+                       err = -EFSCORRUPTED;
                        brelse(bh);
                        continue;
                }
@@ -3026,36 +3002,32 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 #ifdef CONFIG_BLK_DEV_ZONED
                if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
                                !f2fs_sb_has_blkzoned(sbi)) {
-                       f2fs_msg(sbi->sb, KERN_ERR,
-                               "Zoned block device feature not enabled\n");
+                       f2fs_err(sbi, "Zoned block device feature not enabled\n");
                        return -EINVAL;
                }
                if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
                        if (init_blkz_info(sbi, i)) {
-                               f2fs_msg(sbi->sb, KERN_ERR,
-                                       "Failed to initialize F2FS blkzone information");
+                               f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
                                return -EINVAL;
                        }
                        if (max_devices == 1)
                                break;
-                       f2fs_msg(sbi->sb, KERN_INFO,
-                               "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
-                               i, FDEV(i).path,
-                               FDEV(i).total_segments,
-                               FDEV(i).start_blk, FDEV(i).end_blk,
-                               bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
-                               "Host-aware" : "Host-managed");
+                       f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
+                                 i, FDEV(i).path,
+                                 FDEV(i).total_segments,
+                                 FDEV(i).start_blk, FDEV(i).end_blk,
+                                 bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
+                                 "Host-aware" : "Host-managed");
                        continue;
                }
 #endif
-               f2fs_msg(sbi->sb, KERN_INFO,
-                       "Mount Device [%2d]: %20s, %8u, %8x - %8x",
-                               i, FDEV(i).path,
-                               FDEV(i).total_segments,
-                               FDEV(i).start_blk, FDEV(i).end_blk);
-       }
-       f2fs_msg(sbi->sb, KERN_INFO,
-                       "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
+               f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
+                         i, FDEV(i).path,
+                         FDEV(i).total_segments,
+                         FDEV(i).start_blk, FDEV(i).end_blk);
+       }
+       f2fs_info(sbi,
+                 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
        return 0;
 }
 
@@ -3101,7 +3073,7 @@ try_onemore:
        /* Load the checksum driver */
        sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
        if (IS_ERR(sbi->s_chksum_driver)) {
-               f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver.");
+               f2fs_err(sbi, "Cannot load crc32 driver.");
                err = PTR_ERR(sbi->s_chksum_driver);
                sbi->s_chksum_driver = NULL;
                goto free_sbi;
@@ -3109,7 +3081,7 @@ try_onemore:
 
        /* set a block size */
        if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
-               f2fs_msg(sb, KERN_ERR, "unable to set blocksize");
+               f2fs_err(sbi, "unable to set blocksize");
                goto free_sbi;
        }
 
@@ -3133,8 +3105,7 @@ try_onemore:
         */
 #ifndef CONFIG_BLK_DEV_ZONED
        if (f2fs_sb_has_blkzoned(sbi)) {
-               f2fs_msg(sb, KERN_ERR,
-                        "Zoned block device support is not enabled");
+               f2fs_err(sbi, "Zoned block device support is not enabled");
                err = -EOPNOTSUPP;
                goto free_sb_buf;
        }
@@ -3158,10 +3129,7 @@ try_onemore:
 
 #ifdef CONFIG_QUOTA
        sb->dq_op = &f2fs_quota_operations;
-       if (f2fs_sb_has_quota_ino(sbi))
-               sb->s_qcop = &dquot_quotactl_sysfile_ops;
-       else
-               sb->s_qcop = &f2fs_quotactl_ops;
+       sb->s_qcop = &f2fs_quotactl_ops;
        sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 
        if (f2fs_sb_has_quota_ino(sbi)) {
@@ -3190,6 +3158,7 @@ try_onemore:
        mutex_init(&sbi->gc_mutex);
        mutex_init(&sbi->writepages);
        mutex_init(&sbi->cp_mutex);
+       mutex_init(&sbi->resize_mutex);
        init_rwsem(&sbi->node_write);
        init_rwsem(&sbi->node_change);
 
@@ -3225,6 +3194,7 @@ try_onemore:
        }
 
        init_rwsem(&sbi->cp_rwsem);
+       init_rwsem(&sbi->quota_sem);
        init_waitqueue_head(&sbi->cp_wait);
        init_sb_info(sbi);
 
@@ -3244,14 +3214,14 @@ try_onemore:
        /* get an inode for meta space */
        sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
        if (IS_ERR(sbi->meta_inode)) {
-               f2fs_msg(sb, KERN_ERR, "Failed to read F2FS meta data inode");
+               f2fs_err(sbi, "Failed to read F2FS meta data inode");
                err = PTR_ERR(sbi->meta_inode);
                goto free_io_dummy;
        }
 
        err = f2fs_get_valid_checkpoint(sbi);
        if (err) {
-               f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
+               f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
                goto free_meta_inode;
        }
 
@@ -3262,10 +3232,13 @@ try_onemore:
                sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
        }
 
+       if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
+               set_sbi_flag(sbi, SBI_NEED_FSCK);
+
        /* Initialize device list */
        err = f2fs_scan_devices(sbi);
        if (err) {
-               f2fs_msg(sb, KERN_ERR, "Failed to find devices");
+               f2fs_err(sbi, "Failed to find devices");
                goto free_devices;
        }
 
@@ -3285,6 +3258,7 @@ try_onemore:
                INIT_LIST_HEAD(&sbi->inode_list[i]);
                spin_lock_init(&sbi->inode_lock[i]);
        }
+       mutex_init(&sbi->flush_lock);
 
        f2fs_init_extent_cache_info(sbi);
 
@@ -3295,14 +3269,14 @@ try_onemore:
        /* setup f2fs internal modules */
        err = f2fs_build_segment_manager(sbi);
        if (err) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Failed to initialize F2FS segment manager");
+               f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
+                        err);
                goto free_sm;
        }
        err = f2fs_build_node_manager(sbi);
        if (err) {
-               f2fs_msg(sb, KERN_ERR,
-                       "Failed to initialize F2FS node manager");
+               f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
+                        err);
                goto free_nm;
        }
 
@@ -3327,7 +3301,7 @@ try_onemore:
        /* get an inode for node space */
        sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
        if (IS_ERR(sbi->node_inode)) {
-               f2fs_msg(sb, KERN_ERR, "Failed to read node inode");
+               f2fs_err(sbi, "Failed to read node inode");
                err = PTR_ERR(sbi->node_inode);
                goto free_stats;
        }
@@ -3335,7 +3309,7 @@ try_onemore:
        /* read root inode and dentry */
        root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
        if (IS_ERR(root)) {
-               f2fs_msg(sb, KERN_ERR, "Failed to read root inode");
+               f2fs_err(sbi, "Failed to read root inode");
                err = PTR_ERR(root);
                goto free_node_inode;
        }
@@ -3361,8 +3335,7 @@ try_onemore:
        if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
                err = f2fs_enable_quotas(sb);
                if (err)
-                       f2fs_msg(sb, KERN_ERR,
-                               "Cannot turn on quotas: error %d", err);
+                       f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
        }
 #endif
        /* if there are nt orphan nodes free them */
@@ -3382,13 +3355,10 @@ try_onemore:
                if (f2fs_hw_is_readonly(sbi)) {
                        if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
                                err = -EROFS;
-                               f2fs_msg(sb, KERN_ERR,
-                                       "Need to recover fsync data, but "
-                                       "write access unavailable");
+                               f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");
                                goto free_meta;
                        }
-                       f2fs_msg(sbi->sb, KERN_INFO, "write access "
-                               "unavailable, skipping recovery");
+                       f2fs_info(sbi, "write access unavailable, skipping recovery");
                        goto reset_checkpoint;
                }
 
@@ -3403,8 +3373,8 @@ try_onemore:
                        if (err != -ENOMEM)
                                skip_recovery = true;
                        need_fsck = true;
-                       f2fs_msg(sb, KERN_ERR,
-                               "Cannot recover all fsync data errno=%d", err);
+                       f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
+                                err);
                        goto free_meta;
                }
        } else {
@@ -3412,8 +3382,7 @@ try_onemore:
 
                if (!f2fs_readonly(sb) && err > 0) {
                        err = -EINVAL;
-                       f2fs_msg(sb, KERN_ERR,
-                               "Need to recover fsync data");
+                       f2fs_err(sbi, "Need to recover fsync data");
                        goto free_meta;
                }
        }
@@ -3444,17 +3413,16 @@ reset_checkpoint:
        /* recover broken superblock */
        if (recovery) {
                err = f2fs_commit_super(sbi, true);
-               f2fs_msg(sb, KERN_INFO,
-                       "Try to recover %dth superblock, ret: %d",
-                       sbi->valid_super_block ? 1 : 2, err);
+               f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
+                         sbi->valid_super_block ? 1 : 2, err);
        }
 
        f2fs_join_shrinker(sbi);
 
        f2fs_tuning_parameters(sbi);
 
-       f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx",
-                               cur_cp_version(F2FS_CKPT(sbi)));
+       f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
+                   cur_cp_version(F2FS_CKPT(sbi)));
        f2fs_update_time(sbi, CP_TIME);
        f2fs_update_time(sbi, REQ_TIME);
        clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);