Lines Matching full:sbi
67 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, in f2fs_build_fault_attr() argument
70 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; in f2fs_build_fault_attr()
266 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) in f2fs_printk() argument
278 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
322 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) in limit_reserve_root() argument
324 block_t limit = min((sbi->user_block_count >> 3), in limit_reserve_root()
325 sbi->user_block_count - sbi->reserved_blocks); in limit_reserve_root()
328 if (test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
329 F2FS_OPTION(sbi).root_reserved_blocks > limit) { in limit_reserve_root()
330 F2FS_OPTION(sbi).root_reserved_blocks = limit; in limit_reserve_root()
331 f2fs_info(sbi, "Reduce reserved blocks for root = %u", in limit_reserve_root()
332 F2FS_OPTION(sbi).root_reserved_blocks); in limit_reserve_root()
334 if (!test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
335 (!uid_eq(F2FS_OPTION(sbi).s_resuid, in limit_reserve_root()
337 !gid_eq(F2FS_OPTION(sbi).s_resgid, in limit_reserve_root()
339 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", in limit_reserve_root()
341 F2FS_OPTION(sbi).s_resuid), in limit_reserve_root()
343 F2FS_OPTION(sbi).s_resgid)); in limit_reserve_root()
346 static inline int adjust_reserved_segment(struct f2fs_sb_info *sbi) in adjust_reserved_segment() argument
348 unsigned int sec_blks = sbi->blocks_per_seg * sbi->segs_per_sec; in adjust_reserved_segment()
353 if (!F2FS_IO_ALIGNED(sbi)) in adjust_reserved_segment()
357 avg_vblocks = sec_blks / F2FS_IO_SIZE(sbi); in adjust_reserved_segment()
362 wanted_reserved_segments = (F2FS_IO_SIZE(sbi) / avg_vblocks) * in adjust_reserved_segment()
363 reserved_segments(sbi); in adjust_reserved_segment()
364 wanted_reserved_segments -= reserved_segments(sbi); in adjust_reserved_segment()
366 avail_user_block_count = sbi->user_block_count - in adjust_reserved_segment()
367 sbi->current_reserved_blocks - in adjust_reserved_segment()
368 F2FS_OPTION(sbi).root_reserved_blocks; in adjust_reserved_segment()
370 if (wanted_reserved_segments * sbi->blocks_per_seg > in adjust_reserved_segment()
372 …f2fs_err(sbi, "IO align feature can't grab additional reserved segment: %u, available segments: %u… in adjust_reserved_segment()
374 avail_user_block_count >> sbi->log_blocks_per_seg); in adjust_reserved_segment()
378 SM_I(sbi)->additional_reserved_segments = wanted_reserved_segments; in adjust_reserved_segment()
380 f2fs_info(sbi, "IO align feature needs additional reserved segment: %u", in adjust_reserved_segment()
386 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) in adjust_unusable_cap_perc() argument
388 if (!F2FS_OPTION(sbi).unusable_cap_perc) in adjust_unusable_cap_perc()
391 if (F2FS_OPTION(sbi).unusable_cap_perc == 100) in adjust_unusable_cap_perc()
392 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; in adjust_unusable_cap_perc()
394 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * in adjust_unusable_cap_perc()
395 F2FS_OPTION(sbi).unusable_cap_perc; in adjust_unusable_cap_perc()
397 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", in adjust_unusable_cap_perc()
398 F2FS_OPTION(sbi).unusable_cap, in adjust_unusable_cap_perc()
399 F2FS_OPTION(sbi).unusable_cap_perc); in adjust_unusable_cap_perc()
415 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_qf_name() local
419 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
420 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_set_qf_name()
423 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_set_qf_name()
424 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); in f2fs_set_qf_name()
430 f2fs_err(sbi, "Not enough memory for storing quotafile name"); in f2fs_set_qf_name()
433 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
434 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) in f2fs_set_qf_name()
437 f2fs_err(sbi, "%s quota file already specified", in f2fs_set_qf_name()
442 f2fs_err(sbi, "quotafile must be on filesystem root"); in f2fs_set_qf_name()
445 F2FS_OPTION(sbi).s_qf_names[qtype] = qname; in f2fs_set_qf_name()
446 set_opt(sbi, QUOTA); in f2fs_set_qf_name()
455 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_clear_qf_name() local
457 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_clear_qf_name()
458 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_clear_qf_name()
461 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); in f2fs_clear_qf_name()
462 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; in f2fs_clear_qf_name()
466 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) in f2fs_check_quota_options() argument
473 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { in f2fs_check_quota_options()
474 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); in f2fs_check_quota_options()
477 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || in f2fs_check_quota_options()
478 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || in f2fs_check_quota_options()
479 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { in f2fs_check_quota_options()
480 if (test_opt(sbi, USRQUOTA) && in f2fs_check_quota_options()
481 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_check_quota_options()
482 clear_opt(sbi, USRQUOTA); in f2fs_check_quota_options()
484 if (test_opt(sbi, GRPQUOTA) && in f2fs_check_quota_options()
485 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_check_quota_options()
486 clear_opt(sbi, GRPQUOTA); in f2fs_check_quota_options()
488 if (test_opt(sbi, PRJQUOTA) && in f2fs_check_quota_options()
489 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_check_quota_options()
490 clear_opt(sbi, PRJQUOTA); in f2fs_check_quota_options()
492 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || in f2fs_check_quota_options()
493 test_opt(sbi, PRJQUOTA)) { in f2fs_check_quota_options()
494 f2fs_err(sbi, "old and new quota format mixing"); in f2fs_check_quota_options()
498 if (!F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
499 f2fs_err(sbi, "journaled quota format not specified"); in f2fs_check_quota_options()
504 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
505 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); in f2fs_check_quota_options()
506 F2FS_OPTION(sbi).s_jquota_fmt = 0; in f2fs_check_quota_options()
517 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_test_dummy_encryption() local
523 &F2FS_OPTION(sbi).dummy_enc_policy; in f2fs_set_test_dummy_encryption()
527 f2fs_warn(sbi, "test_dummy_encryption option not supported"); in f2fs_set_test_dummy_encryption()
531 if (!f2fs_sb_has_encrypt(sbi)) { in f2fs_set_test_dummy_encryption()
532 f2fs_err(sbi, "Encrypt feature is off"); in f2fs_set_test_dummy_encryption()
543 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); in f2fs_set_test_dummy_encryption()
550 f2fs_warn(sbi, in f2fs_set_test_dummy_encryption()
553 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", in f2fs_set_test_dummy_encryption()
556 f2fs_warn(sbi, "Error processing option \"%s\" [%d]", in f2fs_set_test_dummy_encryption()
560 f2fs_warn(sbi, "Test dummy encryption mode enabled"); in f2fs_set_test_dummy_encryption()
565 static bool is_compress_extension_exist(struct f2fs_sb_info *sbi, in is_compress_extension_exist() argument
573 ext = F2FS_OPTION(sbi).extensions; in is_compress_extension_exist()
574 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in is_compress_extension_exist()
576 ext = F2FS_OPTION(sbi).noextensions; in is_compress_extension_exist()
577 ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in is_compress_extension_exist()
595 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi) in f2fs_test_compress_extension() argument
601 ext = F2FS_OPTION(sbi).extensions; in f2fs_test_compress_extension()
602 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in f2fs_test_compress_extension()
603 noext = F2FS_OPTION(sbi).noextensions; in f2fs_test_compress_extension()
604 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in f2fs_test_compress_extension()
611 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files"); in f2fs_test_compress_extension()
616 …f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension… in f2fs_test_compress_extension()
626 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_lz4hc_level() argument
632 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
639 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_lz4hc_level()
646 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); in f2fs_set_lz4hc_level()
650 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_lz4hc_level()
654 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
657 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); in f2fs_set_lz4hc_level()
664 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_zstd_level() argument
670 F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL; in f2fs_set_zstd_level()
677 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_zstd_level()
684 f2fs_info(sbi, "invalid zstd compress level: %d", level); in f2fs_set_zstd_level()
688 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_zstd_level()
696 struct f2fs_sb_info *sbi = F2FS_SB(sb); in parse_options() local
731 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in parse_options()
733 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; in parse_options()
735 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; in parse_options()
743 set_opt(sbi, DISABLE_ROLL_FORWARD); in parse_options()
747 set_opt(sbi, NORECOVERY); in parse_options()
752 if (!f2fs_hw_support_discard(sbi)) { in parse_options()
753 f2fs_warn(sbi, "device does not support discard"); in parse_options()
756 set_opt(sbi, DISCARD); in parse_options()
759 if (f2fs_hw_should_discard(sbi)) { in parse_options()
760 f2fs_warn(sbi, "discard is required for zoned block devices"); in parse_options()
763 clear_opt(sbi, DISCARD); in parse_options()
766 set_opt(sbi, NOHEAP); in parse_options()
769 clear_opt(sbi, NOHEAP); in parse_options()
773 set_opt(sbi, XATTR_USER); in parse_options()
776 clear_opt(sbi, XATTR_USER); in parse_options()
779 set_opt(sbi, INLINE_XATTR); in parse_options()
782 clear_opt(sbi, INLINE_XATTR); in parse_options()
787 set_opt(sbi, INLINE_XATTR_SIZE); in parse_options()
788 F2FS_OPTION(sbi).inline_xattr_size = arg; in parse_options()
792 f2fs_info(sbi, "user_xattr options not supported"); in parse_options()
795 f2fs_info(sbi, "nouser_xattr options not supported"); in parse_options()
798 f2fs_info(sbi, "inline_xattr options not supported"); in parse_options()
801 f2fs_info(sbi, "noinline_xattr options not supported"); in parse_options()
806 set_opt(sbi, POSIX_ACL); in parse_options()
809 clear_opt(sbi, POSIX_ACL); in parse_options()
813 f2fs_info(sbi, "acl options not supported"); in parse_options()
816 f2fs_info(sbi, "noacl options not supported"); in parse_options()
825 F2FS_OPTION(sbi).active_logs = arg; in parse_options()
828 set_opt(sbi, DISABLE_EXT_IDENTIFY); in parse_options()
831 set_opt(sbi, INLINE_DATA); in parse_options()
834 set_opt(sbi, INLINE_DENTRY); in parse_options()
837 clear_opt(sbi, INLINE_DENTRY); in parse_options()
840 set_opt(sbi, FLUSH_MERGE); in parse_options()
843 clear_opt(sbi, FLUSH_MERGE); in parse_options()
846 set_opt(sbi, NOBARRIER); in parse_options()
849 clear_opt(sbi, NOBARRIER); in parse_options()
852 set_opt(sbi, FASTBOOT); in parse_options()
855 set_opt(sbi, READ_EXTENT_CACHE); in parse_options()
858 clear_opt(sbi, READ_EXTENT_CACHE); in parse_options()
861 clear_opt(sbi, INLINE_DATA); in parse_options()
864 set_opt(sbi, DATA_FLUSH); in parse_options()
869 if (test_opt(sbi, RESERVE_ROOT)) { in parse_options()
870 f2fs_info(sbi, "Preserve previous reserve_root=%u", in parse_options()
871 F2FS_OPTION(sbi).root_reserved_blocks); in parse_options()
873 F2FS_OPTION(sbi).root_reserved_blocks = arg; in parse_options()
874 set_opt(sbi, RESERVE_ROOT); in parse_options()
882 f2fs_err(sbi, "Invalid uid value %d", arg); in parse_options()
885 F2FS_OPTION(sbi).s_resuid = uid; in parse_options()
892 f2fs_err(sbi, "Invalid gid value %d", arg); in parse_options()
895 F2FS_OPTION(sbi).s_resgid = gid; in parse_options()
903 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in parse_options()
905 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in parse_options()
907 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_SEG; in parse_options()
909 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_BLK; in parse_options()
920 f2fs_warn(sbi, "Not support %ld, larger than %d", in parse_options()
924 F2FS_OPTION(sbi).write_io_size_bits = arg; in parse_options()
930 f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); in parse_options()
931 set_opt(sbi, FAULT_INJECTION); in parse_options()
937 f2fs_build_fault_attr(sbi, 0, arg); in parse_options()
938 set_opt(sbi, FAULT_INJECTION); in parse_options()
942 f2fs_info(sbi, "fault_injection options not supported"); in parse_options()
946 f2fs_info(sbi, "fault_type options not supported"); in parse_options()
958 set_opt(sbi, USRQUOTA); in parse_options()
961 set_opt(sbi, GRPQUOTA); in parse_options()
964 set_opt(sbi, PRJQUOTA); in parse_options()
997 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; in parse_options()
1000 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; in parse_options()
1003 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; in parse_options()
1006 clear_opt(sbi, QUOTA); in parse_options()
1007 clear_opt(sbi, USRQUOTA); in parse_options()
1008 clear_opt(sbi, GRPQUOTA); in parse_options()
1009 clear_opt(sbi, PRJQUOTA); in parse_options()
1026 f2fs_info(sbi, "quota operations not supported"); in parse_options()
1035 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in parse_options()
1037 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in parse_options()
1049 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in parse_options()
1051 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; in parse_options()
1053 F2FS_OPTION(sbi).fsync_mode = in parse_options()
1071 f2fs_info(sbi, "inline encryption not supported"); in parse_options()
1079 F2FS_OPTION(sbi).unusable_cap_perc = arg; in parse_options()
1080 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1085 F2FS_OPTION(sbi).unusable_cap = arg; in parse_options()
1086 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1089 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1092 clear_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1095 set_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1098 clear_opt(sbi, MERGE_CHECKPOINT); 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()
1111 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1112 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1115 f2fs_info(sbi, "kernel doesn't support lzo compression"); in parse_options()
1119 ret = f2fs_set_lz4hc_level(sbi, name); in parse_options()
1124 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1127 f2fs_info(sbi, "kernel doesn't support lz4 compression"); in parse_options()
1131 ret = f2fs_set_zstd_level(sbi, name); in parse_options()
1136 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1139 f2fs_info(sbi, "kernel doesn't support zstd compression"); in parse_options()
1143 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1144 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1147 f2fs_info(sbi, "kernel doesn't support lzorle compression"); in parse_options()
1156 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1157 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1164 f2fs_err(sbi, in parse_options()
1168 F2FS_OPTION(sbi).compress_log_size = arg; in parse_options()
1171 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1172 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1179 ext = F2FS_OPTION(sbi).extensions; in parse_options()
1180 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in parse_options()
1184 f2fs_err(sbi, in parse_options()
1190 if (is_compress_extension_exist(sbi, name, true)) { in parse_options()
1196 F2FS_OPTION(sbi).compress_ext_cnt++; in parse_options()
1200 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1201 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1208 noext = F2FS_OPTION(sbi).noextensions; in parse_options()
1209 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in parse_options()
1213 f2fs_err(sbi, in parse_options()
1219 if (is_compress_extension_exist(sbi, name, false)) { in parse_options()
1225 F2FS_OPTION(sbi).nocompress_ext_cnt++; in parse_options()
1229 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1230 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1233 F2FS_OPTION(sbi).compress_chksum = true; in parse_options()
1236 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1237 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1244 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in parse_options()
1246 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; in parse_options()
1254 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1255 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1258 set_opt(sbi, COMPRESS_CACHE); in parse_options()
1268 f2fs_info(sbi, "compression options not supported"); in parse_options()
1272 set_opt(sbi, ATGC); in parse_options()
1275 set_opt(sbi, GC_MERGE); in parse_options()
1278 clear_opt(sbi, GC_MERGE); in parse_options()
1285 F2FS_OPTION(sbi).discard_unit = in parse_options()
1288 F2FS_OPTION(sbi).discard_unit = in parse_options()
1291 F2FS_OPTION(sbi).discard_unit = in parse_options()
1304 F2FS_OPTION(sbi).memory_mode = in parse_options()
1307 F2FS_OPTION(sbi).memory_mode = in parse_options()
1316 set_opt(sbi, AGE_EXTENT_CACHE); in parse_options()
1323 F2FS_OPTION(sbi).errors = in parse_options()
1326 F2FS_OPTION(sbi).errors = in parse_options()
1329 F2FS_OPTION(sbi).errors = in parse_options()
1338 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", in parse_options()
1345 if (f2fs_check_quota_options(sbi)) in parse_options()
1348 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1349 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1352 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1353 …f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1358 if (f2fs_sb_has_casefold(sbi)) { in parse_options()
1359 f2fs_err(sbi, in parse_options()
1369 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1371 if (F2FS_OPTION(sbi).discard_unit != in parse_options()
1373 …f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default… in parse_options()
1374 F2FS_OPTION(sbi).discard_unit = in parse_options()
1378 if (F2FS_OPTION(sbi).fs_mode != FS_MODE_LFS) { in parse_options()
1379 f2fs_info(sbi, "Only lfs mode is allowed with zoned block device feature"); in parse_options()
1383 f2fs_err(sbi, "Zoned block device support is not enabled"); in parse_options()
1389 if (f2fs_test_compress_extension(sbi)) { in parse_options()
1390 f2fs_err(sbi, "invalid compress or nocompress extension"); in parse_options()
1395 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { in parse_options()
1396 f2fs_err(sbi, "Should set mode=lfs with %luKB-sized IO", in parse_options()
1397 F2FS_IO_SIZE_KB(sbi)); in parse_options()
1401 if (test_opt(sbi, INLINE_XATTR_SIZE)) { in parse_options()
1404 if (!f2fs_sb_has_extra_attr(sbi) || in parse_options()
1405 !f2fs_sb_has_flexible_inline_xattr(sbi)) { in parse_options()
1406 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); in parse_options()
1409 if (!test_opt(sbi, INLINE_XATTR)) { in parse_options()
1410 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); in parse_options()
1417 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || in parse_options()
1418 F2FS_OPTION(sbi).inline_xattr_size > max_size) { in parse_options()
1419 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", in parse_options()
1425 if (test_opt(sbi, ATGC) && f2fs_lfs_mode(sbi)) { in parse_options()
1426 f2fs_err(sbi, "LFS is not compatible with ATGC"); in parse_options()
1430 if (f2fs_is_readonly(sbi) && test_opt(sbi, FLUSH_MERGE)) { in parse_options()
1431 f2fs_err(sbi, "FLUSH_MERGE not compatible with readonly mode"); in parse_options()
1435 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1436 f2fs_err(sbi, "Allow to mount readonly mode only"); in parse_options()
1474 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_drop_inode() local
1481 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_drop_inode()
1482 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_drop_inode()
1483 inode->i_ino == F2FS_META_INO(sbi)) { in f2fs_drop_inode()
1532 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_dirtied() local
1535 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1540 stat_inc_dirty_inode(sbi, DIRTY_META); in f2fs_inode_dirtied()
1544 &sbi->inode_list[DIRTY_META]); in f2fs_inode_dirtied()
1545 inc_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_dirtied()
1547 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1553 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_synced() local
1555 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1557 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1562 dec_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_synced()
1567 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1577 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_dirty_inode() local
1579 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_dirty_inode()
1580 inode->i_ino == F2FS_META_INO(sbi)) in f2fs_dirty_inode()
1595 static void destroy_percpu_info(struct f2fs_sb_info *sbi) in destroy_percpu_info() argument
1597 percpu_counter_destroy(&sbi->total_valid_inode_count); in destroy_percpu_info()
1598 percpu_counter_destroy(&sbi->rf_node_block_count); in destroy_percpu_info()
1599 percpu_counter_destroy(&sbi->alloc_valid_block_count); in destroy_percpu_info()
1602 static void destroy_device_list(struct f2fs_sb_info *sbi) in destroy_device_list() argument
1606 for (i = 0; i < sbi->s_ndevs; i++) { in destroy_device_list()
1613 kvfree(sbi->devs); in destroy_device_list()
1618 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_put_super() local
1624 f2fs_unregister_sysfs(sbi); in f2fs_put_super()
1629 mutex_lock(&sbi->umount_mutex); in f2fs_put_super()
1635 f2fs_stop_ckpt_thread(sbi); in f2fs_put_super()
1642 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in f2fs_put_super()
1643 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { in f2fs_put_super()
1647 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_put_super()
1648 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1652 done = f2fs_issue_discard_timeout(sbi); in f2fs_put_super()
1653 if (f2fs_realtime_discard_enable(sbi) && !sbi->discard_blks && done) { in f2fs_put_super()
1657 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_put_super()
1658 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1665 f2fs_release_ino_entry(sbi, true); in f2fs_put_super()
1667 f2fs_leave_shrinker(sbi); in f2fs_put_super()
1668 mutex_unlock(&sbi->umount_mutex); in f2fs_put_super()
1671 f2fs_flush_merged_writes(sbi); in f2fs_put_super()
1673 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); in f2fs_put_super()
1675 if (err || f2fs_cp_error(sbi)) { in f2fs_put_super()
1676 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_put_super()
1677 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_put_super()
1681 if (!get_pages(sbi, i)) in f2fs_put_super()
1683 f2fs_err(sbi, "detect filesystem reference count leak during " in f2fs_put_super()
1684 "umount, type: %d, count: %lld", i, get_pages(sbi, i)); in f2fs_put_super()
1685 f2fs_bug_on(sbi, 1); in f2fs_put_super()
1688 f2fs_bug_on(sbi, sbi->fsync_node_num); in f2fs_put_super()
1690 f2fs_destroy_compress_inode(sbi); in f2fs_put_super()
1692 iput(sbi->node_inode); in f2fs_put_super()
1693 sbi->node_inode = NULL; in f2fs_put_super()
1695 iput(sbi->meta_inode); in f2fs_put_super()
1696 sbi->meta_inode = NULL; in f2fs_put_super()
1702 f2fs_destroy_stats(sbi); in f2fs_put_super()
1705 f2fs_destroy_node_manager(sbi); in f2fs_put_super()
1706 f2fs_destroy_segment_manager(sbi); in f2fs_put_super()
1708 /* flush s_error_work before sbi destroy */ in f2fs_put_super()
1709 flush_work(&sbi->s_error_work); in f2fs_put_super()
1711 f2fs_destroy_post_read_wq(sbi); in f2fs_put_super()
1713 kvfree(sbi->ckpt); in f2fs_put_super()
1715 if (sbi->s_chksum_driver) in f2fs_put_super()
1716 crypto_free_shash(sbi->s_chksum_driver); in f2fs_put_super()
1717 kfree(sbi->raw_super); in f2fs_put_super()
1719 f2fs_destroy_page_array_cache(sbi); in f2fs_put_super()
1720 f2fs_destroy_xattr_caches(sbi); in f2fs_put_super()
1721 mempool_destroy(sbi->write_io_dummy); in f2fs_put_super()
1724 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_put_super()
1726 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_put_super()
1727 destroy_percpu_info(sbi); in f2fs_put_super()
1728 f2fs_destroy_iostat(sbi); in f2fs_put_super()
1730 kvfree(sbi->write_io[i]); in f2fs_put_super()
1738 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_sync_fs() local
1741 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_fs()
1743 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_sync_fs()
1748 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_sync_fs()
1752 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_sync_fs()
1753 err = f2fs_issue_checkpoint(sbi); in f2fs_sync_fs()
1834 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_statfs() local
1840 total_count = le64_to_cpu(sbi->raw_super->block_count); in f2fs_statfs()
1841 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); in f2fs_statfs()
1843 buf->f_bsize = sbi->blocksize; in f2fs_statfs()
1847 spin_lock(&sbi->stat_lock); in f2fs_statfs()
1849 user_block_count = sbi->user_block_count; in f2fs_statfs()
1850 total_valid_node_count = valid_node_count(sbi); in f2fs_statfs()
1851 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_statfs()
1852 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - in f2fs_statfs()
1853 sbi->current_reserved_blocks; in f2fs_statfs()
1855 if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) in f2fs_statfs()
1858 buf->f_bfree -= sbi->unusable_block_count; in f2fs_statfs()
1859 spin_unlock(&sbi->stat_lock); in f2fs_statfs()
1861 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) in f2fs_statfs()
1863 F2FS_OPTION(sbi).root_reserved_blocks; in f2fs_statfs()
1892 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_quota_options() local
1894 if (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1897 switch (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1911 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_show_quota_options()
1913 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); in f2fs_show_quota_options()
1915 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_show_quota_options()
1917 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); in f2fs_show_quota_options()
1919 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_show_quota_options()
1921 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); in f2fs_show_quota_options()
1929 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_compress_options() local
1933 if (!f2fs_sb_has_compression(sbi)) in f2fs_show_compress_options()
1936 switch (F2FS_OPTION(sbi).compress_algorithm) { in f2fs_show_compress_options()
1952 if (F2FS_OPTION(sbi).compress_level) in f2fs_show_compress_options()
1953 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); in f2fs_show_compress_options()
1956 F2FS_OPTION(sbi).compress_log_size); in f2fs_show_compress_options()
1958 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { in f2fs_show_compress_options()
1960 F2FS_OPTION(sbi).extensions[i]); in f2fs_show_compress_options()
1963 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) { in f2fs_show_compress_options()
1965 F2FS_OPTION(sbi).noextensions[i]); in f2fs_show_compress_options()
1968 if (F2FS_OPTION(sbi).compress_chksum) in f2fs_show_compress_options()
1971 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) in f2fs_show_compress_options()
1973 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) in f2fs_show_compress_options()
1976 if (test_opt(sbi, COMPRESS_CACHE)) in f2fs_show_compress_options()
1983 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); in f2fs_show_options() local
1985 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) in f2fs_show_options()
1987 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) in f2fs_show_options()
1989 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) in f2fs_show_options()
1992 if (test_opt(sbi, GC_MERGE)) in f2fs_show_options()
1997 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_show_options()
1999 if (test_opt(sbi, NORECOVERY)) in f2fs_show_options()
2001 if (test_opt(sbi, DISCARD)) { in f2fs_show_options()
2003 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK) in f2fs_show_options()
2005 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT) in f2fs_show_options()
2007 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION) in f2fs_show_options()
2012 if (test_opt(sbi, NOHEAP)) in f2fs_show_options()
2017 if (test_opt(sbi, XATTR_USER)) in f2fs_show_options()
2021 if (test_opt(sbi, INLINE_XATTR)) in f2fs_show_options()
2025 if (test_opt(sbi, INLINE_XATTR_SIZE)) in f2fs_show_options()
2027 F2FS_OPTION(sbi).inline_xattr_size); in f2fs_show_options()
2030 if (test_opt(sbi, POSIX_ACL)) in f2fs_show_options()
2035 if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) in f2fs_show_options()
2037 if (test_opt(sbi, INLINE_DATA)) in f2fs_show_options()
2041 if (test_opt(sbi, INLINE_DENTRY)) in f2fs_show_options()
2045 if (test_opt(sbi, FLUSH_MERGE)) in f2fs_show_options()
2049 if (test_opt(sbi, NOBARRIER)) in f2fs_show_options()
2053 if (test_opt(sbi, FASTBOOT)) in f2fs_show_options()
2055 if (test_opt(sbi, READ_EXTENT_CACHE)) in f2fs_show_options()
2059 if (test_opt(sbi, AGE_EXTENT_CACHE)) in f2fs_show_options()
2061 if (test_opt(sbi, DATA_FLUSH)) in f2fs_show_options()
2065 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) in f2fs_show_options()
2067 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) in f2fs_show_options()
2069 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG) in f2fs_show_options()
2071 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) in f2fs_show_options()
2073 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); in f2fs_show_options()
2074 if (test_opt(sbi, RESERVE_ROOT)) in f2fs_show_options()
2076 F2FS_OPTION(sbi).root_reserved_blocks, in f2fs_show_options()
2078 F2FS_OPTION(sbi).s_resuid), in f2fs_show_options()
2080 F2FS_OPTION(sbi).s_resgid)); in f2fs_show_options()
2081 if (F2FS_IO_SIZE_BITS(sbi)) in f2fs_show_options()
2083 F2FS_OPTION(sbi).write_io_size_bits); in f2fs_show_options()
2085 if (test_opt(sbi, FAULT_INJECTION)) { in f2fs_show_options()
2087 F2FS_OPTION(sbi).fault_info.inject_rate); in f2fs_show_options()
2089 F2FS_OPTION(sbi).fault_info.inject_type); in f2fs_show_options()
2093 if (test_opt(sbi, QUOTA)) in f2fs_show_options()
2095 if (test_opt(sbi, USRQUOTA)) in f2fs_show_options()
2097 if (test_opt(sbi, GRPQUOTA)) in f2fs_show_options()
2099 if (test_opt(sbi, PRJQUOTA)) in f2fs_show_options()
2102 f2fs_show_quota_options(seq, sbi->sb); in f2fs_show_options()
2104 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); in f2fs_show_options()
2106 if (sbi->sb->s_flags & SB_INLINECRYPT) in f2fs_show_options()
2109 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) in f2fs_show_options()
2111 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) in f2fs_show_options()
2114 if (test_opt(sbi, DISABLE_CHECKPOINT)) in f2fs_show_options()
2116 F2FS_OPTION(sbi).unusable_cap); in f2fs_show_options()
2117 if (test_opt(sbi, MERGE_CHECKPOINT)) in f2fs_show_options()
2121 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) in f2fs_show_options()
2123 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) in f2fs_show_options()
2125 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) in f2fs_show_options()
2129 f2fs_show_compress_options(seq, sbi->sb); in f2fs_show_options()
2132 if (test_opt(sbi, ATGC)) in f2fs_show_options()
2135 if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL) in f2fs_show_options()
2137 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW) in f2fs_show_options()
2140 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) in f2fs_show_options()
2142 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE) in f2fs_show_options()
2144 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC) in f2fs_show_options()
2150 static void default_options(struct f2fs_sb_info *sbi, bool remount) in default_options() argument
2154 set_opt(sbi, READ_EXTENT_CACHE); in default_options()
2155 clear_opt(sbi, DISABLE_CHECKPOINT); in default_options()
2157 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) in default_options()
2158 set_opt(sbi, DISCARD); in default_options()
2160 if (f2fs_sb_has_blkzoned(sbi)) in default_options()
2161 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; in default_options()
2163 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; in default_options()
2166 if (f2fs_sb_has_readonly(sbi)) in default_options()
2167 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; in default_options()
2169 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; in default_options()
2171 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; in default_options()
2172 if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main) <= in default_options()
2174 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in default_options()
2176 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in default_options()
2177 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in default_options()
2178 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); in default_options()
2179 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); in default_options()
2180 if (f2fs_sb_has_compression(sbi)) { in default_options()
2181 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; in default_options()
2182 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; in default_options()
2183 F2FS_OPTION(sbi).compress_ext_cnt = 0; in default_options()
2184 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in default_options()
2186 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in default_options()
2187 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL; in default_options()
2188 F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE; in default_options()
2190 sbi->sb->s_flags &= ~SB_INLINECRYPT; in default_options()
2192 set_opt(sbi, INLINE_XATTR); in default_options()
2193 set_opt(sbi, INLINE_DATA); in default_options()
2194 set_opt(sbi, INLINE_DENTRY); in default_options()
2195 set_opt(sbi, NOHEAP); in default_options()
2196 set_opt(sbi, MERGE_CHECKPOINT); in default_options()
2197 F2FS_OPTION(sbi).unusable_cap = 0; in default_options()
2198 sbi->sb->s_flags |= SB_LAZYTIME; in default_options()
2199 if (!f2fs_is_readonly(sbi)) in default_options()
2200 set_opt(sbi, FLUSH_MERGE); in default_options()
2201 if (f2fs_sb_has_blkzoned(sbi)) in default_options()
2202 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in default_options()
2204 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in default_options()
2207 set_opt(sbi, XATTR_USER); in default_options()
2210 set_opt(sbi, POSIX_ACL); in default_options()
2213 f2fs_build_fault_attr(sbi, 0, 0); in default_options()
2220 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_disable_checkpoint() argument
2222 unsigned int s_flags = sbi->sb->s_flags; in f2fs_disable_checkpoint()
2224 unsigned int gc_mode = sbi->gc_mode; in f2fs_disable_checkpoint()
2230 f2fs_err(sbi, "checkpoint=disable on readonly fs"); in f2fs_disable_checkpoint()
2233 sbi->sb->s_flags |= SB_ACTIVE; in f2fs_disable_checkpoint()
2236 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2237 if (!f2fs_disable_cp_again(sbi, unusable)) in f2fs_disable_checkpoint()
2240 f2fs_update_time(sbi, DISABLE_TIME); in f2fs_disable_checkpoint()
2242 sbi->gc_mode = GC_URGENT_HIGH; in f2fs_disable_checkpoint()
2244 while (!f2fs_time_over(sbi, DISABLE_TIME)) { in f2fs_disable_checkpoint()
2252 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2253 stat_inc_gc_call_count(sbi, FOREGROUND); in f2fs_disable_checkpoint()
2254 err = f2fs_gc(sbi, &gc_control); in f2fs_disable_checkpoint()
2263 ret = sync_filesystem(sbi->sb); in f2fs_disable_checkpoint()
2269 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2270 if (f2fs_disable_cp_again(sbi, unusable)) { in f2fs_disable_checkpoint()
2276 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2278 set_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_disable_checkpoint()
2279 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_disable_checkpoint()
2280 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_disable_checkpoint()
2284 spin_lock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2285 sbi->unusable_block_count = unusable; in f2fs_disable_checkpoint()
2286 spin_unlock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2289 f2fs_up_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2291 sbi->gc_mode = gc_mode; in f2fs_disable_checkpoint()
2292 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in f2fs_disable_checkpoint()
2296 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_enable_checkpoint() argument
2302 sync_inodes_sb(sbi->sb); in f2fs_enable_checkpoint()
2304 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); in f2fs_enable_checkpoint()
2307 f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); in f2fs_enable_checkpoint()
2309 f2fs_down_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2310 f2fs_dirty_to_prefree(sbi); in f2fs_enable_checkpoint()
2312 clear_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_enable_checkpoint()
2313 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_enable_checkpoint()
2314 f2fs_up_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2316 f2fs_sync_fs(sbi->sb, 1); in f2fs_enable_checkpoint()
2319 f2fs_flush_ckpt_thread(sbi); in f2fs_enable_checkpoint()
2324 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_remount() local
2332 bool no_read_extent_cache = !test_opt(sbi, READ_EXTENT_CACHE); in f2fs_remount()
2333 bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE); in f2fs_remount()
2334 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2335 bool no_io_align = !F2FS_IO_ALIGNED(sbi); in f2fs_remount()
2336 bool no_atgc = !test_opt(sbi, ATGC); in f2fs_remount()
2337 bool no_discard = !test_opt(sbi, DISCARD); in f2fs_remount()
2338 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); in f2fs_remount()
2339 bool block_unit_discard = f2fs_block_unit_discard(sbi); in f2fs_remount()
2348 org_mount_opt = sbi->mount_opt; in f2fs_remount()
2352 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; in f2fs_remount()
2354 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_remount()
2356 kstrdup(F2FS_OPTION(sbi).s_qf_names[i], in f2fs_remount()
2370 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { in f2fs_remount()
2371 err = f2fs_commit_super(sbi, false); in f2fs_remount()
2372 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", in f2fs_remount()
2375 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_remount()
2378 default_options(sbi, true); in f2fs_remount()
2386 flush_work(&sbi->s_error_work); in f2fs_remount()
2395 if (f2fs_dev_is_readonly(sbi) && !(*flags & SB_RDONLY)) { in f2fs_remount()
2410 } else if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_remount()
2417 if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) { in f2fs_remount()
2419 f2fs_warn(sbi, "LFS is not compatible with IPU"); in f2fs_remount()
2424 if (no_atgc == !!test_opt(sbi, ATGC)) { in f2fs_remount()
2426 f2fs_warn(sbi, "switch atgc option is not allowed"); in f2fs_remount()
2431 if (no_read_extent_cache == !!test_opt(sbi, READ_EXTENT_CACHE)) { in f2fs_remount()
2433 f2fs_warn(sbi, "switch extent_cache option is not allowed"); in f2fs_remount()
2437 if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) { in f2fs_remount()
2439 f2fs_warn(sbi, "switch age_extent_cache option is not allowed"); in f2fs_remount()
2443 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { in f2fs_remount()
2445 f2fs_warn(sbi, "switch io_bits option is not allowed"); in f2fs_remount()
2449 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { in f2fs_remount()
2451 f2fs_warn(sbi, "switch compress_cache option is not allowed"); in f2fs_remount()
2455 if (block_unit_discard != f2fs_block_unit_discard(sbi)) { in f2fs_remount()
2457 f2fs_warn(sbi, "switch discard_unit option is not allowed"); in f2fs_remount()
2461 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2463 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); in f2fs_remount()
2473 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && in f2fs_remount()
2474 !test_opt(sbi, GC_MERGE))) { in f2fs_remount()
2475 if (sbi->gc_thread) { in f2fs_remount()
2476 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2479 } else if (!sbi->gc_thread) { in f2fs_remount()
2480 err = f2fs_start_gc_thread(sbi); in f2fs_remount()
2489 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_remount()
2490 set_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2492 clear_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2499 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { in f2fs_remount()
2500 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2501 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2504 err = f2fs_create_flush_cmd_control(sbi); in f2fs_remount()
2510 if (no_discard == !!test_opt(sbi, DISCARD)) { in f2fs_remount()
2511 if (test_opt(sbi, DISCARD)) { in f2fs_remount()
2512 err = f2fs_start_discard_thread(sbi); in f2fs_remount()
2517 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2518 f2fs_issue_discard_timeout(sbi); in f2fs_remount()
2523 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2524 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2525 err = f2fs_disable_checkpoint(sbi); in f2fs_remount()
2530 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2540 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || in f2fs_remount()
2541 !test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_remount()
2542 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2545 f2fs_flush_ckpt_thread(sbi); in f2fs_remount()
2547 err = f2fs_start_ckpt_thread(sbi); in f2fs_remount()
2549 f2fs_err(sbi, in f2fs_remount()
2564 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_remount()
2566 limit_reserve_root(sbi); in f2fs_remount()
2567 adjust_unusable_cap_perc(sbi); 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()
2613 static bool f2fs_need_recovery(struct f2fs_sb_info *sbi) in f2fs_need_recovery() argument
2616 if (is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG)) in f2fs_need_recovery()
2619 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_need_recovery()
2621 if (test_opt(sbi, NORECOVERY)) in f2fs_need_recovery()
2623 return !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG); in f2fs_need_recovery()
2626 static bool f2fs_recover_quota_begin(struct f2fs_sb_info *sbi) in f2fs_recover_quota_begin() argument
2628 bool readonly = f2fs_readonly(sbi->sb); in f2fs_recover_quota_begin()
2630 if (!f2fs_need_recovery(sbi)) in f2fs_recover_quota_begin()
2634 if (f2fs_hw_is_readonly(sbi)) in f2fs_recover_quota_begin()
2638 sbi->sb->s_flags &= ~SB_RDONLY; in f2fs_recover_quota_begin()
2639 set_sbi_flag(sbi, SBI_IS_WRITABLE); in f2fs_recover_quota_begin()
2646 return f2fs_enable_quota_files(sbi, readonly); in f2fs_recover_quota_begin()
2649 static void f2fs_recover_quota_end(struct f2fs_sb_info *sbi, in f2fs_recover_quota_end() argument
2653 f2fs_quota_off_umount(sbi->sb); in f2fs_recover_quota_end()
2655 if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE)) { in f2fs_recover_quota_end()
2656 clear_sbi_flag(sbi, SBI_IS_WRITABLE); in f2fs_recover_quota_end()
2657 sbi->sb->s_flags |= SB_RDONLY; in f2fs_recover_quota_end()
2781 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) in f2fs_quota_on_mount() argument
2783 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { in f2fs_quota_on_mount()
2784 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); in f2fs_quota_on_mount()
2788 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], in f2fs_quota_on_mount()
2789 F2FS_OPTION(sbi).s_jquota_fmt, type); in f2fs_quota_on_mount()
2792 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) in f2fs_enable_quota_files() argument
2797 if (f2fs_sb_has_quota_ino(sbi) && rdonly) { in f2fs_enable_quota_files()
2798 err = f2fs_enable_quotas(sbi->sb); in f2fs_enable_quota_files()
2800 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); in f2fs_enable_quota_files()
2807 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_enable_quota_files()
2808 err = f2fs_quota_on_mount(sbi, i); in f2fs_enable_quota_files()
2813 f2fs_err(sbi, "Cannot turn on quotas: %d on %d", in f2fs_enable_quota_files()
2857 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_enable_quotas() local
2861 test_opt(sbi, USRQUOTA), in f2fs_enable_quotas()
2862 test_opt(sbi, GRPQUOTA), in f2fs_enable_quotas()
2863 test_opt(sbi, PRJQUOTA), in f2fs_enable_quotas()
2867 f2fs_err(sbi, "quota file may be corrupted, skip loading it"); in f2fs_enable_quotas()
2880 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", in f2fs_enable_quotas()
2893 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) in f2fs_quota_sync_file() argument
2895 struct quota_info *dqopt = sb_dqopt(sbi->sb); in f2fs_quota_sync_file()
2899 ret = dquot_writeback_dquots(sbi->sb, type); in f2fs_quota_sync_file()
2908 if (is_journalled_quota(sbi)) in f2fs_quota_sync_file()
2916 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_sync_file()
2922 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_sync() local
2939 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_quota_sync()
2951 f2fs_lock_op(sbi); in f2fs_quota_sync()
2952 f2fs_down_read(&sbi->quota_sem); in f2fs_quota_sync()
2954 ret = f2fs_quota_sync_file(sbi, cnt); in f2fs_quota_sync()
2956 f2fs_up_read(&sbi->quota_sem); in f2fs_quota_sync()
2957 f2fs_unlock_op(sbi); in f2fs_quota_sync()
2959 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_quota_sync()
3038 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_off() local
3048 if (is_journalled_quota(sbi)) in f2fs_quota_off()
3049 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_off()
3090 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_commit() local
3093 f2fs_down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); in f2fs_dquot_commit()
3096 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit()
3097 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_commit()
3103 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_acquire() local
3106 f2fs_down_read(&sbi->quota_sem); in f2fs_dquot_acquire()
3109 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_acquire()
3110 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_acquire()
3116 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_release() local
3120 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_release()
3127 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_mark_dquot_dirty() local
3131 if (is_journalled_quota(sbi)) in f2fs_dquot_mark_dquot_dirty()
3132 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); in f2fs_dquot_mark_dquot_dirty()
3139 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_commit_info() local
3143 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit_info()
3224 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_set_context() local
3232 if (f2fs_sb_has_lost_found(sbi) && in f2fs_set_context()
3233 inode->i_ino == F2FS_ROOT_INO(sbi)) in f2fs_set_context()
3254 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_devices() local
3258 if (!f2fs_is_multi_device(sbi)) in f2fs_get_devices()
3261 devs = kmalloc_array(sbi->s_ndevs, sizeof(*devs), GFP_KERNEL); in f2fs_get_devices()
3265 for (i = 0; i < sbi->s_ndevs; i++) in f2fs_get_devices()
3267 *num_devs = sbi->s_ndevs; in f2fs_get_devices()
3288 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_nfs_get_inode() local
3291 if (f2fs_check_nid_range(sbi, ino)) in f2fs_nfs_get_inode()
3383 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, in sanity_check_area_boundary() argument
3388 struct super_block *sb = sbi->sb; in sanity_check_area_boundary()
3408 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", in sanity_check_area_boundary()
3415 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3423 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3431 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3439 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3446 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3458 if (f2fs_readonly(sb) || f2fs_hw_is_readonly(sbi)) { in sanity_check_area_boundary()
3459 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in sanity_check_area_boundary()
3465 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3474 static int sanity_check_raw_super(struct f2fs_sb_info *sbi, in sanity_check_raw_super() argument
3485 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", in sanity_check_raw_super()
3495 f2fs_info(sbi, "Invalid SB checksum offset: %zu", in sanity_check_raw_super()
3500 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { in sanity_check_raw_super()
3501 f2fs_info(sbi, "Invalid SB checksum value: %u", crc); in sanity_check_raw_super()
3508 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", in sanity_check_raw_super()
3516 f2fs_info(sbi, "Invalid log blocks per segment (%u)", in sanity_check_raw_super()
3526 f2fs_info(sbi, "Invalid log sectorsize (%u)", in sanity_check_raw_super()
3533 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", in sanity_check_raw_super()
3550 f2fs_info(sbi, "Invalid segment count (%u)", segment_count); in sanity_check_raw_super()
3556 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", in sanity_check_raw_super()
3562 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", in sanity_check_raw_super()
3568 f2fs_info(sbi, "Small segment_count (%u < %u * %u)", in sanity_check_raw_super()
3574 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", in sanity_check_raw_super()
3588 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", in sanity_check_raw_super()
3594 !bdev_is_zoned(sbi->sb->s_bdev)) { in sanity_check_raw_super()
3595 f2fs_info(sbi, "Zoned block device path is missing"); in sanity_check_raw_super()
3601 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", in sanity_check_raw_super()
3609 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", in sanity_check_raw_super()
3619 f2fs_info(sbi, "Insane cp_payload (%u >= %u)", in sanity_check_raw_super()
3630 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", in sanity_check_raw_super()
3638 if (sanity_check_area_boundary(sbi, bh)) in sanity_check_raw_super()
3644 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) in f2fs_sanity_check_ckpt() argument
3647 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_sanity_check_ckpt()
3648 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in f2fs_sanity_check_ckpt()
3676 if (!f2fs_sb_has_readonly(sbi) && in f2fs_sanity_check_ckpt()
3679 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); in f2fs_sanity_check_ckpt()
3684 (f2fs_sb_has_readonly(sbi) ? 1 : 0); in f2fs_sanity_check_ckpt()
3688 f2fs_err(sbi, "Wrong user_block_count: %u", in f2fs_sanity_check_ckpt()
3695 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", in f2fs_sanity_check_ckpt()
3701 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_sanity_check_ckpt()
3703 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", in f2fs_sanity_check_ckpt()
3709 blocks_per_seg = sbi->blocks_per_seg; in f2fs_sanity_check_ckpt()
3716 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3722 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3735 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3741 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3752 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3765 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", in f2fs_sanity_check_ckpt()
3770 cp_pack_start_sum = __start_sum_addr(sbi); in f2fs_sanity_check_ckpt()
3771 cp_payload = __cp_payload(sbi); in f2fs_sanity_check_ckpt()
3775 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", in f2fs_sanity_check_ckpt()
3782 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " in f2fs_sanity_check_ckpt()
3795 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", in f2fs_sanity_check_ckpt()
3800 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_sanity_check_ckpt()
3801 f2fs_err(sbi, "A bug case: need to run fsck"); in f2fs_sanity_check_ckpt()
3807 static void init_sb_info(struct f2fs_sb_info *sbi) in init_sb_info() argument
3809 struct f2fs_super_block *raw_super = sbi->raw_super; in init_sb_info()
3812 sbi->log_sectors_per_block = in init_sb_info()
3814 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); in init_sb_info()
3815 sbi->blocksize = BIT(sbi->log_blocksize); in init_sb_info()
3816 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); in init_sb_info()
3817 sbi->blocks_per_seg = BIT(sbi->log_blocks_per_seg); in init_sb_info()
3818 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); in init_sb_info()
3819 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); in init_sb_info()
3820 sbi->total_sections = le32_to_cpu(raw_super->section_count); in init_sb_info()
3821 sbi->total_node_count = in init_sb_info()
3823 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; in init_sb_info()
3824 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); in init_sb_info()
3825 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); in init_sb_info()
3826 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); in init_sb_info()
3827 sbi->cur_victim_sec = NULL_SECNO; in init_sb_info()
3828 sbi->gc_mode = GC_NORMAL; in init_sb_info()
3829 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in init_sb_info()
3830 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in init_sb_info()
3831 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; in init_sb_info()
3832 sbi->migration_granularity = sbi->segs_per_sec; in init_sb_info()
3833 sbi->seq_file_ra_mul = MIN_RA_MUL; in init_sb_info()
3834 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE; in init_sb_info()
3835 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE; in init_sb_info()
3836 spin_lock_init(&sbi->gc_remaining_trials_lock); in init_sb_info()
3837 atomic64_set(&sbi->current_atomic_write, 0); in init_sb_info()
3839 sbi->dir_level = DEF_DIR_LEVEL; in init_sb_info()
3840 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; in init_sb_info()
3841 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3842 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3843 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3844 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; in init_sb_info()
3845 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = in init_sb_info()
3847 clear_sbi_flag(sbi, SBI_NEED_FSCK); in init_sb_info()
3850 atomic_set(&sbi->nr_pages[i], 0); in init_sb_info()
3853 atomic_set(&sbi->wb_sync_req[i], 0); in init_sb_info()
3855 INIT_LIST_HEAD(&sbi->s_list); in init_sb_info()
3856 mutex_init(&sbi->umount_mutex); in init_sb_info()
3857 init_f2fs_rwsem(&sbi->io_order_lock); in init_sb_info()
3858 spin_lock_init(&sbi->cp_lock); in init_sb_info()
3860 sbi->dirty_device = 0; in init_sb_info()
3861 spin_lock_init(&sbi->dev_lock); in init_sb_info()
3863 init_f2fs_rwsem(&sbi->sb_lock); in init_sb_info()
3864 init_f2fs_rwsem(&sbi->pin_sem); in init_sb_info()
3867 static int init_percpu_info(struct f2fs_sb_info *sbi) in init_percpu_info() argument
3871 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); in init_percpu_info()
3875 err = percpu_counter_init(&sbi->rf_node_block_count, 0, GFP_KERNEL); in init_percpu_info()
3879 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, in init_percpu_info()
3886 percpu_counter_destroy(&sbi->rf_node_block_count); in init_percpu_info()
3888 percpu_counter_destroy(&sbi->alloc_valid_block_count); in init_percpu_info()
3895 struct f2fs_sb_info *sbi; member
3910 if (!rz_args->sbi->unusable_blocks_per_sec) { in f2fs_report_zone_cb()
3911 rz_args->sbi->unusable_blocks_per_sec = unusable_blocks; in f2fs_report_zone_cb()
3914 if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) { in f2fs_report_zone_cb()
3915 f2fs_err(rz_args->sbi, "F2FS supports single zone capacity\n"); in f2fs_report_zone_cb()
3921 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) in init_blkz_info() argument
3929 if (!f2fs_sb_has_blkzoned(sbi)) in init_blkz_info()
3934 f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n"); in init_blkz_info()
3938 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != in init_blkz_info()
3941 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(zone_sectors); in init_blkz_info()
3943 sbi->blocks_per_blkz); in init_blkz_info()
3947 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, in init_blkz_info()
3954 rep_zone_arg.sbi = sbi; in init_blkz_info()
3971 static int read_raw_super_block(struct f2fs_sb_info *sbi, in read_raw_super_block() argument
3975 struct super_block *sb = sbi->sb; in read_raw_super_block()
3988 f2fs_err(sbi, "Unable to read %dth superblock", in read_raw_super_block()
3996 err = sanity_check_raw_super(sbi, bh); in read_raw_super_block()
3998 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", in read_raw_super_block()
4023 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) in f2fs_commit_super() argument
4029 if ((recover && f2fs_readonly(sbi->sb)) || in f2fs_commit_super()
4030 f2fs_hw_is_readonly(sbi)) { in f2fs_commit_super()
4031 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_commit_super()
4036 if (!recover && f2fs_sb_has_sb_chksum(sbi)) { in f2fs_commit_super()
4037 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), in f2fs_commit_super()
4039 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); in f2fs_commit_super()
4043 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); in f2fs_commit_super()
4046 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
4054 bh = sb_bread(sbi->sb, sbi->valid_super_block); in f2fs_commit_super()
4057 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
4062 static void save_stop_reason(struct f2fs_sb_info *sbi, unsigned char reason) in save_stop_reason() argument
4066 spin_lock_irqsave(&sbi->error_lock, flags); in save_stop_reason()
4067 if (sbi->stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0)) in save_stop_reason()
4068 sbi->stop_reason[reason]++; in save_stop_reason()
4069 spin_unlock_irqrestore(&sbi->error_lock, flags); in save_stop_reason()
4072 static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi) in f2fs_record_stop_reason() argument
4074 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_record_stop_reason()
4078 f2fs_down_write(&sbi->sb_lock); in f2fs_record_stop_reason()
4080 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_record_stop_reason()
4081 if (sbi->error_dirty) { in f2fs_record_stop_reason()
4082 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, in f2fs_record_stop_reason()
4084 sbi->error_dirty = false; in f2fs_record_stop_reason()
4086 memcpy(raw_super->s_stop_reason, sbi->stop_reason, MAX_STOP_REASON); in f2fs_record_stop_reason()
4087 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_record_stop_reason()
4089 err = f2fs_commit_super(sbi, false); in f2fs_record_stop_reason()
4091 f2fs_up_write(&sbi->sb_lock); in f2fs_record_stop_reason()
4093 f2fs_err(sbi, "f2fs_commit_super fails to record err:%d", err); in f2fs_record_stop_reason()
4096 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag) in f2fs_save_errors() argument
4100 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_save_errors()
4101 if (!test_bit(flag, (unsigned long *)sbi->errors)) { in f2fs_save_errors()
4102 set_bit(flag, (unsigned long *)sbi->errors); in f2fs_save_errors()
4103 sbi->error_dirty = true; in f2fs_save_errors()
4105 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_save_errors()
4108 static bool f2fs_update_errors(struct f2fs_sb_info *sbi) in f2fs_update_errors() argument
4113 spin_lock_irqsave(&sbi->error_lock, flags); in f2fs_update_errors()
4114 if (sbi->error_dirty) { in f2fs_update_errors()
4115 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors, in f2fs_update_errors()
4117 sbi->error_dirty = false; in f2fs_update_errors()
4120 spin_unlock_irqrestore(&sbi->error_lock, flags); in f2fs_update_errors()
4125 static void f2fs_record_errors(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_record_errors() argument
4129 f2fs_down_write(&sbi->sb_lock); in f2fs_record_errors()
4131 if (!f2fs_update_errors(sbi)) in f2fs_record_errors()
4134 err = f2fs_commit_super(sbi, false); in f2fs_record_errors()
4136 f2fs_err(sbi, "f2fs_commit_super fails to record errors:%u, err:%d", in f2fs_record_errors()
4139 f2fs_up_write(&sbi->sb_lock); in f2fs_record_errors()
4142 void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_handle_error() argument
4144 f2fs_save_errors(sbi, error); in f2fs_handle_error()
4145 f2fs_record_errors(sbi, error); in f2fs_handle_error()
4148 void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error) in f2fs_handle_error_async() argument
4150 f2fs_save_errors(sbi, error); in f2fs_handle_error_async()
4152 if (!sbi->error_dirty) in f2fs_handle_error_async()
4154 if (!test_bit(error, (unsigned long *)sbi->errors)) in f2fs_handle_error_async()
4156 schedule_work(&sbi->s_error_work); in f2fs_handle_error_async()
4165 void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, in f2fs_handle_critical_error() argument
4168 struct super_block *sb = sbi->sb; in f2fs_handle_critical_error()
4171 F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE; in f2fs_handle_critical_error()
4173 set_ckpt_flags(sbi, CP_ERROR_FLAG); in f2fs_handle_critical_error()
4175 if (!f2fs_hw_is_readonly(sbi)) { in f2fs_handle_critical_error()
4176 save_stop_reason(sbi, reason); in f2fs_handle_critical_error()
4179 schedule_work(&sbi->s_error_work); in f2fs_handle_critical_error()
4181 f2fs_record_stop_reason(sbi); in f2fs_handle_critical_error()
4189 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC && in f2fs_handle_critical_error()
4191 !is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN)) in f2fs_handle_critical_error()
4196 set_sbi_flag(sbi, SBI_IS_SHUTDOWN); in f2fs_handle_critical_error()
4202 f2fs_warn(sbi, "Remounting filesystem read-only"); in f2fs_handle_critical_error()
4213 struct f2fs_sb_info *sbi = container_of(work, in f2fs_record_error_work() local
4216 f2fs_record_stop_reason(sbi); in f2fs_record_error_work()
4219 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) in f2fs_scan_devices() argument
4221 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_scan_devices()
4224 blk_mode_t mode = sb_open_mode(sbi->sb->s_flags); in f2fs_scan_devices()
4229 if (!bdev_is_zoned(sbi->sb->s_bdev)) in f2fs_scan_devices()
4238 sbi->devs = f2fs_kzalloc(sbi, in f2fs_scan_devices()
4242 if (!sbi->devs) in f2fs_scan_devices()
4245 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev); in f2fs_scan_devices()
4246 sbi->aligned_blksize = true; in f2fs_scan_devices()
4250 FDEV(0).bdev_handle = sbi->sb->s_bdev_handle; in f2fs_scan_devices()
4263 sbi->log_blocks_per_seg) - 1 + in f2fs_scan_devices()
4269 sbi->log_blocks_per_seg) - 1; in f2fs_scan_devices()
4271 FDEV(i).path, mode, sbi->sb, NULL); in f2fs_scan_devices()
4279 sbi->s_ndevs = i + 1; in f2fs_scan_devices()
4282 sbi->aligned_blksize = false; in f2fs_scan_devices()
4286 if (!f2fs_sb_has_blkzoned(sbi)) { in f2fs_scan_devices()
4287 f2fs_err(sbi, "Zoned block device feature not enabled"); in f2fs_scan_devices()
4290 if (init_blkz_info(sbi, i)) { in f2fs_scan_devices()
4291 f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); in f2fs_scan_devices()
4296 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: Host-managed)", in f2fs_scan_devices()
4303 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", in f2fs_scan_devices()
4308 f2fs_info(sbi, in f2fs_scan_devices()
4309 "IO Block Size: %8ld KB", F2FS_IO_SIZE_KB(sbi)); in f2fs_scan_devices()
4313 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) in f2fs_setup_casefold() argument
4316 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { in f2fs_setup_casefold()
4321 encoding_info = f2fs_sb_read_encoding(sbi->raw_super); in f2fs_setup_casefold()
4323 f2fs_err(sbi, in f2fs_setup_casefold()
4328 encoding_flags = le16_to_cpu(sbi->raw_super->s_encoding_flags); in f2fs_setup_casefold()
4331 f2fs_err(sbi, in f2fs_setup_casefold()
4341 f2fs_info(sbi, "Using encoding defined by superblock: " in f2fs_setup_casefold()
4348 sbi->sb->s_encoding = encoding; in f2fs_setup_casefold()
4349 sbi->sb->s_encoding_flags = encoding_flags; in f2fs_setup_casefold()
4352 if (f2fs_sb_has_casefold(sbi)) { in f2fs_setup_casefold()
4353 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); in f2fs_setup_casefold()
4360 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) in f2fs_tuning_parameters() argument
4363 if (MAIN_SEGS(sbi) <= SMALL_VOLUME_SEGMENTS) { in f2fs_tuning_parameters()
4364 if (f2fs_block_unit_discard(sbi)) in f2fs_tuning_parameters()
4365 SM_I(sbi)->dcc_info->discard_granularity = in f2fs_tuning_parameters()
4367 if (!f2fs_lfs_mode(sbi)) in f2fs_tuning_parameters()
4368 SM_I(sbi)->ipu_policy = BIT(F2FS_IPU_FORCE) | in f2fs_tuning_parameters()
4372 sbi->readdir_ra = true; in f2fs_tuning_parameters()
4377 struct f2fs_sb_info *sbi; in f2fs_fill_super() local
4397 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); in f2fs_fill_super()
4398 if (!sbi) in f2fs_fill_super()
4401 sbi->sb = sb; in f2fs_fill_super()
4404 init_f2fs_rwsem(&sbi->gc_lock); in f2fs_fill_super()
4405 mutex_init(&sbi->writepages); in f2fs_fill_super()
4406 init_f2fs_rwsem(&sbi->cp_global_sem); in f2fs_fill_super()
4407 init_f2fs_rwsem(&sbi->node_write); in f2fs_fill_super()
4408 init_f2fs_rwsem(&sbi->node_change); in f2fs_fill_super()
4409 spin_lock_init(&sbi->stat_lock); in f2fs_fill_super()
4410 init_f2fs_rwsem(&sbi->cp_rwsem); in f2fs_fill_super()
4411 init_f2fs_rwsem(&sbi->quota_sem); in f2fs_fill_super()
4412 init_waitqueue_head(&sbi->cp_wait); in f2fs_fill_super()
4413 spin_lock_init(&sbi->error_lock); in f2fs_fill_super()
4416 INIT_LIST_HEAD(&sbi->inode_list[i]); in f2fs_fill_super()
4417 spin_lock_init(&sbi->inode_lock[i]); in f2fs_fill_super()
4419 mutex_init(&sbi->flush_lock); in f2fs_fill_super()
4422 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); in f2fs_fill_super()
4423 if (IS_ERR(sbi->s_chksum_driver)) { in f2fs_fill_super()
4424 f2fs_err(sbi, "Cannot load crc32 driver."); in f2fs_fill_super()
4425 err = PTR_ERR(sbi->s_chksum_driver); in f2fs_fill_super()
4426 sbi->s_chksum_driver = NULL; in f2fs_fill_super()
4432 f2fs_err(sbi, "unable to set blocksize"); in f2fs_fill_super()
4436 err = read_raw_super_block(sbi, &raw_super, &valid_super_block, in f2fs_fill_super()
4441 sb->s_fs_info = sbi; in f2fs_fill_super()
4442 sbi->raw_super = raw_super; in f2fs_fill_super()
4444 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); in f2fs_fill_super()
4445 memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS); in f2fs_fill_super()
4446 memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON); in f2fs_fill_super()
4449 if (f2fs_sb_has_inode_chksum(sbi)) in f2fs_fill_super()
4450 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, in f2fs_fill_super()
4453 default_options(sbi, false); in f2fs_fill_super()
4469 err = f2fs_setup_casefold(sbi); in f2fs_fill_super()
4478 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_fill_super()
4480 if (f2fs_qf_ino(sbi->sb, i)) in f2fs_fill_super()
4481 sbi->nquota_files++; in f2fs_fill_super()
4498 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_fill_super()
4503 sbi->valid_super_block = valid_super_block; in f2fs_fill_super()
4506 set_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4508 err = f2fs_init_write_merge_io(sbi); in f2fs_fill_super()
4512 init_sb_info(sbi); in f2fs_fill_super()
4514 err = f2fs_init_iostat(sbi); in f2fs_fill_super()
4518 err = init_percpu_info(sbi); in f2fs_fill_super()
4522 if (F2FS_IO_ALIGNED(sbi)) { in f2fs_fill_super()
4523 sbi->write_io_dummy = in f2fs_fill_super()
4524 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); in f2fs_fill_super()
4525 if (!sbi->write_io_dummy) { in f2fs_fill_super()
4531 /* init per sbi slab cache */ in f2fs_fill_super()
4532 err = f2fs_init_xattr_caches(sbi); in f2fs_fill_super()
4535 err = f2fs_init_page_array_cache(sbi); in f2fs_fill_super()
4540 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); in f2fs_fill_super()
4541 if (IS_ERR(sbi->meta_inode)) { in f2fs_fill_super()
4542 f2fs_err(sbi, "Failed to read F2FS meta data inode"); in f2fs_fill_super()
4543 err = PTR_ERR(sbi->meta_inode); in f2fs_fill_super()
4547 err = f2fs_get_valid_checkpoint(sbi); in f2fs_fill_super()
4549 f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); in f2fs_fill_super()
4553 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) in f2fs_fill_super()
4554 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_fill_super()
4555 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { in f2fs_fill_super()
4556 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4557 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; in f2fs_fill_super()
4560 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) in f2fs_fill_super()
4561 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4564 err = f2fs_scan_devices(sbi); in f2fs_fill_super()
4566 f2fs_err(sbi, "Failed to find devices"); in f2fs_fill_super()
4570 err = f2fs_init_post_read_wq(sbi); in f2fs_fill_super()
4572 f2fs_err(sbi, "Failed to initialize post read workqueue"); in f2fs_fill_super()
4576 sbi->total_valid_node_count = in f2fs_fill_super()
4577 le32_to_cpu(sbi->ckpt->valid_node_count); in f2fs_fill_super()
4578 percpu_counter_set(&sbi->total_valid_inode_count, in f2fs_fill_super()
4579 le32_to_cpu(sbi->ckpt->valid_inode_count)); in f2fs_fill_super()
4580 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); in f2fs_fill_super()
4581 sbi->total_valid_block_count = in f2fs_fill_super()
4582 le64_to_cpu(sbi->ckpt->valid_block_count); in f2fs_fill_super()
4583 sbi->last_valid_block_count = sbi->total_valid_block_count; in f2fs_fill_super()
4584 sbi->reserved_blocks = 0; in f2fs_fill_super()
4585 sbi->current_reserved_blocks = 0; in f2fs_fill_super()
4586 limit_reserve_root(sbi); in f2fs_fill_super()
4587 adjust_unusable_cap_perc(sbi); in f2fs_fill_super()
4589 f2fs_init_extent_cache_info(sbi); in f2fs_fill_super()
4591 f2fs_init_ino_entry_info(sbi); in f2fs_fill_super()
4593 f2fs_init_fsync_node_info(sbi); in f2fs_fill_super()
4596 f2fs_init_ckpt_req_control(sbi); in f2fs_fill_super()
4597 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && in f2fs_fill_super()
4598 test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_fill_super()
4599 err = f2fs_start_ckpt_thread(sbi); in f2fs_fill_super()
4601 f2fs_err(sbi, in f2fs_fill_super()
4609 err = f2fs_build_segment_manager(sbi); in f2fs_fill_super()
4611 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", in f2fs_fill_super()
4615 err = f2fs_build_node_manager(sbi); in f2fs_fill_super()
4617 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", in f2fs_fill_super()
4622 err = adjust_reserved_segment(sbi); in f2fs_fill_super()
4627 sbi->sectors_written_start = f2fs_get_sectors_written(sbi); in f2fs_fill_super()
4630 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); in f2fs_fill_super()
4631 if (__exist_node_summaries(sbi)) in f2fs_fill_super()
4632 sbi->kbytes_written = in f2fs_fill_super()
4635 f2fs_build_gc_manager(sbi); in f2fs_fill_super()
4637 err = f2fs_build_stats(sbi); in f2fs_fill_super()
4642 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); in f2fs_fill_super()
4643 if (IS_ERR(sbi->node_inode)) { in f2fs_fill_super()
4644 f2fs_err(sbi, "Failed to read node inode"); in f2fs_fill_super()
4645 err = PTR_ERR(sbi->node_inode); in f2fs_fill_super()
4650 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); in f2fs_fill_super()
4652 f2fs_err(sbi, "Failed to read root inode"); in f2fs_fill_super()
4669 err = f2fs_init_compress_inode(sbi); in f2fs_fill_super()
4673 err = f2fs_register_sysfs(sbi); in f2fs_fill_super()
4679 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4682 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); in f2fs_fill_super()
4685 quota_enabled = f2fs_recover_quota_begin(sbi); in f2fs_fill_super()
4688 err = f2fs_recover_orphan_inodes(sbi); in f2fs_fill_super()
4692 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) in f2fs_fill_super()
4696 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && in f2fs_fill_super()
4697 !test_opt(sbi, NORECOVERY)) { in f2fs_fill_super()
4702 if (f2fs_hw_is_readonly(sbi)) { in f2fs_fill_super()
4703 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in f2fs_fill_super()
4704 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4707 f2fs_err(sbi, "Need to recover fsync data, but " in f2fs_fill_super()
4714 f2fs_info(sbi, "write access unavailable, skipping recovery"); in f2fs_fill_super()
4719 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4724 err = f2fs_recover_fsync_data(sbi, false); in f2fs_fill_super()
4729 f2fs_err(sbi, "Cannot recover all fsync data errno=%d", in f2fs_fill_super()
4734 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4738 f2fs_err(sbi, "Need to recover fsync data"); in f2fs_fill_super()
4744 f2fs_recover_quota_end(sbi, quota_enabled); in f2fs_fill_super()
4751 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) { in f2fs_fill_super()
4752 err = f2fs_check_write_pointer(sbi); in f2fs_fill_super()
4757 f2fs_init_inmem_curseg(sbi); in f2fs_fill_super()
4760 clear_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4762 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_fill_super()
4763 err = f2fs_disable_checkpoint(sbi); in f2fs_fill_super()
4766 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { in f2fs_fill_super()
4767 f2fs_enable_checkpoint(sbi); in f2fs_fill_super()
4774 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || in f2fs_fill_super()
4775 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4777 err = f2fs_start_gc_thread(sbi); in f2fs_fill_super()
4785 err = f2fs_commit_super(sbi, true); in f2fs_fill_super()
4786 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", in f2fs_fill_super()
4787 sbi->valid_super_block ? 1 : 2, err); in f2fs_fill_super()
4790 f2fs_join_shrinker(sbi); in f2fs_fill_super()
4792 f2fs_tuning_parameters(sbi); in f2fs_fill_super()
4794 f2fs_notice(sbi, "Mounted with checkpoint version = %llx", in f2fs_fill_super()
4795 cur_cp_version(F2FS_CKPT(sbi))); in f2fs_fill_super()
4796 f2fs_update_time(sbi, CP_TIME); in f2fs_fill_super()
4797 f2fs_update_time(sbi, REQ_TIME); in f2fs_fill_super()
4798 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4803 sync_filesystem(sbi->sb); in f2fs_fill_super()
4809 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) in f2fs_fill_super()
4810 f2fs_quota_off_umount(sbi->sb); in f2fs_fill_super()
4818 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_fill_super()
4821 f2fs_unregister_sysfs(sbi); in f2fs_fill_super()
4823 f2fs_destroy_compress_inode(sbi); in f2fs_fill_super()
4828 f2fs_release_ino_entry(sbi, true); in f2fs_fill_super()
4829 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_fill_super()
4830 iput(sbi->node_inode); in f2fs_fill_super()
4831 sbi->node_inode = NULL; in f2fs_fill_super()
4833 f2fs_destroy_stats(sbi); in f2fs_fill_super()
4836 f2fs_stop_discard_thread(sbi); in f2fs_fill_super()
4837 f2fs_destroy_node_manager(sbi); in f2fs_fill_super()
4839 f2fs_destroy_segment_manager(sbi); in f2fs_fill_super()
4841 f2fs_stop_ckpt_thread(sbi); in f2fs_fill_super()
4842 /* flush s_error_work before sbi destroy */ in f2fs_fill_super()
4843 flush_work(&sbi->s_error_work); in f2fs_fill_super()
4844 f2fs_destroy_post_read_wq(sbi); in f2fs_fill_super()
4846 destroy_device_list(sbi); in f2fs_fill_super()
4847 kvfree(sbi->ckpt); in f2fs_fill_super()
4849 make_bad_inode(sbi->meta_inode); in f2fs_fill_super()
4850 iput(sbi->meta_inode); in f2fs_fill_super()
4851 sbi->meta_inode = NULL; in f2fs_fill_super()
4853 f2fs_destroy_page_array_cache(sbi); in f2fs_fill_super()
4855 f2fs_destroy_xattr_caches(sbi); in f2fs_fill_super()
4857 mempool_destroy(sbi->write_io_dummy); in f2fs_fill_super()
4859 destroy_percpu_info(sbi); in f2fs_fill_super()
4861 f2fs_destroy_iostat(sbi); in f2fs_fill_super()
4864 kvfree(sbi->write_io[i]); in f2fs_fill_super()
4873 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_fill_super()
4875 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_fill_super()
4880 if (sbi->s_chksum_driver) in f2fs_fill_super()
4881 crypto_free_shash(sbi->s_chksum_driver); in f2fs_fill_super()
4882 kfree(sbi); in f2fs_fill_super()
4902 struct f2fs_sb_info *sbi = F2FS_SB(sb); in kill_f2fs_super() local
4905 set_sbi_flag(sbi, SBI_IS_CLOSE); in kill_f2fs_super()
4906 f2fs_stop_gc_thread(sbi); in kill_f2fs_super()
4907 f2fs_stop_discard_thread(sbi); in kill_f2fs_super()
4914 if (test_opt(sbi, COMPRESS_CACHE)) in kill_f2fs_super()
4915 truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); in kill_f2fs_super()
4918 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in kill_f2fs_super()
4919 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in kill_f2fs_super()
4923 stat_inc_cp_call_count(sbi, TOTAL_CALL); in kill_f2fs_super()
4924 f2fs_write_checkpoint(sbi, &cpc); in kill_f2fs_super()
4927 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) in kill_f2fs_super()
4932 if (sbi) { in kill_f2fs_super()
4933 destroy_device_list(sbi); in kill_f2fs_super()
4934 kfree(sbi); in kill_f2fs_super()