Lines Matching refs:sbi

63 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,  in f2fs_build_fault_attr()  argument
66 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; in f2fs_build_fault_attr()
241 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) in f2fs_printk() argument
253 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
306 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) in limit_reserve_root() argument
308 block_t limit = min((sbi->user_block_count << 1) / 1000, in limit_reserve_root()
309 sbi->user_block_count - sbi->reserved_blocks); in limit_reserve_root()
312 if (test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
313 F2FS_OPTION(sbi).root_reserved_blocks > limit) { in limit_reserve_root()
314 F2FS_OPTION(sbi).root_reserved_blocks = limit; in limit_reserve_root()
315 f2fs_info(sbi, "Reduce reserved blocks for root = %u", in limit_reserve_root()
316 F2FS_OPTION(sbi).root_reserved_blocks); in limit_reserve_root()
318 if (!test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
319 (!uid_eq(F2FS_OPTION(sbi).s_resuid, in limit_reserve_root()
321 !gid_eq(F2FS_OPTION(sbi).s_resgid, in limit_reserve_root()
323 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", in limit_reserve_root()
325 F2FS_OPTION(sbi).s_resuid), in limit_reserve_root()
327 F2FS_OPTION(sbi).s_resgid)); in limit_reserve_root()
330 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) in adjust_unusable_cap_perc() argument
332 if (!F2FS_OPTION(sbi).unusable_cap_perc) in adjust_unusable_cap_perc()
335 if (F2FS_OPTION(sbi).unusable_cap_perc == 100) in adjust_unusable_cap_perc()
336 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; in adjust_unusable_cap_perc()
338 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * in adjust_unusable_cap_perc()
339 F2FS_OPTION(sbi).unusable_cap_perc; in adjust_unusable_cap_perc()
341 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", in adjust_unusable_cap_perc()
342 F2FS_OPTION(sbi).unusable_cap, in adjust_unusable_cap_perc()
343 F2FS_OPTION(sbi).unusable_cap_perc); in adjust_unusable_cap_perc()
359 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_qf_name() local
363 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
364 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_set_qf_name()
367 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_set_qf_name()
368 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); in f2fs_set_qf_name()
374 f2fs_err(sbi, "Not enough memory for storing quotafile name"); in f2fs_set_qf_name()
377 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
378 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) in f2fs_set_qf_name()
381 f2fs_err(sbi, "%s quota file already specified", in f2fs_set_qf_name()
386 f2fs_err(sbi, "quotafile must be on filesystem root"); in f2fs_set_qf_name()
389 F2FS_OPTION(sbi).s_qf_names[qtype] = qname; in f2fs_set_qf_name()
390 set_opt(sbi, QUOTA); in f2fs_set_qf_name()
399 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_clear_qf_name() local
401 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_clear_qf_name()
402 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_clear_qf_name()
405 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); in f2fs_clear_qf_name()
406 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; in f2fs_clear_qf_name()
410 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) in f2fs_check_quota_options() argument
417 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { in f2fs_check_quota_options()
418 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); in f2fs_check_quota_options()
421 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || in f2fs_check_quota_options()
422 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || in f2fs_check_quota_options()
423 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { in f2fs_check_quota_options()
424 if (test_opt(sbi, USRQUOTA) && in f2fs_check_quota_options()
425 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_check_quota_options()
426 clear_opt(sbi, USRQUOTA); in f2fs_check_quota_options()
428 if (test_opt(sbi, GRPQUOTA) && in f2fs_check_quota_options()
429 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_check_quota_options()
430 clear_opt(sbi, GRPQUOTA); in f2fs_check_quota_options()
432 if (test_opt(sbi, PRJQUOTA) && in f2fs_check_quota_options()
433 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_check_quota_options()
434 clear_opt(sbi, PRJQUOTA); in f2fs_check_quota_options()
436 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || in f2fs_check_quota_options()
437 test_opt(sbi, PRJQUOTA)) { in f2fs_check_quota_options()
438 f2fs_err(sbi, "old and new quota format mixing"); in f2fs_check_quota_options()
442 if (!F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
443 f2fs_err(sbi, "journaled quota format not specified"); in f2fs_check_quota_options()
448 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
449 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); in f2fs_check_quota_options()
450 F2FS_OPTION(sbi).s_jquota_fmt = 0; in f2fs_check_quota_options()
461 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_test_dummy_encryption() local
465 if (!f2fs_sb_has_encrypt(sbi)) { in f2fs_set_test_dummy_encryption()
466 f2fs_err(sbi, "Encrypt feature is off"); in f2fs_set_test_dummy_encryption()
476 if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) { in f2fs_set_test_dummy_encryption()
477 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); in f2fs_set_test_dummy_encryption()
481 sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_set_test_dummy_encryption()
484 f2fs_warn(sbi, in f2fs_set_test_dummy_encryption()
487 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", in f2fs_set_test_dummy_encryption()
490 f2fs_warn(sbi, "Error processing option \"%s\" [%d]", in f2fs_set_test_dummy_encryption()
494 f2fs_warn(sbi, "Test dummy encryption mode enabled"); in f2fs_set_test_dummy_encryption()
496 f2fs_warn(sbi, "Test dummy encryption mount option ignored"); in f2fs_set_test_dummy_encryption()
509 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi) in f2fs_test_compress_extension() argument
515 ext = F2FS_OPTION(sbi).extensions; in f2fs_test_compress_extension()
516 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in f2fs_test_compress_extension()
517 noext = F2FS_OPTION(sbi).noextensions; in f2fs_test_compress_extension()
518 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in f2fs_test_compress_extension()
525 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files"); in f2fs_test_compress_extension()
530 …f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension… in f2fs_test_compress_extension()
540 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_lz4hc_level() argument
547 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
555 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_lz4hc_level()
562 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); in f2fs_set_lz4hc_level()
566 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_lz4hc_level()
569 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); in f2fs_set_lz4hc_level()
576 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_zstd_level() argument
582 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_zstd_level()
589 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_zstd_level()
596 f2fs_info(sbi, "invalid zstd compress level: %d", level); in f2fs_set_zstd_level()
600 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_zstd_level()
608 struct f2fs_sb_info *sbi = F2FS_SB(sb); in parse_options() local
643 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in parse_options()
645 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; in parse_options()
647 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; in parse_options()
655 set_opt(sbi, DISABLE_ROLL_FORWARD); in parse_options()
659 set_opt(sbi, NORECOVERY); in parse_options()
664 if (!f2fs_hw_support_discard(sbi)) { in parse_options()
665 f2fs_warn(sbi, "device does not support discard"); in parse_options()
668 set_opt(sbi, DISCARD); in parse_options()
671 if (f2fs_hw_should_discard(sbi)) { in parse_options()
672 f2fs_warn(sbi, "discard is required for zoned block devices"); in parse_options()
675 clear_opt(sbi, DISCARD); in parse_options()
678 set_opt(sbi, NOHEAP); in parse_options()
681 clear_opt(sbi, NOHEAP); in parse_options()
685 set_opt(sbi, XATTR_USER); in parse_options()
688 clear_opt(sbi, XATTR_USER); in parse_options()
691 set_opt(sbi, INLINE_XATTR); in parse_options()
694 clear_opt(sbi, INLINE_XATTR); in parse_options()
699 set_opt(sbi, INLINE_XATTR_SIZE); in parse_options()
700 F2FS_OPTION(sbi).inline_xattr_size = arg; in parse_options()
704 f2fs_info(sbi, "user_xattr options not supported"); in parse_options()
707 f2fs_info(sbi, "nouser_xattr options not supported"); in parse_options()
710 f2fs_info(sbi, "inline_xattr options not supported"); in parse_options()
713 f2fs_info(sbi, "noinline_xattr options not supported"); in parse_options()
718 set_opt(sbi, POSIX_ACL); in parse_options()
721 clear_opt(sbi, POSIX_ACL); in parse_options()
725 f2fs_info(sbi, "acl options not supported"); in parse_options()
728 f2fs_info(sbi, "noacl options not supported"); in parse_options()
737 F2FS_OPTION(sbi).active_logs = arg; in parse_options()
740 set_opt(sbi, DISABLE_EXT_IDENTIFY); in parse_options()
743 set_opt(sbi, INLINE_DATA); in parse_options()
746 set_opt(sbi, INLINE_DENTRY); in parse_options()
749 clear_opt(sbi, INLINE_DENTRY); in parse_options()
752 set_opt(sbi, FLUSH_MERGE); in parse_options()
755 clear_opt(sbi, FLUSH_MERGE); in parse_options()
758 set_opt(sbi, NOBARRIER); in parse_options()
761 set_opt(sbi, FASTBOOT); in parse_options()
764 set_opt(sbi, EXTENT_CACHE); in parse_options()
767 clear_opt(sbi, EXTENT_CACHE); in parse_options()
770 clear_opt(sbi, INLINE_DATA); in parse_options()
773 set_opt(sbi, DATA_FLUSH); in parse_options()
778 if (test_opt(sbi, RESERVE_ROOT)) { in parse_options()
779 f2fs_info(sbi, "Preserve previous reserve_root=%u", in parse_options()
780 F2FS_OPTION(sbi).root_reserved_blocks); in parse_options()
782 F2FS_OPTION(sbi).root_reserved_blocks = arg; in parse_options()
783 set_opt(sbi, RESERVE_ROOT); in parse_options()
791 f2fs_err(sbi, "Invalid uid value %d", arg); in parse_options()
794 F2FS_OPTION(sbi).s_resuid = uid; in parse_options()
801 f2fs_err(sbi, "Invalid gid value %d", arg); in parse_options()
804 F2FS_OPTION(sbi).s_resgid = gid; in parse_options()
812 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
813 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature"); in parse_options()
817 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in parse_options()
819 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in parse_options()
830 f2fs_warn(sbi, "Not support %d, larger than %d", in parse_options()
834 F2FS_OPTION(sbi).write_io_size_bits = arg; in parse_options()
840 f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); in parse_options()
841 set_opt(sbi, FAULT_INJECTION); in parse_options()
847 f2fs_build_fault_attr(sbi, 0, arg); in parse_options()
848 set_opt(sbi, FAULT_INJECTION); in parse_options()
852 f2fs_info(sbi, "fault_injection options not supported"); in parse_options()
856 f2fs_info(sbi, "fault_type options not supported"); in parse_options()
868 set_opt(sbi, USRQUOTA); in parse_options()
871 set_opt(sbi, GRPQUOTA); in parse_options()
874 set_opt(sbi, PRJQUOTA); in parse_options()
907 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; in parse_options()
910 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; in parse_options()
913 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; in parse_options()
916 clear_opt(sbi, QUOTA); in parse_options()
917 clear_opt(sbi, USRQUOTA); in parse_options()
918 clear_opt(sbi, GRPQUOTA); in parse_options()
919 clear_opt(sbi, PRJQUOTA); in parse_options()
936 f2fs_info(sbi, "quota operations not supported"); in parse_options()
944 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; in parse_options()
946 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
948 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; in parse_options()
961 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in parse_options()
963 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in parse_options()
975 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in parse_options()
977 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; in parse_options()
979 F2FS_OPTION(sbi).fsync_mode = in parse_options()
997 f2fs_info(sbi, "inline encryption not supported"); in parse_options()
1005 F2FS_OPTION(sbi).unusable_cap_perc = arg; in parse_options()
1006 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1011 F2FS_OPTION(sbi).unusable_cap = arg; in parse_options()
1012 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1015 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1018 clear_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1021 set_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1024 clear_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1028 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1029 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1037 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1038 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1041 f2fs_info(sbi, "kernel doesn't support lzo compression"); in parse_options()
1045 ret = f2fs_set_lz4hc_level(sbi, name); in parse_options()
1050 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1053 f2fs_info(sbi, "kernel doesn't support lz4 compression"); in parse_options()
1057 ret = f2fs_set_zstd_level(sbi, name); in parse_options()
1062 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1065 f2fs_info(sbi, "kernel doesn't support zstd compression"); in parse_options()
1069 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1070 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1073 f2fs_info(sbi, "kernel doesn't support lzorle compression"); 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()
1090 f2fs_err(sbi, in parse_options()
1094 F2FS_OPTION(sbi).compress_log_size = arg; in parse_options()
1097 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1098 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1105 ext = F2FS_OPTION(sbi).extensions; in parse_options()
1106 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in parse_options()
1110 f2fs_err(sbi, in parse_options()
1117 F2FS_OPTION(sbi).compress_ext_cnt++; in parse_options()
1121 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1122 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1129 noext = F2FS_OPTION(sbi).noextensions; in parse_options()
1130 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt; in parse_options()
1134 f2fs_err(sbi, in parse_options()
1141 F2FS_OPTION(sbi).nocompress_ext_cnt++; in parse_options()
1145 F2FS_OPTION(sbi).compress_chksum = true; in parse_options()
1152 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in parse_options()
1154 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; in parse_options()
1162 set_opt(sbi, COMPRESS_CACHE); in parse_options()
1172 f2fs_info(sbi, "compression options not supported"); in parse_options()
1176 set_opt(sbi, ATGC); in parse_options()
1179 set_opt(sbi, GC_MERGE); in parse_options()
1182 clear_opt(sbi, GC_MERGE); in parse_options()
1189 F2FS_OPTION(sbi).discard_unit = in parse_options()
1192 F2FS_OPTION(sbi).discard_unit = in parse_options()
1195 F2FS_OPTION(sbi).discard_unit = in parse_options()
1204 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", in parse_options()
1211 if (f2fs_check_quota_options(sbi)) in parse_options()
1214 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1215 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1218 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1219 …f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1224 if (f2fs_sb_has_casefold(sbi)) { in parse_options()
1225 f2fs_err(sbi, in parse_options()
1236 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1237 f2fs_err(sbi, "Zoned block device support is not enabled"); in parse_options()
1241 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1242 if (F2FS_OPTION(sbi).discard_unit != in parse_options()
1244 …f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default… in parse_options()
1245 F2FS_OPTION(sbi).discard_unit = in parse_options()
1251 if (f2fs_test_compress_extension(sbi)) { in parse_options()
1252 f2fs_err(sbi, "invalid compress or nocompress extension"); in parse_options()
1257 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { in parse_options()
1258 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", in parse_options()
1259 F2FS_IO_SIZE_KB(sbi)); in parse_options()
1263 if (test_opt(sbi, INLINE_XATTR_SIZE)) { in parse_options()
1266 if (!f2fs_sb_has_extra_attr(sbi) || in parse_options()
1267 !f2fs_sb_has_flexible_inline_xattr(sbi)) { in parse_options()
1268 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); in parse_options()
1271 if (!test_opt(sbi, INLINE_XATTR)) { in parse_options()
1272 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); in parse_options()
1279 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || in parse_options()
1280 F2FS_OPTION(sbi).inline_xattr_size > max_size) { in parse_options()
1281 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", in parse_options()
1287 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { in parse_options()
1288 f2fs_err(sbi, "LFS not compatible with checkpoint=disable"); in parse_options()
1295 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE) in parse_options()
1296 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
1298 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1299 f2fs_err(sbi, "Allow to mount readonly mode only"); in parse_options()
1338 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_drop_inode() local
1345 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_drop_inode()
1346 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_drop_inode()
1347 inode->i_ino == F2FS_META_INO(sbi)) { in f2fs_drop_inode()
1400 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_dirtied() local
1403 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1408 stat_inc_dirty_inode(sbi, DIRTY_META); in f2fs_inode_dirtied()
1412 &sbi->inode_list[DIRTY_META]); in f2fs_inode_dirtied()
1413 inc_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_dirtied()
1415 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1421 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_synced() local
1423 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1425 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1430 dec_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_synced()
1435 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1445 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_dirty_inode() local
1447 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_dirty_inode()
1448 inode->i_ino == F2FS_META_INO(sbi)) in f2fs_dirty_inode()
1463 static void destroy_percpu_info(struct f2fs_sb_info *sbi) in destroy_percpu_info() argument
1465 percpu_counter_destroy(&sbi->alloc_valid_block_count); in destroy_percpu_info()
1466 percpu_counter_destroy(&sbi->total_valid_inode_count); in destroy_percpu_info()
1469 static void destroy_device_list(struct f2fs_sb_info *sbi) in destroy_device_list() argument
1473 for (i = 0; i < sbi->s_ndevs; i++) { in destroy_device_list()
1480 kvfree(sbi->devs); in destroy_device_list()
1485 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_put_super() local
1490 f2fs_unregister_sysfs(sbi); in f2fs_put_super()
1495 mutex_lock(&sbi->umount_mutex); in f2fs_put_super()
1501 f2fs_stop_ckpt_thread(sbi); in f2fs_put_super()
1508 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in f2fs_put_super()
1509 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { in f2fs_put_super()
1513 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1517 dropped = f2fs_issue_discard_timeout(sbi); in f2fs_put_super()
1519 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) && in f2fs_put_super()
1520 !sbi->discard_blks && !dropped) { in f2fs_put_super()
1524 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1531 f2fs_release_ino_entry(sbi, true); in f2fs_put_super()
1533 f2fs_leave_shrinker(sbi); in f2fs_put_super()
1534 mutex_unlock(&sbi->umount_mutex); in f2fs_put_super()
1537 f2fs_flush_merged_writes(sbi); in f2fs_put_super()
1539 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); in f2fs_put_super()
1541 f2fs_bug_on(sbi, sbi->fsync_node_num); in f2fs_put_super()
1543 f2fs_destroy_compress_inode(sbi); in f2fs_put_super()
1545 iput(sbi->node_inode); in f2fs_put_super()
1546 sbi->node_inode = NULL; in f2fs_put_super()
1548 iput(sbi->meta_inode); in f2fs_put_super()
1549 sbi->meta_inode = NULL; in f2fs_put_super()
1555 f2fs_destroy_stats(sbi); in f2fs_put_super()
1558 f2fs_destroy_node_manager(sbi); in f2fs_put_super()
1559 f2fs_destroy_segment_manager(sbi); in f2fs_put_super()
1561 f2fs_destroy_post_read_wq(sbi); in f2fs_put_super()
1563 kvfree(sbi->ckpt); in f2fs_put_super()
1566 if (sbi->s_chksum_driver) in f2fs_put_super()
1567 crypto_free_shash(sbi->s_chksum_driver); in f2fs_put_super()
1568 kfree(sbi->raw_super); in f2fs_put_super()
1570 destroy_device_list(sbi); in f2fs_put_super()
1571 f2fs_destroy_page_array_cache(sbi); in f2fs_put_super()
1572 f2fs_destroy_xattr_caches(sbi); in f2fs_put_super()
1573 mempool_destroy(sbi->write_io_dummy); in f2fs_put_super()
1576 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_put_super()
1578 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_put_super()
1579 destroy_percpu_info(sbi); in f2fs_put_super()
1580 f2fs_destroy_iostat(sbi); in f2fs_put_super()
1582 kvfree(sbi->write_io[i]); in f2fs_put_super()
1586 kfree(sbi); in f2fs_put_super()
1591 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_sync_fs() local
1594 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_fs()
1596 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_sync_fs()
1601 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_sync_fs()
1605 err = f2fs_issue_checkpoint(sbi); in f2fs_sync_fs()
1682 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_statfs() local
1687 total_count = le64_to_cpu(sbi->raw_super->block_count); in f2fs_statfs()
1688 user_block_count = sbi->user_block_count; in f2fs_statfs()
1689 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); in f2fs_statfs()
1691 buf->f_bsize = sbi->blocksize; in f2fs_statfs()
1694 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - in f2fs_statfs()
1695 sbi->current_reserved_blocks; in f2fs_statfs()
1697 spin_lock(&sbi->stat_lock); in f2fs_statfs()
1698 if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) in f2fs_statfs()
1701 buf->f_bfree -= sbi->unusable_block_count; in f2fs_statfs()
1702 spin_unlock(&sbi->stat_lock); in f2fs_statfs()
1704 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) in f2fs_statfs()
1706 F2FS_OPTION(sbi).root_reserved_blocks; in f2fs_statfs()
1710 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_statfs()
1717 buf->f_ffree = min(avail_node_count - valid_node_count(sbi), in f2fs_statfs()
1737 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_quota_options() local
1739 if (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1742 switch (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1756 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_show_quota_options()
1758 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); in f2fs_show_quota_options()
1760 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_show_quota_options()
1762 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); in f2fs_show_quota_options()
1764 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_show_quota_options()
1766 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); in f2fs_show_quota_options()
1774 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_compress_options() local
1778 if (!f2fs_sb_has_compression(sbi)) in f2fs_show_compress_options()
1781 switch (F2FS_OPTION(sbi).compress_algorithm) { in f2fs_show_compress_options()
1797 if (F2FS_OPTION(sbi).compress_level) in f2fs_show_compress_options()
1798 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); in f2fs_show_compress_options()
1801 F2FS_OPTION(sbi).compress_log_size); in f2fs_show_compress_options()
1803 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { in f2fs_show_compress_options()
1805 F2FS_OPTION(sbi).extensions[i]); in f2fs_show_compress_options()
1808 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) { in f2fs_show_compress_options()
1810 F2FS_OPTION(sbi).noextensions[i]); in f2fs_show_compress_options()
1813 if (F2FS_OPTION(sbi).compress_chksum) in f2fs_show_compress_options()
1816 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) in f2fs_show_compress_options()
1818 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) in f2fs_show_compress_options()
1821 if (test_opt(sbi, COMPRESS_CACHE)) in f2fs_show_compress_options()
1828 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); in f2fs_show_options() local
1830 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) in f2fs_show_options()
1832 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) in f2fs_show_options()
1834 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) in f2fs_show_options()
1837 if (test_opt(sbi, GC_MERGE)) in f2fs_show_options()
1840 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_show_options()
1842 if (test_opt(sbi, NORECOVERY)) in f2fs_show_options()
1844 if (test_opt(sbi, DISCARD)) in f2fs_show_options()
1848 if (test_opt(sbi, NOHEAP)) in f2fs_show_options()
1853 if (test_opt(sbi, XATTR_USER)) in f2fs_show_options()
1857 if (test_opt(sbi, INLINE_XATTR)) in f2fs_show_options()
1861 if (test_opt(sbi, INLINE_XATTR_SIZE)) in f2fs_show_options()
1863 F2FS_OPTION(sbi).inline_xattr_size); in f2fs_show_options()
1866 if (test_opt(sbi, POSIX_ACL)) in f2fs_show_options()
1871 if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) in f2fs_show_options()
1873 if (test_opt(sbi, INLINE_DATA)) in f2fs_show_options()
1877 if (test_opt(sbi, INLINE_DENTRY)) in f2fs_show_options()
1881 if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE)) in f2fs_show_options()
1883 if (test_opt(sbi, NOBARRIER)) in f2fs_show_options()
1885 if (test_opt(sbi, FASTBOOT)) in f2fs_show_options()
1887 if (test_opt(sbi, EXTENT_CACHE)) in f2fs_show_options()
1891 if (test_opt(sbi, DATA_FLUSH)) in f2fs_show_options()
1895 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) in f2fs_show_options()
1897 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) in f2fs_show_options()
1899 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); in f2fs_show_options()
1900 if (test_opt(sbi, RESERVE_ROOT)) in f2fs_show_options()
1902 F2FS_OPTION(sbi).root_reserved_blocks, in f2fs_show_options()
1904 F2FS_OPTION(sbi).s_resuid), in f2fs_show_options()
1906 F2FS_OPTION(sbi).s_resgid)); in f2fs_show_options()
1907 if (F2FS_IO_SIZE_BITS(sbi)) in f2fs_show_options()
1909 F2FS_OPTION(sbi).write_io_size_bits); in f2fs_show_options()
1911 if (test_opt(sbi, FAULT_INJECTION)) { in f2fs_show_options()
1913 F2FS_OPTION(sbi).fault_info.inject_rate); in f2fs_show_options()
1915 F2FS_OPTION(sbi).fault_info.inject_type); in f2fs_show_options()
1919 if (test_opt(sbi, QUOTA)) in f2fs_show_options()
1921 if (test_opt(sbi, USRQUOTA)) in f2fs_show_options()
1923 if (test_opt(sbi, GRPQUOTA)) in f2fs_show_options()
1925 if (test_opt(sbi, PRJQUOTA)) in f2fs_show_options()
1928 f2fs_show_quota_options(seq, sbi->sb); in f2fs_show_options()
1929 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) in f2fs_show_options()
1931 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) in f2fs_show_options()
1934 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); in f2fs_show_options()
1936 if (sbi->sb->s_flags & SB_INLINECRYPT) in f2fs_show_options()
1939 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) in f2fs_show_options()
1941 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) in f2fs_show_options()
1944 if (test_opt(sbi, DISABLE_CHECKPOINT)) in f2fs_show_options()
1946 F2FS_OPTION(sbi).unusable_cap); in f2fs_show_options()
1947 if (test_opt(sbi, MERGE_CHECKPOINT)) in f2fs_show_options()
1951 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) in f2fs_show_options()
1953 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) in f2fs_show_options()
1955 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) in f2fs_show_options()
1959 f2fs_show_compress_options(seq, sbi->sb); in f2fs_show_options()
1962 if (test_opt(sbi, ATGC)) in f2fs_show_options()
1965 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK) in f2fs_show_options()
1967 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT) in f2fs_show_options()
1969 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION) in f2fs_show_options()
1975 static void default_options(struct f2fs_sb_info *sbi) in default_options() argument
1978 if (f2fs_sb_has_readonly(sbi)) in default_options()
1979 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; in default_options()
1981 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; in default_options()
1983 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; in default_options()
1984 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in default_options()
1985 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in default_options()
1986 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in default_options()
1987 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); in default_options()
1988 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); in default_options()
1989 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; in default_options()
1990 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; in default_options()
1991 F2FS_OPTION(sbi).compress_ext_cnt = 0; in default_options()
1992 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in default_options()
1993 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in default_options()
1995 sbi->sb->s_flags &= ~SB_INLINECRYPT; in default_options()
1997 set_opt(sbi, INLINE_XATTR); in default_options()
1998 set_opt(sbi, INLINE_DATA); in default_options()
1999 set_opt(sbi, INLINE_DENTRY); in default_options()
2000 set_opt(sbi, EXTENT_CACHE); in default_options()
2001 set_opt(sbi, NOHEAP); in default_options()
2002 clear_opt(sbi, DISABLE_CHECKPOINT); in default_options()
2003 set_opt(sbi, MERGE_CHECKPOINT); in default_options()
2004 F2FS_OPTION(sbi).unusable_cap = 0; in default_options()
2005 sbi->sb->s_flags |= SB_LAZYTIME; in default_options()
2006 set_opt(sbi, FLUSH_MERGE); in default_options()
2007 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) in default_options()
2008 set_opt(sbi, DISCARD); in default_options()
2009 if (f2fs_sb_has_blkzoned(sbi)) { in default_options()
2010 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in default_options()
2011 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION; in default_options()
2013 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in default_options()
2014 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK; in default_options()
2018 set_opt(sbi, XATTR_USER); in default_options()
2021 set_opt(sbi, POSIX_ACL); in default_options()
2024 f2fs_build_fault_attr(sbi, 0, 0); in default_options()
2031 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_disable_checkpoint() argument
2033 unsigned int s_flags = sbi->sb->s_flags; in f2fs_disable_checkpoint()
2040 f2fs_err(sbi, "checkpoint=disable on readonly fs"); in f2fs_disable_checkpoint()
2043 sbi->sb->s_flags |= SB_ACTIVE; in f2fs_disable_checkpoint()
2045 f2fs_update_time(sbi, DISABLE_TIME); in f2fs_disable_checkpoint()
2047 while (!f2fs_time_over(sbi, DISABLE_TIME)) { in f2fs_disable_checkpoint()
2048 down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2049 err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); in f2fs_disable_checkpoint()
2058 ret = sync_filesystem(sbi->sb); in f2fs_disable_checkpoint()
2064 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2065 if (f2fs_disable_cp_again(sbi, unusable)) { in f2fs_disable_checkpoint()
2070 down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2072 set_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_disable_checkpoint()
2073 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_disable_checkpoint()
2077 spin_lock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2078 sbi->unusable_block_count = unusable; in f2fs_disable_checkpoint()
2079 spin_unlock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2082 up_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2084 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in f2fs_disable_checkpoint()
2088 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_enable_checkpoint() argument
2094 sync_inodes_sb(sbi->sb); in f2fs_enable_checkpoint()
2097 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); in f2fs_enable_checkpoint()
2100 f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); in f2fs_enable_checkpoint()
2102 down_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2103 f2fs_dirty_to_prefree(sbi); in f2fs_enable_checkpoint()
2105 clear_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_enable_checkpoint()
2106 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_enable_checkpoint()
2107 up_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2109 f2fs_sync_fs(sbi->sb, 1); in f2fs_enable_checkpoint()
2114 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_remount() local
2122 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); in f2fs_remount()
2123 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2124 bool no_io_align = !F2FS_IO_ALIGNED(sbi); in f2fs_remount()
2125 bool no_atgc = !test_opt(sbi, ATGC); in f2fs_remount()
2126 bool no_discard = !test_opt(sbi, DISCARD); in f2fs_remount()
2127 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); in f2fs_remount()
2128 bool block_unit_discard = f2fs_block_unit_discard(sbi); in f2fs_remount()
2138 org_mount_opt = sbi->mount_opt; in f2fs_remount()
2142 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; in f2fs_remount()
2144 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_remount()
2146 kstrdup(F2FS_OPTION(sbi).s_qf_names[i], in f2fs_remount()
2160 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { in f2fs_remount()
2161 err = f2fs_commit_super(sbi, false); in f2fs_remount()
2162 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", in f2fs_remount()
2165 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_remount()
2168 default_options(sbi); in f2fs_remount()
2182 if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { in f2fs_remount()
2197 } else if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_remount()
2205 if (no_atgc == !!test_opt(sbi, ATGC)) { in f2fs_remount()
2207 f2fs_warn(sbi, "switch atgc option is not allowed"); in f2fs_remount()
2212 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { in f2fs_remount()
2214 f2fs_warn(sbi, "switch extent_cache option is not allowed"); in f2fs_remount()
2218 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { in f2fs_remount()
2220 f2fs_warn(sbi, "switch io_bits option is not allowed"); in f2fs_remount()
2224 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { in f2fs_remount()
2226 f2fs_warn(sbi, "switch compress_cache option is not allowed"); in f2fs_remount()
2230 if (block_unit_discard != f2fs_block_unit_discard(sbi)) { in f2fs_remount()
2232 f2fs_warn(sbi, "switch discard_unit option is not allowed"); in f2fs_remount()
2236 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2238 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); in f2fs_remount()
2248 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && in f2fs_remount()
2249 !test_opt(sbi, GC_MERGE))) { in f2fs_remount()
2250 if (sbi->gc_thread) { in f2fs_remount()
2251 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2254 } else if (!sbi->gc_thread) { in f2fs_remount()
2255 err = f2fs_start_gc_thread(sbi); in f2fs_remount()
2262 F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) { in f2fs_remount()
2265 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_remount()
2266 set_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2268 clear_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2271 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || in f2fs_remount()
2272 !test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_remount()
2273 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2276 err = f2fs_start_ckpt_thread(sbi); in f2fs_remount()
2278 f2fs_err(sbi, in f2fs_remount()
2290 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { in f2fs_remount()
2291 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2292 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2295 err = f2fs_create_flush_cmd_control(sbi); in f2fs_remount()
2301 if (no_discard == !!test_opt(sbi, DISCARD)) { in f2fs_remount()
2302 if (test_opt(sbi, DISCARD)) { in f2fs_remount()
2303 err = f2fs_start_discard_thread(sbi); in f2fs_remount()
2308 dcc = SM_I(sbi)->dcc_info; in f2fs_remount()
2309 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2311 f2fs_issue_discard_timeout(sbi); in f2fs_remount()
2316 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2317 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2318 err = f2fs_disable_checkpoint(sbi); in f2fs_remount()
2322 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2334 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_remount()
2336 limit_reserve_root(sbi); in f2fs_remount()
2337 adjust_unusable_cap_perc(sbi); in f2fs_remount()
2342 if (f2fs_start_discard_thread(sbi)) in f2fs_remount()
2343 f2fs_warn(sbi, "discard has been stopped"); in f2fs_remount()
2345 f2fs_stop_discard_thread(sbi); in f2fs_remount()
2349 if (f2fs_create_flush_cmd_control(sbi)) in f2fs_remount()
2350 f2fs_warn(sbi, "background flush thread has stopped"); in f2fs_remount()
2352 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2353 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2357 if (f2fs_start_ckpt_thread(sbi)) in f2fs_remount()
2358 f2fs_warn(sbi, "background ckpt thread has stopped"); in f2fs_remount()
2360 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2364 if (f2fs_start_gc_thread(sbi)) in f2fs_remount()
2365 f2fs_warn(sbi, "background gc thread has stopped"); in f2fs_remount()
2367 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2371 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; in f2fs_remount()
2373 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_remount()
2374 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; in f2fs_remount()
2377 sbi->mount_opt = org_mount_opt; in f2fs_remount()
2504 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) in f2fs_quota_on_mount() argument
2506 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { in f2fs_quota_on_mount()
2507 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); in f2fs_quota_on_mount()
2511 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], in f2fs_quota_on_mount()
2512 F2FS_OPTION(sbi).s_jquota_fmt, type); in f2fs_quota_on_mount()
2515 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) in f2fs_enable_quota_files() argument
2520 if (f2fs_sb_has_quota_ino(sbi) && rdonly) { in f2fs_enable_quota_files()
2521 err = f2fs_enable_quotas(sbi->sb); in f2fs_enable_quota_files()
2523 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); in f2fs_enable_quota_files()
2530 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_enable_quota_files()
2531 err = f2fs_quota_on_mount(sbi, i); in f2fs_enable_quota_files()
2536 f2fs_err(sbi, "Cannot turn on quotas: %d on %d", in f2fs_enable_quota_files()
2571 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_enable_quotas() local
2575 test_opt(sbi, USRQUOTA), in f2fs_enable_quotas()
2576 test_opt(sbi, GRPQUOTA), in f2fs_enable_quotas()
2577 test_opt(sbi, PRJQUOTA), in f2fs_enable_quotas()
2581 f2fs_err(sbi, "quota file may be corrupted, skip loading it"); in f2fs_enable_quotas()
2594 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", in f2fs_enable_quotas()
2607 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) in f2fs_quota_sync_file() argument
2609 struct quota_info *dqopt = sb_dqopt(sbi->sb); in f2fs_quota_sync_file()
2613 ret = dquot_writeback_dquots(sbi->sb, type); in f2fs_quota_sync_file()
2622 if (is_journalled_quota(sbi)) in f2fs_quota_sync_file()
2630 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_sync_file()
2636 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_sync() local
2664 f2fs_lock_op(sbi); in f2fs_quota_sync()
2665 down_read(&sbi->quota_sem); in f2fs_quota_sync()
2667 ret = f2fs_quota_sync_file(sbi, cnt); in f2fs_quota_sync()
2669 up_read(&sbi->quota_sem); in f2fs_quota_sync()
2670 f2fs_unlock_op(sbi); in f2fs_quota_sync()
2739 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_off() local
2749 if (is_journalled_quota(sbi)) in f2fs_quota_off()
2750 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_off()
2791 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_commit() local
2794 down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); in f2fs_dquot_commit()
2797 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit()
2798 up_read(&sbi->quota_sem); in f2fs_dquot_commit()
2804 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_acquire() local
2807 down_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2810 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_acquire()
2811 up_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2817 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_release() local
2821 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_release()
2828 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_mark_dquot_dirty() local
2832 if (is_journalled_quota(sbi)) in f2fs_dquot_mark_dquot_dirty()
2833 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); in f2fs_dquot_mark_dquot_dirty()
2840 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_commit_info() local
2844 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit_info()
2920 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_set_context() local
2928 if (f2fs_sb_has_lost_found(sbi) && in f2fs_set_context()
2929 inode->i_ino == F2FS_ROOT_INO(sbi)) in f2fs_set_context()
2956 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_num_devices() local
2958 if (f2fs_is_multi_device(sbi)) in f2fs_get_num_devices()
2959 return sbi->s_ndevs; in f2fs_get_num_devices()
2966 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_devices() local
2969 for (i = 0; i < sbi->s_ndevs; i++) in f2fs_get_devices()
2990 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_nfs_get_inode() local
2993 if (f2fs_check_nid_range(sbi, ino)) in f2fs_nfs_get_inode()
3076 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, in sanity_check_area_boundary() argument
3081 struct super_block *sb = sbi->sb; in sanity_check_area_boundary()
3101 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", in sanity_check_area_boundary()
3108 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3116 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3124 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3132 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3139 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3152 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in sanity_check_area_boundary()
3158 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3167 static int sanity_check_raw_super(struct f2fs_sb_info *sbi, in sanity_check_raw_super() argument
3178 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", in sanity_check_raw_super()
3188 f2fs_info(sbi, "Invalid SB checksum offset: %zu", in sanity_check_raw_super()
3193 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { in sanity_check_raw_super()
3194 f2fs_info(sbi, "Invalid SB checksum value: %u", crc); in sanity_check_raw_super()
3201 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", in sanity_check_raw_super()
3209 f2fs_info(sbi, "Invalid log blocks per segment (%u)", in sanity_check_raw_super()
3219 f2fs_info(sbi, "Invalid log sectorsize (%u)", in sanity_check_raw_super()
3226 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", in sanity_check_raw_super()
3243 f2fs_info(sbi, "Invalid segment count (%u)", segment_count); in sanity_check_raw_super()
3249 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", in sanity_check_raw_super()
3255 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", in sanity_check_raw_super()
3261 f2fs_info(sbi, "Small segment_count (%u < %u * %u)", in sanity_check_raw_super()
3267 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", in sanity_check_raw_super()
3281 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", in sanity_check_raw_super()
3287 !bdev_is_zoned(sbi->sb->s_bdev)) { in sanity_check_raw_super()
3288 f2fs_info(sbi, "Zoned block device path is missing"); in sanity_check_raw_super()
3294 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", in sanity_check_raw_super()
3302 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", in sanity_check_raw_super()
3312 f2fs_info(sbi, "Insane cp_payload (%u >= %u)", in sanity_check_raw_super()
3323 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", in sanity_check_raw_super()
3331 if (sanity_check_area_boundary(sbi, bh)) in sanity_check_raw_super()
3337 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) in f2fs_sanity_check_ckpt() argument
3340 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_sanity_check_ckpt()
3341 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in f2fs_sanity_check_ckpt()
3369 if (!f2fs_sb_has_readonly(sbi) && in f2fs_sanity_check_ckpt()
3372 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); in f2fs_sanity_check_ckpt()
3377 (f2fs_sb_has_readonly(sbi) ? 1 : 0); in f2fs_sanity_check_ckpt()
3381 f2fs_err(sbi, "Wrong user_block_count: %u", in f2fs_sanity_check_ckpt()
3388 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", in f2fs_sanity_check_ckpt()
3394 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_sanity_check_ckpt()
3396 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", in f2fs_sanity_check_ckpt()
3402 blocks_per_seg = sbi->blocks_per_seg; in f2fs_sanity_check_ckpt()
3409 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3415 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3428 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3434 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3445 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3458 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", in f2fs_sanity_check_ckpt()
3463 cp_pack_start_sum = __start_sum_addr(sbi); in f2fs_sanity_check_ckpt()
3464 cp_payload = __cp_payload(sbi); in f2fs_sanity_check_ckpt()
3468 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", in f2fs_sanity_check_ckpt()
3475 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " in f2fs_sanity_check_ckpt()
3488 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", in f2fs_sanity_check_ckpt()
3493 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_sanity_check_ckpt()
3494 f2fs_err(sbi, "A bug case: need to run fsck"); in f2fs_sanity_check_ckpt()
3500 static void init_sb_info(struct f2fs_sb_info *sbi) in init_sb_info() argument
3502 struct f2fs_super_block *raw_super = sbi->raw_super; in init_sb_info()
3505 sbi->log_sectors_per_block = in init_sb_info()
3507 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); in init_sb_info()
3508 sbi->blocksize = 1 << sbi->log_blocksize; in init_sb_info()
3509 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); in init_sb_info()
3510 sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; in init_sb_info()
3511 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); in init_sb_info()
3512 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); in init_sb_info()
3513 sbi->total_sections = le32_to_cpu(raw_super->section_count); in init_sb_info()
3514 sbi->total_node_count = in init_sb_info()
3516 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; in init_sb_info()
3517 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); in init_sb_info()
3518 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); in init_sb_info()
3519 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); in init_sb_info()
3520 sbi->cur_victim_sec = NULL_SECNO; in init_sb_info()
3521 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in init_sb_info()
3522 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in init_sb_info()
3523 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; in init_sb_info()
3524 sbi->migration_granularity = sbi->segs_per_sec; in init_sb_info()
3525 sbi->seq_file_ra_mul = MIN_RA_MUL; in init_sb_info()
3527 sbi->dir_level = DEF_DIR_LEVEL; in init_sb_info()
3528 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; in init_sb_info()
3529 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3530 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3531 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3532 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; in init_sb_info()
3533 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = in init_sb_info()
3535 clear_sbi_flag(sbi, SBI_NEED_FSCK); in init_sb_info()
3538 atomic_set(&sbi->nr_pages[i], 0); in init_sb_info()
3541 atomic_set(&sbi->wb_sync_req[i], 0); in init_sb_info()
3543 INIT_LIST_HEAD(&sbi->s_list); in init_sb_info()
3544 mutex_init(&sbi->umount_mutex); in init_sb_info()
3545 init_rwsem(&sbi->io_order_lock); in init_sb_info()
3546 spin_lock_init(&sbi->cp_lock); in init_sb_info()
3548 sbi->dirty_device = 0; in init_sb_info()
3549 spin_lock_init(&sbi->dev_lock); in init_sb_info()
3551 init_rwsem(&sbi->sb_lock); in init_sb_info()
3552 init_rwsem(&sbi->pin_sem); in init_sb_info()
3555 static int init_percpu_info(struct f2fs_sb_info *sbi) in init_percpu_info() argument
3559 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); in init_percpu_info()
3563 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, in init_percpu_info()
3566 percpu_counter_destroy(&sbi->alloc_valid_block_count); in init_percpu_info()
3595 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) in init_blkz_info() argument
3602 if (!f2fs_sb_has_blkzoned(sbi)) in init_blkz_info()
3605 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != in init_blkz_info()
3608 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); in init_blkz_info()
3609 if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz != in init_blkz_info()
3610 __ilog2_u32(sbi->blocks_per_blkz)) in init_blkz_info()
3612 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz); in init_blkz_info()
3614 sbi->log_blocks_per_blkz; in init_blkz_info()
3618 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, in init_blkz_info()
3626 FDEV(devi).zone_capacity_blocks = f2fs_kzalloc(sbi, in init_blkz_info()
3655 static int read_raw_super_block(struct f2fs_sb_info *sbi, in read_raw_super_block() argument
3659 struct super_block *sb = sbi->sb; in read_raw_super_block()
3672 f2fs_err(sbi, "Unable to read %dth superblock", in read_raw_super_block()
3680 err = sanity_check_raw_super(sbi, bh); in read_raw_super_block()
3682 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", in read_raw_super_block()
3707 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) in f2fs_commit_super() argument
3713 if ((recover && f2fs_readonly(sbi->sb)) || in f2fs_commit_super()
3714 bdev_read_only(sbi->sb->s_bdev)) { in f2fs_commit_super()
3715 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_commit_super()
3720 if (!recover && f2fs_sb_has_sb_chksum(sbi)) { in f2fs_commit_super()
3721 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), in f2fs_commit_super()
3723 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); in f2fs_commit_super()
3727 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); in f2fs_commit_super()
3730 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3738 bh = sb_bread(sbi->sb, sbi->valid_super_block); in f2fs_commit_super()
3741 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3746 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) in f2fs_scan_devices() argument
3748 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_scan_devices()
3754 if (!bdev_is_zoned(sbi->sb->s_bdev)) in f2fs_scan_devices()
3763 sbi->devs = f2fs_kzalloc(sbi, in f2fs_scan_devices()
3767 if (!sbi->devs) in f2fs_scan_devices()
3778 blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, in f2fs_scan_devices()
3779 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3789 sbi->log_blocks_per_seg) - 1 + in f2fs_scan_devices()
3795 sbi->log_blocks_per_seg) - 1; in f2fs_scan_devices()
3798 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3804 sbi->s_ndevs = i + 1; in f2fs_scan_devices()
3808 !f2fs_sb_has_blkzoned(sbi)) { in f2fs_scan_devices()
3809 f2fs_err(sbi, "Zoned block device feature not enabled"); in f2fs_scan_devices()
3813 if (init_blkz_info(sbi, i)) { in f2fs_scan_devices()
3814 f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); in f2fs_scan_devices()
3819 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", in f2fs_scan_devices()
3828 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", in f2fs_scan_devices()
3833 f2fs_info(sbi, in f2fs_scan_devices()
3834 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); in f2fs_scan_devices()
3838 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) in f2fs_setup_casefold() argument
3841 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { in f2fs_setup_casefold()
3846 if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info, in f2fs_setup_casefold()
3848 f2fs_err(sbi, in f2fs_setup_casefold()
3855 f2fs_err(sbi, in f2fs_setup_casefold()
3862 f2fs_info(sbi, "Using encoding defined by superblock: " in f2fs_setup_casefold()
3866 sbi->sb->s_encoding = encoding; in f2fs_setup_casefold()
3867 sbi->sb->s_encoding_flags = encoding_flags; in f2fs_setup_casefold()
3870 if (f2fs_sb_has_casefold(sbi)) { in f2fs_setup_casefold()
3871 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); in f2fs_setup_casefold()
3878 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) in f2fs_tuning_parameters() argument
3880 struct f2fs_sm_info *sm_i = SM_I(sbi); in f2fs_tuning_parameters()
3884 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in f2fs_tuning_parameters()
3885 if (f2fs_block_unit_discard(sbi)) in f2fs_tuning_parameters()
3890 sbi->readdir_ra = 1; in f2fs_tuning_parameters()
3895 struct f2fs_sb_info *sbi; in f2fs_fill_super() local
3912 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); in f2fs_fill_super()
3913 if (!sbi) in f2fs_fill_super()
3916 sbi->sb = sb; in f2fs_fill_super()
3919 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); in f2fs_fill_super()
3920 if (IS_ERR(sbi->s_chksum_driver)) { in f2fs_fill_super()
3921 f2fs_err(sbi, "Cannot load crc32 driver."); in f2fs_fill_super()
3922 err = PTR_ERR(sbi->s_chksum_driver); in f2fs_fill_super()
3923 sbi->s_chksum_driver = NULL; in f2fs_fill_super()
3929 f2fs_err(sbi, "unable to set blocksize"); in f2fs_fill_super()
3933 err = read_raw_super_block(sbi, &raw_super, &valid_super_block, in f2fs_fill_super()
3938 sb->s_fs_info = sbi; in f2fs_fill_super()
3939 sbi->raw_super = raw_super; in f2fs_fill_super()
3942 if (f2fs_sb_has_inode_chksum(sbi)) in f2fs_fill_super()
3943 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, in f2fs_fill_super()
3946 default_options(sbi); in f2fs_fill_super()
3962 err = f2fs_setup_casefold(sbi); in f2fs_fill_super()
3971 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_fill_super()
3973 if (f2fs_qf_ino(sbi->sb, i)) in f2fs_fill_super()
3974 sbi->nquota_files++; in f2fs_fill_super()
3991 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_fill_super()
3996 sbi->valid_super_block = valid_super_block; in f2fs_fill_super()
3997 init_rwsem(&sbi->gc_lock); in f2fs_fill_super()
3998 mutex_init(&sbi->writepages); in f2fs_fill_super()
3999 init_rwsem(&sbi->cp_global_sem); in f2fs_fill_super()
4000 init_rwsem(&sbi->node_write); in f2fs_fill_super()
4001 init_rwsem(&sbi->node_change); in f2fs_fill_super()
4004 set_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4005 spin_lock_init(&sbi->stat_lock); in f2fs_fill_super()
4011 sbi->write_io[i] = in f2fs_fill_super()
4012 f2fs_kmalloc(sbi, in f2fs_fill_super()
4016 if (!sbi->write_io[i]) { in f2fs_fill_super()
4022 init_rwsem(&sbi->write_io[i][j].io_rwsem); in f2fs_fill_super()
4023 sbi->write_io[i][j].sbi = sbi; in f2fs_fill_super()
4024 sbi->write_io[i][j].bio = NULL; in f2fs_fill_super()
4025 spin_lock_init(&sbi->write_io[i][j].io_lock); in f2fs_fill_super()
4026 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); in f2fs_fill_super()
4027 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); in f2fs_fill_super()
4028 init_rwsem(&sbi->write_io[i][j].bio_list_lock); in f2fs_fill_super()
4032 init_rwsem(&sbi->cp_rwsem); in f2fs_fill_super()
4033 init_rwsem(&sbi->quota_sem); in f2fs_fill_super()
4034 init_waitqueue_head(&sbi->cp_wait); in f2fs_fill_super()
4035 init_sb_info(sbi); in f2fs_fill_super()
4037 err = f2fs_init_iostat(sbi); in f2fs_fill_super()
4041 err = init_percpu_info(sbi); in f2fs_fill_super()
4045 if (F2FS_IO_ALIGNED(sbi)) { in f2fs_fill_super()
4046 sbi->write_io_dummy = in f2fs_fill_super()
4047 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); in f2fs_fill_super()
4048 if (!sbi->write_io_dummy) { in f2fs_fill_super()
4055 err = f2fs_init_xattr_caches(sbi); in f2fs_fill_super()
4058 err = f2fs_init_page_array_cache(sbi); in f2fs_fill_super()
4063 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); in f2fs_fill_super()
4064 if (IS_ERR(sbi->meta_inode)) { in f2fs_fill_super()
4065 f2fs_err(sbi, "Failed to read F2FS meta data inode"); in f2fs_fill_super()
4066 err = PTR_ERR(sbi->meta_inode); in f2fs_fill_super()
4070 err = f2fs_get_valid_checkpoint(sbi); in f2fs_fill_super()
4072 f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); in f2fs_fill_super()
4076 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) in f2fs_fill_super()
4077 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_fill_super()
4078 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { in f2fs_fill_super()
4079 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4080 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; in f2fs_fill_super()
4083 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) in f2fs_fill_super()
4084 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4087 err = f2fs_scan_devices(sbi); in f2fs_fill_super()
4089 f2fs_err(sbi, "Failed to find devices"); in f2fs_fill_super()
4093 err = f2fs_init_post_read_wq(sbi); in f2fs_fill_super()
4095 f2fs_err(sbi, "Failed to initialize post read workqueue"); in f2fs_fill_super()
4099 sbi->total_valid_node_count = in f2fs_fill_super()
4100 le32_to_cpu(sbi->ckpt->valid_node_count); in f2fs_fill_super()
4101 percpu_counter_set(&sbi->total_valid_inode_count, in f2fs_fill_super()
4102 le32_to_cpu(sbi->ckpt->valid_inode_count)); in f2fs_fill_super()
4103 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); in f2fs_fill_super()
4104 sbi->total_valid_block_count = in f2fs_fill_super()
4105 le64_to_cpu(sbi->ckpt->valid_block_count); in f2fs_fill_super()
4106 sbi->last_valid_block_count = sbi->total_valid_block_count; in f2fs_fill_super()
4107 sbi->reserved_blocks = 0; in f2fs_fill_super()
4108 sbi->current_reserved_blocks = 0; in f2fs_fill_super()
4109 limit_reserve_root(sbi); in f2fs_fill_super()
4110 adjust_unusable_cap_perc(sbi); in f2fs_fill_super()
4113 INIT_LIST_HEAD(&sbi->inode_list[i]); in f2fs_fill_super()
4114 spin_lock_init(&sbi->inode_lock[i]); in f2fs_fill_super()
4116 mutex_init(&sbi->flush_lock); in f2fs_fill_super()
4118 f2fs_init_extent_cache_info(sbi); in f2fs_fill_super()
4120 f2fs_init_ino_entry_info(sbi); in f2fs_fill_super()
4122 f2fs_init_fsync_node_info(sbi); in f2fs_fill_super()
4125 f2fs_init_ckpt_req_control(sbi); in f2fs_fill_super()
4126 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && in f2fs_fill_super()
4127 test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_fill_super()
4128 err = f2fs_start_ckpt_thread(sbi); in f2fs_fill_super()
4130 f2fs_err(sbi, in f2fs_fill_super()
4138 err = f2fs_build_segment_manager(sbi); in f2fs_fill_super()
4140 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", in f2fs_fill_super()
4144 err = f2fs_build_node_manager(sbi); in f2fs_fill_super()
4146 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", in f2fs_fill_super()
4152 sbi->sectors_written_start = f2fs_get_sectors_written(sbi); in f2fs_fill_super()
4155 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); in f2fs_fill_super()
4156 if (__exist_node_summaries(sbi)) in f2fs_fill_super()
4157 sbi->kbytes_written = in f2fs_fill_super()
4160 f2fs_build_gc_manager(sbi); in f2fs_fill_super()
4162 err = f2fs_build_stats(sbi); in f2fs_fill_super()
4167 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); in f2fs_fill_super()
4168 if (IS_ERR(sbi->node_inode)) { in f2fs_fill_super()
4169 f2fs_err(sbi, "Failed to read node inode"); in f2fs_fill_super()
4170 err = PTR_ERR(sbi->node_inode); in f2fs_fill_super()
4175 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); in f2fs_fill_super()
4177 f2fs_err(sbi, "Failed to read root inode"); in f2fs_fill_super()
4194 err = f2fs_init_compress_inode(sbi); in f2fs_fill_super()
4198 err = f2fs_register_sysfs(sbi); in f2fs_fill_super()
4204 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4207 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); in f2fs_fill_super()
4211 err = f2fs_recover_orphan_inodes(sbi); in f2fs_fill_super()
4215 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) in f2fs_fill_super()
4219 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && in f2fs_fill_super()
4220 !test_opt(sbi, NORECOVERY)) { in f2fs_fill_super()
4225 if (f2fs_hw_is_readonly(sbi)) { in f2fs_fill_super()
4226 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in f2fs_fill_super()
4227 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4230 f2fs_err(sbi, "Need to recover fsync data, but " in f2fs_fill_super()
4237 f2fs_info(sbi, "write access unavailable, skipping recovery"); in f2fs_fill_super()
4242 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4247 err = f2fs_recover_fsync_data(sbi, false); in f2fs_fill_super()
4252 f2fs_err(sbi, "Cannot recover all fsync data errno=%d", in f2fs_fill_super()
4257 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4261 f2fs_err(sbi, "Need to recover fsync data"); in f2fs_fill_super()
4270 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) { in f2fs_fill_super()
4271 err = f2fs_check_write_pointer(sbi); in f2fs_fill_super()
4277 f2fs_init_inmem_curseg(sbi); in f2fs_fill_super()
4280 clear_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4282 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_fill_super()
4283 err = f2fs_disable_checkpoint(sbi); in f2fs_fill_super()
4286 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { in f2fs_fill_super()
4287 f2fs_enable_checkpoint(sbi); in f2fs_fill_super()
4294 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || in f2fs_fill_super()
4295 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4297 err = f2fs_start_gc_thread(sbi); in f2fs_fill_super()
4305 err = f2fs_commit_super(sbi, true); in f2fs_fill_super()
4306 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", in f2fs_fill_super()
4307 sbi->valid_super_block ? 1 : 2, err); in f2fs_fill_super()
4310 f2fs_join_shrinker(sbi); in f2fs_fill_super()
4312 f2fs_tuning_parameters(sbi); in f2fs_fill_super()
4314 f2fs_notice(sbi, "Mounted with checkpoint version = %llx", in f2fs_fill_super()
4315 cur_cp_version(F2FS_CKPT(sbi))); in f2fs_fill_super()
4316 f2fs_update_time(sbi, CP_TIME); in f2fs_fill_super()
4317 f2fs_update_time(sbi, REQ_TIME); in f2fs_fill_super()
4318 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4323 sync_filesystem(sbi->sb); in f2fs_fill_super()
4329 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) in f2fs_fill_super()
4330 f2fs_quota_off_umount(sbi->sb); in f2fs_fill_super()
4338 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_fill_super()
4341 f2fs_unregister_sysfs(sbi); in f2fs_fill_super()
4343 f2fs_destroy_compress_inode(sbi); in f2fs_fill_super()
4348 f2fs_release_ino_entry(sbi, true); in f2fs_fill_super()
4349 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_fill_super()
4350 iput(sbi->node_inode); in f2fs_fill_super()
4351 sbi->node_inode = NULL; in f2fs_fill_super()
4353 f2fs_destroy_stats(sbi); in f2fs_fill_super()
4355 f2fs_destroy_node_manager(sbi); in f2fs_fill_super()
4357 f2fs_destroy_segment_manager(sbi); in f2fs_fill_super()
4358 f2fs_destroy_post_read_wq(sbi); in f2fs_fill_super()
4360 f2fs_stop_ckpt_thread(sbi); in f2fs_fill_super()
4362 destroy_device_list(sbi); in f2fs_fill_super()
4363 kvfree(sbi->ckpt); in f2fs_fill_super()
4365 make_bad_inode(sbi->meta_inode); in f2fs_fill_super()
4366 iput(sbi->meta_inode); in f2fs_fill_super()
4367 sbi->meta_inode = NULL; in f2fs_fill_super()
4369 f2fs_destroy_page_array_cache(sbi); in f2fs_fill_super()
4371 f2fs_destroy_xattr_caches(sbi); in f2fs_fill_super()
4373 mempool_destroy(sbi->write_io_dummy); in f2fs_fill_super()
4375 destroy_percpu_info(sbi); in f2fs_fill_super()
4377 f2fs_destroy_iostat(sbi); in f2fs_fill_super()
4380 kvfree(sbi->write_io[i]); in f2fs_fill_super()
4389 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_fill_super()
4391 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_fill_super()
4396 if (sbi->s_chksum_driver) in f2fs_fill_super()
4397 crypto_free_shash(sbi->s_chksum_driver); in f2fs_fill_super()
4398 kfree(sbi); in f2fs_fill_super()
4418 struct f2fs_sb_info *sbi = F2FS_SB(sb); in kill_f2fs_super() local
4420 set_sbi_flag(sbi, SBI_IS_CLOSE); in kill_f2fs_super()
4421 f2fs_stop_gc_thread(sbi); in kill_f2fs_super()
4422 f2fs_stop_discard_thread(sbi); in kill_f2fs_super()
4429 if (test_opt(sbi, COMPRESS_CACHE)) in kill_f2fs_super()
4430 truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); in kill_f2fs_super()
4433 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in kill_f2fs_super()
4434 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in kill_f2fs_super()
4438 f2fs_write_checkpoint(sbi, &cpc); in kill_f2fs_super()
4441 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) in kill_f2fs_super()