Lines Matching full:sbi
68 int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate, in f2fs_build_fault_attr() argument
71 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; in f2fs_build_fault_attr()
89 f2fs_info(sbi, in f2fs_build_fault_attr()
275 void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate, in f2fs_printk() argument
289 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
292 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
336 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) in limit_reserve_root() argument
338 block_t limit = min((sbi->user_block_count >> 3), in limit_reserve_root()
339 sbi->user_block_count - sbi->reserved_blocks); in limit_reserve_root()
342 if (test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
343 F2FS_OPTION(sbi).root_reserved_blocks > limit) { in limit_reserve_root()
344 F2FS_OPTION(sbi).root_reserved_blocks = limit; in limit_reserve_root()
345 f2fs_info(sbi, "Reduce reserved blocks for root = %u", in limit_reserve_root()
346 F2FS_OPTION(sbi).root_reserved_blocks); in limit_reserve_root()
348 if (!test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
349 (!uid_eq(F2FS_OPTION(sbi).s_resuid, in limit_reserve_root()
351 !gid_eq(F2FS_OPTION(sbi).s_resgid, in limit_reserve_root()
353 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", in limit_reserve_root()
355 F2FS_OPTION(sbi).s_resuid), in limit_reserve_root()
357 F2FS_OPTION(sbi).s_resgid)); in limit_reserve_root()
360 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) in adjust_unusable_cap_perc() argument
362 if (!F2FS_OPTION(sbi).unusable_cap_perc) in adjust_unusable_cap_perc()
365 if (F2FS_OPTION(sbi).unusable_cap_perc == 100) in adjust_unusable_cap_perc()
366 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; in adjust_unusable_cap_perc()
368 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * in adjust_unusable_cap_perc()
369 F2FS_OPTION(sbi).unusable_cap_perc; in adjust_unusable_cap_perc()
371 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", in adjust_unusable_cap_perc()
372 F2FS_OPTION(sbi).unusable_cap, in adjust_unusable_cap_perc()
373 F2FS_OPTION(sbi).unusable_cap_perc); in adjust_unusable_cap_perc()
389 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_qf_name() local
393 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
394 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_set_qf_name()
397 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_set_qf_name()
398 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); in f2fs_set_qf_name()
404 f2fs_err(sbi, "Not enough memory for storing quotafile name"); in f2fs_set_qf_name()
407 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
408 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) in f2fs_set_qf_name()
411 f2fs_err(sbi, "%s quota file already specified", in f2fs_set_qf_name()
416 f2fs_err(sbi, "quotafile must be on filesystem root"); in f2fs_set_qf_name()
419 F2FS_OPTION(sbi).s_qf_names[qtype] = qname; in f2fs_set_qf_name()
420 set_opt(sbi, QUOTA); in f2fs_set_qf_name()
429 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_clear_qf_name() local
431 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_clear_qf_name()
432 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_clear_qf_name()
435 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); in f2fs_clear_qf_name()
436 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; in f2fs_clear_qf_name()
440 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) in f2fs_check_quota_options() argument
447 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { in f2fs_check_quota_options()
448 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); in f2fs_check_quota_options()
451 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || in f2fs_check_quota_options()
452 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || in f2fs_check_quota_options()
453 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { in f2fs_check_quota_options()
454 if (test_opt(sbi, USRQUOTA) && in f2fs_check_quota_options()
455 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_check_quota_options()
456 clear_opt(sbi, USRQUOTA); in f2fs_check_quota_options()
458 if (test_opt(sbi, GRPQUOTA) && in f2fs_check_quota_options()
459 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_check_quota_options()
460 clear_opt(sbi, GRPQUOTA); in f2fs_check_quota_options()
462 if (test_opt(sbi, PRJQUOTA) && in f2fs_check_quota_options()
463 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_check_quota_options()
464 clear_opt(sbi, PRJQUOTA); in f2fs_check_quota_options()
466 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || in f2fs_check_quota_options()
467 test_opt(sbi, PRJQUOTA)) { in f2fs_check_quota_options()
468 f2fs_err(sbi, "old and new quota format mixing"); in f2fs_check_quota_options()
472 if (!F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
473 f2fs_err(sbi, "journaled quota format not specified"); in f2fs_check_quota_options()
478 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
479 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); in f2fs_check_quota_options()
480 F2FS_OPTION(sbi).s_jquota_fmt = 0; in f2fs_check_quota_options()
491 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_test_dummy_encryption() local
497 &F2FS_OPTION(sbi).dummy_enc_policy; in f2fs_set_test_dummy_encryption()
501 f2fs_warn(sbi, "test_dummy_encryption option not supported"); in f2fs_set_test_dummy_encryption()
505 if (!f2fs_sb_has_encrypt(sbi)) { in f2fs_set_test_dummy_encryption()
506 f2fs_err(sbi, "Encrypt feature is off"); in f2fs_set_test_dummy_encryption()
517 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); in f2fs_set_test_dummy_encryption()
524 f2fs_warn(sbi, in f2fs_set_test_dummy_encryption()
527 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", in f2fs_set_test_dummy_encryption()
530 f2fs_warn(sbi, "Error processing option \"%s\" [%d]", in f2fs_set_test_dummy_encryption()
534 f2fs_warn(sbi, "Test dummy encryption mode enabled"); in f2fs_set_test_dummy_encryption()
539 static bool is_compress_extension_exist(struct f2fs_sb_info *sbi, in is_compress_extension_exist() argument
547 ext = F2FS_OPTION(sbi).extensions; in is_compress_extension_exist()
548 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in is_compress_extension_exist()
550 ext = F2FS_OPTION(sbi).noextensions; in is_compress_extension_exist()
551 ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in is_compress_extension_exist()
569 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi) in f2fs_test_compress_extension() argument
575 ext = F2FS_OPTION(sbi).extensions; in f2fs_test_compress_extension()
576 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in f2fs_test_compress_extension()
577 noext = F2FS_OPTION(sbi).noextensions; in f2fs_test_compress_extension()
578 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in f2fs_test_compress_extension()
585 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files"); in f2fs_test_compress_extension()
590 …f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension… in f2fs_test_compress_extension()
600 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_lz4hc_level() argument
606 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
613 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_lz4hc_level()
620 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); in f2fs_set_lz4hc_level()
624 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_lz4hc_level()
628 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
631 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); in f2fs_set_lz4hc_level()
638 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_zstd_level() argument
644 F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL; in f2fs_set_zstd_level()
651 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_zstd_level()
659 f2fs_info(sbi, "do not support negative compress level: %d", level); in f2fs_set_zstd_level()
664 f2fs_info(sbi, "invalid zstd compress level: %d", level); in f2fs_set_zstd_level()
668 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_zstd_level()
676 struct f2fs_sb_info *sbi = F2FS_SB(sb); in parse_options() local
711 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in parse_options()
713 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
714 f2fs_warn(sbi, "zoned devices need bggc"); in parse_options()
718 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; in parse_options()
720 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; in parse_options()
728 set_opt(sbi, DISABLE_ROLL_FORWARD); in parse_options()
732 set_opt(sbi, NORECOVERY); in parse_options()
737 if (!f2fs_hw_support_discard(sbi)) { in parse_options()
738 f2fs_warn(sbi, "device does not support discard"); in parse_options()
741 set_opt(sbi, DISCARD); in parse_options()
744 if (f2fs_hw_should_discard(sbi)) { in parse_options()
745 f2fs_warn(sbi, "discard is required for zoned block devices"); in parse_options()
748 clear_opt(sbi, DISCARD); in parse_options()
752 f2fs_warn(sbi, "heap/no_heap options were deprecated"); in parse_options()
756 set_opt(sbi, XATTR_USER); in parse_options()
759 clear_opt(sbi, XATTR_USER); in parse_options()
762 set_opt(sbi, INLINE_XATTR); in parse_options()
765 clear_opt(sbi, INLINE_XATTR); in parse_options()
770 set_opt(sbi, INLINE_XATTR_SIZE); in parse_options()
771 F2FS_OPTION(sbi).inline_xattr_size = arg; in parse_options()
775 f2fs_info(sbi, "user_xattr options not supported"); in parse_options()
778 f2fs_info(sbi, "nouser_xattr options not supported"); in parse_options()
781 f2fs_info(sbi, "inline_xattr options not supported"); in parse_options()
784 f2fs_info(sbi, "noinline_xattr options not supported"); in parse_options()
789 set_opt(sbi, POSIX_ACL); in parse_options()
792 clear_opt(sbi, POSIX_ACL); in parse_options()
796 f2fs_info(sbi, "acl options not supported"); in parse_options()
799 f2fs_info(sbi, "noacl options not supported"); in parse_options()
808 F2FS_OPTION(sbi).active_logs = arg; in parse_options()
811 set_opt(sbi, DISABLE_EXT_IDENTIFY); in parse_options()
814 set_opt(sbi, INLINE_DATA); in parse_options()
817 set_opt(sbi, INLINE_DENTRY); in parse_options()
820 clear_opt(sbi, INLINE_DENTRY); in parse_options()
823 set_opt(sbi, FLUSH_MERGE); in parse_options()
826 clear_opt(sbi, FLUSH_MERGE); in parse_options()
829 set_opt(sbi, NOBARRIER); in parse_options()
832 clear_opt(sbi, NOBARRIER); in parse_options()
835 set_opt(sbi, FASTBOOT); in parse_options()
838 set_opt(sbi, READ_EXTENT_CACHE); in parse_options()
841 if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_DEVICE_ALIAS)) { in parse_options()
842 f2fs_err(sbi, "device aliasing requires extent cache"); in parse_options()
845 clear_opt(sbi, READ_EXTENT_CACHE); in parse_options()
848 clear_opt(sbi, INLINE_DATA); in parse_options()
851 set_opt(sbi, DATA_FLUSH); in parse_options()
856 if (test_opt(sbi, RESERVE_ROOT)) { in parse_options()
857 f2fs_info(sbi, "Preserve previous reserve_root=%u", in parse_options()
858 F2FS_OPTION(sbi).root_reserved_blocks); in parse_options()
860 F2FS_OPTION(sbi).root_reserved_blocks = arg; in parse_options()
861 set_opt(sbi, RESERVE_ROOT); in parse_options()
869 f2fs_err(sbi, "Invalid uid value %d", arg); in parse_options()
872 F2FS_OPTION(sbi).s_resuid = uid; in parse_options()
879 f2fs_err(sbi, "Invalid gid value %d", arg); in parse_options()
882 F2FS_OPTION(sbi).s_resgid = gid; in parse_options()
890 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in parse_options()
892 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in parse_options()
894 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_SEG; in parse_options()
896 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_BLK; in parse_options()
907 if (f2fs_build_fault_attr(sbi, arg, in parse_options()
910 set_opt(sbi, FAULT_INJECTION); in parse_options()
916 if (f2fs_build_fault_attr(sbi, 0, arg)) in parse_options()
918 set_opt(sbi, FAULT_INJECTION); in parse_options()
922 f2fs_info(sbi, "fault_injection options not supported"); in parse_options()
926 f2fs_info(sbi, "fault_type options not supported"); in parse_options()
938 set_opt(sbi, USRQUOTA); in parse_options()
941 set_opt(sbi, GRPQUOTA); in parse_options()
944 set_opt(sbi, PRJQUOTA); in parse_options()
977 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; in parse_options()
980 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; in parse_options()
983 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; in parse_options()
986 clear_opt(sbi, QUOTA); in parse_options()
987 clear_opt(sbi, USRQUOTA); in parse_options()
988 clear_opt(sbi, GRPQUOTA); in parse_options()
989 clear_opt(sbi, PRJQUOTA); in parse_options()
1006 f2fs_info(sbi, "quota operations not supported"); in parse_options()
1015 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in parse_options()
1017 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in parse_options()
1029 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in parse_options()
1031 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; in parse_options()
1033 F2FS_OPTION(sbi).fsync_mode = in parse_options()
1051 f2fs_info(sbi, "inline encryption not supported"); in parse_options()
1059 F2FS_OPTION(sbi).unusable_cap_perc = arg; in parse_options()
1060 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1065 F2FS_OPTION(sbi).unusable_cap = arg; in parse_options()
1066 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1069 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1072 clear_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1075 set_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1078 clear_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1082 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1083 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1091 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1092 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1095 f2fs_info(sbi, "kernel doesn't support lzo compression"); in parse_options()
1099 ret = f2fs_set_lz4hc_level(sbi, name); in parse_options()
1104 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1107 f2fs_info(sbi, "kernel doesn't support lz4 compression"); in parse_options()
1111 ret = f2fs_set_zstd_level(sbi, name); in parse_options()
1116 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1119 f2fs_info(sbi, "kernel doesn't support zstd compression"); in parse_options()
1123 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1124 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1127 f2fs_info(sbi, "kernel doesn't support lzorle compression"); in parse_options()
1136 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1137 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1144 f2fs_err(sbi, in parse_options()
1148 F2FS_OPTION(sbi).compress_log_size = arg; in parse_options()
1151 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1152 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1159 ext = F2FS_OPTION(sbi).extensions; in parse_options()
1160 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in parse_options()
1164 f2fs_err(sbi, in parse_options()
1170 if (is_compress_extension_exist(sbi, name, true)) { in parse_options()
1180 F2FS_OPTION(sbi).compress_ext_cnt++; in parse_options()
1184 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1185 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1192 noext = F2FS_OPTION(sbi).noextensions; in parse_options()
1193 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in parse_options()
1197 f2fs_err(sbi, in parse_options()
1203 if (is_compress_extension_exist(sbi, name, false)) { in parse_options()
1213 F2FS_OPTION(sbi).nocompress_ext_cnt++; in parse_options()
1217 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1218 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1221 F2FS_OPTION(sbi).compress_chksum = true; in parse_options()
1224 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1225 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1232 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in parse_options()
1234 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; in parse_options()
1242 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1243 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1246 set_opt(sbi, COMPRESS_CACHE); in parse_options()
1256 f2fs_info(sbi, "compression options not supported"); in parse_options()
1260 set_opt(sbi, ATGC); in parse_options()
1263 set_opt(sbi, GC_MERGE); in parse_options()
1266 clear_opt(sbi, GC_MERGE); in parse_options()
1273 F2FS_OPTION(sbi).discard_unit = in parse_options()
1276 F2FS_OPTION(sbi).discard_unit = in parse_options()
1279 F2FS_OPTION(sbi).discard_unit = in parse_options()
1292 F2FS_OPTION(sbi).memory_mode = in parse_options()
1295 F2FS_OPTION(sbi).memory_mode = in parse_options()
1304 set_opt(sbi, AGE_EXTENT_CACHE); in parse_options()
1311 F2FS_OPTION(sbi).errors = in parse_options()
1314 F2FS_OPTION(sbi).errors = in parse_options()
1317 F2FS_OPTION(sbi).errors = in parse_options()
1326 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", in parse_options()
1333 if (f2fs_check_quota_options(sbi)) in parse_options()
1336 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1337 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1340 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1341 …f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1346 if (!IS_ENABLED(CONFIG_UNICODE) && f2fs_sb_has_casefold(sbi)) { in parse_options()
1347 f2fs_err(sbi, in parse_options()
1357 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1359 if (F2FS_OPTION(sbi).discard_unit != in parse_options()
1361 …f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default… in parse_options()
1362 F2FS_OPTION(sbi).discard_unit = in parse_options()
1366 if (F2FS_OPTION(sbi).fs_mode != FS_MODE_LFS) { in parse_options()
1367 f2fs_info(sbi, "Only lfs mode is allowed with zoned block device feature"); in parse_options()
1371 f2fs_err(sbi, "Zoned block device support is not enabled"); in parse_options()
1377 if (f2fs_test_compress_extension(sbi)) { in parse_options()
1378 f2fs_err(sbi, "invalid compress or nocompress extension"); in parse_options()
1383 if (test_opt(sbi, INLINE_XATTR_SIZE)) { in parse_options()
1386 if (!f2fs_sb_has_extra_attr(sbi) || in parse_options()
1387 !f2fs_sb_has_flexible_inline_xattr(sbi)) { in parse_options()
1388 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); in parse_options()
1391 if (!test_opt(sbi, INLINE_XATTR)) { in parse_options()
1392 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); in parse_options()
1399 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || in parse_options()
1400 F2FS_OPTION(sbi).inline_xattr_size > max_size) { in parse_options()
1401 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", in parse_options()
1407 if (test_opt(sbi, ATGC) && f2fs_lfs_mode(sbi)) { in parse_options()
1408 f2fs_err(sbi, "LFS is not compatible with ATGC"); in parse_options()
1412 if (f2fs_is_readonly(sbi) && test_opt(sbi, FLUSH_MERGE)) { in parse_options()
1413 f2fs_err(sbi, "FLUSH_MERGE not compatible with readonly mode"); in parse_options()
1417 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1418 f2fs_err(sbi, "Allow to mount readonly mode only"); in parse_options()
1456 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_drop_inode() local
1463 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_drop_inode()
1464 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_drop_inode()
1465 inode->i_ino == F2FS_META_INO(sbi)) { in f2fs_drop_inode()
1514 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_dirtied() local
1517 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1522 stat_inc_dirty_inode(sbi, DIRTY_META); in f2fs_inode_dirtied()
1526 &sbi->inode_list[DIRTY_META]); in f2fs_inode_dirtied()
1527 inc_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_dirtied()
1529 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1539 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_synced() local
1541 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1543 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1548 dec_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_synced()
1553 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1563 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_dirty_inode() local
1565 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_dirty_inode()
1566 inode->i_ino == F2FS_META_INO(sbi)) in f2fs_dirty_inode()
1581 static void destroy_percpu_info(struct f2fs_sb_info *sbi) in destroy_percpu_info() argument
1583 percpu_counter_destroy(&sbi->total_valid_inode_count); in destroy_percpu_info()
1584 percpu_counter_destroy(&sbi->rf_node_block_count); in destroy_percpu_info()
1585 percpu_counter_destroy(&sbi->alloc_valid_block_count); in destroy_percpu_info()
1588 static void destroy_device_list(struct f2fs_sb_info *sbi) in destroy_device_list() argument
1592 for (i = 0; i < sbi->s_ndevs; i++) { in destroy_device_list()
1599 kvfree(sbi->devs); in destroy_device_list()
1604 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_put_super() local
1610 f2fs_unregister_sysfs(sbi); in f2fs_put_super()
1615 mutex_lock(&sbi->umount_mutex); in f2fs_put_super()
1621 f2fs_stop_ckpt_thread(sbi); in f2fs_put_super()
1628 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in f2fs_put_super()
1629 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { in f2fs_put_super()
1633 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_put_super()
1634 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1638 done = f2fs_issue_discard_timeout(sbi); in f2fs_put_super()
1639 if (f2fs_realtime_discard_enable(sbi) && !sbi->discard_blks && done) { in f2fs_put_super()
1643 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_put_super()
1644 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1651 f2fs_release_ino_entry(sbi, true); in f2fs_put_super()
1653 f2fs_leave_shrinker(sbi); in f2fs_put_super()
1654 mutex_unlock(&sbi->umount_mutex); in f2fs_put_super()
1657 f2fs_flush_merged_writes(sbi); in f2fs_put_super()
1659 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); in f2fs_put_super()
1661 if (err || f2fs_cp_error(sbi)) { in f2fs_put_super()
1662 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_put_super()
1663 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_put_super()
1667 if (!get_pages(sbi, i)) in f2fs_put_super()
1669 f2fs_err(sbi, "detect filesystem reference count leak during " in f2fs_put_super()
1670 "umount, type: %d, count: %lld", i, get_pages(sbi, i)); in f2fs_put_super()
1671 f2fs_bug_on(sbi, 1); in f2fs_put_super()
1674 f2fs_bug_on(sbi, sbi->fsync_node_num); in f2fs_put_super()
1676 f2fs_destroy_compress_inode(sbi); in f2fs_put_super()
1678 iput(sbi->node_inode); in f2fs_put_super()
1679 sbi->node_inode = NULL; in f2fs_put_super()
1681 iput(sbi->meta_inode); in f2fs_put_super()
1682 sbi->meta_inode = NULL; in f2fs_put_super()
1688 f2fs_destroy_stats(sbi); in f2fs_put_super()
1691 f2fs_destroy_node_manager(sbi); in f2fs_put_super()
1692 f2fs_destroy_segment_manager(sbi); in f2fs_put_super()
1694 /* flush s_error_work before sbi destroy */ in f2fs_put_super()
1695 flush_work(&sbi->s_error_work); in f2fs_put_super()
1697 f2fs_destroy_post_read_wq(sbi); in f2fs_put_super()
1699 kvfree(sbi->ckpt); in f2fs_put_super()
1701 kfree(sbi->raw_super); in f2fs_put_super()
1703 f2fs_destroy_page_array_cache(sbi); in f2fs_put_super()
1704 f2fs_destroy_xattr_caches(sbi); in f2fs_put_super()
1707 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_put_super()
1709 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_put_super()
1710 destroy_percpu_info(sbi); in f2fs_put_super()
1711 f2fs_destroy_iostat(sbi); in f2fs_put_super()
1713 kvfree(sbi->write_io[i]); in f2fs_put_super()
1721 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_sync_fs() local
1724 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_fs()
1726 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_sync_fs()
1731 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_sync_fs()
1735 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_sync_fs()
1736 err = f2fs_issue_checkpoint(sbi); in f2fs_sync_fs()
1744 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_freeze() local
1750 if (unlikely(f2fs_cp_error(sbi))) in f2fs_freeze()
1754 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY)) in f2fs_freeze()
1757 sbi->umount_lock_holder = current; in f2fs_freeze()
1760 f2fs_flush_ckpt_thread(sbi); in f2fs_freeze()
1762 sbi->umount_lock_holder = NULL; in f2fs_freeze()
1765 set_sbi_flag(sbi, SBI_IS_FREEZING); in f2fs_freeze()
1771 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_unfreeze() local
1780 if (test_opt(sbi, DISCARD) && !f2fs_hw_support_discard(sbi)) in f2fs_unfreeze()
1781 f2fs_issue_discard_timeout(sbi); in f2fs_unfreeze()
1835 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_statfs() local
1841 total_count = le64_to_cpu(sbi->raw_super->block_count); in f2fs_statfs()
1842 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); in f2fs_statfs()
1844 buf->f_bsize = sbi->blocksize; in f2fs_statfs()
1848 spin_lock(&sbi->stat_lock); in f2fs_statfs()
1850 user_block_count = sbi->user_block_count; in f2fs_statfs()
1851 total_valid_node_count = valid_node_count(sbi); in f2fs_statfs()
1852 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_statfs()
1853 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - in f2fs_statfs()
1854 sbi->current_reserved_blocks; in f2fs_statfs()
1856 if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) in f2fs_statfs()
1859 buf->f_bfree -= sbi->unusable_block_count; in f2fs_statfs()
1860 spin_unlock(&sbi->stat_lock); in f2fs_statfs()
1862 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) in f2fs_statfs()
1864 F2FS_OPTION(sbi).root_reserved_blocks; in f2fs_statfs()
1893 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_quota_options() local
1895 if (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1898 switch (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1912 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_show_quota_options()
1914 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); in f2fs_show_quota_options()
1916 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_show_quota_options()
1918 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); in f2fs_show_quota_options()
1920 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_show_quota_options()
1922 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); in f2fs_show_quota_options()
1930 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_compress_options() local
1934 if (!f2fs_sb_has_compression(sbi)) in f2fs_show_compress_options()
1937 switch (F2FS_OPTION(sbi).compress_algorithm) { in f2fs_show_compress_options()
1953 if (F2FS_OPTION(sbi).compress_level) in f2fs_show_compress_options()
1954 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); in f2fs_show_compress_options()
1957 F2FS_OPTION(sbi).compress_log_size); in f2fs_show_compress_options()
1959 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { in f2fs_show_compress_options()
1961 F2FS_OPTION(sbi).extensions[i]); in f2fs_show_compress_options()
1964 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) { in f2fs_show_compress_options()
1966 F2FS_OPTION(sbi).noextensions[i]); in f2fs_show_compress_options()
1969 if (F2FS_OPTION(sbi).compress_chksum) in f2fs_show_compress_options()
1972 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) in f2fs_show_compress_options()
1974 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) in f2fs_show_compress_options()
1977 if (test_opt(sbi, COMPRESS_CACHE)) in f2fs_show_compress_options()
1984 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); in f2fs_show_options() local
1986 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) in f2fs_show_options()
1988 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) in f2fs_show_options()
1990 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) in f2fs_show_options()
1993 if (test_opt(sbi, GC_MERGE)) in f2fs_show_options()
1998 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_show_options()
2000 if (test_opt(sbi, NORECOVERY)) in f2fs_show_options()
2002 if (test_opt(sbi, DISCARD)) { in f2fs_show_options()
2004 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK) in f2fs_show_options()
2006 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT) in f2fs_show_options()
2008 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION) in f2fs_show_options()
2014 if (test_opt(sbi, XATTR_USER)) in f2fs_show_options()
2018 if (test_opt(sbi, INLINE_XATTR)) in f2fs_show_options()
2022 if (test_opt(sbi, INLINE_XATTR_SIZE)) in f2fs_show_options()
2024 F2FS_OPTION(sbi).inline_xattr_size); in f2fs_show_options()
2027 if (test_opt(sbi, POSIX_ACL)) in f2fs_show_options()
2032 if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) in f2fs_show_options()
2034 if (test_opt(sbi, INLINE_DATA)) in f2fs_show_options()
2038 if (test_opt(sbi, INLINE_DENTRY)) in f2fs_show_options()
2042 if (test_opt(sbi, FLUSH_MERGE)) in f2fs_show_options()
2046 if (test_opt(sbi, NOBARRIER)) in f2fs_show_options()
2050 if (test_opt(sbi, FASTBOOT)) in f2fs_show_options()
2052 if (test_opt(sbi, READ_EXTENT_CACHE)) in f2fs_show_options()
2056 if (test_opt(sbi, AGE_EXTENT_CACHE)) in f2fs_show_options()
2058 if (test_opt(sbi, DATA_FLUSH)) in f2fs_show_options()
2062 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) in f2fs_show_options()
2064 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) in f2fs_show_options()
2066 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG) in f2fs_show_options()
2068 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) in f2fs_show_options()
2070 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); in f2fs_show_options()
2071 if (test_opt(sbi, RESERVE_ROOT)) in f2fs_show_options()
2073 F2FS_OPTION(sbi).root_reserved_blocks, in f2fs_show_options()
2075 F2FS_OPTION(sbi).s_resuid), in f2fs_show_options()
2077 F2FS_OPTION(sbi).s_resgid)); in f2fs_show_options()
2079 if (test_opt(sbi, FAULT_INJECTION)) { in f2fs_show_options()
2081 F2FS_OPTION(sbi).fault_info.inject_rate); in f2fs_show_options()
2083 F2FS_OPTION(sbi).fault_info.inject_type); in f2fs_show_options()
2087 if (test_opt(sbi, QUOTA)) in f2fs_show_options()
2089 if (test_opt(sbi, USRQUOTA)) in f2fs_show_options()
2091 if (test_opt(sbi, GRPQUOTA)) in f2fs_show_options()
2093 if (test_opt(sbi, PRJQUOTA)) in f2fs_show_options()
2096 f2fs_show_quota_options(seq, sbi->sb); in f2fs_show_options()
2098 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); in f2fs_show_options()
2100 if (sbi->sb->s_flags & SB_INLINECRYPT) in f2fs_show_options()
2103 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) in f2fs_show_options()
2105 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) in f2fs_show_options()
2108 if (test_opt(sbi, DISABLE_CHECKPOINT)) in f2fs_show_options()
2110 F2FS_OPTION(sbi).unusable_cap); in f2fs_show_options()
2111 if (test_opt(sbi, MERGE_CHECKPOINT)) in f2fs_show_options()
2115 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) in f2fs_show_options()
2117 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) in f2fs_show_options()
2119 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) in f2fs_show_options()
2123 f2fs_show_compress_options(seq, sbi->sb); in f2fs_show_options()
2126 if (test_opt(sbi, ATGC)) in f2fs_show_options()
2129 if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL) in f2fs_show_options()
2131 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW) in f2fs_show_options()
2134 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) in f2fs_show_options()
2136 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE) in f2fs_show_options()
2138 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC) in f2fs_show_options()
2144 static void default_options(struct f2fs_sb_info *sbi, bool remount) in default_options() argument
2148 set_opt(sbi, READ_EXTENT_CACHE); in default_options()
2149 clear_opt(sbi, DISABLE_CHECKPOINT); in default_options()
2151 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) in default_options()
2152 set_opt(sbi, DISCARD); in default_options()
2154 if (f2fs_sb_has_blkzoned(sbi)) in default_options()
2155 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; in default_options()
2157 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; in default_options()
2160 if (f2fs_sb_has_readonly(sbi)) in default_options()
2161 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; in default_options()
2163 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; in default_options()
2165 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; in default_options()
2166 if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main) <= in default_options()
2168 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in default_options()
2170 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in default_options()
2171 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in default_options()
2172 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); in default_options()
2173 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); in default_options()
2174 if (f2fs_sb_has_compression(sbi)) { in default_options()
2175 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; in default_options()
2176 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; in default_options()
2177 F2FS_OPTION(sbi).compress_ext_cnt = 0; in default_options()
2178 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in default_options()
2180 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in default_options()
2181 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL; in default_options()
2182 F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE; in default_options()
2184 set_opt(sbi, INLINE_XATTR); in default_options()
2185 set_opt(sbi, INLINE_DATA); in default_options()
2186 set_opt(sbi, INLINE_DENTRY); in default_options()
2187 set_opt(sbi, MERGE_CHECKPOINT); in default_options()
2188 F2FS_OPTION(sbi).unusable_cap = 0; in default_options()
2189 sbi->sb->s_flags |= SB_LAZYTIME; in default_options()
2190 if (!f2fs_is_readonly(sbi)) in default_options()
2191 set_opt(sbi, FLUSH_MERGE); in default_options()
2192 if (f2fs_sb_has_blkzoned(sbi)) in default_options()
2193 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in default_options()
2195 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in default_options()
2198 set_opt(sbi, XATTR_USER); in default_options()
2201 set_opt(sbi, POSIX_ACL); in default_options()
2204 f2fs_build_fault_attr(sbi, 0, 0); in default_options()
2211 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_disable_checkpoint() argument
2213 unsigned int s_flags = sbi->sb->s_flags; in f2fs_disable_checkpoint()
2215 unsigned int gc_mode = sbi->gc_mode; in f2fs_disable_checkpoint()
2221 f2fs_err(sbi, "checkpoint=disable on readonly fs"); in f2fs_disable_checkpoint()
2224 sbi->sb->s_flags |= SB_ACTIVE; in f2fs_disable_checkpoint()
2227 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2228 if (!f2fs_disable_cp_again(sbi, unusable)) in f2fs_disable_checkpoint()
2231 f2fs_update_time(sbi, DISABLE_TIME); in f2fs_disable_checkpoint()
2233 sbi->gc_mode = GC_URGENT_HIGH; in f2fs_disable_checkpoint()
2235 while (!f2fs_time_over(sbi, DISABLE_TIME)) { in f2fs_disable_checkpoint()
2244 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2245 stat_inc_gc_call_count(sbi, FOREGROUND); in f2fs_disable_checkpoint()
2246 err = f2fs_gc(sbi, &gc_control); in f2fs_disable_checkpoint()
2255 ret = sync_filesystem(sbi->sb); in f2fs_disable_checkpoint()
2261 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2262 if (f2fs_disable_cp_again(sbi, unusable)) { in f2fs_disable_checkpoint()
2268 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2270 set_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_disable_checkpoint()
2271 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_disable_checkpoint()
2272 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_disable_checkpoint()
2276 spin_lock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2277 sbi->unusable_block_count = unusable; in f2fs_disable_checkpoint()
2278 spin_unlock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2281 f2fs_up_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2283 sbi->gc_mode = gc_mode; in f2fs_disable_checkpoint()
2284 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in f2fs_disable_checkpoint()
2288 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_enable_checkpoint() argument
2294 sync_inodes_sb(sbi->sb); in f2fs_enable_checkpoint()
2296 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); in f2fs_enable_checkpoint()
2299 f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); in f2fs_enable_checkpoint()
2301 f2fs_down_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2302 f2fs_dirty_to_prefree(sbi); in f2fs_enable_checkpoint()
2304 clear_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_enable_checkpoint()
2305 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_enable_checkpoint()
2306 f2fs_up_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2308 f2fs_sync_fs(sbi->sb, 1); in f2fs_enable_checkpoint()
2311 f2fs_flush_ckpt_thread(sbi); in f2fs_enable_checkpoint()
2316 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_remount() local
2324 bool no_read_extent_cache = !test_opt(sbi, READ_EXTENT_CACHE); in f2fs_remount()
2325 bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE); in f2fs_remount()
2326 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2327 bool no_atgc = !test_opt(sbi, ATGC); in f2fs_remount()
2328 bool no_discard = !test_opt(sbi, DISCARD); in f2fs_remount()
2329 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); in f2fs_remount()
2330 bool block_unit_discard = f2fs_block_unit_discard(sbi); in f2fs_remount()
2339 org_mount_opt = sbi->mount_opt; in f2fs_remount()
2342 sbi->umount_lock_holder = current; in f2fs_remount()
2345 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; in f2fs_remount()
2347 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_remount()
2349 kstrdup(F2FS_OPTION(sbi).s_qf_names[i], in f2fs_remount()
2363 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { in f2fs_remount()
2364 err = f2fs_commit_super(sbi, false); in f2fs_remount()
2365 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", in f2fs_remount()
2368 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_remount()
2371 default_options(sbi, true); in f2fs_remount()
2379 if (f2fs_sb_has_blkzoned(sbi) && in f2fs_remount()
2380 sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { in f2fs_remount()
2381 f2fs_err(sbi, in f2fs_remount()
2383 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); in f2fs_remount()
2390 flush_work(&sbi->s_error_work); in f2fs_remount()
2399 if (f2fs_dev_is_readonly(sbi) && !(*flags & SB_RDONLY)) { in f2fs_remount()
2414 } else if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_remount()
2421 if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) { in f2fs_remount()
2423 f2fs_warn(sbi, "LFS is not compatible with IPU"); in f2fs_remount()
2428 if (no_atgc == !!test_opt(sbi, ATGC)) { in f2fs_remount()
2430 f2fs_warn(sbi, "switch atgc option is not allowed"); in f2fs_remount()
2435 if (no_read_extent_cache == !!test_opt(sbi, READ_EXTENT_CACHE)) { in f2fs_remount()
2437 f2fs_warn(sbi, "switch extent_cache option is not allowed"); in f2fs_remount()
2441 if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) { in f2fs_remount()
2443 f2fs_warn(sbi, "switch age_extent_cache option is not allowed"); in f2fs_remount()
2447 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { in f2fs_remount()
2449 f2fs_warn(sbi, "switch compress_cache option is not allowed"); in f2fs_remount()
2453 if (block_unit_discard != f2fs_block_unit_discard(sbi)) { in f2fs_remount()
2455 f2fs_warn(sbi, "switch discard_unit option is not allowed"); in f2fs_remount()
2459 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2461 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); in f2fs_remount()
2471 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && in f2fs_remount()
2472 !test_opt(sbi, GC_MERGE))) { in f2fs_remount()
2473 if (sbi->gc_thread) { in f2fs_remount()
2474 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2477 } else if (!sbi->gc_thread) { in f2fs_remount()
2478 err = f2fs_start_gc_thread(sbi); in f2fs_remount()
2487 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_remount()
2488 set_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2490 clear_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2497 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { in f2fs_remount()
2498 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2499 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2502 err = f2fs_create_flush_cmd_control(sbi); in f2fs_remount()
2508 if (no_discard == !!test_opt(sbi, DISCARD)) { in f2fs_remount()
2509 if (test_opt(sbi, DISCARD)) { in f2fs_remount()
2510 err = f2fs_start_discard_thread(sbi); in f2fs_remount()
2515 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2516 f2fs_issue_discard_timeout(sbi); in f2fs_remount()
2521 adjust_unusable_cap_perc(sbi); in f2fs_remount()
2522 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2523 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2524 err = f2fs_disable_checkpoint(sbi); in f2fs_remount()
2529 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2539 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || in f2fs_remount()
2540 !test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_remount()
2541 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2544 f2fs_flush_ckpt_thread(sbi); in f2fs_remount()
2546 err = f2fs_start_ckpt_thread(sbi); in f2fs_remount()
2548 f2fs_err(sbi, in f2fs_remount()
2563 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_remount()
2565 limit_reserve_root(sbi); in f2fs_remount()
2568 sbi->umount_lock_holder = NULL; in f2fs_remount()
2572 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2574 if (f2fs_disable_checkpoint(sbi)) in f2fs_remount()
2575 f2fs_warn(sbi, "checkpoint has not been disabled"); in f2fs_remount()
2579 if (f2fs_start_discard_thread(sbi)) in f2fs_remount()
2580 f2fs_warn(sbi, "discard has been stopped"); in f2fs_remount()
2582 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2586 if (f2fs_create_flush_cmd_control(sbi)) in f2fs_remount()
2587 f2fs_warn(sbi, "background flush thread has stopped"); in f2fs_remount()
2589 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2590 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2594 if (f2fs_start_gc_thread(sbi)) in f2fs_remount()
2595 f2fs_warn(sbi, "background gc thread has stopped"); in f2fs_remount()
2597 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2601 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; in f2fs_remount()
2603 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_remount()
2604 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; in f2fs_remount()
2607 sbi->mount_opt = org_mount_opt; in f2fs_remount()
2610 sbi->umount_lock_holder = NULL; in f2fs_remount()
2620 static bool f2fs_need_recovery(struct f2fs_sb_info *sbi) in f2fs_need_recovery() argument
2623 if (is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG)) in f2fs_need_recovery()
2626 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_need_recovery()
2628 if (test_opt(sbi, NORECOVERY)) in f2fs_need_recovery()
2630 return !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG); in f2fs_need_recovery()
2633 static bool f2fs_recover_quota_begin(struct f2fs_sb_info *sbi) in f2fs_recover_quota_begin() argument
2635 bool readonly = f2fs_readonly(sbi->sb); in f2fs_recover_quota_begin()
2637 if (!f2fs_need_recovery(sbi)) in f2fs_recover_quota_begin()
2641 if (f2fs_hw_is_readonly(sbi)) in f2fs_recover_quota_begin()
2645 sbi->sb->s_flags &= ~SB_RDONLY; in f2fs_recover_quota_begin()
2646 set_sbi_flag(sbi, SBI_IS_WRITABLE); in f2fs_recover_quota_begin()
2653 return f2fs_enable_quota_files(sbi, readonly); in f2fs_recover_quota_begin()
2656 static void f2fs_recover_quota_end(struct f2fs_sb_info *sbi, in f2fs_recover_quota_end() argument
2660 f2fs_quota_off_umount(sbi->sb); in f2fs_recover_quota_end()
2662 if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE)) { in f2fs_recover_quota_end()
2663 clear_sbi_flag(sbi, SBI_IS_WRITABLE); in f2fs_recover_quota_end()
2664 sbi->sb->s_flags |= SB_RDONLY; in f2fs_recover_quota_end()
2788 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) in f2fs_quota_on_mount() argument
2790 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { in f2fs_quota_on_mount()
2791 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); in f2fs_quota_on_mount()
2795 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], in f2fs_quota_on_mount()
2796 F2FS_OPTION(sbi).s_jquota_fmt, type); in f2fs_quota_on_mount()
2799 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) in f2fs_enable_quota_files() argument
2804 if (f2fs_sb_has_quota_ino(sbi) && rdonly) { in f2fs_enable_quota_files()
2805 err = f2fs_enable_quotas(sbi->sb); in f2fs_enable_quota_files()
2807 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); in f2fs_enable_quota_files()
2814 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_enable_quota_files()
2815 err = f2fs_quota_on_mount(sbi, i); in f2fs_enable_quota_files()
2820 f2fs_err(sbi, "Cannot turn on quotas: %d on %d", in f2fs_enable_quota_files()
2864 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_enable_quotas() local
2868 test_opt(sbi, USRQUOTA), in f2fs_enable_quotas()
2869 test_opt(sbi, GRPQUOTA), in f2fs_enable_quotas()
2870 test_opt(sbi, PRJQUOTA), in f2fs_enable_quotas()
2874 f2fs_err(sbi, "quota file may be corrupted, skip loading it"); in f2fs_enable_quotas()
2887 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", in f2fs_enable_quotas()
2900 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) in f2fs_quota_sync_file() argument
2902 struct quota_info *dqopt = sb_dqopt(sbi->sb); in f2fs_quota_sync_file()
2906 ret = dquot_writeback_dquots(sbi->sb, type); in f2fs_quota_sync_file()
2915 if (is_journalled_quota(sbi)) in f2fs_quota_sync_file()
2923 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_sync_file()
2929 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_do_quota_sync() local
2946 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_do_quota_sync()
2958 f2fs_lock_op(sbi); in f2fs_do_quota_sync()
2959 f2fs_down_read(&sbi->quota_sem); in f2fs_do_quota_sync()
2961 ret = f2fs_quota_sync_file(sbi, cnt); in f2fs_do_quota_sync()
2963 f2fs_up_read(&sbi->quota_sem); in f2fs_do_quota_sync()
2964 f2fs_unlock_op(sbi); in f2fs_do_quota_sync()
2966 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_do_quota_sync()
3058 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_off() local
3070 if (is_journalled_quota(sbi)) in f2fs_quota_off()
3071 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_off()
3115 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_commit() local
3118 f2fs_down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); in f2fs_dquot_commit()
3121 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit()
3122 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_commit()
3128 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_acquire() local
3131 f2fs_down_read(&sbi->quota_sem); in f2fs_dquot_acquire()
3134 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_acquire()
3135 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_acquire()
3141 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_release() local
3145 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_release()
3152 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_mark_dquot_dirty() local
3156 if (is_journalled_quota(sbi)) in f2fs_dquot_mark_dquot_dirty()
3157 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); in f2fs_dquot_mark_dquot_dirty()
3164 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_commit_info() local
3168 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit_info()
3250 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_set_context() local
3258 if (f2fs_sb_has_lost_found(sbi) && in f2fs_set_context()
3259 inode->i_ino == F2FS_ROOT_INO(sbi)) in f2fs_set_context()
3280 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_devices() local
3284 if (!f2fs_is_multi_device(sbi)) in f2fs_get_devices()
3287 devs = kmalloc_array(sbi->s_ndevs, sizeof(*devs), GFP_KERNEL); in f2fs_get_devices()
3291 for (i = 0; i < sbi->s_ndevs; i++) in f2fs_get_devices()
3293 *num_devs = sbi->s_ndevs; in f2fs_get_devices()
3314 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_nfs_get_inode() local
3317 if (f2fs_check_nid_range(sbi, ino)) in f2fs_nfs_get_inode()
3396 static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio, in __f2fs_commit_super() argument
3407 memcpy(F2FS_SUPER_BLOCK(folio, index), F2FS_RAW_SUPER(sbi), in __f2fs_commit_super()
3414 bio = bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS); in __f2fs_commit_super()
3420 f2fs_bug_on(sbi, 1); in __f2fs_commit_super()
3428 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, in sanity_check_area_boundary() argument
3432 struct super_block *sb = sbi->sb; in sanity_check_area_boundary()
3452 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", in sanity_check_area_boundary()
3459 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3467 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3475 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3483 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3490 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3502 if (f2fs_readonly(sb) || f2fs_hw_is_readonly(sbi)) { in sanity_check_area_boundary()
3503 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in sanity_check_area_boundary()
3506 err = __f2fs_commit_super(sbi, folio, index, false); in sanity_check_area_boundary()
3509 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3518 static int sanity_check_raw_super(struct f2fs_sb_info *sbi, in sanity_check_raw_super() argument
3528 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", in sanity_check_raw_super()
3538 f2fs_info(sbi, "Invalid SB checksum offset: %zu", in sanity_check_raw_super()
3543 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { in sanity_check_raw_super()
3544 f2fs_info(sbi, "Invalid SB checksum value: %u", crc); in sanity_check_raw_super()
3551 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", in sanity_check_raw_super()
3559 f2fs_info(sbi, "Invalid log blocks per segment (%u)", in sanity_check_raw_super()
3569 f2fs_info(sbi, "Invalid log sectorsize (%u)", in sanity_check_raw_super()
3576 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", in sanity_check_raw_super()
3593 f2fs_info(sbi, "Invalid segment count (%u)", segment_count); in sanity_check_raw_super()
3599 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", in sanity_check_raw_super()
3605 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", in sanity_check_raw_super()
3611 f2fs_info(sbi, "Small segment_count (%u < %u * %u)", in sanity_check_raw_super()
3617 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", in sanity_check_raw_super()
3631 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", in sanity_check_raw_super()
3637 !bdev_is_zoned(sbi->sb->s_bdev)) { in sanity_check_raw_super()
3638 f2fs_info(sbi, "Zoned block device path is missing"); in sanity_check_raw_super()
3644 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", in sanity_check_raw_super()
3652 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", in sanity_check_raw_super()
3662 f2fs_info(sbi, "Insane cp_payload (%u >= %u)", in sanity_check_raw_super()
3673 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", in sanity_check_raw_super()
3681 if (sanity_check_area_boundary(sbi, folio, index)) in sanity_check_raw_super()
3687 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) in f2fs_sanity_check_ckpt() argument
3690 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_sanity_check_ckpt()
3691 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in f2fs_sanity_check_ckpt()
3719 if (!f2fs_sb_has_readonly(sbi) && in f2fs_sanity_check_ckpt()
3722 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); in f2fs_sanity_check_ckpt()
3727 (f2fs_sb_has_readonly(sbi) ? 1 : 0); in f2fs_sanity_check_ckpt()
3731 f2fs_err(sbi, "Wrong user_block_count: %u", in f2fs_sanity_check_ckpt()
3738 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", in f2fs_sanity_check_ckpt()
3744 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_sanity_check_ckpt()
3746 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", in f2fs_sanity_check_ckpt()
3752 blocks_per_seg = BLKS_PER_SEG(sbi); in f2fs_sanity_check_ckpt()
3759 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3765 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3778 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3784 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3795 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3808 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", in f2fs_sanity_check_ckpt()
3813 cp_pack_start_sum = __start_sum_addr(sbi); in f2fs_sanity_check_ckpt()
3814 cp_payload = __cp_payload(sbi); in f2fs_sanity_check_ckpt()
3818 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", in f2fs_sanity_check_ckpt()
3825 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " in f2fs_sanity_check_ckpt()
3838 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", in f2fs_sanity_check_ckpt()
3843 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_sanity_check_ckpt()
3844 f2fs_err(sbi, "A bug case: need to run fsck"); in f2fs_sanity_check_ckpt()
3850 static void init_sb_info(struct f2fs_sb_info *sbi) in init_sb_info() argument
3852 struct f2fs_super_block *raw_super = sbi->raw_super; in init_sb_info()
3855 sbi->log_sectors_per_block = in init_sb_info()
3857 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); in init_sb_info()
3858 sbi->blocksize = BIT(sbi->log_blocksize); in init_sb_info()
3859 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); in init_sb_info()
3860 sbi->blocks_per_seg = BIT(sbi->log_blocks_per_seg); in init_sb_info()
3861 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); in init_sb_info()
3862 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); in init_sb_info()
3863 sbi->total_sections = le32_to_cpu(raw_super->section_count); in init_sb_info()
3864 sbi->total_node_count = SEGS_TO_BLKS(sbi, in init_sb_info()
3867 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); in init_sb_info()
3868 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); in init_sb_info()
3869 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); in init_sb_info()
3870 sbi->cur_victim_sec = NULL_SECNO; in init_sb_info()
3871 sbi->gc_mode = GC_NORMAL; in init_sb_info()
3872 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in init_sb_info()
3873 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in init_sb_info()
3874 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; in init_sb_info()
3875 sbi->migration_granularity = SEGS_PER_SEC(sbi); in init_sb_info()
3876 sbi->migration_window_granularity = f2fs_sb_has_blkzoned(sbi) ? in init_sb_info()
3877 DEF_MIGRATION_WINDOW_GRANULARITY_ZONED : SEGS_PER_SEC(sbi); in init_sb_info()
3878 sbi->seq_file_ra_mul = MIN_RA_MUL; in init_sb_info()
3879 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE; in init_sb_info()
3880 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE; in init_sb_info()
3881 spin_lock_init(&sbi->gc_remaining_trials_lock); in init_sb_info()
3882 atomic64_set(&sbi->current_atomic_write, 0); in init_sb_info()
3884 sbi->dir_level = DEF_DIR_LEVEL; in init_sb_info()
3885 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; in init_sb_info()
3886 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3887 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3888 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3889 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; in init_sb_info()
3890 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = in init_sb_info()
3892 clear_sbi_flag(sbi, SBI_NEED_FSCK); in init_sb_info()
3895 atomic_set(&sbi->nr_pages[i], 0); in init_sb_info()
3898 atomic_set(&sbi->wb_sync_req[i], 0); in init_sb_info()
3900 INIT_LIST_HEAD(&sbi->s_list); in init_sb_info()
3901 mutex_init(&sbi->umount_mutex); in init_sb_info()
3902 init_f2fs_rwsem(&sbi->io_order_lock); in init_sb_info()
3903 spin_lock_init(&sbi->cp_lock); in init_sb_info()
3905 sbi->dirty_device = 0; in init_sb_info()
3906 spin_lock_init(&sbi->dev_lock); in init_sb_info()
3908 init_f2fs_rwsem(&sbi->sb_lock); in init_sb_info()
3909 init_f2fs_rwsem(&sbi->pin_sem); in init_sb_info()
3912 static int init_percpu_info(struct f2fs_sb_info *sbi) in init_percpu_info() argument
3916 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); in init_percpu_info()
3920 err = percpu_counter_init(&sbi->rf_node_block_count, 0, GFP_KERNEL); in init_percpu_info()
3924 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, in init_percpu_info()
3931 percpu_counter_destroy(&sbi->rf_node_block_count); in init_percpu_info()
3933 percpu_counter_destroy(&sbi->alloc_valid_block_count); in init_percpu_info()
3940 struct f2fs_sb_info *sbi; member
3955 if (!rz_args->sbi->unusable_blocks_per_sec) { in f2fs_report_zone_cb()
3956 rz_args->sbi->unusable_blocks_per_sec = unusable_blocks; in f2fs_report_zone_cb()
3959 if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) { in f2fs_report_zone_cb()
3960 f2fs_err(rz_args->sbi, "F2FS supports single zone capacity\n"); in f2fs_report_zone_cb()
3966 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) in init_blkz_info() argument
3975 if (!f2fs_sb_has_blkzoned(sbi)) in init_blkz_info()
3980 if (max_open_zones && (max_open_zones < sbi->max_open_zones)) in init_blkz_info()
3981 sbi->max_open_zones = max_open_zones; in init_blkz_info()
3982 if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { in init_blkz_info()
3983 f2fs_err(sbi, in init_blkz_info()
3985 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); in init_blkz_info()
3991 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != in init_blkz_info()
3994 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(zone_sectors); in init_blkz_info()
3996 sbi->blocks_per_blkz); in init_blkz_info()
4000 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, in init_blkz_info()
4007 rep_zone_arg.sbi = sbi; in init_blkz_info()
4024 static int read_raw_super_block(struct f2fs_sb_info *sbi, in read_raw_super_block() argument
4028 struct super_block *sb = sbi->sb; in read_raw_super_block()
4041 f2fs_err(sbi, "Unable to read %dth superblock", in read_raw_super_block()
4049 err = sanity_check_raw_super(sbi, folio, block); in read_raw_super_block()
4051 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", in read_raw_super_block()
4076 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) in f2fs_commit_super() argument
4083 if ((recover && f2fs_readonly(sbi->sb)) || in f2fs_commit_super()
4084 f2fs_hw_is_readonly(sbi)) { in f2fs_commit_super()
4085 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_commit_super()
4090 if (!recover && f2fs_sb_has_sb_chksum(sbi)) { in f2fs_commit_super()
4091 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), in f2fs_commit_super()
4093 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); in f2fs_commit_super()
4097 index = sbi->valid_super_block ? 0 : 1; in f2fs_commit_super()
4098 folio = read_mapping_folio(sbi->sb->s_bdev->bd_mapping, index, NULL); in f2fs_commit_super()
4101 err = __f2fs_commit_super(sbi, folio, index, true); in f2fs_commit_super()
4109 index = sbi->valid_super_block; in f2fs_commit_super()
4110 folio = read_mapping_folio(sbi->sb->s_bdev->bd_mapping, index, NULL); in f2fs_commit_super()
4113 err = __f2fs_commit_super(sbi, folio, index, true); in f2fs_commit_super()
4118 static void save_stop_reason(struct f2fs_sb_info *sbi, unsigned char reason) in save_stop_reason() argument
4122 spin_lock_irqsave(&sbi->error_lock, flags); in save_stop_reason()
4123 if (sbi->stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0)) in save_stop_reason()
4124 sbi->stop_reason[reason]++; in save_stop_reason()
4125 spin_unlock_irqrestore(&sbi->error_lock, flags); in save_stop_reason()
4128 static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi) in f2fs_record_stop_reason() argument
4130 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_record_stop_reason()
4134 f2fs_down_write(&sbi->sb_lock); in f2fs_record_stop_reason()
4136 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_record_stop_reason()
4137 if (sbi->error_dirty) { in f2fs_record_stop_reason()
4138 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, in f2fs_record_stop_reason()
4140 sbi->error_dirty = false; in f2fs_record_stop_reason()
4142 memcpy(raw_super->s_stop_reason, sbi->stop_reason, MAX_STOP_REASON); in f2fs_record_stop_reason()
4143 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_record_stop_reason()
4145 err = f2fs_commit_super(sbi, false); in f2fs_record_stop_reason()
4147 f2fs_up_write(&sbi->sb_lock); in f2fs_record_stop_reason()
4149 f2fs_err_ratelimited(sbi, in f2fs_record_stop_reason()
4154 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag) in f2fs_save_errors() argument
4158 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_save_errors()
4159 if (!test_bit(flag, (unsigned long *)sbi->errors)) { in f2fs_save_errors()
4160 set_bit(flag, (unsigned long *)sbi->errors); in f2fs_save_errors()
4161 sbi->error_dirty = true; in f2fs_save_errors()
4163 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_save_errors()
4166 static bool f2fs_update_errors(struct f2fs_sb_info *sbi) in f2fs_update_errors() argument
4171 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_update_errors()
4172 if (sbi->error_dirty) { in f2fs_update_errors()
4173 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, in f2fs_update_errors()
4175 sbi->error_dirty = false; in f2fs_update_errors()
4178 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_update_errors()
4183 static void f2fs_record_errors(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_record_errors() argument
4187 f2fs_down_write(&sbi->sb_lock); in f2fs_record_errors()
4189 if (!f2fs_update_errors(sbi)) in f2fs_record_errors()
4192 err = f2fs_commit_super(sbi, false); in f2fs_record_errors()
4194 f2fs_err_ratelimited(sbi, in f2fs_record_errors()
4198 f2fs_up_write(&sbi->sb_lock); in f2fs_record_errors()
4201 void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_handle_error() argument
4203 f2fs_save_errors(sbi, error); in f2fs_handle_error()
4204 f2fs_record_errors(sbi, error); in f2fs_handle_error()
4207 void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_handle_error_async() argument
4209 f2fs_save_errors(sbi, error); in f2fs_handle_error_async()
4211 if (!sbi->error_dirty) in f2fs_handle_error_async()
4213 if (!test_bit(error, (unsigned long *)sbi->errors)) in f2fs_handle_error_async()
4215 schedule_work(&sbi->s_error_work); in f2fs_handle_error_async()
4224 void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason) in f2fs_handle_critical_error() argument
4226 struct super_block *sb = sbi->sb; in f2fs_handle_critical_error()
4229 F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE; in f2fs_handle_critical_error()
4231 set_ckpt_flags(sbi, CP_ERROR_FLAG); in f2fs_handle_critical_error()
4233 if (!f2fs_hw_is_readonly(sbi)) { in f2fs_handle_critical_error()
4234 save_stop_reason(sbi, reason); in f2fs_handle_critical_error()
4241 schedule_work(&sbi->s_error_work); in f2fs_handle_critical_error()
4249 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC && in f2fs_handle_critical_error()
4251 !is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN)) in f2fs_handle_critical_error()
4256 set_sbi_flag(sbi, SBI_IS_SHUTDOWN); in f2fs_handle_critical_error()
4264 f2fs_warn(sbi, "Stopped filesystem due to reason: %d", reason); in f2fs_handle_critical_error()
4268 f2fs_warn(sbi, "Remounting filesystem read-only"); in f2fs_handle_critical_error()
4281 struct f2fs_sb_info *sbi = container_of(work, in f2fs_record_error_work() local
4284 f2fs_record_stop_reason(sbi); in f2fs_record_error_work()
4287 static inline unsigned int get_first_zoned_segno(struct f2fs_sb_info *sbi) in get_first_zoned_segno() argument
4291 for (devi = 0; devi < sbi->s_ndevs; devi++) in get_first_zoned_segno()
4293 return GET_SEGNO(sbi, FDEV(devi).start_blk); in get_first_zoned_segno()
4297 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) in f2fs_scan_devices() argument
4299 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_scan_devices()
4302 blk_mode_t mode = sb_open_mode(sbi->sb->s_flags); in f2fs_scan_devices()
4307 if (!bdev_is_zoned(sbi->sb->s_bdev)) in f2fs_scan_devices()
4316 sbi->devs = f2fs_kzalloc(sbi, in f2fs_scan_devices()
4320 if (!sbi->devs) in f2fs_scan_devices()
4323 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev); in f2fs_scan_devices()
4324 sbi->aligned_blksize = true; in f2fs_scan_devices()
4326 sbi->max_open_zones = UINT_MAX; in f2fs_scan_devices()
4327 sbi->blkzone_alloc_policy = BLKZONE_ALLOC_PRIOR_SEQ; in f2fs_scan_devices()
4332 FDEV(0).bdev_file = sbi->sb->s_bdev_file; in f2fs_scan_devices()
4344 SEGS_TO_BLKS(sbi, in f2fs_scan_devices()
4350 SEGS_TO_BLKS(sbi, in f2fs_scan_devices()
4353 FDEV(i).path, mode, sbi->sb, NULL); in f2fs_scan_devices()
4361 sbi->s_ndevs = i + 1; in f2fs_scan_devices()
4364 sbi->aligned_blksize = false; in f2fs_scan_devices()
4368 if (!f2fs_sb_has_blkzoned(sbi)) { in f2fs_scan_devices()
4369 f2fs_err(sbi, "Zoned block device feature not enabled"); in f2fs_scan_devices()
4372 if (init_blkz_info(sbi, i)) { in f2fs_scan_devices()
4373 f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); in f2fs_scan_devices()
4378 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: Host-managed)", in f2fs_scan_devices()
4385 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", in f2fs_scan_devices()
4393 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) in f2fs_setup_casefold() argument
4396 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { in f2fs_setup_casefold()
4401 encoding_info = f2fs_sb_read_encoding(sbi->raw_super); in f2fs_setup_casefold()
4403 f2fs_err(sbi, in f2fs_setup_casefold()
4408 encoding_flags = le16_to_cpu(sbi->raw_super->s_encoding_flags); in f2fs_setup_casefold()
4411 f2fs_err(sbi, in f2fs_setup_casefold()
4421 f2fs_info(sbi, "Using encoding defined by superblock: " in f2fs_setup_casefold()
4428 sbi->sb->s_encoding = encoding; in f2fs_setup_casefold()
4429 sbi->sb->s_encoding_flags = encoding_flags; in f2fs_setup_casefold()
4432 if (f2fs_sb_has_casefold(sbi)) { in f2fs_setup_casefold()
4433 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); in f2fs_setup_casefold()
4440 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) in f2fs_tuning_parameters() argument
4443 if (MAIN_SEGS(sbi) <= SMALL_VOLUME_SEGMENTS) { in f2fs_tuning_parameters()
4444 if (f2fs_block_unit_discard(sbi)) in f2fs_tuning_parameters()
4445 SM_I(sbi)->dcc_info->discard_granularity = in f2fs_tuning_parameters()
4447 if (!f2fs_lfs_mode(sbi)) in f2fs_tuning_parameters()
4448 SM_I(sbi)->ipu_policy = BIT(F2FS_IPU_FORCE) | in f2fs_tuning_parameters()
4452 sbi->readdir_ra = true; in f2fs_tuning_parameters()
4457 struct f2fs_sb_info *sbi; in f2fs_fill_super() local
4477 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); in f2fs_fill_super()
4478 if (!sbi) in f2fs_fill_super()
4481 sbi->sb = sb; in f2fs_fill_super()
4484 init_f2fs_rwsem(&sbi->gc_lock); in f2fs_fill_super()
4485 mutex_init(&sbi->writepages); in f2fs_fill_super()
4486 init_f2fs_rwsem(&sbi->cp_global_sem); in f2fs_fill_super()
4487 init_f2fs_rwsem(&sbi->node_write); in f2fs_fill_super()
4488 init_f2fs_rwsem(&sbi->node_change); in f2fs_fill_super()
4489 spin_lock_init(&sbi->stat_lock); in f2fs_fill_super()
4490 init_f2fs_rwsem(&sbi->cp_rwsem); in f2fs_fill_super()
4491 init_f2fs_rwsem(&sbi->quota_sem); in f2fs_fill_super()
4492 init_waitqueue_head(&sbi->cp_wait); in f2fs_fill_super()
4493 spin_lock_init(&sbi->error_lock); in f2fs_fill_super()
4496 INIT_LIST_HEAD(&sbi->inode_list[i]); in f2fs_fill_super()
4497 spin_lock_init(&sbi->inode_lock[i]); in f2fs_fill_super()
4499 mutex_init(&sbi->flush_lock); in f2fs_fill_super()
4503 f2fs_err(sbi, "unable to set blocksize"); in f2fs_fill_super()
4507 err = read_raw_super_block(sbi, &raw_super, &valid_super_block, in f2fs_fill_super()
4512 sb->s_fs_info = sbi; in f2fs_fill_super()
4513 sbi->raw_super = raw_super; in f2fs_fill_super()
4515 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); in f2fs_fill_super()
4516 memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS); in f2fs_fill_super()
4517 memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON); in f2fs_fill_super()
4520 if (f2fs_sb_has_inode_chksum(sbi)) in f2fs_fill_super()
4521 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, in f2fs_fill_super()
4524 default_options(sbi, false); in f2fs_fill_super()
4540 err = f2fs_setup_casefold(sbi); in f2fs_fill_super()
4549 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_fill_super()
4551 if (f2fs_qf_ino(sbi->sb, i)) in f2fs_fill_super()
4552 sbi->nquota_files++; in f2fs_fill_super()
4569 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_fill_super()
4575 sbi->valid_super_block = valid_super_block; in f2fs_fill_super()
4578 set_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4580 err = f2fs_init_write_merge_io(sbi); in f2fs_fill_super()
4584 init_sb_info(sbi); in f2fs_fill_super()
4586 err = f2fs_init_iostat(sbi); in f2fs_fill_super()
4590 err = init_percpu_info(sbi); in f2fs_fill_super()
4594 /* init per sbi slab cache */ in f2fs_fill_super()
4595 err = f2fs_init_xattr_caches(sbi); in f2fs_fill_super()
4598 err = f2fs_init_page_array_cache(sbi); in f2fs_fill_super()
4603 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); in f2fs_fill_super()
4604 if (IS_ERR(sbi->meta_inode)) { in f2fs_fill_super()
4605 f2fs_err(sbi, "Failed to read F2FS meta data inode"); in f2fs_fill_super()
4606 err = PTR_ERR(sbi->meta_inode); in f2fs_fill_super()
4610 err = f2fs_get_valid_checkpoint(sbi); in f2fs_fill_super()
4612 f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); in f2fs_fill_super()
4616 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) in f2fs_fill_super()
4617 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_fill_super()
4618 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { in f2fs_fill_super()
4619 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4620 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; in f2fs_fill_super()
4623 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) in f2fs_fill_super()
4624 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4627 err = f2fs_scan_devices(sbi); in f2fs_fill_super()
4629 f2fs_err(sbi, "Failed to find devices"); in f2fs_fill_super()
4633 err = f2fs_init_post_read_wq(sbi); in f2fs_fill_super()
4635 f2fs_err(sbi, "Failed to initialize post read workqueue"); in f2fs_fill_super()
4639 sbi->total_valid_node_count = in f2fs_fill_super()
4640 le32_to_cpu(sbi->ckpt->valid_node_count); in f2fs_fill_super()
4641 percpu_counter_set(&sbi->total_valid_inode_count, in f2fs_fill_super()
4642 le32_to_cpu(sbi->ckpt->valid_inode_count)); in f2fs_fill_super()
4643 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); in f2fs_fill_super()
4644 sbi->total_valid_block_count = in f2fs_fill_super()
4645 le64_to_cpu(sbi->ckpt->valid_block_count); in f2fs_fill_super()
4646 sbi->last_valid_block_count = sbi->total_valid_block_count; in f2fs_fill_super()
4647 sbi->reserved_blocks = 0; in f2fs_fill_super()
4648 sbi->current_reserved_blocks = 0; in f2fs_fill_super()
4649 limit_reserve_root(sbi); in f2fs_fill_super()
4650 adjust_unusable_cap_perc(sbi); in f2fs_fill_super()
4652 f2fs_init_extent_cache_info(sbi); in f2fs_fill_super()
4654 f2fs_init_ino_entry_info(sbi); in f2fs_fill_super()
4656 f2fs_init_fsync_node_info(sbi); in f2fs_fill_super()
4659 f2fs_init_ckpt_req_control(sbi); in f2fs_fill_super()
4660 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && in f2fs_fill_super()
4661 test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_fill_super()
4662 err = f2fs_start_ckpt_thread(sbi); in f2fs_fill_super()
4664 f2fs_err(sbi, in f2fs_fill_super()
4672 err = f2fs_build_segment_manager(sbi); in f2fs_fill_super()
4674 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", in f2fs_fill_super()
4678 err = f2fs_build_node_manager(sbi); in f2fs_fill_super()
4680 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", in f2fs_fill_super()
4686 sbi->sectors_written_start = f2fs_get_sectors_written(sbi); in f2fs_fill_super()
4689 sbi->first_zoned_segno = get_first_zoned_segno(sbi); in f2fs_fill_super()
4692 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); in f2fs_fill_super()
4693 if (__exist_node_summaries(sbi)) in f2fs_fill_super()
4694 sbi->kbytes_written = in f2fs_fill_super()
4697 f2fs_build_gc_manager(sbi); in f2fs_fill_super()
4699 err = f2fs_build_stats(sbi); in f2fs_fill_super()
4704 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); in f2fs_fill_super()
4705 if (IS_ERR(sbi->node_inode)) { in f2fs_fill_super()
4706 f2fs_err(sbi, "Failed to read node inode"); in f2fs_fill_super()
4707 err = PTR_ERR(sbi->node_inode); in f2fs_fill_super()
4712 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); in f2fs_fill_super()
4714 f2fs_err(sbi, "Failed to read root inode"); in f2fs_fill_super()
4732 err = f2fs_init_compress_inode(sbi); in f2fs_fill_super()
4736 err = f2fs_register_sysfs(sbi); in f2fs_fill_super()
4740 sbi->umount_lock_holder = current; in f2fs_fill_super()
4743 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4746 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); in f2fs_fill_super()
4749 quota_enabled = f2fs_recover_quota_begin(sbi); in f2fs_fill_super()
4752 err = f2fs_recover_orphan_inodes(sbi); in f2fs_fill_super()
4756 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) { in f2fs_fill_super()
4762 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && in f2fs_fill_super()
4763 !test_opt(sbi, NORECOVERY)) { in f2fs_fill_super()
4768 if (f2fs_hw_is_readonly(sbi)) { in f2fs_fill_super()
4769 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in f2fs_fill_super()
4770 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4773 f2fs_err(sbi, "Need to recover fsync data, but " in f2fs_fill_super()
4780 f2fs_info(sbi, "write access unavailable, skipping recovery"); in f2fs_fill_super()
4785 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4790 err = f2fs_recover_fsync_data(sbi, false); in f2fs_fill_super()
4795 f2fs_err(sbi, "Cannot recover all fsync data errno=%d", in f2fs_fill_super()
4800 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4804 f2fs_err(sbi, "Need to recover fsync data"); in f2fs_fill_super()
4811 f2fs_recover_quota_end(sbi, quota_enabled); in f2fs_fill_super()
4821 err = f2fs_check_and_fix_write_pointer(sbi); in f2fs_fill_super()
4826 clear_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4828 err = f2fs_init_inmem_curseg(sbi); in f2fs_fill_super()
4832 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_fill_super()
4833 err = f2fs_disable_checkpoint(sbi); in f2fs_fill_super()
4836 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { in f2fs_fill_super()
4837 f2fs_enable_checkpoint(sbi); in f2fs_fill_super()
4844 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || in f2fs_fill_super()
4845 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4847 err = f2fs_start_gc_thread(sbi); in f2fs_fill_super()
4855 err = f2fs_commit_super(sbi, true); in f2fs_fill_super()
4856 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", in f2fs_fill_super()
4857 sbi->valid_super_block ? 1 : 2, err); in f2fs_fill_super()
4860 f2fs_join_shrinker(sbi); in f2fs_fill_super()
4862 f2fs_tuning_parameters(sbi); in f2fs_fill_super()
4864 f2fs_notice(sbi, "Mounted with checkpoint version = %llx", in f2fs_fill_super()
4865 cur_cp_version(F2FS_CKPT(sbi))); in f2fs_fill_super()
4866 f2fs_update_time(sbi, CP_TIME); in f2fs_fill_super()
4867 f2fs_update_time(sbi, REQ_TIME); in f2fs_fill_super()
4868 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4870 sbi->umount_lock_holder = NULL; in f2fs_fill_super()
4875 sync_filesystem(sbi->sb); in f2fs_fill_super()
4881 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) in f2fs_fill_super()
4882 f2fs_quota_off_umount(sbi->sb); in f2fs_fill_super()
4890 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_fill_super()
4893 f2fs_unregister_sysfs(sbi); in f2fs_fill_super()
4895 f2fs_destroy_compress_inode(sbi); in f2fs_fill_super()
4900 f2fs_release_ino_entry(sbi, true); in f2fs_fill_super()
4901 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_fill_super()
4902 iput(sbi->node_inode); in f2fs_fill_super()
4903 sbi->node_inode = NULL; in f2fs_fill_super()
4905 f2fs_destroy_stats(sbi); in f2fs_fill_super()
4908 f2fs_stop_discard_thread(sbi); in f2fs_fill_super()
4909 f2fs_destroy_node_manager(sbi); in f2fs_fill_super()
4911 f2fs_destroy_segment_manager(sbi); in f2fs_fill_super()
4913 f2fs_stop_ckpt_thread(sbi); in f2fs_fill_super()
4914 /* flush s_error_work before sbi destroy */ in f2fs_fill_super()
4915 flush_work(&sbi->s_error_work); in f2fs_fill_super()
4916 f2fs_destroy_post_read_wq(sbi); in f2fs_fill_super()
4918 destroy_device_list(sbi); in f2fs_fill_super()
4919 kvfree(sbi->ckpt); in f2fs_fill_super()
4921 make_bad_inode(sbi->meta_inode); in f2fs_fill_super()
4922 iput(sbi->meta_inode); in f2fs_fill_super()
4923 sbi->meta_inode = NULL; in f2fs_fill_super()
4925 f2fs_destroy_page_array_cache(sbi); in f2fs_fill_super()
4927 f2fs_destroy_xattr_caches(sbi); in f2fs_fill_super()
4929 destroy_percpu_info(sbi); in f2fs_fill_super()
4931 f2fs_destroy_iostat(sbi); in f2fs_fill_super()
4934 kvfree(sbi->write_io[i]); in f2fs_fill_super()
4943 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_fill_super()
4945 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_fill_super()
4950 kfree(sbi); in f2fs_fill_super()
4970 struct f2fs_sb_info *sbi = F2FS_SB(sb); in kill_f2fs_super() local
4973 sbi->umount_lock_holder = current; in kill_f2fs_super()
4975 set_sbi_flag(sbi, SBI_IS_CLOSE); in kill_f2fs_super()
4976 f2fs_stop_gc_thread(sbi); in kill_f2fs_super()
4977 f2fs_stop_discard_thread(sbi); in kill_f2fs_super()
4984 if (test_opt(sbi, COMPRESS_CACHE)) in kill_f2fs_super()
4985 truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); in kill_f2fs_super()
4988 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in kill_f2fs_super()
4989 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in kill_f2fs_super()
4993 stat_inc_cp_call_count(sbi, TOTAL_CALL); in kill_f2fs_super()
4994 f2fs_write_checkpoint(sbi, &cpc); in kill_f2fs_super()
4997 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) in kill_f2fs_super()
5002 if (sbi) { in kill_f2fs_super()
5003 destroy_device_list(sbi); in kill_f2fs_super()
5004 kfree(sbi); in kill_f2fs_super()