Lines Matching refs:sbi

61 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,  in f2fs_build_fault_attr()  argument
64 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; in f2fs_build_fault_attr()
239 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) in f2fs_printk() argument
251 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); in f2fs_printk()
304 static inline void limit_reserve_root(struct f2fs_sb_info *sbi) in limit_reserve_root() argument
306 block_t limit = min((sbi->user_block_count >> 3), in limit_reserve_root()
307 sbi->user_block_count - sbi->reserved_blocks); in limit_reserve_root()
310 if (test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
311 F2FS_OPTION(sbi).root_reserved_blocks > limit && in limit_reserve_root()
312 F2FS_OPTION(sbi).root_reserved_blocks > MIN_ROOT_RESERVED_BLOCKS) { in limit_reserve_root()
313 F2FS_OPTION(sbi).root_reserved_blocks = limit; in limit_reserve_root()
314 f2fs_info(sbi, "Reduce reserved blocks for root = %u", in limit_reserve_root()
315 F2FS_OPTION(sbi).root_reserved_blocks); in limit_reserve_root()
317 if (!test_opt(sbi, RESERVE_ROOT) && in limit_reserve_root()
318 (!uid_eq(F2FS_OPTION(sbi).s_resuid, in limit_reserve_root()
320 !gid_eq(F2FS_OPTION(sbi).s_resgid, in limit_reserve_root()
322 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", in limit_reserve_root()
324 F2FS_OPTION(sbi).s_resuid), in limit_reserve_root()
326 F2FS_OPTION(sbi).s_resgid)); in limit_reserve_root()
329 static inline int adjust_reserved_segment(struct f2fs_sb_info *sbi) in adjust_reserved_segment() argument
331 unsigned int sec_blks = sbi->blocks_per_seg * sbi->segs_per_sec; in adjust_reserved_segment()
336 if (!F2FS_IO_ALIGNED(sbi)) in adjust_reserved_segment()
340 avg_vblocks = sec_blks / F2FS_IO_SIZE(sbi); in adjust_reserved_segment()
345 wanted_reserved_segments = (F2FS_IO_SIZE(sbi) / avg_vblocks) * in adjust_reserved_segment()
346 reserved_segments(sbi); in adjust_reserved_segment()
347 wanted_reserved_segments -= reserved_segments(sbi); in adjust_reserved_segment()
349 avail_user_block_count = sbi->user_block_count - in adjust_reserved_segment()
350 sbi->current_reserved_blocks - in adjust_reserved_segment()
351 F2FS_OPTION(sbi).root_reserved_blocks; in adjust_reserved_segment()
353 if (wanted_reserved_segments * sbi->blocks_per_seg > in adjust_reserved_segment()
355 …f2fs_err(sbi, "IO align feature can't grab additional reserved segment: %u, available segments: %u… in adjust_reserved_segment()
357 avail_user_block_count >> sbi->log_blocks_per_seg); in adjust_reserved_segment()
361 SM_I(sbi)->additional_reserved_segments = wanted_reserved_segments; in adjust_reserved_segment()
363 f2fs_info(sbi, "IO align feature needs additional reserved segment: %u", in adjust_reserved_segment()
369 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) in adjust_unusable_cap_perc() argument
371 if (!F2FS_OPTION(sbi).unusable_cap_perc) in adjust_unusable_cap_perc()
374 if (F2FS_OPTION(sbi).unusable_cap_perc == 100) in adjust_unusable_cap_perc()
375 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; in adjust_unusable_cap_perc()
377 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * in adjust_unusable_cap_perc()
378 F2FS_OPTION(sbi).unusable_cap_perc; in adjust_unusable_cap_perc()
380 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", in adjust_unusable_cap_perc()
381 F2FS_OPTION(sbi).unusable_cap, in adjust_unusable_cap_perc()
382 F2FS_OPTION(sbi).unusable_cap_perc); in adjust_unusable_cap_perc()
398 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_qf_name() local
402 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
403 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_set_qf_name()
406 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_set_qf_name()
407 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); in f2fs_set_qf_name()
413 f2fs_err(sbi, "Not enough memory for storing quotafile name"); in f2fs_set_qf_name()
416 if (F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_set_qf_name()
417 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) in f2fs_set_qf_name()
420 f2fs_err(sbi, "%s quota file already specified", in f2fs_set_qf_name()
425 f2fs_err(sbi, "quotafile must be on filesystem root"); in f2fs_set_qf_name()
428 F2FS_OPTION(sbi).s_qf_names[qtype] = qname; in f2fs_set_qf_name()
429 set_opt(sbi, QUOTA); in f2fs_set_qf_name()
438 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_clear_qf_name() local
440 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { in f2fs_clear_qf_name()
441 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); in f2fs_clear_qf_name()
444 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); in f2fs_clear_qf_name()
445 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; in f2fs_clear_qf_name()
449 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) in f2fs_check_quota_options() argument
456 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { in f2fs_check_quota_options()
457 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); in f2fs_check_quota_options()
460 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || in f2fs_check_quota_options()
461 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || in f2fs_check_quota_options()
462 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { in f2fs_check_quota_options()
463 if (test_opt(sbi, USRQUOTA) && in f2fs_check_quota_options()
464 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_check_quota_options()
465 clear_opt(sbi, USRQUOTA); in f2fs_check_quota_options()
467 if (test_opt(sbi, GRPQUOTA) && in f2fs_check_quota_options()
468 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_check_quota_options()
469 clear_opt(sbi, GRPQUOTA); in f2fs_check_quota_options()
471 if (test_opt(sbi, PRJQUOTA) && in f2fs_check_quota_options()
472 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_check_quota_options()
473 clear_opt(sbi, PRJQUOTA); in f2fs_check_quota_options()
475 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || in f2fs_check_quota_options()
476 test_opt(sbi, PRJQUOTA)) { in f2fs_check_quota_options()
477 f2fs_err(sbi, "old and new quota format mixing"); in f2fs_check_quota_options()
481 if (!F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
482 f2fs_err(sbi, "journaled quota format not specified"); in f2fs_check_quota_options()
487 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_check_quota_options()
488 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); in f2fs_check_quota_options()
489 F2FS_OPTION(sbi).s_jquota_fmt = 0; in f2fs_check_quota_options()
500 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_set_test_dummy_encryption() local
504 if (!f2fs_sb_has_encrypt(sbi)) { in f2fs_set_test_dummy_encryption()
505 f2fs_err(sbi, "Encrypt feature is off"); in f2fs_set_test_dummy_encryption()
515 if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) { in f2fs_set_test_dummy_encryption()
516 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); in f2fs_set_test_dummy_encryption()
520 sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_set_test_dummy_encryption()
523 f2fs_warn(sbi, in f2fs_set_test_dummy_encryption()
526 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", in f2fs_set_test_dummy_encryption()
529 f2fs_warn(sbi, "Error processing option \"%s\" [%d]", in f2fs_set_test_dummy_encryption()
533 f2fs_warn(sbi, "Test dummy encryption mode enabled"); in f2fs_set_test_dummy_encryption()
535 f2fs_warn(sbi, "Test dummy encryption mount option ignored"); in f2fs_set_test_dummy_encryption()
542 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_lz4hc_level() argument
549 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_lz4hc_level()
557 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_lz4hc_level()
564 f2fs_info(sbi, "invalid lz4hc compress level: %d", level); in f2fs_set_lz4hc_level()
568 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_lz4hc_level()
571 f2fs_info(sbi, "kernel doesn't support lz4hc compression"); in f2fs_set_lz4hc_level()
578 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) in f2fs_set_zstd_level() argument
584 F2FS_OPTION(sbi).compress_level = 0; in f2fs_set_zstd_level()
591 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); in f2fs_set_zstd_level()
598 f2fs_info(sbi, "invalid zstd compress level: %d", level); in f2fs_set_zstd_level()
602 F2FS_OPTION(sbi).compress_level = level; in f2fs_set_zstd_level()
610 struct f2fs_sb_info *sbi = F2FS_SB(sb); in parse_options() local
644 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in parse_options()
646 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; in parse_options()
648 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; in parse_options()
656 set_opt(sbi, DISABLE_ROLL_FORWARD); in parse_options()
660 set_opt(sbi, NORECOVERY); in parse_options()
665 set_opt(sbi, DISCARD); in parse_options()
668 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
669 f2fs_warn(sbi, "discard is required for zoned block devices"); in parse_options()
672 clear_opt(sbi, DISCARD); in parse_options()
675 set_opt(sbi, NOHEAP); in parse_options()
678 clear_opt(sbi, NOHEAP); in parse_options()
682 set_opt(sbi, XATTR_USER); in parse_options()
685 clear_opt(sbi, XATTR_USER); in parse_options()
688 set_opt(sbi, INLINE_XATTR); in parse_options()
691 clear_opt(sbi, INLINE_XATTR); in parse_options()
696 set_opt(sbi, INLINE_XATTR_SIZE); in parse_options()
697 F2FS_OPTION(sbi).inline_xattr_size = arg; in parse_options()
701 f2fs_info(sbi, "user_xattr options not supported"); in parse_options()
704 f2fs_info(sbi, "nouser_xattr options not supported"); in parse_options()
707 f2fs_info(sbi, "inline_xattr options not supported"); in parse_options()
710 f2fs_info(sbi, "noinline_xattr options not supported"); in parse_options()
715 set_opt(sbi, POSIX_ACL); in parse_options()
718 clear_opt(sbi, POSIX_ACL); in parse_options()
722 f2fs_info(sbi, "acl options not supported"); in parse_options()
725 f2fs_info(sbi, "noacl options not supported"); in parse_options()
734 F2FS_OPTION(sbi).active_logs = arg; in parse_options()
737 set_opt(sbi, DISABLE_EXT_IDENTIFY); in parse_options()
740 set_opt(sbi, INLINE_DATA); in parse_options()
743 set_opt(sbi, INLINE_DENTRY); in parse_options()
746 clear_opt(sbi, INLINE_DENTRY); in parse_options()
749 set_opt(sbi, FLUSH_MERGE); in parse_options()
752 clear_opt(sbi, FLUSH_MERGE); in parse_options()
755 set_opt(sbi, NOBARRIER); in parse_options()
758 set_opt(sbi, FASTBOOT); in parse_options()
761 set_opt(sbi, READ_EXTENT_CACHE); in parse_options()
764 clear_opt(sbi, READ_EXTENT_CACHE); in parse_options()
767 clear_opt(sbi, INLINE_DATA); in parse_options()
770 set_opt(sbi, DATA_FLUSH); in parse_options()
775 if (test_opt(sbi, RESERVE_ROOT)) { in parse_options()
776 f2fs_info(sbi, "Preserve previous reserve_root=%u", in parse_options()
777 F2FS_OPTION(sbi).root_reserved_blocks); in parse_options()
779 F2FS_OPTION(sbi).root_reserved_blocks = arg; in parse_options()
780 set_opt(sbi, RESERVE_ROOT); in parse_options()
788 f2fs_err(sbi, "Invalid uid value %d", arg); in parse_options()
791 F2FS_OPTION(sbi).s_resuid = uid; in parse_options()
798 f2fs_err(sbi, "Invalid gid value %d", arg); in parse_options()
801 F2FS_OPTION(sbi).s_resgid = gid; in parse_options()
809 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
810 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature"); in parse_options()
814 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in parse_options()
816 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in parse_options()
827 f2fs_warn(sbi, "Not support %d, larger than %d", in parse_options()
831 F2FS_OPTION(sbi).write_io_size_bits = arg; in parse_options()
837 f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); in parse_options()
838 set_opt(sbi, FAULT_INJECTION); in parse_options()
844 f2fs_build_fault_attr(sbi, 0, arg); in parse_options()
845 set_opt(sbi, FAULT_INJECTION); in parse_options()
849 f2fs_info(sbi, "fault_injection options not supported"); in parse_options()
853 f2fs_info(sbi, "fault_type options not supported"); in parse_options()
865 set_opt(sbi, USRQUOTA); in parse_options()
868 set_opt(sbi, GRPQUOTA); in parse_options()
871 set_opt(sbi, PRJQUOTA); in parse_options()
904 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; in parse_options()
907 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; in parse_options()
910 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; in parse_options()
913 clear_opt(sbi, QUOTA); in parse_options()
914 clear_opt(sbi, USRQUOTA); in parse_options()
915 clear_opt(sbi, GRPQUOTA); in parse_options()
916 clear_opt(sbi, PRJQUOTA); in parse_options()
933 f2fs_info(sbi, "quota operations not supported"); in parse_options()
941 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; in parse_options()
943 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
945 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; in parse_options()
958 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in parse_options()
960 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in parse_options()
972 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in parse_options()
974 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; in parse_options()
976 F2FS_OPTION(sbi).fsync_mode = in parse_options()
994 f2fs_info(sbi, "inline encryption not supported"); in parse_options()
1002 F2FS_OPTION(sbi).unusable_cap_perc = arg; in parse_options()
1003 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1008 F2FS_OPTION(sbi).unusable_cap = arg; in parse_options()
1009 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1012 set_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1015 clear_opt(sbi, DISABLE_CHECKPOINT); in parse_options()
1018 set_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1021 clear_opt(sbi, MERGE_CHECKPOINT); in parse_options()
1025 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1026 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1034 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1035 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1038 f2fs_info(sbi, "kernel doesn't support lzo compression"); in parse_options()
1042 ret = f2fs_set_lz4hc_level(sbi, name); in parse_options()
1047 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1050 f2fs_info(sbi, "kernel doesn't support lz4 compression"); in parse_options()
1054 ret = f2fs_set_zstd_level(sbi, name); in parse_options()
1059 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1062 f2fs_info(sbi, "kernel doesn't support zstd compression"); in parse_options()
1066 F2FS_OPTION(sbi).compress_level = 0; in parse_options()
1067 F2FS_OPTION(sbi).compress_algorithm = in parse_options()
1070 f2fs_info(sbi, "kernel doesn't support lzorle compression"); in parse_options()
1079 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1080 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1087 f2fs_err(sbi, in parse_options()
1091 F2FS_OPTION(sbi).compress_log_size = arg; in parse_options()
1094 if (!f2fs_sb_has_compression(sbi)) { in parse_options()
1095 f2fs_info(sbi, "Image doesn't support compression"); in parse_options()
1102 ext = F2FS_OPTION(sbi).extensions; in parse_options()
1103 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; in parse_options()
1107 f2fs_err(sbi, in parse_options()
1114 F2FS_OPTION(sbi).compress_ext_cnt++; in parse_options()
1118 F2FS_OPTION(sbi).compress_chksum = true; in parse_options()
1125 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in parse_options()
1127 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; in parse_options()
1135 set_opt(sbi, COMPRESS_CACHE); in parse_options()
1144 f2fs_info(sbi, "compression options not supported"); in parse_options()
1148 set_opt(sbi, ATGC); in parse_options()
1151 set_opt(sbi, GC_MERGE); in parse_options()
1154 clear_opt(sbi, GC_MERGE); in parse_options()
1157 set_opt(sbi, AGE_EXTENT_CACHE); in parse_options()
1164 F2FS_OPTION(sbi).memory_mode = in parse_options()
1167 F2FS_OPTION(sbi).memory_mode = in parse_options()
1176 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", in parse_options()
1183 if (f2fs_check_quota_options(sbi)) in parse_options()
1186 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1187 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1190 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1191 …f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); in parse_options()
1196 if (f2fs_sb_has_casefold(sbi)) { in parse_options()
1197 f2fs_err(sbi, in parse_options()
1208 if (f2fs_sb_has_blkzoned(sbi)) { in parse_options()
1209 f2fs_err(sbi, "Zoned block device support is not enabled"); in parse_options()
1214 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { in parse_options()
1215 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", in parse_options()
1216 F2FS_IO_SIZE_KB(sbi)); in parse_options()
1220 if (test_opt(sbi, INLINE_XATTR_SIZE)) { in parse_options()
1223 if (!f2fs_sb_has_extra_attr(sbi) || in parse_options()
1224 !f2fs_sb_has_flexible_inline_xattr(sbi)) { in parse_options()
1225 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); in parse_options()
1228 if (!test_opt(sbi, INLINE_XATTR)) { in parse_options()
1229 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); in parse_options()
1236 if (F2FS_OPTION(sbi).inline_xattr_size < min_size || in parse_options()
1237 F2FS_OPTION(sbi).inline_xattr_size > max_size) { in parse_options()
1238 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", in parse_options()
1244 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { in parse_options()
1245 f2fs_err(sbi, "LFS not compatible with checkpoint=disable"); in parse_options()
1252 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_PERSIST_TYPE) in parse_options()
1253 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in parse_options()
1255 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { in parse_options()
1256 f2fs_err(sbi, "Allow to mount readonly mode only"); in parse_options()
1295 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_drop_inode() local
1302 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_drop_inode()
1303 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_drop_inode()
1304 inode->i_ino == F2FS_META_INO(sbi)) { in f2fs_drop_inode()
1357 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_dirtied() local
1360 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1365 stat_inc_dirty_inode(sbi, DIRTY_META); in f2fs_inode_dirtied()
1369 &sbi->inode_list[DIRTY_META]); in f2fs_inode_dirtied()
1370 inc_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_dirtied()
1372 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_dirtied()
1378 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_inode_synced() local
1380 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1382 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1387 dec_page_count(sbi, F2FS_DIRTY_IMETA); in f2fs_inode_synced()
1392 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_inode_synced()
1402 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_dirty_inode() local
1404 if (inode->i_ino == F2FS_NODE_INO(sbi) || in f2fs_dirty_inode()
1405 inode->i_ino == F2FS_META_INO(sbi)) in f2fs_dirty_inode()
1423 static void destroy_percpu_info(struct f2fs_sb_info *sbi) in destroy_percpu_info() argument
1425 percpu_counter_destroy(&sbi->alloc_valid_block_count); in destroy_percpu_info()
1426 percpu_counter_destroy(&sbi->total_valid_inode_count); in destroy_percpu_info()
1429 static void destroy_device_list(struct f2fs_sb_info *sbi) in destroy_device_list() argument
1433 for (i = 0; i < sbi->s_ndevs; i++) { in destroy_device_list()
1440 kvfree(sbi->devs); in destroy_device_list()
1445 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_put_super() local
1450 f2fs_unregister_sysfs(sbi); in f2fs_put_super()
1455 mutex_lock(&sbi->umount_mutex); in f2fs_put_super()
1461 f2fs_stop_ckpt_thread(sbi); in f2fs_put_super()
1468 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in f2fs_put_super()
1469 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { in f2fs_put_super()
1473 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1477 dropped = f2fs_issue_discard_timeout(sbi); in f2fs_put_super()
1479 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) && in f2fs_put_super()
1480 !sbi->discard_blks && !dropped) { in f2fs_put_super()
1484 f2fs_write_checkpoint(sbi, &cpc); in f2fs_put_super()
1491 f2fs_release_ino_entry(sbi, true); in f2fs_put_super()
1493 f2fs_leave_shrinker(sbi); in f2fs_put_super()
1494 mutex_unlock(&sbi->umount_mutex); in f2fs_put_super()
1497 f2fs_flush_merged_writes(sbi); in f2fs_put_super()
1499 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); in f2fs_put_super()
1501 f2fs_bug_on(sbi, sbi->fsync_node_num); in f2fs_put_super()
1503 f2fs_destroy_compress_inode(sbi); in f2fs_put_super()
1505 iput(sbi->node_inode); in f2fs_put_super()
1506 sbi->node_inode = NULL; in f2fs_put_super()
1508 iput(sbi->meta_inode); in f2fs_put_super()
1509 sbi->meta_inode = NULL; in f2fs_put_super()
1515 f2fs_destroy_stats(sbi); in f2fs_put_super()
1518 f2fs_destroy_node_manager(sbi); in f2fs_put_super()
1519 f2fs_destroy_segment_manager(sbi); in f2fs_put_super()
1521 f2fs_destroy_post_read_wq(sbi); in f2fs_put_super()
1523 kvfree(sbi->ckpt); in f2fs_put_super()
1526 if (sbi->s_chksum_driver) in f2fs_put_super()
1527 crypto_free_shash(sbi->s_chksum_driver); in f2fs_put_super()
1528 kfree(sbi->raw_super); in f2fs_put_super()
1530 destroy_device_list(sbi); in f2fs_put_super()
1531 f2fs_destroy_page_array_cache(sbi); in f2fs_put_super()
1532 f2fs_destroy_xattr_caches(sbi); in f2fs_put_super()
1533 mempool_destroy(sbi->write_io_dummy); in f2fs_put_super()
1536 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_put_super()
1538 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_put_super()
1539 destroy_percpu_info(sbi); in f2fs_put_super()
1541 kvfree(sbi->write_io[i]); in f2fs_put_super()
1545 kfree(sbi); in f2fs_put_super()
1550 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_sync_fs() local
1553 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_fs()
1555 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_sync_fs()
1560 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_sync_fs()
1564 err = f2fs_issue_checkpoint(sbi); in f2fs_sync_fs()
1565 atomic_set(&sbi->no_cp_fsync_pages, 0); in f2fs_sync_fs()
1646 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_statfs() local
1651 total_count = le64_to_cpu(sbi->raw_super->block_count); in f2fs_statfs()
1652 user_block_count = sbi->user_block_count; in f2fs_statfs()
1653 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); in f2fs_statfs()
1655 buf->f_bsize = sbi->blocksize; in f2fs_statfs()
1659 buf->f_bfree = user_block_count - valid_user_blocks(sbi) - in f2fs_statfs()
1660 sbi->current_reserved_blocks; in f2fs_statfs()
1662 spin_lock(&sbi->stat_lock); in f2fs_statfs()
1663 if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) in f2fs_statfs()
1666 buf->f_bfree -= sbi->unusable_block_count; in f2fs_statfs()
1667 spin_unlock(&sbi->stat_lock); in f2fs_statfs()
1669 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) in f2fs_statfs()
1671 F2FS_OPTION(sbi).root_reserved_blocks; in f2fs_statfs()
1675 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_statfs()
1682 buf->f_ffree = min(avail_node_count - valid_node_count(sbi), in f2fs_statfs()
1702 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_quota_options() local
1704 if (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1707 switch (F2FS_OPTION(sbi).s_jquota_fmt) { in f2fs_show_quota_options()
1721 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) in f2fs_show_quota_options()
1723 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); in f2fs_show_quota_options()
1725 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) in f2fs_show_quota_options()
1727 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); in f2fs_show_quota_options()
1729 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) in f2fs_show_quota_options()
1731 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); in f2fs_show_quota_options()
1739 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_show_compress_options() local
1743 if (!f2fs_sb_has_compression(sbi)) in f2fs_show_compress_options()
1746 switch (F2FS_OPTION(sbi).compress_algorithm) { in f2fs_show_compress_options()
1762 if (F2FS_OPTION(sbi).compress_level) in f2fs_show_compress_options()
1763 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); in f2fs_show_compress_options()
1766 F2FS_OPTION(sbi).compress_log_size); in f2fs_show_compress_options()
1768 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { in f2fs_show_compress_options()
1770 F2FS_OPTION(sbi).extensions[i]); in f2fs_show_compress_options()
1773 if (F2FS_OPTION(sbi).compress_chksum) in f2fs_show_compress_options()
1776 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) in f2fs_show_compress_options()
1778 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) in f2fs_show_compress_options()
1781 if (test_opt(sbi, COMPRESS_CACHE)) in f2fs_show_compress_options()
1788 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); in f2fs_show_options() local
1790 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) in f2fs_show_options()
1792 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) in f2fs_show_options()
1794 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) in f2fs_show_options()
1797 if (test_opt(sbi, GC_MERGE)) in f2fs_show_options()
1800 if (test_opt(sbi, DISABLE_ROLL_FORWARD)) in f2fs_show_options()
1802 if (test_opt(sbi, NORECOVERY)) in f2fs_show_options()
1804 if (test_opt(sbi, DISCARD)) in f2fs_show_options()
1808 if (test_opt(sbi, NOHEAP)) in f2fs_show_options()
1813 if (test_opt(sbi, XATTR_USER)) in f2fs_show_options()
1817 if (test_opt(sbi, INLINE_XATTR)) in f2fs_show_options()
1821 if (test_opt(sbi, INLINE_XATTR_SIZE)) in f2fs_show_options()
1823 F2FS_OPTION(sbi).inline_xattr_size); in f2fs_show_options()
1826 if (test_opt(sbi, POSIX_ACL)) in f2fs_show_options()
1831 if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) in f2fs_show_options()
1833 if (test_opt(sbi, INLINE_DATA)) in f2fs_show_options()
1837 if (test_opt(sbi, INLINE_DENTRY)) in f2fs_show_options()
1841 if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE)) in f2fs_show_options()
1843 if (test_opt(sbi, NOBARRIER)) in f2fs_show_options()
1845 if (test_opt(sbi, FASTBOOT)) in f2fs_show_options()
1847 if (test_opt(sbi, READ_EXTENT_CACHE)) in f2fs_show_options()
1851 if (test_opt(sbi, AGE_EXTENT_CACHE)) in f2fs_show_options()
1853 if (test_opt(sbi, DATA_FLUSH)) in f2fs_show_options()
1857 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) in f2fs_show_options()
1859 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) in f2fs_show_options()
1861 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); in f2fs_show_options()
1862 if (test_opt(sbi, RESERVE_ROOT)) in f2fs_show_options()
1864 F2FS_OPTION(sbi).root_reserved_blocks, in f2fs_show_options()
1866 F2FS_OPTION(sbi).s_resuid), in f2fs_show_options()
1868 F2FS_OPTION(sbi).s_resgid)); in f2fs_show_options()
1869 if (F2FS_IO_SIZE_BITS(sbi)) in f2fs_show_options()
1871 F2FS_OPTION(sbi).write_io_size_bits); in f2fs_show_options()
1873 if (test_opt(sbi, FAULT_INJECTION)) { in f2fs_show_options()
1875 F2FS_OPTION(sbi).fault_info.inject_rate); in f2fs_show_options()
1877 F2FS_OPTION(sbi).fault_info.inject_type); in f2fs_show_options()
1881 if (test_opt(sbi, QUOTA)) in f2fs_show_options()
1883 if (test_opt(sbi, USRQUOTA)) in f2fs_show_options()
1885 if (test_opt(sbi, GRPQUOTA)) in f2fs_show_options()
1887 if (test_opt(sbi, PRJQUOTA)) in f2fs_show_options()
1890 f2fs_show_quota_options(seq, sbi->sb); in f2fs_show_options()
1891 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) in f2fs_show_options()
1893 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) in f2fs_show_options()
1896 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); in f2fs_show_options()
1898 if (sbi->sb->s_flags & SB_INLINECRYPT) in f2fs_show_options()
1901 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) in f2fs_show_options()
1903 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) in f2fs_show_options()
1906 if (test_opt(sbi, DISABLE_CHECKPOINT)) in f2fs_show_options()
1908 F2FS_OPTION(sbi).unusable_cap); in f2fs_show_options()
1909 if (test_opt(sbi, MERGE_CHECKPOINT)) in f2fs_show_options()
1913 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) in f2fs_show_options()
1915 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) in f2fs_show_options()
1917 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) in f2fs_show_options()
1921 f2fs_show_compress_options(seq, sbi->sb); in f2fs_show_options()
1924 if (test_opt(sbi, ATGC)) in f2fs_show_options()
1927 if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL) in f2fs_show_options()
1929 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW) in f2fs_show_options()
1935 static void default_options(struct f2fs_sb_info *sbi) in default_options() argument
1938 if (f2fs_sb_has_readonly(sbi)) in default_options()
1939 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; in default_options()
1941 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; in default_options()
1943 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; in default_options()
1944 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; in default_options()
1945 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; in default_options()
1946 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; in default_options()
1947 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); in default_options()
1948 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); in default_options()
1949 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; in default_options()
1950 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; in default_options()
1951 F2FS_OPTION(sbi).compress_ext_cnt = 0; in default_options()
1952 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; in default_options()
1953 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; in default_options()
1954 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL; in default_options()
1956 sbi->sb->s_flags &= ~SB_INLINECRYPT; in default_options()
1958 set_opt(sbi, INLINE_XATTR); in default_options()
1959 set_opt(sbi, INLINE_DATA); in default_options()
1960 set_opt(sbi, INLINE_DENTRY); in default_options()
1961 set_opt(sbi, READ_EXTENT_CACHE); in default_options()
1962 set_opt(sbi, NOHEAP); in default_options()
1963 clear_opt(sbi, DISABLE_CHECKPOINT); in default_options()
1964 set_opt(sbi, MERGE_CHECKPOINT); in default_options()
1965 F2FS_OPTION(sbi).unusable_cap = 0; in default_options()
1966 sbi->sb->s_flags |= SB_LAZYTIME; in default_options()
1967 set_opt(sbi, FLUSH_MERGE); in default_options()
1968 set_opt(sbi, DISCARD); in default_options()
1969 if (f2fs_sb_has_blkzoned(sbi)) in default_options()
1970 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; in default_options()
1972 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; in default_options()
1975 set_opt(sbi, XATTR_USER); in default_options()
1978 set_opt(sbi, POSIX_ACL); in default_options()
1981 f2fs_build_fault_attr(sbi, 0, 0); in default_options()
1988 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_disable_checkpoint() argument
1990 unsigned int s_flags = sbi->sb->s_flags; in f2fs_disable_checkpoint()
1997 f2fs_err(sbi, "checkpoint=disable on readonly fs"); in f2fs_disable_checkpoint()
2000 sbi->sb->s_flags |= SB_ACTIVE; in f2fs_disable_checkpoint()
2002 f2fs_update_time(sbi, DISABLE_TIME); in f2fs_disable_checkpoint()
2004 while (!f2fs_time_over(sbi, DISABLE_TIME)) { in f2fs_disable_checkpoint()
2005 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2006 err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); in f2fs_disable_checkpoint()
2015 ret = sync_filesystem(sbi->sb); in f2fs_disable_checkpoint()
2021 unusable = f2fs_get_unusable_blocks(sbi); in f2fs_disable_checkpoint()
2022 if (f2fs_disable_cp_again(sbi, unusable)) { in f2fs_disable_checkpoint()
2027 f2fs_down_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2029 set_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_disable_checkpoint()
2030 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_disable_checkpoint()
2034 spin_lock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2035 sbi->unusable_block_count = unusable; in f2fs_disable_checkpoint()
2036 spin_unlock(&sbi->stat_lock); in f2fs_disable_checkpoint()
2039 f2fs_up_write(&sbi->gc_lock); in f2fs_disable_checkpoint()
2041 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ in f2fs_disable_checkpoint()
2045 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) in f2fs_enable_checkpoint() argument
2051 sync_inodes_sb(sbi->sb); in f2fs_enable_checkpoint()
2054 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); in f2fs_enable_checkpoint()
2057 f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); in f2fs_enable_checkpoint()
2059 f2fs_down_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2060 f2fs_dirty_to_prefree(sbi); in f2fs_enable_checkpoint()
2062 clear_sbi_flag(sbi, SBI_CP_DISABLED); in f2fs_enable_checkpoint()
2063 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_enable_checkpoint()
2064 f2fs_up_write(&sbi->gc_lock); in f2fs_enable_checkpoint()
2066 f2fs_sync_fs(sbi->sb, 1); in f2fs_enable_checkpoint()
2069 f2fs_flush_ckpt_thread(sbi); in f2fs_enable_checkpoint()
2074 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_remount() local
2081 bool no_read_extent_cache = !test_opt(sbi, READ_EXTENT_CACHE); in f2fs_remount()
2082 bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE); in f2fs_remount()
2083 bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2084 bool no_io_align = !F2FS_IO_ALIGNED(sbi); in f2fs_remount()
2085 bool no_atgc = !test_opt(sbi, ATGC); in f2fs_remount()
2086 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE); in f2fs_remount()
2096 org_mount_opt = sbi->mount_opt; in f2fs_remount()
2100 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; in f2fs_remount()
2102 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_remount()
2104 kstrdup(F2FS_OPTION(sbi).s_qf_names[i], in f2fs_remount()
2118 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { in f2fs_remount()
2119 err = f2fs_commit_super(sbi, false); in f2fs_remount()
2120 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", in f2fs_remount()
2123 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_remount()
2126 default_options(sbi); in f2fs_remount()
2133 disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT); in f2fs_remount()
2142 if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { in f2fs_remount()
2157 } else if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_remount()
2165 if (no_atgc == !!test_opt(sbi, ATGC)) { in f2fs_remount()
2167 f2fs_warn(sbi, "switch atgc option is not allowed"); in f2fs_remount()
2172 if (no_read_extent_cache == !!test_opt(sbi, READ_EXTENT_CACHE)) { in f2fs_remount()
2174 f2fs_warn(sbi, "switch extent_cache option is not allowed"); in f2fs_remount()
2178 if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) { in f2fs_remount()
2180 f2fs_warn(sbi, "switch age_extent_cache option is not allowed"); in f2fs_remount()
2184 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { in f2fs_remount()
2186 f2fs_warn(sbi, "switch io_bits option is not allowed"); in f2fs_remount()
2190 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) { in f2fs_remount()
2192 f2fs_warn(sbi, "switch compress_cache option is not allowed"); in f2fs_remount()
2196 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2198 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); in f2fs_remount()
2208 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && in f2fs_remount()
2209 !test_opt(sbi, GC_MERGE))) { in f2fs_remount()
2210 if (sbi->gc_thread) { in f2fs_remount()
2211 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2214 } else if (!sbi->gc_thread) { in f2fs_remount()
2215 err = f2fs_start_gc_thread(sbi); in f2fs_remount()
2222 F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) { in f2fs_remount()
2225 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_remount()
2226 set_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2228 clear_sbi_flag(sbi, SBI_IS_CLOSE); in f2fs_remount()
2231 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || in f2fs_remount()
2232 !test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_remount()
2233 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2237 f2fs_flush_ckpt_thread(sbi); in f2fs_remount()
2239 err = f2fs_start_ckpt_thread(sbi); in f2fs_remount()
2241 f2fs_err(sbi, in f2fs_remount()
2253 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { in f2fs_remount()
2254 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2255 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2258 err = f2fs_create_flush_cmd_control(sbi); in f2fs_remount()
2265 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_remount()
2266 err = f2fs_disable_checkpoint(sbi); in f2fs_remount()
2270 f2fs_enable_checkpoint(sbi); in f2fs_remount()
2282 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_remount()
2284 limit_reserve_root(sbi); in f2fs_remount()
2285 adjust_unusable_cap_perc(sbi); in f2fs_remount()
2290 if (f2fs_create_flush_cmd_control(sbi)) in f2fs_remount()
2291 f2fs_warn(sbi, "background flush thread has stopped"); in f2fs_remount()
2293 clear_opt(sbi, FLUSH_MERGE); in f2fs_remount()
2294 f2fs_destroy_flush_cmd_control(sbi, false); in f2fs_remount()
2298 if (f2fs_start_ckpt_thread(sbi)) in f2fs_remount()
2299 f2fs_warn(sbi, "background ckpt thread has stopped"); in f2fs_remount()
2301 f2fs_stop_ckpt_thread(sbi); in f2fs_remount()
2305 if (f2fs_start_gc_thread(sbi)) in f2fs_remount()
2306 f2fs_warn(sbi, "background gc thread has stopped"); in f2fs_remount()
2308 f2fs_stop_gc_thread(sbi); in f2fs_remount()
2312 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; in f2fs_remount()
2314 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_remount()
2315 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; in f2fs_remount()
2318 sbi->mount_opt = org_mount_opt; in f2fs_remount()
2445 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) in f2fs_quota_on_mount() argument
2447 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { in f2fs_quota_on_mount()
2448 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); in f2fs_quota_on_mount()
2452 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], in f2fs_quota_on_mount()
2453 F2FS_OPTION(sbi).s_jquota_fmt, type); in f2fs_quota_on_mount()
2456 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) in f2fs_enable_quota_files() argument
2461 if (f2fs_sb_has_quota_ino(sbi) && rdonly) { in f2fs_enable_quota_files()
2462 err = f2fs_enable_quotas(sbi->sb); in f2fs_enable_quota_files()
2464 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); in f2fs_enable_quota_files()
2471 if (F2FS_OPTION(sbi).s_qf_names[i]) { in f2fs_enable_quota_files()
2472 err = f2fs_quota_on_mount(sbi, i); in f2fs_enable_quota_files()
2477 f2fs_err(sbi, "Cannot turn on quotas: %d on %d", in f2fs_enable_quota_files()
2512 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_enable_quotas() local
2516 test_opt(sbi, USRQUOTA), in f2fs_enable_quotas()
2517 test_opt(sbi, GRPQUOTA), in f2fs_enable_quotas()
2518 test_opt(sbi, PRJQUOTA), in f2fs_enable_quotas()
2522 f2fs_err(sbi, "quota file may be corrupted, skip loading it"); in f2fs_enable_quotas()
2535 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", in f2fs_enable_quotas()
2548 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type) in f2fs_quota_sync_file() argument
2550 struct quota_info *dqopt = sb_dqopt(sbi->sb); in f2fs_quota_sync_file()
2554 ret = dquot_writeback_dquots(sbi->sb, type); in f2fs_quota_sync_file()
2563 if (is_journalled_quota(sbi)) in f2fs_quota_sync_file()
2571 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_sync_file()
2577 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_sync() local
2594 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_quota_sync()
2606 f2fs_lock_op(sbi); in f2fs_quota_sync()
2607 f2fs_down_read(&sbi->quota_sem); in f2fs_quota_sync()
2609 ret = f2fs_quota_sync_file(sbi, cnt); in f2fs_quota_sync()
2611 f2fs_up_read(&sbi->quota_sem); in f2fs_quota_sync()
2612 f2fs_unlock_op(sbi); in f2fs_quota_sync()
2614 if (!f2fs_sb_has_quota_ino(sbi)) in f2fs_quota_sync()
2682 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_quota_off() local
2692 if (is_journalled_quota(sbi)) in f2fs_quota_off()
2693 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_quota_off()
2734 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_commit() local
2737 f2fs_down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); in f2fs_dquot_commit()
2740 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit()
2741 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_commit()
2747 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_acquire() local
2750 f2fs_down_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2753 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_acquire()
2754 f2fs_up_read(&sbi->quota_sem); in f2fs_dquot_acquire()
2760 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); in f2fs_dquot_release() local
2764 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_release()
2771 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_mark_dquot_dirty() local
2775 if (is_journalled_quota(sbi)) in f2fs_dquot_mark_dquot_dirty()
2776 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); in f2fs_dquot_mark_dquot_dirty()
2783 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_dquot_commit_info() local
2787 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_dquot_commit_info()
2863 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_set_context() local
2871 if (f2fs_sb_has_lost_found(sbi) && in f2fs_set_context()
2872 inode->i_ino == F2FS_ROOT_INO(sbi)) in f2fs_set_context()
2899 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_num_devices() local
2901 if (f2fs_is_multi_device(sbi)) in f2fs_get_num_devices()
2902 return sbi->s_ndevs; in f2fs_get_num_devices()
2909 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_get_devices() local
2912 for (i = 0; i < sbi->s_ndevs; i++) in f2fs_get_devices()
2933 struct f2fs_sb_info *sbi = F2FS_SB(sb); in f2fs_nfs_get_inode() local
2936 if (f2fs_check_nid_range(sbi, ino)) in f2fs_nfs_get_inode()
3019 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, in sanity_check_area_boundary() argument
3024 struct super_block *sb = sbi->sb; in sanity_check_area_boundary()
3044 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", in sanity_check_area_boundary()
3051 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3059 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3067 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3075 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", in sanity_check_area_boundary()
3082 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3095 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in sanity_check_area_boundary()
3101 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", in sanity_check_area_boundary()
3110 static int sanity_check_raw_super(struct f2fs_sb_info *sbi, in sanity_check_raw_super() argument
3121 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", in sanity_check_raw_super()
3131 f2fs_info(sbi, "Invalid SB checksum offset: %zu", in sanity_check_raw_super()
3136 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { in sanity_check_raw_super()
3137 f2fs_info(sbi, "Invalid SB checksum value: %u", crc); in sanity_check_raw_super()
3144 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", in sanity_check_raw_super()
3152 f2fs_info(sbi, "Invalid log blocks per segment (%u)", in sanity_check_raw_super()
3162 f2fs_info(sbi, "Invalid log sectorsize (%u)", in sanity_check_raw_super()
3169 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", in sanity_check_raw_super()
3186 f2fs_info(sbi, "Invalid segment count (%u)", segment_count); in sanity_check_raw_super()
3192 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", in sanity_check_raw_super()
3198 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", in sanity_check_raw_super()
3204 f2fs_info(sbi, "Small segment_count (%u < %u * %u)", in sanity_check_raw_super()
3210 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", in sanity_check_raw_super()
3224 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", in sanity_check_raw_super()
3230 !bdev_is_zoned(sbi->sb->s_bdev)) { in sanity_check_raw_super()
3231 f2fs_info(sbi, "Zoned block device path is missing"); in sanity_check_raw_super()
3237 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", in sanity_check_raw_super()
3245 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", in sanity_check_raw_super()
3255 f2fs_info(sbi, "Insane cp_payload (%u >= %u)", in sanity_check_raw_super()
3266 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", in sanity_check_raw_super()
3274 if (sanity_check_area_boundary(sbi, bh)) in sanity_check_raw_super()
3280 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) in f2fs_sanity_check_ckpt() argument
3283 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_sanity_check_ckpt()
3284 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in f2fs_sanity_check_ckpt()
3312 if (!f2fs_sb_has_readonly(sbi) && in f2fs_sanity_check_ckpt()
3315 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); in f2fs_sanity_check_ckpt()
3320 (f2fs_sb_has_readonly(sbi) ? 1 : 0); in f2fs_sanity_check_ckpt()
3324 f2fs_err(sbi, "Wrong user_block_count: %u", in f2fs_sanity_check_ckpt()
3331 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", in f2fs_sanity_check_ckpt()
3337 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; in f2fs_sanity_check_ckpt()
3339 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", in f2fs_sanity_check_ckpt()
3345 blocks_per_seg = sbi->blocks_per_seg; in f2fs_sanity_check_ckpt()
3352 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3358 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3371 if (f2fs_sb_has_readonly(sbi)) in f2fs_sanity_check_ckpt()
3377 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3388 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", in f2fs_sanity_check_ckpt()
3401 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", in f2fs_sanity_check_ckpt()
3406 cp_pack_start_sum = __start_sum_addr(sbi); in f2fs_sanity_check_ckpt()
3407 cp_payload = __cp_payload(sbi); in f2fs_sanity_check_ckpt()
3411 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", in f2fs_sanity_check_ckpt()
3418 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " in f2fs_sanity_check_ckpt()
3431 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)", in f2fs_sanity_check_ckpt()
3436 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_sanity_check_ckpt()
3437 f2fs_err(sbi, "A bug case: need to run fsck"); in f2fs_sanity_check_ckpt()
3443 static void init_sb_info(struct f2fs_sb_info *sbi) in init_sb_info() argument
3445 struct f2fs_super_block *raw_super = sbi->raw_super; in init_sb_info()
3448 sbi->log_sectors_per_block = in init_sb_info()
3450 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); in init_sb_info()
3451 sbi->blocksize = 1 << sbi->log_blocksize; in init_sb_info()
3452 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); in init_sb_info()
3453 sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; in init_sb_info()
3454 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); in init_sb_info()
3455 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); in init_sb_info()
3456 sbi->total_sections = le32_to_cpu(raw_super->section_count); in init_sb_info()
3457 sbi->total_node_count = in init_sb_info()
3459 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; in init_sb_info()
3460 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); in init_sb_info()
3461 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); in init_sb_info()
3462 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); in init_sb_info()
3463 sbi->cur_victim_sec = NULL_SECNO; in init_sb_info()
3464 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in init_sb_info()
3465 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in init_sb_info()
3466 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; in init_sb_info()
3467 sbi->migration_granularity = sbi->segs_per_sec; in init_sb_info()
3469 sbi->dir_level = DEF_DIR_LEVEL; in init_sb_info()
3470 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; in init_sb_info()
3471 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3472 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3473 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; in init_sb_info()
3474 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; in init_sb_info()
3475 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = in init_sb_info()
3477 clear_sbi_flag(sbi, SBI_NEED_FSCK); in init_sb_info()
3480 atomic_set(&sbi->nr_pages[i], 0); in init_sb_info()
3483 atomic_set(&sbi->wb_sync_req[i], 0); in init_sb_info()
3485 INIT_LIST_HEAD(&sbi->s_list); in init_sb_info()
3486 mutex_init(&sbi->umount_mutex); in init_sb_info()
3487 init_f2fs_rwsem(&sbi->io_order_lock); in init_sb_info()
3488 spin_lock_init(&sbi->cp_lock); in init_sb_info()
3490 sbi->dirty_device = 0; in init_sb_info()
3491 spin_lock_init(&sbi->dev_lock); in init_sb_info()
3493 init_f2fs_rwsem(&sbi->sb_lock); in init_sb_info()
3494 init_f2fs_rwsem(&sbi->pin_sem); in init_sb_info()
3497 static int init_percpu_info(struct f2fs_sb_info *sbi) in init_percpu_info() argument
3501 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); in init_percpu_info()
3505 err = percpu_counter_init(&sbi->total_valid_inode_count, 0, in init_percpu_info()
3508 percpu_counter_destroy(&sbi->alloc_valid_block_count); in init_percpu_info()
3537 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) in init_blkz_info() argument
3544 if (!f2fs_sb_has_blkzoned(sbi)) in init_blkz_info()
3547 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != in init_blkz_info()
3550 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); in init_blkz_info()
3551 if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz != in init_blkz_info()
3552 __ilog2_u32(sbi->blocks_per_blkz)) in init_blkz_info()
3554 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz); in init_blkz_info()
3556 sbi->log_blocks_per_blkz; in init_blkz_info()
3560 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, in init_blkz_info()
3568 FDEV(devi).zone_capacity_blocks = f2fs_kzalloc(sbi, in init_blkz_info()
3597 static int read_raw_super_block(struct f2fs_sb_info *sbi, in read_raw_super_block() argument
3601 struct super_block *sb = sbi->sb; in read_raw_super_block()
3614 f2fs_err(sbi, "Unable to read %dth superblock", in read_raw_super_block()
3622 err = sanity_check_raw_super(sbi, bh); in read_raw_super_block()
3624 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", in read_raw_super_block()
3649 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) in f2fs_commit_super() argument
3655 if ((recover && f2fs_readonly(sbi->sb)) || in f2fs_commit_super()
3656 bdev_read_only(sbi->sb->s_bdev)) { in f2fs_commit_super()
3657 set_sbi_flag(sbi, SBI_NEED_SB_WRITE); in f2fs_commit_super()
3662 if (!recover && f2fs_sb_has_sb_chksum(sbi)) { in f2fs_commit_super()
3663 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), in f2fs_commit_super()
3665 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); in f2fs_commit_super()
3669 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); in f2fs_commit_super()
3672 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3680 bh = sb_bread(sbi->sb, sbi->valid_super_block); in f2fs_commit_super()
3683 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); in f2fs_commit_super()
3688 void f2fs_handle_stop(struct f2fs_sb_info *sbi, unsigned char reason) in f2fs_handle_stop() argument
3690 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_handle_stop()
3693 f2fs_bug_on(sbi, reason >= MAX_STOP_REASON); in f2fs_handle_stop()
3695 f2fs_down_write(&sbi->sb_lock); in f2fs_handle_stop()
3700 err = f2fs_commit_super(sbi, false); in f2fs_handle_stop()
3702 f2fs_err(sbi, "f2fs_commit_super fails to record reason:%u err:%d", in f2fs_handle_stop()
3705 f2fs_up_write(&sbi->sb_lock); in f2fs_handle_stop()
3708 static int f2fs_scan_devices(struct f2fs_sb_info *sbi) in f2fs_scan_devices() argument
3710 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); in f2fs_scan_devices()
3716 if (!bdev_is_zoned(sbi->sb->s_bdev)) in f2fs_scan_devices()
3725 sbi->devs = f2fs_kzalloc(sbi, in f2fs_scan_devices()
3729 if (!sbi->devs) in f2fs_scan_devices()
3740 blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, in f2fs_scan_devices()
3741 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3751 sbi->log_blocks_per_seg) - 1 + in f2fs_scan_devices()
3757 sbi->log_blocks_per_seg) - 1; in f2fs_scan_devices()
3760 sbi->sb->s_mode, sbi->sb->s_type); in f2fs_scan_devices()
3766 sbi->s_ndevs = i + 1; in f2fs_scan_devices()
3770 !f2fs_sb_has_blkzoned(sbi)) { in f2fs_scan_devices()
3771 f2fs_err(sbi, "Zoned block device feature not enabled"); in f2fs_scan_devices()
3775 if (init_blkz_info(sbi, i)) { in f2fs_scan_devices()
3776 f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); in f2fs_scan_devices()
3781 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", in f2fs_scan_devices()
3790 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", in f2fs_scan_devices()
3795 f2fs_info(sbi, in f2fs_scan_devices()
3796 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); in f2fs_scan_devices()
3800 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) in f2fs_setup_casefold() argument
3803 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { in f2fs_setup_casefold()
3808 if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info, in f2fs_setup_casefold()
3810 f2fs_err(sbi, in f2fs_setup_casefold()
3817 f2fs_err(sbi, in f2fs_setup_casefold()
3824 f2fs_info(sbi, "Using encoding defined by superblock: " in f2fs_setup_casefold()
3828 sbi->sb->s_encoding = encoding; in f2fs_setup_casefold()
3829 sbi->sb->s_encoding_flags = encoding_flags; in f2fs_setup_casefold()
3832 if (f2fs_sb_has_casefold(sbi)) { in f2fs_setup_casefold()
3833 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); in f2fs_setup_casefold()
3840 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) in f2fs_tuning_parameters() argument
3842 struct f2fs_sm_info *sm_i = SM_I(sbi); in f2fs_tuning_parameters()
3846 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; in f2fs_tuning_parameters()
3852 sbi->readdir_ra = 1; in f2fs_tuning_parameters()
3857 struct f2fs_sb_info *sbi; in f2fs_fill_super() local
3874 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); in f2fs_fill_super()
3875 if (!sbi) in f2fs_fill_super()
3878 sbi->sb = sb; in f2fs_fill_super()
3881 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); in f2fs_fill_super()
3882 if (IS_ERR(sbi->s_chksum_driver)) { in f2fs_fill_super()
3883 f2fs_err(sbi, "Cannot load crc32 driver."); in f2fs_fill_super()
3884 err = PTR_ERR(sbi->s_chksum_driver); in f2fs_fill_super()
3885 sbi->s_chksum_driver = NULL; in f2fs_fill_super()
3891 f2fs_err(sbi, "unable to set blocksize"); in f2fs_fill_super()
3895 err = read_raw_super_block(sbi, &raw_super, &valid_super_block, in f2fs_fill_super()
3900 sb->s_fs_info = sbi; in f2fs_fill_super()
3901 sbi->raw_super = raw_super; in f2fs_fill_super()
3904 if (f2fs_sb_has_inode_chksum(sbi)) in f2fs_fill_super()
3905 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, in f2fs_fill_super()
3908 default_options(sbi); in f2fs_fill_super()
3924 err = f2fs_setup_casefold(sbi); in f2fs_fill_super()
3933 if (f2fs_sb_has_quota_ino(sbi)) { in f2fs_fill_super()
3935 if (f2fs_qf_ino(sbi->sb, i)) in f2fs_fill_super()
3936 sbi->nquota_files++; in f2fs_fill_super()
3953 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); in f2fs_fill_super()
3958 sbi->valid_super_block = valid_super_block; in f2fs_fill_super()
3959 init_f2fs_rwsem(&sbi->gc_lock); in f2fs_fill_super()
3960 mutex_init(&sbi->writepages); in f2fs_fill_super()
3961 init_f2fs_rwsem(&sbi->cp_global_sem); in f2fs_fill_super()
3962 init_f2fs_rwsem(&sbi->node_write); in f2fs_fill_super()
3963 init_f2fs_rwsem(&sbi->node_change); in f2fs_fill_super()
3966 set_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
3967 spin_lock_init(&sbi->stat_lock); in f2fs_fill_super()
3970 spin_lock_init(&sbi->iostat_lock); in f2fs_fill_super()
3971 sbi->iostat_enable = false; in f2fs_fill_super()
3972 sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS; in f2fs_fill_super()
3978 sbi->write_io[i] = in f2fs_fill_super()
3979 f2fs_kmalloc(sbi, in f2fs_fill_super()
3983 if (!sbi->write_io[i]) { in f2fs_fill_super()
3989 init_f2fs_rwsem(&sbi->write_io[i][j].io_rwsem); in f2fs_fill_super()
3990 sbi->write_io[i][j].sbi = sbi; in f2fs_fill_super()
3991 sbi->write_io[i][j].bio = NULL; in f2fs_fill_super()
3992 spin_lock_init(&sbi->write_io[i][j].io_lock); in f2fs_fill_super()
3993 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); in f2fs_fill_super()
3994 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); in f2fs_fill_super()
3995 init_f2fs_rwsem(&sbi->write_io[i][j].bio_list_lock); in f2fs_fill_super()
3999 init_f2fs_rwsem(&sbi->cp_rwsem); in f2fs_fill_super()
4000 init_f2fs_rwsem(&sbi->quota_sem); in f2fs_fill_super()
4001 init_waitqueue_head(&sbi->cp_wait); in f2fs_fill_super()
4002 init_sb_info(sbi); in f2fs_fill_super()
4004 err = init_percpu_info(sbi); in f2fs_fill_super()
4008 if (F2FS_IO_ALIGNED(sbi)) { in f2fs_fill_super()
4009 sbi->write_io_dummy = in f2fs_fill_super()
4010 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); in f2fs_fill_super()
4011 if (!sbi->write_io_dummy) { in f2fs_fill_super()
4018 err = f2fs_init_xattr_caches(sbi); in f2fs_fill_super()
4021 err = f2fs_init_page_array_cache(sbi); in f2fs_fill_super()
4026 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); in f2fs_fill_super()
4027 if (IS_ERR(sbi->meta_inode)) { in f2fs_fill_super()
4028 f2fs_err(sbi, "Failed to read F2FS meta data inode"); in f2fs_fill_super()
4029 err = PTR_ERR(sbi->meta_inode); in f2fs_fill_super()
4033 err = f2fs_get_valid_checkpoint(sbi); in f2fs_fill_super()
4035 f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); in f2fs_fill_super()
4039 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) in f2fs_fill_super()
4040 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); in f2fs_fill_super()
4041 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { in f2fs_fill_super()
4042 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4043 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; in f2fs_fill_super()
4046 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) in f2fs_fill_super()
4047 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4050 err = f2fs_scan_devices(sbi); in f2fs_fill_super()
4052 f2fs_err(sbi, "Failed to find devices"); in f2fs_fill_super()
4056 err = f2fs_init_post_read_wq(sbi); in f2fs_fill_super()
4058 f2fs_err(sbi, "Failed to initialize post read workqueue"); in f2fs_fill_super()
4062 sbi->total_valid_node_count = in f2fs_fill_super()
4063 le32_to_cpu(sbi->ckpt->valid_node_count); in f2fs_fill_super()
4064 percpu_counter_set(&sbi->total_valid_inode_count, in f2fs_fill_super()
4065 le32_to_cpu(sbi->ckpt->valid_inode_count)); in f2fs_fill_super()
4066 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); in f2fs_fill_super()
4067 sbi->total_valid_block_count = in f2fs_fill_super()
4068 le64_to_cpu(sbi->ckpt->valid_block_count); in f2fs_fill_super()
4069 sbi->last_valid_block_count = sbi->total_valid_block_count; in f2fs_fill_super()
4070 sbi->reserved_blocks = 0; in f2fs_fill_super()
4071 sbi->current_reserved_blocks = 0; in f2fs_fill_super()
4072 limit_reserve_root(sbi); in f2fs_fill_super()
4073 adjust_unusable_cap_perc(sbi); in f2fs_fill_super()
4076 INIT_LIST_HEAD(&sbi->inode_list[i]); in f2fs_fill_super()
4077 spin_lock_init(&sbi->inode_lock[i]); in f2fs_fill_super()
4079 mutex_init(&sbi->flush_lock); in f2fs_fill_super()
4081 f2fs_init_extent_cache_info(sbi); in f2fs_fill_super()
4083 f2fs_init_ino_entry_info(sbi); in f2fs_fill_super()
4085 f2fs_init_fsync_node_info(sbi); in f2fs_fill_super()
4088 f2fs_init_ckpt_req_control(sbi); in f2fs_fill_super()
4089 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && in f2fs_fill_super()
4090 test_opt(sbi, MERGE_CHECKPOINT)) { in f2fs_fill_super()
4091 err = f2fs_start_ckpt_thread(sbi); in f2fs_fill_super()
4093 f2fs_err(sbi, in f2fs_fill_super()
4101 err = f2fs_build_segment_manager(sbi); in f2fs_fill_super()
4103 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", in f2fs_fill_super()
4107 err = f2fs_build_node_manager(sbi); in f2fs_fill_super()
4109 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", in f2fs_fill_super()
4114 err = adjust_reserved_segment(sbi); in f2fs_fill_super()
4119 sbi->sectors_written_start = f2fs_get_sectors_written(sbi); in f2fs_fill_super()
4122 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); in f2fs_fill_super()
4123 if (__exist_node_summaries(sbi)) in f2fs_fill_super()
4124 sbi->kbytes_written = in f2fs_fill_super()
4127 f2fs_build_gc_manager(sbi); in f2fs_fill_super()
4129 atomic_set(&sbi->no_cp_fsync_pages, 0); in f2fs_fill_super()
4131 err = f2fs_build_stats(sbi); in f2fs_fill_super()
4136 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); in f2fs_fill_super()
4137 if (IS_ERR(sbi->node_inode)) { in f2fs_fill_super()
4138 f2fs_err(sbi, "Failed to read node inode"); in f2fs_fill_super()
4139 err = PTR_ERR(sbi->node_inode); in f2fs_fill_super()
4144 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); in f2fs_fill_super()
4146 f2fs_err(sbi, "Failed to read root inode"); in f2fs_fill_super()
4163 err = f2fs_init_compress_inode(sbi); in f2fs_fill_super()
4167 err = f2fs_register_sysfs(sbi); in f2fs_fill_super()
4173 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4176 f2fs_err(sbi, "Cannot turn on quotas: error %d", err); in f2fs_fill_super()
4180 err = f2fs_recover_orphan_inodes(sbi); in f2fs_fill_super()
4184 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) in f2fs_fill_super()
4188 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && in f2fs_fill_super()
4189 !test_opt(sbi, NORECOVERY)) { in f2fs_fill_super()
4194 if (f2fs_hw_is_readonly(sbi)) { in f2fs_fill_super()
4195 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in f2fs_fill_super()
4196 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4199 f2fs_err(sbi, "Need to recover fsync data, but " in f2fs_fill_super()
4206 f2fs_info(sbi, "write access unavailable, skipping recovery"); in f2fs_fill_super()
4211 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_fill_super()
4216 err = f2fs_recover_fsync_data(sbi, false); in f2fs_fill_super()
4221 f2fs_err(sbi, "Cannot recover all fsync data errno=%d", in f2fs_fill_super()
4226 err = f2fs_recover_fsync_data(sbi, true); in f2fs_fill_super()
4230 f2fs_err(sbi, "Need to recover fsync data"); in f2fs_fill_super()
4239 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) { in f2fs_fill_super()
4240 err = f2fs_check_write_pointer(sbi); in f2fs_fill_super()
4246 f2fs_init_inmem_curseg(sbi); in f2fs_fill_super()
4249 clear_sbi_flag(sbi, SBI_POR_DOING); in f2fs_fill_super()
4251 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_fill_super()
4252 err = f2fs_disable_checkpoint(sbi); in f2fs_fill_super()
4255 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { in f2fs_fill_super()
4256 f2fs_enable_checkpoint(sbi); in f2fs_fill_super()
4263 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || in f2fs_fill_super()
4264 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { in f2fs_fill_super()
4266 err = f2fs_start_gc_thread(sbi); in f2fs_fill_super()
4274 err = f2fs_commit_super(sbi, true); in f2fs_fill_super()
4275 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", in f2fs_fill_super()
4276 sbi->valid_super_block ? 1 : 2, err); in f2fs_fill_super()
4279 f2fs_join_shrinker(sbi); in f2fs_fill_super()
4281 f2fs_tuning_parameters(sbi); in f2fs_fill_super()
4283 f2fs_notice(sbi, "Mounted with checkpoint version = %llx", in f2fs_fill_super()
4284 cur_cp_version(F2FS_CKPT(sbi))); in f2fs_fill_super()
4285 f2fs_update_time(sbi, CP_TIME); in f2fs_fill_super()
4286 f2fs_update_time(sbi, REQ_TIME); in f2fs_fill_super()
4287 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); in f2fs_fill_super()
4292 sync_filesystem(sbi->sb); in f2fs_fill_super()
4298 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) in f2fs_fill_super()
4299 f2fs_quota_off_umount(sbi->sb); in f2fs_fill_super()
4307 truncate_inode_pages_final(META_MAPPING(sbi)); in f2fs_fill_super()
4310 f2fs_unregister_sysfs(sbi); in f2fs_fill_super()
4312 f2fs_destroy_compress_inode(sbi); in f2fs_fill_super()
4317 f2fs_release_ino_entry(sbi, true); in f2fs_fill_super()
4318 truncate_inode_pages_final(NODE_MAPPING(sbi)); in f2fs_fill_super()
4319 iput(sbi->node_inode); in f2fs_fill_super()
4320 sbi->node_inode = NULL; in f2fs_fill_super()
4322 f2fs_destroy_stats(sbi); in f2fs_fill_super()
4325 f2fs_stop_discard_thread(sbi); in f2fs_fill_super()
4326 f2fs_destroy_node_manager(sbi); in f2fs_fill_super()
4328 f2fs_destroy_segment_manager(sbi); in f2fs_fill_super()
4329 f2fs_destroy_post_read_wq(sbi); in f2fs_fill_super()
4331 f2fs_stop_ckpt_thread(sbi); in f2fs_fill_super()
4333 destroy_device_list(sbi); in f2fs_fill_super()
4334 kvfree(sbi->ckpt); in f2fs_fill_super()
4336 make_bad_inode(sbi->meta_inode); in f2fs_fill_super()
4337 iput(sbi->meta_inode); in f2fs_fill_super()
4338 sbi->meta_inode = NULL; in f2fs_fill_super()
4340 f2fs_destroy_page_array_cache(sbi); in f2fs_fill_super()
4342 f2fs_destroy_xattr_caches(sbi); in f2fs_fill_super()
4344 mempool_destroy(sbi->write_io_dummy); in f2fs_fill_super()
4346 destroy_percpu_info(sbi); in f2fs_fill_super()
4349 kvfree(sbi->write_io[i]); in f2fs_fill_super()
4358 kfree(F2FS_OPTION(sbi).s_qf_names[i]); in f2fs_fill_super()
4360 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); in f2fs_fill_super()
4365 if (sbi->s_chksum_driver) in f2fs_fill_super()
4366 crypto_free_shash(sbi->s_chksum_driver); in f2fs_fill_super()
4367 kfree(sbi); in f2fs_fill_super()
4387 struct f2fs_sb_info *sbi = F2FS_SB(sb); in kill_f2fs_super() local
4389 set_sbi_flag(sbi, SBI_IS_CLOSE); in kill_f2fs_super()
4390 f2fs_stop_gc_thread(sbi); in kill_f2fs_super()
4391 f2fs_stop_discard_thread(sbi); in kill_f2fs_super()
4398 if (test_opt(sbi, COMPRESS_CACHE)) in kill_f2fs_super()
4399 truncate_inode_pages_final(COMPRESS_MAPPING(sbi)); in kill_f2fs_super()
4402 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || in kill_f2fs_super()
4403 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { in kill_f2fs_super()
4407 f2fs_write_checkpoint(sbi, &cpc); in kill_f2fs_super()
4410 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) in kill_f2fs_super()