Lines Matching refs:sbi
64 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, in f2fs_build_fault_attr() argument
67 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; in f2fs_build_fault_attr()
242 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) in f2fs_printk() argument
254 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
307 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) in limit_reserve_root() argument
309 block_t limit = min((sbi->user_block_count << 1) / 1000, in limit_reserve_root()
310 sbi->user_block_count - sbi->reserved_blocks); in limit_reserve_root()
313 if (test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
314 F2FS_OPTION(sbi).root_reserved_blocks > limit) { in limit_reserve_root()
315 F2FS_OPTION(sbi).root_reserved_blocks = limit; in limit_reserve_root()
316 f2fs_info(sbi, "Reduce reserved blocks for root = %u", in limit_reserve_root()
317 F2FS_OPTION(sbi).root_reserved_blocks); in limit_reserve_root()
319 if (!test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
320 (!uid_eq(F2FS_OPTION(sbi).s_resuid, in limit_reserve_root()
322 !gid_eq(F2FS_OPTION(sbi).s_resgid, in limit_reserve_root()
324 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", in limit_reserve_root()
326 F2FS_OPTION(sbi).s_resuid), in limit_reserve_root()
328 F2FS_OPTION(sbi).s_resgid)); in limit_reserve_root()
331 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) in adjust_unusable_cap_perc() argument
333 if (!F2FS_OPTION(sbi).unusable_cap_perc) in adjust_unusable_cap_perc()
336 if (F2FS_OPTION(sbi).unusable_cap_perc == 100) in adjust_unusable_cap_perc()
337 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; in adjust_unusable_cap_perc()
339 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * in adjust_unusable_cap_perc()
340 F2FS_OPTION(sbi).unusable_cap_perc; in adjust_unusable_cap_perc()
342 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", in adjust_unusable_cap_perc()
343 F2FS_OPTION(sbi).unusable_cap, in adjust_unusable_cap_perc()
344 F2FS_OPTION(sbi).unusable_cap_perc); in adjust_unusable_cap_perc()
360 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_qf_name() local
364 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
365 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_set_qf_name()
368 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_set_qf_name()
369 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); in f2fs_set_qf_name()
375 f2fs_err(sbi, "Not enough memory for storing quotafile name"); in f2fs_set_qf_name()
378 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
379 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) in f2fs_set_qf_name()
382 f2fs_err(sbi, "%s quota file already specified", in f2fs_set_qf_name()
387 f2fs_err(sbi, "quotafile must be on filesystem root"); in f2fs_set_qf_name()
390 F2FS_OPTION(sbi).s_qf_names[qtype] = qname; in f2fs_set_qf_name()
391 set_opt(sbi, QUOTA); in f2fs_set_qf_name()
400 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_clear_qf_name() local
402 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_clear_qf_name()
403 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_clear_qf_name()
406 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); in f2fs_clear_qf_name()
407 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; in f2fs_clear_qf_name()
411 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) in f2fs_check_quota_options() argument
418 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { in f2fs_check_quota_options()
419 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); in f2fs_check_quota_options()
422 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || in f2fs_check_quota_options()
423 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || in f2fs_check_quota_options()
424 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { in f2fs_check_quota_options()
425 if (test_opt(sbi, USRQUOTA) && in f2fs_check_quota_options()
426 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_check_quota_options()
427 clear_opt(sbi, USRQUOTA); in f2fs_check_quota_options()
429 if (test_opt(sbi, GRPQUOTA) && in f2fs_check_quota_options()
430 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_check_quota_options()
431 clear_opt(sbi, GRPQUOTA); in f2fs_check_quota_options()
433 if (test_opt(sbi, PRJQUOTA) && in f2fs_check_quota_options()
434 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_check_quota_options()
435 clear_opt(sbi, PRJQUOTA); in f2fs_check_quota_options()
437 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || in f2fs_check_quota_options()
438 test_opt(sbi, PRJQUOTA)) { in f2fs_check_quota_options()
439 f2fs_err(sbi, "old and new quota format mixing"); in f2fs_check_quota_options()
443 if (!F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
444 f2fs_err(sbi, "journaled quota format not specified"); in f2fs_check_quota_options()
449 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
450 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); in f2fs_check_quota_options()
451 F2FS_OPTION(sbi).s_jquota_fmt = 0; in f2fs_check_quota_options()
462 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_test_dummy_encryption() local
466 if (!f2fs_sb_has_encrypt(sbi)) { in f2fs_set_test_dummy_encryption()
467 f2fs_err(sbi, "Encrypt feature is off"); in f2fs_set_test_dummy_encryption()
477 if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) { in f2fs_set_test_dummy_encryption()
478 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); in f2fs_set_test_dummy_encryption()
482 sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_set_test_dummy_encryption()
485 f2fs_warn(sbi, in f2fs_set_test_dummy_encryption()
488 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", in f2fs_set_test_dummy_encryption()
491 f2fs_warn(sbi, "Error processing option \"%s\" [%d]", in f2fs_set_test_dummy_encryption()
495 f2fs_warn(sbi, "Test dummy encryption mode enabled"); in f2fs_set_test_dummy_encryption()
497 f2fs_warn(sbi, "Test dummy encryption mount option ignored"); in f2fs_set_test_dummy_encryption()
510 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi) in f2fs_test_compress_extension() argument
516 ext = F2FS_OPTION(sbi).extensions; in f2fs_test_compress_extension()
517 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in f2fs_test_compress_extension()
518 noext = F2FS_OPTION(sbi).noextensions; in f2fs_test_compress_extension()
519 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in f2fs_test_compress_extension()
526 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files"); in f2fs_test_compress_extension()
531 …f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension… in f2fs_test_compress_extension()
541 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_lz4hc_level() argument
548 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
556 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_lz4hc_level()
563 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); in f2fs_set_lz4hc_level()
567 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_lz4hc_level()
570 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); in f2fs_set_lz4hc_level()
577 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_zstd_level() argument
583 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_zstd_level()
590 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_zstd_level()
597 f2fs_info(sbi, "invalid zstd compress level: %d", level); in f2fs_set_zstd_level()
601 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_zstd_level()
609 struct f2fs_sb_info *sbi = F2FS_SB(sb); in parse_options() local
644 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in parse_options()
646 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; in parse_options()
648 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; in parse_options()
656 set_opt(sbi, DISABLE_ROLL_FORWARD); in parse_options()
660 set_opt(sbi, NORECOVERY); in parse_options()
665 if (!f2fs_hw_support_discard(sbi)) { in parse_options()
666 f2fs_warn(sbi, "device does not support discard"); in parse_options()
669 set_opt(sbi, DISCARD); in parse_options()
672 if (f2fs_hw_should_discard(sbi)) { in parse_options()
673 f2fs_warn(sbi, "discard is required for zoned block devices"); in parse_options()
676 clear_opt(sbi, DISCARD); in parse_options()
679 set_opt(sbi, NOHEAP); in parse_options()
682 clear_opt(sbi, NOHEAP); in parse_options()
686 set_opt(sbi, XATTR_USER); in parse_options()
689 clear_opt(sbi, XATTR_USER); in parse_options()
692 set_opt(sbi, INLINE_XATTR); in parse_options()
695 clear_opt(sbi, INLINE_XATTR); in parse_options()
700 set_opt(sbi, INLINE_XATTR_SIZE); in parse_options()
701 F2FS_OPTION(sbi).inline_xattr_size = arg; in parse_options()
705 f2fs_info(sbi, "user_xattr options not supported"); in parse_options()
708 f2fs_info(sbi, "nouser_xattr options not supported"); in parse_options()
711 f2fs_info(sbi, "inline_xattr options not supported"); in parse_options()
714 f2fs_info(sbi, "noinline_xattr options not supported"); in parse_options()
719 set_opt(sbi, POSIX_ACL); in parse_options()
722 clear_opt(sbi, POSIX_ACL); in parse_options()
726 f2fs_info(sbi, "acl options not supported"); in parse_options()
729 f2fs_info(sbi, "noacl options not supported"); in parse_options()
738 F2FS_OPTION(sbi).active_logs = arg; in parse_options()
741 set_opt(sbi, DISABLE_EXT_IDENTIFY); in parse_options()
744 set_opt(sbi, INLINE_DATA); in parse_options()
747 set_opt(sbi, INLINE_DENTRY); in parse_options()
750 clear_opt(sbi, INLINE_DENTRY); in parse_options()
753 set_opt(sbi, FLUSH_MERGE); in parse_options()
756 clear_opt(sbi, FLUSH_MERGE); in parse_options()
759 set_opt(sbi, NOBARRIER); in parse_options()
762 set_opt(sbi, FASTBOOT); in parse_options()
765 set_opt(sbi, EXTENT_CACHE); in parse_options()
768 clear_opt(sbi, EXTENT_CACHE); in parse_options()
771 clear_opt(sbi, INLINE_DATA); in parse_options()
774 set_opt(sbi, DATA_FLUSH); in parse_options()
779 if (test_opt(sbi, RESERVE_ROOT)) { in parse_options()
780 f2fs_info(sbi, "Preserve previous reserve_root=%u", in parse_options()
781 F2FS_OPTION(sbi).root_reserved_blocks); in parse_options()
783 F2FS_OPTION(sbi).root_reserved_blocks = arg; in parse_options()
784 set_opt(sbi, RESERVE_ROOT); in parse_options()
792 f2fs_err(sbi, "Invalid uid value %d", arg); in parse_options()
795 F2FS_OPTION(sbi).s_resuid = uid; in parse_options()
802 f2fs_err(sbi, "Invalid gid value %d", arg); in parse_options()
805 F2FS_OPTION(sbi).s_resgid = gid; in parse_options()
813 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
814 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature"); in parse_options()
818 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in parse_options()
820 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in parse_options()
822 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_SEG; in parse_options()
824 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_BLK; in parse_options()
835 f2fs_warn(sbi, "Not support %d, larger than %d", in parse_options()
839 F2FS_OPTION(sbi).write_io_size_bits = arg; in parse_options()
845 f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); in parse_options()
846 set_opt(sbi, FAULT_INJECTION); in parse_options()
852 f2fs_build_fault_attr(sbi, 0, arg); in parse_options()
853 set_opt(sbi, FAULT_INJECTION); in parse_options()
857 f2fs_info(sbi, "fault_injection options not supported"); in parse_options()
861 f2fs_info(sbi, "fault_type options not supported"); in parse_options()
873 set_opt(sbi, USRQUOTA); in parse_options()
876 set_opt(sbi, GRPQUOTA); in parse_options()
879 set_opt(sbi, PRJQUOTA); in parse_options()
912 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; in parse_options()
915 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; in parse_options()
918 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; in parse_options()
921 clear_opt(sbi, QUOTA); in parse_options()
922 clear_opt(sbi, USRQUOTA); in parse_options()
923 clear_opt(sbi, GRPQUOTA); in parse_options()
924 clear_opt(sbi, PRJQUOTA); in parse_options()
941 f2fs_info(sbi, "quota operations not supported"); in parse_options()
949 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; in parse_options()
951 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
953 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; in parse_options()
966 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in parse_options()
968 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in parse_options()
980 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in parse_options()
982 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; in parse_options()
984 F2FS_OPTION(sbi).fsync_mode = in parse_options()
1002 f2fs_info(sbi, "inline encryption not supported"); in parse_options()
1010 F2FS_OPTION(sbi).unusable_cap_perc = arg; in parse_options()
1011 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1016 F2FS_OPTION(sbi).unusable_cap = arg; in parse_options()
1017 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1020 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1023 clear_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1026 set_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1029 clear_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1033 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1034 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1042 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1043 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1046 f2fs_info(sbi, "kernel doesn't support lzo compression"); in parse_options()
1050 ret = f2fs_set_lz4hc_level(sbi, name); in parse_options()
1055 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1058 f2fs_info(sbi, "kernel doesn't support lz4 compression"); in parse_options()
1062 ret = f2fs_set_zstd_level(sbi, name); in parse_options()
1067 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1070 f2fs_info(sbi, "kernel doesn't support zstd compression"); in parse_options()
1074 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1075 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1078 f2fs_info(sbi, "kernel doesn't support lzorle compression"); in parse_options()
1087 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1088 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1095 f2fs_err(sbi, in parse_options()
1099 F2FS_OPTION(sbi).compress_log_size = arg; in parse_options()
1102 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1103 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1110 ext = F2FS_OPTION(sbi).extensions; in parse_options()
1111 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in parse_options()
1115 f2fs_err(sbi, in parse_options()
1122 F2FS_OPTION(sbi).compress_ext_cnt++; in parse_options()
1126 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1127 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1134 noext = F2FS_OPTION(sbi).noextensions; in parse_options()
1135 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in parse_options()
1139 f2fs_err(sbi, in parse_options()
1146 F2FS_OPTION(sbi).nocompress_ext_cnt++; in parse_options()
1150 F2FS_OPTION(sbi).compress_chksum = true; in parse_options()
1157 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in parse_options()
1159 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; in parse_options()
1167 set_opt(sbi, COMPRESS_CACHE); in parse_options()
1177 f2fs_info(sbi, "compression options not supported"); in parse_options()
1181 set_opt(sbi, ATGC); in parse_options()
1184 set_opt(sbi, GC_MERGE); in parse_options()
1187 clear_opt(sbi, GC_MERGE); in parse_options()
1194 F2FS_OPTION(sbi).discard_unit = in parse_options()
1197 F2FS_OPTION(sbi).discard_unit = in parse_options()
1200 F2FS_OPTION(sbi).discard_unit = in parse_options()
1209 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", in parse_options()
1216 if (f2fs_check_quota_options(sbi)) in parse_options()
1219 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1220 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1223 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1224 …f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1229 if (f2fs_sb_has_casefold(sbi)) { in parse_options()
1230 f2fs_err(sbi, in parse_options()
1241 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1242 f2fs_err(sbi, "Zoned block device support is not enabled"); in parse_options()
1246 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1247 if (F2FS_OPTION(sbi).discard_unit != in parse_options()
1249 …f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default… in parse_options()
1250 F2FS_OPTION(sbi).discard_unit = in parse_options()
1256 if (f2fs_test_compress_extension(sbi)) { in parse_options()
1257 f2fs_err(sbi, "invalid compress or nocompress extension"); in parse_options()
1262 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { in parse_options()
1263 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", in parse_options()
1264 F2FS_IO_SIZE_KB(sbi)); in parse_options()
1268 if (test_opt(sbi, INLINE_XATTR_SIZE)) { in parse_options()
1271 if (!f2fs_sb_has_extra_attr(sbi) || in parse_options()
1272 !f2fs_sb_has_flexible_inline_xattr(sbi)) { in parse_options()
1273 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); in parse_options()
1276 if (!test_opt(sbi, INLINE_XATTR)) { in parse_options()
1277 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); in parse_options()
1284 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || in parse_options()
1285 F2FS_OPTION(sbi).inline_xattr_size > max_size) { in parse_options()
1286 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", in parse_options()
1292 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { in parse_options()
1293 f2fs_err(sbi, "LFS not compatible with checkpoint=disable"); in parse_options()
1300 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_PERSIST_TYPE) in parse_options()
1301 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
1303 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1304 f2fs_err(sbi, "Allow to mount readonly mode only"); in parse_options()
1343 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_drop_inode() local
1350 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_drop_inode()
1351 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_drop_inode()
1352 inode->i_ino == F2FS_META_INO(sbi)) { in f2fs_drop_inode()
1405 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_dirtied() local
1408 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1413 stat_inc_dirty_inode(sbi, DIRTY_META); in f2fs_inode_dirtied()
1417 &sbi->inode_list[DIRTY_META]); in f2fs_inode_dirtied()
1418 inc_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_dirtied()
1420 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1426 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_synced() local
1428 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1430 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1435 dec_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_synced()
1440 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1450 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_dirty_inode() local
1452 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_dirty_inode()
1453 inode->i_ino == F2FS_META_INO(sbi)) in f2fs_dirty_inode()
1468 static void destroy_percpu_info(struct f2fs_sb_info *sbi) in destroy_percpu_info() argument
1470 percpu_counter_destroy(&sbi->alloc_valid_block_count); in destroy_percpu_info()
1471 percpu_counter_destroy(&sbi->total_valid_inode_count); in destroy_percpu_info()
1474 static void destroy_device_list(struct f2fs_sb_info *sbi) in destroy_device_list() argument
1478 for (i = 0; i < sbi->s_ndevs; i++) { in destroy_device_list()
1485 kvfree(sbi->devs); in destroy_device_list()
1490 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_put_super() local
1495 f2fs_unregister_sysfs(sbi); in f2fs_put_super()
1500 mutex_lock(&sbi->umount_mutex); in f2fs_put_super()
1506 f2fs_stop_ckpt_thread(sbi); in f2fs_put_super()
1513 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in f2fs_put_super()
1514 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { in f2fs_put_super()
1518 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1522 dropped = f2fs_issue_discard_timeout(sbi); in f2fs_put_super()
1524 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) && in f2fs_put_super()
1525 !sbi->discard_blks && !dropped) { in f2fs_put_super()
1529 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1536 f2fs_release_ino_entry(sbi, true); in f2fs_put_super()
1538 f2fs_leave_shrinker(sbi); in f2fs_put_super()
1539 mutex_unlock(&sbi->umount_mutex); in f2fs_put_super()
1542 f2fs_flush_merged_writes(sbi); in f2fs_put_super()
1544 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); in f2fs_put_super()
1546 f2fs_bug_on(sbi, sbi->fsync_node_num); in f2fs_put_super()
1548 f2fs_destroy_compress_inode(sbi); in f2fs_put_super()
1550 iput(sbi->node_inode); in f2fs_put_super()
1551 sbi->node_inode = NULL; in f2fs_put_super()
1553 iput(sbi->meta_inode); in f2fs_put_super()
1554 sbi->meta_inode = NULL; in f2fs_put_super()
1560 f2fs_destroy_stats(sbi); in f2fs_put_super()
1563 f2fs_destroy_node_manager(sbi); in f2fs_put_super()
1564 f2fs_destroy_segment_manager(sbi); in f2fs_put_super()
1566 f2fs_destroy_post_read_wq(sbi); in f2fs_put_super()
1568 kvfree(sbi->ckpt); in f2fs_put_super()
1571 if (sbi->s_chksum_driver) in f2fs_put_super()
1572 crypto_free_shash(sbi->s_chksum_driver); in f2fs_put_super()
1573 kfree(sbi->raw_super); in f2fs_put_super()
1575 destroy_device_list(sbi); in f2fs_put_super()
1576 f2fs_destroy_page_array_cache(sbi); in f2fs_put_super()
1577 f2fs_destroy_xattr_caches(sbi); in f2fs_put_super()
1578 mempool_destroy(sbi->write_io_dummy); in f2fs_put_super()
1581 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_put_super()
1583 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_put_super()
1584 destroy_percpu_info(sbi); in f2fs_put_super()
1585 f2fs_destroy_iostat(sbi); in f2fs_put_super()
1587 kvfree(sbi->write_io[i]); in f2fs_put_super()
1591 kfree(sbi); in f2fs_put_super()
1596 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_sync_fs() local
1599 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_fs()
1601 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_sync_fs()
1606 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_sync_fs()
1610 err = f2fs_issue_checkpoint(sbi); in f2fs_sync_fs()
1687 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_statfs() local
1692 total_count = le64_to_cpu(sbi->raw_super->block_count); in f2fs_statfs()
1693 user_block_count = sbi->user_block_count; in f2fs_statfs()
1694 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); in f2fs_statfs()
1696 buf->f_bsize = sbi->blocksize; in f2fs_statfs()
1699 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - in f2fs_statfs()
1700 sbi->current_reserved_blocks; in f2fs_statfs()
1702 spin_lock(&sbi->stat_lock); in f2fs_statfs()
1703 if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) in f2fs_statfs()
1706 buf->f_bfree -= sbi->unusable_block_count; in f2fs_statfs()
1707 spin_unlock(&sbi->stat_lock); in f2fs_statfs()
1709 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) in f2fs_statfs()
1711 F2FS_OPTION(sbi).root_reserved_blocks; in f2fs_statfs()
1715 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_statfs()
1722 buf->f_ffree = min(avail_node_count - valid_node_count(sbi), in f2fs_statfs()
1742 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_quota_options() local
1744 if (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1747 switch (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1761 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_show_quota_options()
1763 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); in f2fs_show_quota_options()
1765 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_show_quota_options()
1767 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); in f2fs_show_quota_options()
1769 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_show_quota_options()
1771 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); in f2fs_show_quota_options()
1779 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_compress_options() local
1783 if (!f2fs_sb_has_compression(sbi)) in f2fs_show_compress_options()
1786 switch (F2FS_OPTION(sbi).compress_algorithm) { in f2fs_show_compress_options()
1802 if (F2FS_OPTION(sbi).compress_level) in f2fs_show_compress_options()
1803 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); in f2fs_show_compress_options()
1806 F2FS_OPTION(sbi).compress_log_size); in f2fs_show_compress_options()
1808 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { in f2fs_show_compress_options()
1810 F2FS_OPTION(sbi).extensions[i]); in f2fs_show_compress_options()
1813 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) { in f2fs_show_compress_options()
1815 F2FS_OPTION(sbi).noextensions[i]); in f2fs_show_compress_options()
1818 if (F2FS_OPTION(sbi).compress_chksum) in f2fs_show_compress_options()
1821 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) in f2fs_show_compress_options()
1823 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) in f2fs_show_compress_options()
1826 if (test_opt(sbi, COMPRESS_CACHE)) in f2fs_show_compress_options()
1833 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); in f2fs_show_options() local
1835 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) in f2fs_show_options()
1837 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) in f2fs_show_options()
1839 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) in f2fs_show_options()
1842 if (test_opt(sbi, GC_MERGE)) in f2fs_show_options()
1845 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_show_options()
1847 if (test_opt(sbi, NORECOVERY)) in f2fs_show_options()
1849 if (test_opt(sbi, DISCARD)) in f2fs_show_options()
1853 if (test_opt(sbi, NOHEAP)) in f2fs_show_options()
1858 if (test_opt(sbi, XATTR_USER)) in f2fs_show_options()
1862 if (test_opt(sbi, INLINE_XATTR)) in f2fs_show_options()
1866 if (test_opt(sbi, INLINE_XATTR_SIZE)) in f2fs_show_options()
1868 F2FS_OPTION(sbi).inline_xattr_size); in f2fs_show_options()
1871 if (test_opt(sbi, POSIX_ACL)) in f2fs_show_options()
1876 if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) in f2fs_show_options()
1878 if (test_opt(sbi, INLINE_DATA)) in f2fs_show_options()
1882 if (test_opt(sbi, INLINE_DENTRY)) in f2fs_show_options()
1886 if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE)) in f2fs_show_options()
1888 if (test_opt(sbi, NOBARRIER)) in f2fs_show_options()
1890 if (test_opt(sbi, FASTBOOT)) in f2fs_show_options()
1892 if (test_opt(sbi, EXTENT_CACHE)) in f2fs_show_options()
1896 if (test_opt(sbi, DATA_FLUSH)) in f2fs_show_options()
1900 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) in f2fs_show_options()
1902 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) in f2fs_show_options()
1904 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG) in f2fs_show_options()
1906 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) in f2fs_show_options()
1908 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); in f2fs_show_options()
1909 if (test_opt(sbi, RESERVE_ROOT)) in f2fs_show_options()
1911 F2FS_OPTION(sbi).root_reserved_blocks, in f2fs_show_options()
1913 F2FS_OPTION(sbi).s_resuid), in f2fs_show_options()
1915 F2FS_OPTION(sbi).s_resgid)); in f2fs_show_options()
1916 if (F2FS_IO_SIZE_BITS(sbi)) in f2fs_show_options()
1918 F2FS_OPTION(sbi).write_io_size_bits); in f2fs_show_options()
1920 if (test_opt(sbi, FAULT_INJECTION)) { in f2fs_show_options()
1922 F2FS_OPTION(sbi).fault_info.inject_rate); in f2fs_show_options()
1924 F2FS_OPTION(sbi).fault_info.inject_type); in f2fs_show_options()
1928 if (test_opt(sbi, QUOTA)) in f2fs_show_options()
1930 if (test_opt(sbi, USRQUOTA)) in f2fs_show_options()
1932 if (test_opt(sbi, GRPQUOTA)) in f2fs_show_options()
1934 if (test_opt(sbi, PRJQUOTA)) in f2fs_show_options()
1937 f2fs_show_quota_options(seq, sbi->sb); in f2fs_show_options()
1938 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) in f2fs_show_options()
1940 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) in f2fs_show_options()
1943 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); in f2fs_show_options()
1945 if (sbi->sb->s_flags & SB_INLINECRYPT) in f2fs_show_options()
1948 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) in f2fs_show_options()
1950 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) in f2fs_show_options()
1953 if (test_opt(sbi, DISABLE_CHECKPOINT)) in f2fs_show_options()
1955 F2FS_OPTION(sbi).unusable_cap); in f2fs_show_options()
1956 if (test_opt(sbi, MERGE_CHECKPOINT)) in f2fs_show_options()
1960 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) in f2fs_show_options()
1962 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) in f2fs_show_options()
1964 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) in f2fs_show_options()
1968 f2fs_show_compress_options(seq, sbi->sb); in f2fs_show_options()
1971 if (test_opt(sbi, ATGC)) in f2fs_show_options()
1974 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK) in f2fs_show_options()
1976 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT) in f2fs_show_options()
1978 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION) in f2fs_show_options()
1984 static void default_options(struct f2fs_sb_info *sbi) in default_options() argument
1987 if (f2fs_sb_has_readonly(sbi)) in default_options()
1988 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; in default_options()
1990 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; in default_options()
1992 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; in default_options()
1993 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in default_options()
1994 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in default_options()
1995 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in default_options()
1996 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); in default_options()
1997 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); in default_options()
1998 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; in default_options()
1999 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; in default_options()
2000 F2FS_OPTION(sbi).compress_ext_cnt = 0; in default_options()
2001 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in default_options()
2002 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in default_options()
2004 sbi->sb->s_flags &= ~SB_INLINECRYPT; in default_options()
2006 set_opt(sbi, INLINE_XATTR); in default_options()
2007 set_opt(sbi, INLINE_DATA); in default_options()
2008 set_opt(sbi, INLINE_DENTRY); in default_options()
2009 set_opt(sbi, EXTENT_CACHE); in default_options()
2010 set_opt(sbi, NOHEAP); in default_options()
2011 clear_opt(sbi, DISABLE_CHECKPOINT); in default_options()
2012 set_opt(sbi, MERGE_CHECKPOINT); in default_options()
2013 F2FS_OPTION(sbi).unusable_cap = 0; in default_options()
2014 sbi->sb->s_flags |= SB_LAZYTIME; in default_options()
2015 set_opt(sbi, FLUSH_MERGE); in default_options()
2016 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) in default_options()
2017 set_opt(sbi, DISCARD); in default_options()
2018 if (f2fs_sb_has_blkzoned(sbi)) { in default_options()
2019 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in default_options()
2020 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; in default_options()
2022 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in default_options()
2023 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; in default_options()
2027 set_opt(sbi, XATTR_USER); in default_options()
2030 set_opt(sbi, POSIX_ACL); in default_options()
2033 f2fs_build_fault_attr(sbi, 0, 0); in default_options()
2040 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_disable_checkpoint() argument
2042 unsigned int s_flags = sbi->sb->s_flags; in f2fs_disable_checkpoint()
2049 f2fs_err(sbi, "checkpoint=disable on readonly fs"); in f2fs_disable_checkpoint()
2052 sbi->sb->s_flags |= SB_ACTIVE; in f2fs_disable_checkpoint()
2054 f2fs_update_time(sbi, DISABLE_TIME); in f2fs_disable_checkpoint()
2056 while (!f2fs_time_over(sbi, DISABLE_TIME)) { in f2fs_disable_checkpoint()
2057 down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2058 err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); in f2fs_disable_checkpoint()
2067 ret = sync_filesystem(sbi->sb); in f2fs_disable_checkpoint()
2073 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2074 if (f2fs_disable_cp_again(sbi, unusable)) { in f2fs_disable_checkpoint()
2079 down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2081 set_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_disable_checkpoint()
2082 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_disable_checkpoint()
2086 spin_lock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2087 sbi->unusable_block_count = unusable; in f2fs_disable_checkpoint()
2088 spin_unlock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2091 up_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2093 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in f2fs_disable_checkpoint()
2097 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_enable_checkpoint() argument
2103 sync_inodes_sb(sbi->sb); in f2fs_enable_checkpoint()
2106 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); in f2fs_enable_checkpoint()
2109 f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); in f2fs_enable_checkpoint()
2111 down_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2112 f2fs_dirty_to_prefree(sbi); in f2fs_enable_checkpoint()
2114 clear_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_enable_checkpoint()
2115 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_enable_checkpoint()
2116 up_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2118 f2fs_sync_fs(sbi->sb, 1); in f2fs_enable_checkpoint()
2123 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_remount() local
2131 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); in f2fs_remount()
2132 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2133 bool no_io_align = !F2FS_IO_ALIGNED(sbi); in f2fs_remount()
2134 bool no_atgc = !test_opt(sbi, ATGC); in f2fs_remount()
2135 bool no_discard = !test_opt(sbi, DISCARD); in f2fs_remount()
2136 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); in f2fs_remount()
2137 bool block_unit_discard = f2fs_block_unit_discard(sbi); in f2fs_remount()
2147 org_mount_opt = sbi->mount_opt; in f2fs_remount()
2151 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; in f2fs_remount()
2153 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_remount()
2155 kstrdup(F2FS_OPTION(sbi).s_qf_names[i], in f2fs_remount()
2169 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { in f2fs_remount()
2170 err = f2fs_commit_super(sbi, false); in f2fs_remount()
2171 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", in f2fs_remount()
2174 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_remount()
2177 default_options(sbi); in f2fs_remount()
2191 if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { in f2fs_remount()
2206 } else if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_remount()
2214 if (no_atgc == !!test_opt(sbi, ATGC)) { in f2fs_remount()
2216 f2fs_warn(sbi, "switch atgc option is not allowed"); in f2fs_remount()
2221 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { in f2fs_remount()
2223 f2fs_warn(sbi, "switch extent_cache option is not allowed"); in f2fs_remount()
2227 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { in f2fs_remount()
2229 f2fs_warn(sbi, "switch io_bits option is not allowed"); in f2fs_remount()
2233 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { in f2fs_remount()
2235 f2fs_warn(sbi, "switch compress_cache option is not allowed"); in f2fs_remount()
2239 if (block_unit_discard != f2fs_block_unit_discard(sbi)) { in f2fs_remount()
2241 f2fs_warn(sbi, "switch discard_unit option is not allowed"); in f2fs_remount()
2245 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2247 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); in f2fs_remount()
2257 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && in f2fs_remount()
2258 !test_opt(sbi, GC_MERGE))) { in f2fs_remount()
2259 if (sbi->gc_thread) { in f2fs_remount()
2260 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2263 } else if (!sbi->gc_thread) { in f2fs_remount()
2264 err = f2fs_start_gc_thread(sbi); in f2fs_remount()
2271 F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) { in f2fs_remount()
2274 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_remount()
2275 set_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2277 clear_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2280 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || in f2fs_remount()
2281 !test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_remount()
2282 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2285 err = f2fs_start_ckpt_thread(sbi); in f2fs_remount()
2287 f2fs_err(sbi, in f2fs_remount()
2299 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { in f2fs_remount()
2300 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2301 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2304 err = f2fs_create_flush_cmd_control(sbi); in f2fs_remount()
2310 if (no_discard == !!test_opt(sbi, DISCARD)) { in f2fs_remount()
2311 if (test_opt(sbi, DISCARD)) { in f2fs_remount()
2312 err = f2fs_start_discard_thread(sbi); in f2fs_remount()
2317 dcc = SM_I(sbi)->dcc_info; in f2fs_remount()
2318 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2320 f2fs_issue_discard_timeout(sbi); in f2fs_remount()
2325 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2326 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2327 err = f2fs_disable_checkpoint(sbi); in f2fs_remount()
2331 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2343 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_remount()
2345 limit_reserve_root(sbi); in f2fs_remount()
2346 adjust_unusable_cap_perc(sbi); in f2fs_remount()
2351 if (f2fs_start_discard_thread(sbi)) in f2fs_remount()
2352 f2fs_warn(sbi, "discard has been stopped"); in f2fs_remount()
2354 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2358 if (f2fs_create_flush_cmd_control(sbi)) in f2fs_remount()
2359 f2fs_warn(sbi, "background flush thread has stopped"); in f2fs_remount()
2361 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2362 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2366 if (f2fs_start_ckpt_thread(sbi)) in f2fs_remount()
2367 f2fs_warn(sbi, "background ckpt thread has stopped"); in f2fs_remount()
2369 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2373 if (f2fs_start_gc_thread(sbi)) in f2fs_remount()
2374 f2fs_warn(sbi, "background gc thread has stopped"); in f2fs_remount()
2376 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2380 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; in f2fs_remount()
2382 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_remount()
2383 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; in f2fs_remount()
2386 sbi->mount_opt = org_mount_opt; in f2fs_remount()
2523 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) in f2fs_quota_on_mount() argument
2525 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { in f2fs_quota_on_mount()
2526 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); in f2fs_quota_on_mount()
2530 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], in f2fs_quota_on_mount()
2531 F2FS_OPTION(sbi).s_jquota_fmt, type); in f2fs_quota_on_mount()
2534 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) in f2fs_enable_quota_files() argument
2539 if (f2fs_sb_has_quota_ino(sbi) && rdonly) { in f2fs_enable_quota_files()
2540 err = f2fs_enable_quotas(sbi->sb); in f2fs_enable_quota_files()
2542 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); in f2fs_enable_quota_files()
2549 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_enable_quota_files()
2550 err = f2fs_quota_on_mount(sbi, i); in f2fs_enable_quota_files()
2555 f2fs_err(sbi, "Cannot turn on quotas: %d on %d", in f2fs_enable_quota_files()
2590 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_enable_quotas() local
2594 test_opt(sbi, USRQUOTA), in f2fs_enable_quotas()
2595 test_opt(sbi, GRPQUOTA), in f2fs_enable_quotas()
2596 test_opt(sbi, PRJQUOTA), in f2fs_enable_quotas()
2600 f2fs_err(sbi, "quota file may be corrupted, skip loading it"); in f2fs_enable_quotas()
2613 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", in f2fs_enable_quotas()
2626 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) in f2fs_quota_sync_file() argument
2628 struct quota_info *dqopt = sb_dqopt(sbi->sb); in f2fs_quota_sync_file()
2632 ret = dquot_writeback_dquots(sbi->sb, type); in f2fs_quota_sync_file()
2641 if (is_journalled_quota(sbi)) in f2fs_quota_sync_file()
2649 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_sync_file()
2655 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_sync() local
2683 f2fs_lock_op(sbi); in f2fs_quota_sync()
2684 down_read(&sbi->quota_sem); in f2fs_quota_sync()
2686 ret = f2fs_quota_sync_file(sbi, cnt); in f2fs_quota_sync()
2688 up_read(&sbi->quota_sem); in f2fs_quota_sync()
2689 f2fs_unlock_op(sbi); in f2fs_quota_sync()
2758 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_off() local
2768 if (is_journalled_quota(sbi)) in f2fs_quota_off()
2769 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_off()
2810 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_commit() local
2813 down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); in f2fs_dquot_commit()
2816 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit()
2817 up_read(&sbi->quota_sem); in f2fs_dquot_commit()
2823 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_acquire() local
2826 down_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2829 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_acquire()
2830 up_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2836 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_release() local
2840 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_release()
2847 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_mark_dquot_dirty() local
2851 if (is_journalled_quota(sbi)) in f2fs_dquot_mark_dquot_dirty()
2852 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); in f2fs_dquot_mark_dquot_dirty()
2859 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_commit_info() local
2863 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit_info()
2944 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_set_context() local
2952 if (f2fs_sb_has_lost_found(sbi) && in f2fs_set_context()
2953 inode->i_ino == F2FS_ROOT_INO(sbi)) in f2fs_set_context()
2980 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_num_devices() local
2982 if (f2fs_is_multi_device(sbi)) in f2fs_get_num_devices()
2983 return sbi->s_ndevs; in f2fs_get_num_devices()
2990 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_devices() local
2993 for (i = 0; i < sbi->s_ndevs; i++) in f2fs_get_devices()
3013 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_nfs_get_inode() local
3016 if (f2fs_check_nid_range(sbi, ino)) in f2fs_nfs_get_inode()
3099 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, in sanity_check_area_boundary() argument
3104 struct super_block *sb = sbi->sb; in sanity_check_area_boundary()
3124 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", in sanity_check_area_boundary()
3131 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3139 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3147 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3155 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3162 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3175 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in sanity_check_area_boundary()
3181 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3190 static int sanity_check_raw_super(struct f2fs_sb_info *sbi, in sanity_check_raw_super() argument
3201 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", in sanity_check_raw_super()
3211 f2fs_info(sbi, "Invalid SB checksum offset: %zu", in sanity_check_raw_super()
3216 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { in sanity_check_raw_super()
3217 f2fs_info(sbi, "Invalid SB checksum value: %u", crc); in sanity_check_raw_super()
3224 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", in sanity_check_raw_super()
3232 f2fs_info(sbi, "Invalid log blocks per segment (%u)", in sanity_check_raw_super()
3242 f2fs_info(sbi, "Invalid log sectorsize (%u)", in sanity_check_raw_super()
3249 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", in sanity_check_raw_super()
3266 f2fs_info(sbi, "Invalid segment count (%u)", segment_count); in sanity_check_raw_super()
3272 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", in sanity_check_raw_super()
3278 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", in sanity_check_raw_super()
3284 f2fs_info(sbi, "Small segment_count (%u < %u * %u)", in sanity_check_raw_super()
3290 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", in sanity_check_raw_super()
3304 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", in sanity_check_raw_super()
3310 !bdev_is_zoned(sbi->sb->s_bdev)) { in sanity_check_raw_super()
3311 f2fs_info(sbi, "Zoned block device path is missing"); in sanity_check_raw_super()
3317 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", in sanity_check_raw_super()
3325 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", in sanity_check_raw_super()
3335 f2fs_info(sbi, "Insane cp_payload (%u >= %u)", in sanity_check_raw_super()
3346 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", in sanity_check_raw_super()
3354 if (sanity_check_area_boundary(sbi, bh)) in sanity_check_raw_super()
3360 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) in f2fs_sanity_check_ckpt() argument
3363 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_sanity_check_ckpt()
3364 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in f2fs_sanity_check_ckpt()
3392 if (!f2fs_sb_has_readonly(sbi) && in f2fs_sanity_check_ckpt()
3395 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); in f2fs_sanity_check_ckpt()
3400 (f2fs_sb_has_readonly(sbi) ? 1 : 0); in f2fs_sanity_check_ckpt()
3404 f2fs_err(sbi, "Wrong user_block_count: %u", in f2fs_sanity_check_ckpt()
3411 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", in f2fs_sanity_check_ckpt()
3417 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_sanity_check_ckpt()
3419 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", in f2fs_sanity_check_ckpt()
3425 blocks_per_seg = sbi->blocks_per_seg; in f2fs_sanity_check_ckpt()
3432 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3438 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3451 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3457 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3468 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3481 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", in f2fs_sanity_check_ckpt()
3486 cp_pack_start_sum = __start_sum_addr(sbi); in f2fs_sanity_check_ckpt()
3487 cp_payload = __cp_payload(sbi); in f2fs_sanity_check_ckpt()
3491 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", in f2fs_sanity_check_ckpt()
3498 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " in f2fs_sanity_check_ckpt()
3511 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", in f2fs_sanity_check_ckpt()
3516 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_sanity_check_ckpt()
3517 f2fs_err(sbi, "A bug case: need to run fsck"); in f2fs_sanity_check_ckpt()
3523 static void init_sb_info(struct f2fs_sb_info *sbi) in init_sb_info() argument
3525 struct f2fs_super_block *raw_super = sbi->raw_super; in init_sb_info()
3528 sbi->log_sectors_per_block = in init_sb_info()
3530 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); in init_sb_info()
3531 sbi->blocksize = 1 << sbi->log_blocksize; in init_sb_info()
3532 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); in init_sb_info()
3533 sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; in init_sb_info()
3534 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); in init_sb_info()
3535 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); in init_sb_info()
3536 sbi->total_sections = le32_to_cpu(raw_super->section_count); in init_sb_info()
3537 sbi->total_node_count = in init_sb_info()
3539 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; in init_sb_info()
3540 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); in init_sb_info()
3541 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); in init_sb_info()
3542 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); in init_sb_info()
3543 sbi->cur_victim_sec = NULL_SECNO; in init_sb_info()
3544 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in init_sb_info()
3545 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in init_sb_info()
3546 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; in init_sb_info()
3547 sbi->migration_granularity = sbi->segs_per_sec; in init_sb_info()
3548 sbi->seq_file_ra_mul = MIN_RA_MUL; in init_sb_info()
3549 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE; in init_sb_info()
3550 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE; in init_sb_info()
3552 sbi->dir_level = DEF_DIR_LEVEL; in init_sb_info()
3553 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; in init_sb_info()
3554 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3555 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3556 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3557 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; in init_sb_info()
3558 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = in init_sb_info()
3560 clear_sbi_flag(sbi, SBI_NEED_FSCK); in init_sb_info()
3563 atomic_set(&sbi->nr_pages[i], 0); in init_sb_info()
3566 atomic_set(&sbi->wb_sync_req[i], 0); in init_sb_info()
3568 INIT_LIST_HEAD(&sbi->s_list); in init_sb_info()
3569 mutex_init(&sbi->umount_mutex); in init_sb_info()
3570 init_rwsem(&sbi->io_order_lock); in init_sb_info()
3571 spin_lock_init(&sbi->cp_lock); in init_sb_info()
3573 sbi->dirty_device = 0; in init_sb_info()
3574 spin_lock_init(&sbi->dev_lock); in init_sb_info()
3576 init_rwsem(&sbi->sb_lock); in init_sb_info()
3577 init_rwsem(&sbi->pin_sem); in init_sb_info()
3580 static int init_percpu_info(struct f2fs_sb_info *sbi) in init_percpu_info() argument
3584 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); in init_percpu_info()
3588 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, in init_percpu_info()
3591 percpu_counter_destroy(&sbi->alloc_valid_block_count); in init_percpu_info()
3620 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) in init_blkz_info() argument
3627 if (!f2fs_sb_has_blkzoned(sbi)) in init_blkz_info()
3630 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != in init_blkz_info()
3633 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); in init_blkz_info()
3634 if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz != in init_blkz_info()
3635 __ilog2_u32(sbi->blocks_per_blkz)) in init_blkz_info()
3637 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz); in init_blkz_info()
3639 sbi->log_blocks_per_blkz; in init_blkz_info()
3643 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, in init_blkz_info()
3651 FDEV(devi).zone_capacity_blocks = f2fs_kzalloc(sbi, in init_blkz_info()
3680 static int read_raw_super_block(struct f2fs_sb_info *sbi, in read_raw_super_block() argument
3684 struct super_block *sb = sbi->sb; in read_raw_super_block()
3697 f2fs_err(sbi, "Unable to read %dth superblock", in read_raw_super_block()
3705 err = sanity_check_raw_super(sbi, bh); in read_raw_super_block()
3707 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", in read_raw_super_block()
3732 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) in f2fs_commit_super() argument
3738 if ((recover && f2fs_readonly(sbi->sb)) || in f2fs_commit_super()
3739 bdev_read_only(sbi->sb->s_bdev)) { in f2fs_commit_super()
3740 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_commit_super()
3745 if (!recover && f2fs_sb_has_sb_chksum(sbi)) { in f2fs_commit_super()
3746 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), in f2fs_commit_super()
3748 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); in f2fs_commit_super()
3752 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); in f2fs_commit_super()
3755 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3763 bh = sb_bread(sbi->sb, sbi->valid_super_block); in f2fs_commit_super()
3766 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3771 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) in f2fs_scan_devices() argument
3773 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_scan_devices()
3780 if (!bdev_is_zoned(sbi->sb->s_bdev)) in f2fs_scan_devices()
3789 sbi->devs = f2fs_kzalloc(sbi, in f2fs_scan_devices()
3793 if (!sbi->devs) in f2fs_scan_devices()
3796 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev); in f2fs_scan_devices()
3797 sbi->aligned_blksize = true; in f2fs_scan_devices()
3807 blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, in f2fs_scan_devices()
3808 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3818 sbi->log_blocks_per_seg) - 1 + in f2fs_scan_devices()
3824 sbi->log_blocks_per_seg) - 1; in f2fs_scan_devices()
3827 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3833 sbi->s_ndevs = i + 1; in f2fs_scan_devices()
3836 sbi->aligned_blksize = false; in f2fs_scan_devices()
3840 !f2fs_sb_has_blkzoned(sbi)) { in f2fs_scan_devices()
3841 f2fs_err(sbi, "Zoned block device feature not enabled"); in f2fs_scan_devices()
3845 if (init_blkz_info(sbi, i)) { in f2fs_scan_devices()
3846 f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); in f2fs_scan_devices()
3851 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", in f2fs_scan_devices()
3860 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", in f2fs_scan_devices()
3865 f2fs_info(sbi, in f2fs_scan_devices()
3866 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); in f2fs_scan_devices()
3870 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) in f2fs_setup_casefold() argument
3873 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { in f2fs_setup_casefold()
3878 if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info, in f2fs_setup_casefold()
3880 f2fs_err(sbi, in f2fs_setup_casefold()
3887 f2fs_err(sbi, in f2fs_setup_casefold()
3894 f2fs_info(sbi, "Using encoding defined by superblock: " in f2fs_setup_casefold()
3898 sbi->sb->s_encoding = encoding; in f2fs_setup_casefold()
3899 sbi->sb->s_encoding_flags = encoding_flags; in f2fs_setup_casefold()
3902 if (f2fs_sb_has_casefold(sbi)) { in f2fs_setup_casefold()
3903 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); in f2fs_setup_casefold()
3910 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) in f2fs_tuning_parameters() argument
3912 struct f2fs_sm_info *sm_i = SM_I(sbi); in f2fs_tuning_parameters()
3916 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in f2fs_tuning_parameters()
3917 if (f2fs_block_unit_discard(sbi)) in f2fs_tuning_parameters()
3922 sbi->readdir_ra = 1; in f2fs_tuning_parameters()
3927 struct f2fs_sb_info *sbi; in f2fs_fill_super() local
3944 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); in f2fs_fill_super()
3945 if (!sbi) in f2fs_fill_super()
3948 sbi->sb = sb; in f2fs_fill_super()
3951 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); in f2fs_fill_super()
3952 if (IS_ERR(sbi->s_chksum_driver)) { in f2fs_fill_super()
3953 f2fs_err(sbi, "Cannot load crc32 driver."); in f2fs_fill_super()
3954 err = PTR_ERR(sbi->s_chksum_driver); in f2fs_fill_super()
3955 sbi->s_chksum_driver = NULL; in f2fs_fill_super()
3961 f2fs_err(sbi, "unable to set blocksize"); in f2fs_fill_super()
3965 err = read_raw_super_block(sbi, &raw_super, &valid_super_block, in f2fs_fill_super()
3970 sb->s_fs_info = sbi; in f2fs_fill_super()
3971 sbi->raw_super = raw_super; in f2fs_fill_super()
3974 if (f2fs_sb_has_inode_chksum(sbi)) in f2fs_fill_super()
3975 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, in f2fs_fill_super()
3978 default_options(sbi); in f2fs_fill_super()
3994 err = f2fs_setup_casefold(sbi); in f2fs_fill_super()
4003 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_fill_super()
4005 if (f2fs_qf_ino(sbi->sb, i)) in f2fs_fill_super()
4006 sbi->nquota_files++; in f2fs_fill_super()
4023 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_fill_super()
4028 sbi->valid_super_block = valid_super_block; in f2fs_fill_super()
4029 init_rwsem(&sbi->gc_lock); in f2fs_fill_super()
4030 mutex_init(&sbi->writepages); in f2fs_fill_super()
4031 init_rwsem(&sbi->cp_global_sem); in f2fs_fill_super()
4032 init_rwsem(&sbi->node_write); in f2fs_fill_super()
4033 init_rwsem(&sbi->node_change); in f2fs_fill_super()
4036 set_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4037 spin_lock_init(&sbi->stat_lock); in f2fs_fill_super()
4043 sbi->write_io[i] = in f2fs_fill_super()
4044 f2fs_kmalloc(sbi, in f2fs_fill_super()
4048 if (!sbi->write_io[i]) { in f2fs_fill_super()
4054 init_rwsem(&sbi->write_io[i][j].io_rwsem); in f2fs_fill_super()
4055 sbi->write_io[i][j].sbi = sbi; in f2fs_fill_super()
4056 sbi->write_io[i][j].bio = NULL; in f2fs_fill_super()
4057 spin_lock_init(&sbi->write_io[i][j].io_lock); in f2fs_fill_super()
4058 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); in f2fs_fill_super()
4059 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); in f2fs_fill_super()
4060 init_rwsem(&sbi->write_io[i][j].bio_list_lock); in f2fs_fill_super()
4064 init_rwsem(&sbi->cp_rwsem); in f2fs_fill_super()
4065 init_rwsem(&sbi->quota_sem); in f2fs_fill_super()
4066 init_waitqueue_head(&sbi->cp_wait); in f2fs_fill_super()
4067 init_sb_info(sbi); in f2fs_fill_super()
4069 err = f2fs_init_iostat(sbi); in f2fs_fill_super()
4073 err = init_percpu_info(sbi); in f2fs_fill_super()
4077 if (F2FS_IO_ALIGNED(sbi)) { in f2fs_fill_super()
4078 sbi->write_io_dummy = in f2fs_fill_super()
4079 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); in f2fs_fill_super()
4080 if (!sbi->write_io_dummy) { in f2fs_fill_super()
4087 err = f2fs_init_xattr_caches(sbi); in f2fs_fill_super()
4090 err = f2fs_init_page_array_cache(sbi); in f2fs_fill_super()
4095 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); in f2fs_fill_super()
4096 if (IS_ERR(sbi->meta_inode)) { in f2fs_fill_super()
4097 f2fs_err(sbi, "Failed to read F2FS meta data inode"); in f2fs_fill_super()
4098 err = PTR_ERR(sbi->meta_inode); in f2fs_fill_super()
4102 err = f2fs_get_valid_checkpoint(sbi); in f2fs_fill_super()
4104 f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); in f2fs_fill_super()
4108 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) in f2fs_fill_super()
4109 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_fill_super()
4110 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { in f2fs_fill_super()
4111 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4112 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; in f2fs_fill_super()
4115 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) in f2fs_fill_super()
4116 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4119 err = f2fs_scan_devices(sbi); in f2fs_fill_super()
4121 f2fs_err(sbi, "Failed to find devices"); in f2fs_fill_super()
4125 err = f2fs_init_post_read_wq(sbi); in f2fs_fill_super()
4127 f2fs_err(sbi, "Failed to initialize post read workqueue"); in f2fs_fill_super()
4131 sbi->total_valid_node_count = in f2fs_fill_super()
4132 le32_to_cpu(sbi->ckpt->valid_node_count); in f2fs_fill_super()
4133 percpu_counter_set(&sbi->total_valid_inode_count, in f2fs_fill_super()
4134 le32_to_cpu(sbi->ckpt->valid_inode_count)); in f2fs_fill_super()
4135 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); in f2fs_fill_super()
4136 sbi->total_valid_block_count = in f2fs_fill_super()
4137 le64_to_cpu(sbi->ckpt->valid_block_count); in f2fs_fill_super()
4138 sbi->last_valid_block_count = sbi->total_valid_block_count; in f2fs_fill_super()
4139 sbi->reserved_blocks = 0; in f2fs_fill_super()
4140 sbi->current_reserved_blocks = 0; in f2fs_fill_super()
4141 limit_reserve_root(sbi); in f2fs_fill_super()
4142 adjust_unusable_cap_perc(sbi); in f2fs_fill_super()
4145 INIT_LIST_HEAD(&sbi->inode_list[i]); in f2fs_fill_super()
4146 spin_lock_init(&sbi->inode_lock[i]); in f2fs_fill_super()
4148 mutex_init(&sbi->flush_lock); in f2fs_fill_super()
4150 f2fs_init_extent_cache_info(sbi); in f2fs_fill_super()
4152 f2fs_init_ino_entry_info(sbi); in f2fs_fill_super()
4154 f2fs_init_fsync_node_info(sbi); in f2fs_fill_super()
4157 f2fs_init_ckpt_req_control(sbi); in f2fs_fill_super()
4158 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && in f2fs_fill_super()
4159 test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_fill_super()
4160 err = f2fs_start_ckpt_thread(sbi); in f2fs_fill_super()
4162 f2fs_err(sbi, in f2fs_fill_super()
4170 err = f2fs_build_segment_manager(sbi); in f2fs_fill_super()
4172 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", in f2fs_fill_super()
4176 err = f2fs_build_node_manager(sbi); in f2fs_fill_super()
4178 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", in f2fs_fill_super()
4184 sbi->sectors_written_start = f2fs_get_sectors_written(sbi); in f2fs_fill_super()
4187 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); in f2fs_fill_super()
4188 if (__exist_node_summaries(sbi)) in f2fs_fill_super()
4189 sbi->kbytes_written = in f2fs_fill_super()
4192 f2fs_build_gc_manager(sbi); in f2fs_fill_super()
4194 err = f2fs_build_stats(sbi); in f2fs_fill_super()
4199 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); in f2fs_fill_super()
4200 if (IS_ERR(sbi->node_inode)) { in f2fs_fill_super()
4201 f2fs_err(sbi, "Failed to read node inode"); in f2fs_fill_super()
4202 err = PTR_ERR(sbi->node_inode); in f2fs_fill_super()
4207 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); in f2fs_fill_super()
4209 f2fs_err(sbi, "Failed to read root inode"); in f2fs_fill_super()
4226 err = f2fs_init_compress_inode(sbi); in f2fs_fill_super()
4230 err = f2fs_register_sysfs(sbi); in f2fs_fill_super()
4236 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4239 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); in f2fs_fill_super()
4243 err = f2fs_recover_orphan_inodes(sbi); in f2fs_fill_super()
4247 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) in f2fs_fill_super()
4251 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && in f2fs_fill_super()
4252 !test_opt(sbi, NORECOVERY)) { in f2fs_fill_super()
4257 if (f2fs_hw_is_readonly(sbi)) { in f2fs_fill_super()
4258 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in f2fs_fill_super()
4259 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4262 f2fs_err(sbi, "Need to recover fsync data, but " in f2fs_fill_super()
4269 f2fs_info(sbi, "write access unavailable, skipping recovery"); in f2fs_fill_super()
4274 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4279 err = f2fs_recover_fsync_data(sbi, false); in f2fs_fill_super()
4284 f2fs_err(sbi, "Cannot recover all fsync data errno=%d", in f2fs_fill_super()
4289 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4293 f2fs_err(sbi, "Need to recover fsync data"); in f2fs_fill_super()
4302 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) { in f2fs_fill_super()
4303 err = f2fs_check_write_pointer(sbi); in f2fs_fill_super()
4309 f2fs_init_inmem_curseg(sbi); in f2fs_fill_super()
4312 clear_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4314 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_fill_super()
4315 err = f2fs_disable_checkpoint(sbi); in f2fs_fill_super()
4318 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { in f2fs_fill_super()
4319 f2fs_enable_checkpoint(sbi); in f2fs_fill_super()
4326 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || in f2fs_fill_super()
4327 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4329 err = f2fs_start_gc_thread(sbi); in f2fs_fill_super()
4337 err = f2fs_commit_super(sbi, true); in f2fs_fill_super()
4338 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", in f2fs_fill_super()
4339 sbi->valid_super_block ? 1 : 2, err); in f2fs_fill_super()
4342 f2fs_join_shrinker(sbi); in f2fs_fill_super()
4344 f2fs_tuning_parameters(sbi); in f2fs_fill_super()
4346 f2fs_notice(sbi, "Mounted with checkpoint version = %llx", in f2fs_fill_super()
4347 cur_cp_version(F2FS_CKPT(sbi))); in f2fs_fill_super()
4348 f2fs_update_time(sbi, CP_TIME); in f2fs_fill_super()
4349 f2fs_update_time(sbi, REQ_TIME); in f2fs_fill_super()
4350 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4355 sync_filesystem(sbi->sb); in f2fs_fill_super()
4361 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) in f2fs_fill_super()
4362 f2fs_quota_off_umount(sbi->sb); in f2fs_fill_super()
4370 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_fill_super()
4373 f2fs_unregister_sysfs(sbi); in f2fs_fill_super()
4375 f2fs_destroy_compress_inode(sbi); in f2fs_fill_super()
4380 f2fs_release_ino_entry(sbi, true); in f2fs_fill_super()
4381 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_fill_super()
4382 iput(sbi->node_inode); in f2fs_fill_super()
4383 sbi->node_inode = NULL; in f2fs_fill_super()
4385 f2fs_destroy_stats(sbi); in f2fs_fill_super()
4388 f2fs_stop_discard_thread(sbi); in f2fs_fill_super()
4389 f2fs_destroy_node_manager(sbi); in f2fs_fill_super()
4391 f2fs_destroy_segment_manager(sbi); in f2fs_fill_super()
4392 f2fs_destroy_post_read_wq(sbi); in f2fs_fill_super()
4394 f2fs_stop_ckpt_thread(sbi); in f2fs_fill_super()
4396 destroy_device_list(sbi); in f2fs_fill_super()
4397 kvfree(sbi->ckpt); in f2fs_fill_super()
4399 make_bad_inode(sbi->meta_inode); in f2fs_fill_super()
4400 iput(sbi->meta_inode); in f2fs_fill_super()
4401 sbi->meta_inode = NULL; in f2fs_fill_super()
4403 f2fs_destroy_page_array_cache(sbi); in f2fs_fill_super()
4405 f2fs_destroy_xattr_caches(sbi); in f2fs_fill_super()
4407 mempool_destroy(sbi->write_io_dummy); in f2fs_fill_super()
4409 destroy_percpu_info(sbi); in f2fs_fill_super()
4411 f2fs_destroy_iostat(sbi); in f2fs_fill_super()
4414 kvfree(sbi->write_io[i]); in f2fs_fill_super()
4423 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_fill_super()
4425 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_fill_super()
4430 if (sbi->s_chksum_driver) in f2fs_fill_super()
4431 crypto_free_shash(sbi->s_chksum_driver); in f2fs_fill_super()
4432 kfree(sbi); in f2fs_fill_super()
4452 struct f2fs_sb_info *sbi = F2FS_SB(sb); in kill_f2fs_super() local
4454 set_sbi_flag(sbi, SBI_IS_CLOSE); in kill_f2fs_super()
4455 f2fs_stop_gc_thread(sbi); in kill_f2fs_super()
4456 f2fs_stop_discard_thread(sbi); in kill_f2fs_super()
4463 if (test_opt(sbi, COMPRESS_CACHE)) in kill_f2fs_super()
4464 truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); in kill_f2fs_super()
4467 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in kill_f2fs_super()
4468 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in kill_f2fs_super()
4472 f2fs_write_checkpoint(sbi, &cpc); in kill_f2fs_super()
4475 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) in kill_f2fs_super()