Lines Matching refs:sbi

67 void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
70 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
251 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
263 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
307 static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
309 block_t limit = min((sbi->user_block_count >> 3),
310 sbi->user_block_count - sbi->reserved_blocks);
313 if (test_opt(sbi, RESERVE_ROOT) &&
314 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
315 F2FS_OPTION(sbi).root_reserved_blocks = limit;
316 f2fs_info(sbi, "Reduce reserved blocks for root = %u",
317 F2FS_OPTION(sbi).root_reserved_blocks);
319 if (!test_opt(sbi, RESERVE_ROOT) &&
320 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
322 !gid_eq(F2FS_OPTION(sbi).s_resgid,
324 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
326 F2FS_OPTION(sbi).s_resuid),
328 F2FS_OPTION(sbi).s_resgid));
331 static inline int adjust_reserved_segment(struct f2fs_sb_info *sbi)
333 unsigned int sec_blks = sbi->blocks_per_seg * sbi->segs_per_sec;
338 if (!F2FS_IO_ALIGNED(sbi))
342 avg_vblocks = sec_blks / F2FS_IO_SIZE(sbi);
347 wanted_reserved_segments = (F2FS_IO_SIZE(sbi) / avg_vblocks) *
348 reserved_segments(sbi);
349 wanted_reserved_segments -= reserved_segments(sbi);
351 avail_user_block_count = sbi->user_block_count -
352 sbi->current_reserved_blocks -
353 F2FS_OPTION(sbi).root_reserved_blocks;
355 if (wanted_reserved_segments * sbi->blocks_per_seg >
357 f2fs_err(sbi, "IO align feature can't grab additional reserved segment: %u, available segments: %u",
359 avail_user_block_count >> sbi->log_blocks_per_seg);
363 SM_I(sbi)->additional_reserved_segments = wanted_reserved_segments;
365 f2fs_info(sbi, "IO align feature needs additional reserved segment: %u",
371 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
373 if (!F2FS_OPTION(sbi).unusable_cap_perc)
376 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
377 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
379 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) *
380 F2FS_OPTION(sbi).unusable_cap_perc;
382 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%",
383 F2FS_OPTION(sbi).unusable_cap,
384 F2FS_OPTION(sbi).unusable_cap_perc);
400 struct f2fs_sb_info *sbi = F2FS_SB(sb);
404 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
405 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
408 if (f2fs_sb_has_quota_ino(sbi)) {
409 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
415 f2fs_err(sbi, "Not enough memory for storing quotafile name");
418 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
419 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
422 f2fs_err(sbi, "%s quota file already specified",
427 f2fs_err(sbi, "quotafile must be on filesystem root");
430 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
431 set_opt(sbi, QUOTA);
440 struct f2fs_sb_info *sbi = F2FS_SB(sb);
442 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
443 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
446 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
447 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
451 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
458 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
459 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
462 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
463 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
464 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
465 if (test_opt(sbi, USRQUOTA) &&
466 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
467 clear_opt(sbi, USRQUOTA);
469 if (test_opt(sbi, GRPQUOTA) &&
470 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
471 clear_opt(sbi, GRPQUOTA);
473 if (test_opt(sbi, PRJQUOTA) &&
474 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
475 clear_opt(sbi, PRJQUOTA);
477 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
478 test_opt(sbi, PRJQUOTA)) {
479 f2fs_err(sbi, "old and new quota format mixing");
483 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
484 f2fs_err(sbi, "journaled quota format not specified");
489 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
490 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
491 F2FS_OPTION(sbi).s_jquota_fmt = 0;
502 struct f2fs_sb_info *sbi = F2FS_SB(sb);
508 &F2FS_OPTION(sbi).dummy_enc_policy;
512 f2fs_warn(sbi, "test_dummy_encryption option not supported");
516 if (!f2fs_sb_has_encrypt(sbi)) {
517 f2fs_err(sbi, "Encrypt feature is off");
528 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount");
535 f2fs_warn(sbi,
538 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized",
541 f2fs_warn(sbi, "Error processing option \"%s\" [%d]",
545 f2fs_warn(sbi, "Test dummy encryption mode enabled");
550 static bool is_compress_extension_exist(struct f2fs_sb_info *sbi,
558 ext = F2FS_OPTION(sbi).extensions;
559 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
561 ext = F2FS_OPTION(sbi).noextensions;
562 ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
580 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
586 ext = F2FS_OPTION(sbi).extensions;
587 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
588 noext = F2FS_OPTION(sbi).noextensions;
589 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
596 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files");
601 f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
611 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
617 F2FS_OPTION(sbi).compress_level = 0;
624 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
631 f2fs_info(sbi, "invalid lz4hc compress level: %d", level);
635 F2FS_OPTION(sbi).compress_level = level;
639 F2FS_OPTION(sbi).compress_level = 0;
642 f2fs_info(sbi, "kernel doesn't support lz4hc compression");
649 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
655 F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL;
662 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
670 f2fs_info(sbi, "do not support negative compress level: %d", level);
675 f2fs_info(sbi, "invalid zstd compress level: %d", level);
679 F2FS_OPTION(sbi).compress_level = level;
687 struct f2fs_sb_info *sbi = F2FS_SB(sb);
722 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
724 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
726 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
734 set_opt(sbi, DISABLE_ROLL_FORWARD);
738 set_opt(sbi, NORECOVERY);
743 if (!f2fs_hw_support_discard(sbi)) {
744 f2fs_warn(sbi, "device does not support discard");
747 set_opt(sbi, DISCARD);
750 if (f2fs_hw_should_discard(sbi)) {
751 f2fs_warn(sbi, "discard is required for zoned block devices");
754 clear_opt(sbi, DISCARD);
757 set_opt(sbi, NOHEAP);
760 clear_opt(sbi, NOHEAP);
764 set_opt(sbi, XATTR_USER);
767 clear_opt(sbi, XATTR_USER);
770 set_opt(sbi, INLINE_XATTR);
773 clear_opt(sbi, INLINE_XATTR);
778 set_opt(sbi, INLINE_XATTR_SIZE);
779 F2FS_OPTION(sbi).inline_xattr_size = arg;
783 f2fs_info(sbi, "user_xattr options not supported");
786 f2fs_info(sbi, "nouser_xattr options not supported");
789 f2fs_info(sbi, "inline_xattr options not supported");
792 f2fs_info(sbi, "noinline_xattr options not supported");
797 set_opt(sbi, POSIX_ACL);
800 clear_opt(sbi, POSIX_ACL);
804 f2fs_info(sbi, "acl options not supported");
807 f2fs_info(sbi, "noacl options not supported");
816 F2FS_OPTION(sbi).active_logs = arg;
819 set_opt(sbi, DISABLE_EXT_IDENTIFY);
822 set_opt(sbi, INLINE_DATA);
825 set_opt(sbi, INLINE_DENTRY);
828 clear_opt(sbi, INLINE_DENTRY);
831 set_opt(sbi, FLUSH_MERGE);
834 clear_opt(sbi, FLUSH_MERGE);
837 set_opt(sbi, NOBARRIER);
840 clear_opt(sbi, NOBARRIER);
843 set_opt(sbi, FASTBOOT);
846 set_opt(sbi, READ_EXTENT_CACHE);
849 clear_opt(sbi, READ_EXTENT_CACHE);
852 clear_opt(sbi, INLINE_DATA);
855 set_opt(sbi, DATA_FLUSH);
860 if (test_opt(sbi, RESERVE_ROOT)) {
861 f2fs_info(sbi, "Preserve previous reserve_root=%u",
862 F2FS_OPTION(sbi).root_reserved_blocks);
864 F2FS_OPTION(sbi).root_reserved_blocks = arg;
865 set_opt(sbi, RESERVE_ROOT);
873 f2fs_err(sbi, "Invalid uid value %d", arg);
876 F2FS_OPTION(sbi).s_resuid = uid;
883 f2fs_err(sbi, "Invalid gid value %d", arg);
886 F2FS_OPTION(sbi).s_resgid = gid;
894 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
896 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
898 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_SEG;
900 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_BLK;
911 f2fs_warn(sbi, "Not support %ld, larger than %d",
915 F2FS_OPTION(sbi).write_io_size_bits = arg;
921 f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE);
922 set_opt(sbi, FAULT_INJECTION);
928 f2fs_build_fault_attr(sbi, 0, arg);
929 set_opt(sbi, FAULT_INJECTION);
933 f2fs_info(sbi, "fault_injection options not supported");
937 f2fs_info(sbi, "fault_type options not supported");
949 set_opt(sbi, USRQUOTA);
952 set_opt(sbi, GRPQUOTA);
955 set_opt(sbi, PRJQUOTA);
988 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
991 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
994 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
997 clear_opt(sbi, QUOTA);
998 clear_opt(sbi, USRQUOTA);
999 clear_opt(sbi, GRPQUOTA);
1000 clear_opt(sbi, PRJQUOTA);
1017 f2fs_info(sbi, "quota operations not supported");
1026 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
1028 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
1040 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1042 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
1044 F2FS_OPTION(sbi).fsync_mode =
1062 f2fs_info(sbi, "inline encryption not supported");
1070 F2FS_OPTION(sbi).unusable_cap_perc = arg;
1071 set_opt(sbi, DISABLE_CHECKPOINT);
1076 F2FS_OPTION(sbi).unusable_cap = arg;
1077 set_opt(sbi, DISABLE_CHECKPOINT);
1080 set_opt(sbi, DISABLE_CHECKPOINT);
1083 clear_opt(sbi, DISABLE_CHECKPOINT);
1086 set_opt(sbi, MERGE_CHECKPOINT);
1089 clear_opt(sbi, MERGE_CHECKPOINT);
1093 if (!f2fs_sb_has_compression(sbi)) {
1094 f2fs_info(sbi, "Image doesn't support compression");
1102 F2FS_OPTION(sbi).compress_level = 0;
1103 F2FS_OPTION(sbi).compress_algorithm =
1106 f2fs_info(sbi, "kernel doesn't support lzo compression");
1110 ret = f2fs_set_lz4hc_level(sbi, name);
1115 F2FS_OPTION(sbi).compress_algorithm =
1118 f2fs_info(sbi, "kernel doesn't support lz4 compression");
1122 ret = f2fs_set_zstd_level(sbi, name);
1127 F2FS_OPTION(sbi).compress_algorithm =
1130 f2fs_info(sbi, "kernel doesn't support zstd compression");
1134 F2FS_OPTION(sbi).compress_level = 0;
1135 F2FS_OPTION(sbi).compress_algorithm =
1138 f2fs_info(sbi, "kernel doesn't support lzorle compression");
1147 if (!f2fs_sb_has_compression(sbi)) {
1148 f2fs_info(sbi, "Image doesn't support compression");
1155 f2fs_err(sbi,
1159 F2FS_OPTION(sbi).compress_log_size = arg;
1162 if (!f2fs_sb_has_compression(sbi)) {
1163 f2fs_info(sbi, "Image doesn't support compression");
1170 ext = F2FS_OPTION(sbi).extensions;
1171 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
1175 f2fs_err(sbi,
1181 if (is_compress_extension_exist(sbi, name, true)) {
1187 F2FS_OPTION(sbi).compress_ext_cnt++;
1191 if (!f2fs_sb_has_compression(sbi)) {
1192 f2fs_info(sbi, "Image doesn't support compression");
1199 noext = F2FS_OPTION(sbi).noextensions;
1200 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
1204 f2fs_err(sbi,
1210 if (is_compress_extension_exist(sbi, name, false)) {
1216 F2FS_OPTION(sbi).nocompress_ext_cnt++;
1220 if (!f2fs_sb_has_compression(sbi)) {
1221 f2fs_info(sbi, "Image doesn't support compression");
1224 F2FS_OPTION(sbi).compress_chksum = true;
1227 if (!f2fs_sb_has_compression(sbi)) {
1228 f2fs_info(sbi, "Image doesn't support compression");
1235 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
1237 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER;
1245 if (!f2fs_sb_has_compression(sbi)) {
1246 f2fs_info(sbi, "Image doesn't support compression");
1249 set_opt(sbi, COMPRESS_CACHE);
1259 f2fs_info(sbi, "compression options not supported");
1263 set_opt(sbi, ATGC);
1266 set_opt(sbi, GC_MERGE);
1269 clear_opt(sbi, GC_MERGE);
1276 F2FS_OPTION(sbi).discard_unit =
1279 F2FS_OPTION(sbi).discard_unit =
1282 F2FS_OPTION(sbi).discard_unit =
1295 F2FS_OPTION(sbi).memory_mode =
1298 F2FS_OPTION(sbi).memory_mode =
1307 set_opt(sbi, AGE_EXTENT_CACHE);
1314 F2FS_OPTION(sbi).errors =
1317 F2FS_OPTION(sbi).errors =
1320 F2FS_OPTION(sbi).errors =
1329 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
1336 if (f2fs_check_quota_options(sbi))
1339 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
1340 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1343 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
1344 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1349 if (f2fs_sb_has_casefold(sbi)) {
1350 f2fs_err(sbi,
1360 if (f2fs_sb_has_blkzoned(sbi)) {
1362 if (F2FS_OPTION(sbi).discard_unit !=
1364 f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default");
1365 F2FS_OPTION(sbi).discard_unit =
1369 if (F2FS_OPTION(sbi).fs_mode != FS_MODE_LFS) {
1370 f2fs_info(sbi, "Only lfs mode is allowed with zoned block device feature");
1374 f2fs_err(sbi, "Zoned block device support is not enabled");
1380 if (f2fs_test_compress_extension(sbi)) {
1381 f2fs_err(sbi, "invalid compress or nocompress extension");
1386 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
1387 f2fs_err(sbi, "Should set mode=lfs with %luKB-sized IO",
1388 F2FS_IO_SIZE_KB(sbi));
1392 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
1395 if (!f2fs_sb_has_extra_attr(sbi) ||
1396 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
1397 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
1400 if (!test_opt(sbi, INLINE_XATTR)) {
1401 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
1408 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
1409 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
1410 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
1416 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
1417 f2fs_err(sbi, "LFS is not compatible with checkpoint=disable");
1421 if (test_opt(sbi, ATGC) && f2fs_lfs_mode(sbi)) {
1422 f2fs_err(sbi, "LFS is not compatible with ATGC");
1426 if (f2fs_is_readonly(sbi) && test_opt(sbi, FLUSH_MERGE)) {
1427 f2fs_err(sbi, "FLUSH_MERGE not compatible with readonly mode");
1431 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) {
1432 f2fs_err(sbi, "Allow to mount readonly mode only");
1470 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1477 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
1478 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1479 inode->i_ino == F2FS_META_INO(sbi)) {
1528 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1531 spin_lock(&sbi->inode_lock[DIRTY_META]);
1536 stat_inc_dirty_inode(sbi, DIRTY_META);
1540 &sbi->inode_list[DIRTY_META]);
1541 inc_page_count(sbi, F2FS_DIRTY_IMETA);
1543 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1549 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1551 spin_lock(&sbi->inode_lock[DIRTY_META]);
1553 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1558 dec_page_count(sbi, F2FS_DIRTY_IMETA);
1563 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1573 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1575 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1576 inode->i_ino == F2FS_META_INO(sbi))
1591 static void destroy_percpu_info(struct f2fs_sb_info *sbi)
1593 percpu_counter_destroy(&sbi->total_valid_inode_count);
1594 percpu_counter_destroy(&sbi->rf_node_block_count);
1595 percpu_counter_destroy(&sbi->alloc_valid_block_count);
1598 static void destroy_device_list(struct f2fs_sb_info *sbi)
1602 for (i = 0; i < sbi->s_ndevs; i++) {
1604 blkdev_put(FDEV(i).bdev, sbi->sb);
1609 kvfree(sbi->devs);
1614 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1620 f2fs_unregister_sysfs(sbi);
1625 mutex_lock(&sbi->umount_mutex);
1631 f2fs_stop_ckpt_thread(sbi);
1638 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
1639 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) {
1643 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1644 err = f2fs_write_checkpoint(sbi, &cpc);
1648 done = f2fs_issue_discard_timeout(sbi);
1649 if (f2fs_realtime_discard_enable(sbi) && !sbi->discard_blks && done) {
1653 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1654 err = f2fs_write_checkpoint(sbi, &cpc);
1661 f2fs_release_ino_entry(sbi, true);
1663 f2fs_leave_shrinker(sbi);
1664 mutex_unlock(&sbi->umount_mutex);
1667 f2fs_flush_merged_writes(sbi);
1669 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
1671 if (err || f2fs_cp_error(sbi)) {
1672 truncate_inode_pages_final(NODE_MAPPING(sbi));
1673 truncate_inode_pages_final(META_MAPPING(sbi));
1677 if (!get_pages(sbi, i))
1679 f2fs_err(sbi, "detect filesystem reference count leak during "
1680 "umount, type: %d, count: %lld", i, get_pages(sbi, i));
1681 f2fs_bug_on(sbi, 1);
1684 f2fs_bug_on(sbi, sbi->fsync_node_num);
1686 f2fs_destroy_compress_inode(sbi);
1688 iput(sbi->node_inode);
1689 sbi->node_inode = NULL;
1691 iput(sbi->meta_inode);
1692 sbi->meta_inode = NULL;
1698 f2fs_destroy_stats(sbi);
1701 f2fs_destroy_node_manager(sbi);
1702 f2fs_destroy_segment_manager(sbi);
1704 /* flush s_error_work before sbi destroy */
1705 flush_work(&sbi->s_error_work);
1707 f2fs_destroy_post_read_wq(sbi);
1709 kvfree(sbi->ckpt);
1712 if (sbi->s_chksum_driver)
1713 crypto_free_shash(sbi->s_chksum_driver);
1714 kfree(sbi->raw_super);
1716 destroy_device_list(sbi);
1717 f2fs_destroy_page_array_cache(sbi);
1718 f2fs_destroy_xattr_caches(sbi);
1719 mempool_destroy(sbi->write_io_dummy);
1722 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1724 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
1725 destroy_percpu_info(sbi);
1726 f2fs_destroy_iostat(sbi);
1728 kvfree(sbi->write_io[i]);
1732 kfree(sbi);
1737 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1740 if (unlikely(f2fs_cp_error(sbi)))
1742 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
1747 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1751 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1752 err = f2fs_issue_checkpoint(sbi);
1833 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1839 total_count = le64_to_cpu(sbi->raw_super->block_count);
1840 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
1842 buf->f_bsize = sbi->blocksize;
1846 spin_lock(&sbi->stat_lock);
1848 user_block_count = sbi->user_block_count;
1849 total_valid_node_count = valid_node_count(sbi);
1850 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
1851 buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
1852 sbi->current_reserved_blocks;
1854 if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
1857 buf->f_bfree -= sbi->unusable_block_count;
1858 spin_unlock(&sbi->stat_lock);
1860 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
1862 F2FS_OPTION(sbi).root_reserved_blocks;
1891 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1893 if (F2FS_OPTION(sbi).s_jquota_fmt) {
1896 switch (F2FS_OPTION(sbi).s_jquota_fmt) {
1910 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
1912 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
1914 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
1916 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
1918 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
1920 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
1928 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1932 if (!f2fs_sb_has_compression(sbi))
1935 switch (F2FS_OPTION(sbi).compress_algorithm) {
1951 if (F2FS_OPTION(sbi).compress_level)
1952 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level);
1955 F2FS_OPTION(sbi).compress_log_size);
1957 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
1959 F2FS_OPTION(sbi).extensions[i]);
1962 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
1964 F2FS_OPTION(sbi).noextensions[i]);
1967 if (F2FS_OPTION(sbi).compress_chksum)
1970 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS)
1972 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER)
1975 if (test_opt(sbi, COMPRESS_CACHE))
1982 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
1984 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
1986 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
1988 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
1991 if (test_opt(sbi, GC_MERGE))
1996 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
1998 if (test_opt(sbi, NORECOVERY))
2000 if (test_opt(sbi, DISCARD)) {
2002 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK)
2004 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT)
2006 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
2011 if (test_opt(sbi, NOHEAP))
2016 if (test_opt(sbi, XATTR_USER))
2020 if (test_opt(sbi, INLINE_XATTR))
2024 if (test_opt(sbi, INLINE_XATTR_SIZE))
2026 F2FS_OPTION(sbi).inline_xattr_size);
2029 if (test_opt(sbi, POSIX_ACL))
2034 if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
2036 if (test_opt(sbi, INLINE_DATA))
2040 if (test_opt(sbi, INLINE_DENTRY))
2044 if (test_opt(sbi, FLUSH_MERGE))
2048 if (test_opt(sbi, NOBARRIER))
2052 if (test_opt(sbi, FASTBOOT))
2054 if (test_opt(sbi, READ_EXTENT_CACHE))
2058 if (test_opt(sbi, AGE_EXTENT_CACHE))
2060 if (test_opt(sbi, DATA_FLUSH))
2064 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE)
2066 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS)
2068 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG)
2070 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK)
2072 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
2073 if (test_opt(sbi, RESERVE_ROOT))
2075 F2FS_OPTION(sbi).root_reserved_blocks,
2077 F2FS_OPTION(sbi).s_resuid),
2079 F2FS_OPTION(sbi).s_resgid));
2080 if (F2FS_IO_SIZE_BITS(sbi))
2082 F2FS_OPTION(sbi).write_io_size_bits);
2084 if (test_opt(sbi, FAULT_INJECTION)) {
2086 F2FS_OPTION(sbi).fault_info.inject_rate);
2088 F2FS_OPTION(sbi).fault_info.inject_type);
2092 if (test_opt(sbi, QUOTA))
2094 if (test_opt(sbi, USRQUOTA))
2096 if (test_opt(sbi, GRPQUOTA))
2098 if (test_opt(sbi, PRJQUOTA))
2101 f2fs_show_quota_options(seq, sbi->sb);
2103 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb);
2105 if (sbi->sb->s_flags & SB_INLINECRYPT)
2108 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
2110 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
2113 if (test_opt(sbi, DISABLE_CHECKPOINT))
2115 F2FS_OPTION(sbi).unusable_cap);
2116 if (test_opt(sbi, MERGE_CHECKPOINT))
2120 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
2122 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
2124 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER)
2128 f2fs_show_compress_options(seq, sbi->sb);
2131 if (test_opt(sbi, ATGC))
2134 if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL)
2136 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW)
2139 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY)
2141 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE)
2143 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC)
2149 static void default_options(struct f2fs_sb_info *sbi, bool remount)
2153 set_opt(sbi, READ_EXTENT_CACHE);
2154 clear_opt(sbi, DISABLE_CHECKPOINT);
2156 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi))
2157 set_opt(sbi, DISCARD);
2159 if (f2fs_sb_has_blkzoned(sbi))
2160 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION;
2162 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK;
2165 if (f2fs_sb_has_readonly(sbi))
2166 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
2168 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
2170 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
2171 if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main) <=
2173 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
2175 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
2176 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
2177 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
2178 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
2179 if (f2fs_sb_has_compression(sbi)) {
2180 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
2181 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
2182 F2FS_OPTION(sbi).compress_ext_cnt = 0;
2183 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
2185 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
2186 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL;
2187 F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE;
2189 sbi->sb->s_flags &= ~SB_INLINECRYPT;
2191 set_opt(sbi, INLINE_XATTR);
2192 set_opt(sbi, INLINE_DATA);
2193 set_opt(sbi, INLINE_DENTRY);
2194 set_opt(sbi, NOHEAP);
2195 set_opt(sbi, MERGE_CHECKPOINT);
2196 F2FS_OPTION(sbi).unusable_cap = 0;
2197 sbi->sb->s_flags |= SB_LAZYTIME;
2198 if (!f2fs_is_readonly(sbi))
2199 set_opt(sbi, FLUSH_MERGE);
2200 if (f2fs_sb_has_blkzoned(sbi))
2201 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
2203 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
2206 set_opt(sbi, XATTR_USER);
2209 set_opt(sbi, POSIX_ACL);
2212 f2fs_build_fault_attr(sbi, 0, 0);
2219 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
2221 unsigned int s_flags = sbi->sb->s_flags;
2223 unsigned int gc_mode = sbi->gc_mode;
2229 f2fs_err(sbi, "checkpoint=disable on readonly fs");
2232 sbi->sb->s_flags |= SB_ACTIVE;
2235 unusable = f2fs_get_unusable_blocks(sbi);
2236 if (!f2fs_disable_cp_again(sbi, unusable))
2239 f2fs_update_time(sbi, DISABLE_TIME);
2241 sbi->gc_mode = GC_URGENT_HIGH;
2243 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
2251 f2fs_down_write(&sbi->gc_lock);
2252 stat_inc_gc_call_count(sbi, FOREGROUND);
2253 err = f2fs_gc(sbi, &gc_control);
2262 ret = sync_filesystem(sbi->sb);
2268 unusable = f2fs_get_unusable_blocks(sbi);
2269 if (f2fs_disable_cp_again(sbi, unusable)) {
2275 f2fs_down_write(&sbi->gc_lock);
2277 set_sbi_flag(sbi, SBI_CP_DISABLED);
2278 stat_inc_cp_call_count(sbi, TOTAL_CALL);
2279 err = f2fs_write_checkpoint(sbi, &cpc);
2283 spin_lock(&sbi->stat_lock);
2284 sbi->unusable_block_count = unusable;
2285 spin_unlock(&sbi->stat_lock);
2288 f2fs_up_write(&sbi->gc_lock);
2290 sbi->gc_mode = gc_mode;
2291 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
2295 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
2301 sync_inodes_sb(sbi->sb);
2303 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--);
2306 f2fs_warn(sbi, "checkpoint=enable has some unwritten data.");
2308 f2fs_down_write(&sbi->gc_lock);
2309 f2fs_dirty_to_prefree(sbi);
2311 clear_sbi_flag(sbi, SBI_CP_DISABLED);
2312 set_sbi_flag(sbi, SBI_IS_DIRTY);
2313 f2fs_up_write(&sbi->gc_lock);
2315 f2fs_sync_fs(sbi->sb, 1);
2318 f2fs_flush_ckpt_thread(sbi);
2323 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2331 bool no_read_extent_cache = !test_opt(sbi, READ_EXTENT_CACHE);
2332 bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE);
2333 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT);
2334 bool no_io_align = !F2FS_IO_ALIGNED(sbi);
2335 bool no_atgc = !test_opt(sbi, ATGC);
2336 bool no_discard = !test_opt(sbi, DISCARD);
2337 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
2338 bool block_unit_discard = f2fs_block_unit_discard(sbi);
2347 org_mount_opt = sbi->mount_opt;
2351 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
2353 if (F2FS_OPTION(sbi).s_qf_names[i]) {
2355 kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
2369 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
2370 err = f2fs_commit_super(sbi, false);
2371 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
2374 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
2377 default_options(sbi, true);
2385 flush_work(&sbi->s_error_work);
2394 if (f2fs_dev_is_readonly(sbi) && !(*flags & SB_RDONLY)) {
2409 } else if (f2fs_sb_has_quota_ino(sbi)) {
2416 if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
2418 f2fs_warn(sbi, "LFS is not compatible with IPU");
2423 if (no_atgc == !!test_opt(sbi, ATGC)) {
2425 f2fs_warn(sbi, "switch atgc option is not allowed");
2430 if (no_read_extent_cache == !!test_opt(sbi, READ_EXTENT_CACHE)) {
2432 f2fs_warn(sbi, "switch extent_cache option is not allowed");
2436 if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) {
2438 f2fs_warn(sbi, "switch age_extent_cache option is not allowed");
2442 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) {
2444 f2fs_warn(sbi, "switch io_bits option is not allowed");
2448 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) {
2450 f2fs_warn(sbi, "switch compress_cache option is not allowed");
2454 if (block_unit_discard != f2fs_block_unit_discard(sbi)) {
2456 f2fs_warn(sbi, "switch discard_unit option is not allowed");
2460 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
2462 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
2472 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
2473 !test_opt(sbi, GC_MERGE))) {
2474 if (sbi->gc_thread) {
2475 f2fs_stop_gc_thread(sbi);
2478 } else if (!sbi->gc_thread) {
2479 err = f2fs_start_gc_thread(sbi);
2488 set_sbi_flag(sbi, SBI_IS_DIRTY);
2489 set_sbi_flag(sbi, SBI_IS_CLOSE);
2491 clear_sbi_flag(sbi, SBI_IS_CLOSE);
2494 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) ||
2495 !test_opt(sbi, MERGE_CHECKPOINT)) {
2496 f2fs_stop_ckpt_thread(sbi);
2500 f2fs_flush_ckpt_thread(sbi);
2502 err = f2fs_start_ckpt_thread(sbi);
2504 f2fs_err(sbi,
2516 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
2517 clear_opt(sbi, FLUSH_MERGE);
2518 f2fs_destroy_flush_cmd_control(sbi, false);
2521 err = f2fs_create_flush_cmd_control(sbi);
2527 if (no_discard == !!test_opt(sbi, DISCARD)) {
2528 if (test_opt(sbi, DISCARD)) {
2529 err = f2fs_start_discard_thread(sbi);
2534 f2fs_stop_discard_thread(sbi);
2535 f2fs_issue_discard_timeout(sbi);
2540 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) {
2541 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
2542 err = f2fs_disable_checkpoint(sbi);
2546 f2fs_enable_checkpoint(sbi);
2558 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
2560 limit_reserve_root(sbi);
2561 adjust_unusable_cap_perc(sbi);
2566 if (f2fs_start_discard_thread(sbi))
2567 f2fs_warn(sbi, "discard has been stopped");
2569 f2fs_stop_discard_thread(sbi);
2573 if (f2fs_create_flush_cmd_control(sbi))
2574 f2fs_warn(sbi, "background flush thread has stopped");
2576 clear_opt(sbi, FLUSH_MERGE);
2577 f2fs_destroy_flush_cmd_control(sbi, false);
2581 if (f2fs_start_ckpt_thread(sbi))
2582 f2fs_warn(sbi, "background ckpt thread has stopped");
2584 f2fs_stop_ckpt_thread(sbi);
2588 if (f2fs_start_gc_thread(sbi))
2589 f2fs_warn(sbi, "background gc thread has stopped");
2591 f2fs_stop_gc_thread(sbi);
2595 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
2597 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
2598 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
2601 sbi->mount_opt = org_mount_opt;
2607 static bool f2fs_need_recovery(struct f2fs_sb_info *sbi)
2610 if (is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
2613 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
2615 if (test_opt(sbi, NORECOVERY))
2617 return !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG);
2620 static bool f2fs_recover_quota_begin(struct f2fs_sb_info *sbi)
2622 bool readonly = f2fs_readonly(sbi->sb);
2624 if (!f2fs_need_recovery(sbi))
2628 if (f2fs_hw_is_readonly(sbi))
2632 sbi->sb->s_flags &= ~SB_RDONLY;
2633 set_sbi_flag(sbi, SBI_IS_WRITABLE);
2640 return f2fs_enable_quota_files(sbi, readonly);
2643 static void f2fs_recover_quota_end(struct f2fs_sb_info *sbi,
2647 f2fs_quota_off_umount(sbi->sb);
2649 if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE)) {
2650 clear_sbi_flag(sbi, SBI_IS_WRITABLE);
2651 sbi->sb->s_flags |= SB_RDONLY;
2775 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
2777 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
2778 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
2782 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
2783 F2FS_OPTION(sbi).s_jquota_fmt, type);
2786 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
2791 if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
2792 err = f2fs_enable_quotas(sbi->sb);
2794 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
2801 if (F2FS_OPTION(sbi).s_qf_names[i]) {
2802 err = f2fs_quota_on_mount(sbi, i);
2807 f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
2851 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2855 test_opt(sbi, USRQUOTA),
2856 test_opt(sbi, GRPQUOTA),
2857 test_opt(sbi, PRJQUOTA),
2861 f2fs_err(sbi, "quota file may be corrupted, skip loading it");
2874 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
2887 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type)
2889 struct quota_info *dqopt = sb_dqopt(sbi->sb);
2893 ret = dquot_writeback_dquots(sbi->sb, type);
2902 if (is_journalled_quota(sbi))
2910 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2916 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2933 if (!f2fs_sb_has_quota_ino(sbi))
2945 f2fs_lock_op(sbi);
2946 f2fs_down_read(&sbi->quota_sem);
2948 ret = f2fs_quota_sync_file(sbi, cnt);
2950 f2fs_up_read(&sbi->quota_sem);
2951 f2fs_unlock_op(sbi);
2953 if (!f2fs_sb_has_quota_ino(sbi))
3032 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3042 if (is_journalled_quota(sbi))
3043 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3084 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3087 f2fs_down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING);
3090 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3091 f2fs_up_read(&sbi->quota_sem);
3097 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3100 f2fs_down_read(&sbi->quota_sem);
3103 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3104 f2fs_up_read(&sbi->quota_sem);
3110 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3114 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3121 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3125 if (is_journalled_quota(sbi))
3126 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
3133 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3137 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3218 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
3226 if (f2fs_sb_has_lost_found(sbi) &&
3227 inode->i_ino == F2FS_ROOT_INO(sbi))
3255 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3259 if (!f2fs_is_multi_device(sbi))
3262 devs = kmalloc_array(sbi->s_ndevs, sizeof(*devs), GFP_KERNEL);
3266 for (i = 0; i < sbi->s_ndevs; i++)
3268 *num_devs = sbi->s_ndevs;
3287 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3290 if (f2fs_check_nid_range(sbi, ino))
3373 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
3378 struct super_block *sb = sbi->sb;
3398 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
3405 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
3413 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
3421 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
3429 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
3436 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)",
3448 if (f2fs_readonly(sb) || f2fs_hw_is_readonly(sbi)) {
3449 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
3455 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)",
3464 static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
3475 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
3485 f2fs_info(sbi, "Invalid SB checksum offset: %zu",
3490 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
3491 f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
3498 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u",
3506 f2fs_info(sbi, "Invalid log blocks per segment (%u)",
3516 f2fs_info(sbi, "Invalid log sectorsize (%u)",
3523 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
3540 f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
3546 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
3552 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)",
3558 f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
3564 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
3578 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)",
3584 !bdev_is_zoned(sbi->sb->s_bdev)) {
3585 f2fs_info(sbi, "Zoned block device path is missing");
3591 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
3599 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
3609 f2fs_info(sbi, "Insane cp_payload (%u >= %u)",
3620 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
3628 if (sanity_check_area_boundary(sbi, bh))
3634 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
3637 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
3638 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
3666 if (!f2fs_sb_has_readonly(sbi) &&
3669 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
3674 (f2fs_sb_has_readonly(sbi) ? 1 : 0);
3678 f2fs_err(sbi, "Wrong user_block_count: %u",
3685 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
3691 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
3693 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
3699 blocks_per_seg = sbi->blocks_per_seg;
3706 if (f2fs_sb_has_readonly(sbi))
3712 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
3725 if (f2fs_sb_has_readonly(sbi))
3731 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
3742 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u",
3755 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
3760 cp_pack_start_sum = __start_sum_addr(sbi);
3761 cp_payload = __cp_payload(sbi);
3765 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
3772 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
3785 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)",
3790 if (unlikely(f2fs_cp_error(sbi))) {
3791 f2fs_err(sbi, "A bug case: need to run fsck");
3797 static void init_sb_info(struct f2fs_sb_info *sbi)
3799 struct f2fs_super_block *raw_super = sbi->raw_super;
3802 sbi->log_sectors_per_block =
3804 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
3805 sbi->blocksize = BIT(sbi->log_blocksize);
3806 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
3807 sbi->blocks_per_seg = BIT(sbi->log_blocks_per_seg);
3808 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
3809 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
3810 sbi->total_sections = le32_to_cpu(raw_super->section_count);
3811 sbi->total_node_count =
3813 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
3814 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino);
3815 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino);
3816 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino);
3817 sbi->cur_victim_sec = NULL_SECNO;
3818 sbi->gc_mode = GC_NORMAL;
3819 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
3820 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
3821 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
3822 sbi->migration_granularity = sbi->segs_per_sec;
3823 sbi->seq_file_ra_mul = MIN_RA_MUL;
3824 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
3825 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
3826 spin_lock_init(&sbi->gc_remaining_trials_lock);
3827 atomic64_set(&sbi->current_atomic_write, 0);
3829 sbi->dir_level = DEF_DIR_LEVEL;
3830 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
3831 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
3832 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
3833 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
3834 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
3835 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =
3837 clear_sbi_flag(sbi, SBI_NEED_FSCK);
3840 atomic_set(&sbi->nr_pages[i], 0);
3843 atomic_set(&sbi->wb_sync_req[i], 0);
3845 INIT_LIST_HEAD(&sbi->s_list);
3846 mutex_init(&sbi->umount_mutex);
3847 init_f2fs_rwsem(&sbi->io_order_lock);
3848 spin_lock_init(&sbi->cp_lock);
3850 sbi->dirty_device = 0;
3851 spin_lock_init(&sbi->dev_lock);
3853 init_f2fs_rwsem(&sbi->sb_lock);
3854 init_f2fs_rwsem(&sbi->pin_sem);
3857 static int init_percpu_info(struct f2fs_sb_info *sbi)
3861 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
3865 err = percpu_counter_init(&sbi->rf_node_block_count, 0, GFP_KERNEL);
3869 err = percpu_counter_init(&sbi->total_valid_inode_count, 0,
3876 percpu_counter_destroy(&sbi->rf_node_block_count);
3878 percpu_counter_destroy(&sbi->alloc_valid_block_count);
3885 struct f2fs_sb_info *sbi;
3900 if (!rz_args->sbi->unusable_blocks_per_sec) {
3901 rz_args->sbi->unusable_blocks_per_sec = unusable_blocks;
3904 if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) {
3905 f2fs_err(rz_args->sbi, "F2FS supports single zone capacity\n");
3911 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
3919 if (!f2fs_sb_has_blkzoned(sbi))
3923 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
3926 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(zone_sectors);
3928 sbi->blocks_per_blkz);
3932 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
3939 rep_zone_arg.sbi = sbi;
3956 static int read_raw_super_block(struct f2fs_sb_info *sbi,
3960 struct super_block *sb = sbi->sb;
3973 f2fs_err(sbi, "Unable to read %dth superblock",
3981 err = sanity_check_raw_super(sbi, bh);
3983 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
4008 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
4014 if ((recover && f2fs_readonly(sbi->sb)) ||
4015 f2fs_hw_is_readonly(sbi)) {
4016 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
4021 if (!recover && f2fs_sb_has_sb_chksum(sbi)) {
4022 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi),
4024 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc);
4028 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
4031 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
4039 bh = sb_bread(sbi->sb, sbi->valid_super_block);
4042 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
4047 static void save_stop_reason(struct f2fs_sb_info *sbi, unsigned char reason)
4051 spin_lock_irqsave(&sbi->error_lock, flags);
4052 if (sbi->stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0))
4053 sbi->stop_reason[reason]++;
4054 spin_unlock_irqrestore(&sbi->error_lock, flags);
4057 static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi)
4059 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
4063 f2fs_down_write(&sbi->sb_lock);
4065 spin_lock_irqsave(&sbi->error_lock, flags);
4066 if (sbi->error_dirty) {
4067 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors,
4069 sbi->error_dirty = false;
4071 memcpy(raw_super->s_stop_reason, sbi->stop_reason, MAX_STOP_REASON);
4072 spin_unlock_irqrestore(&sbi->error_lock, flags);
4074 err = f2fs_commit_super(sbi, false);
4076 f2fs_up_write(&sbi->sb_lock);
4078 f2fs_err(sbi, "f2fs_commit_super fails to record err:%d", err);
4081 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag)
4085 spin_lock_irqsave(&sbi->error_lock, flags);
4086 if (!test_bit(flag, (unsigned long *)sbi->errors)) {
4087 set_bit(flag, (unsigned long *)sbi->errors);
4088 sbi->error_dirty = true;
4090 spin_unlock_irqrestore(&sbi->error_lock, flags);
4093 static bool f2fs_update_errors(struct f2fs_sb_info *sbi)
4098 spin_lock_irqsave(&sbi->error_lock, flags);
4099 if (sbi->error_dirty) {
4100 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors,
4102 sbi->error_dirty = false;
4105 spin_unlock_irqrestore(&sbi->error_lock, flags);
4110 static void f2fs_record_errors(struct f2fs_sb_info *sbi, unsigned char error)
4114 f2fs_down_write(&sbi->sb_lock);
4116 if (!f2fs_update_errors(sbi))
4119 err = f2fs_commit_super(sbi, false);
4121 f2fs_err(sbi, "f2fs_commit_super fails to record errors:%u, err:%d",
4124 f2fs_up_write(&sbi->sb_lock);
4127 void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error)
4129 f2fs_save_errors(sbi, error);
4130 f2fs_record_errors(sbi, error);
4133 void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error)
4135 f2fs_save_errors(sbi, error);
4137 if (!sbi->error_dirty)
4139 if (!test_bit(error, (unsigned long *)sbi->errors))
4141 schedule_work(&sbi->s_error_work);
4150 void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
4153 struct super_block *sb = sbi->sb;
4156 F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE;
4158 set_ckpt_flags(sbi, CP_ERROR_FLAG);
4160 if (!f2fs_hw_is_readonly(sbi)) {
4161 save_stop_reason(sbi, reason);
4164 schedule_work(&sbi->s_error_work);
4166 f2fs_record_stop_reason(sbi);
4174 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC &&
4176 !is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN))
4181 set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
4187 f2fs_warn(sbi, "Remounting filesystem read-only");
4198 struct f2fs_sb_info *sbi = container_of(work,
4201 f2fs_record_stop_reason(sbi);
4204 static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
4206 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
4209 blk_mode_t mode = sb_open_mode(sbi->sb->s_flags);
4214 if (!bdev_is_zoned(sbi->sb->s_bdev))
4223 sbi->devs = f2fs_kzalloc(sbi,
4227 if (!sbi->devs)
4230 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
4231 sbi->aligned_blksize = true;
4235 FDEV(0).bdev = sbi->sb->s_bdev;
4248 sbi->log_blocks_per_seg) - 1 +
4254 sbi->log_blocks_per_seg) - 1;
4256 mode, sbi->sb, NULL);
4263 sbi->s_ndevs = i + 1;
4266 sbi->aligned_blksize = false;
4270 !f2fs_sb_has_blkzoned(sbi)) {
4271 f2fs_err(sbi, "Zoned block device feature not enabled");
4275 if (init_blkz_info(sbi, i)) {
4276 f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
4281 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
4290 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
4295 f2fs_info(sbi,
4296 "IO Block Size: %8ld KB", F2FS_IO_SIZE_KB(sbi));
4300 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
4303 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
4308 encoding_info = f2fs_sb_read_encoding(sbi->raw_super);
4310 f2fs_err(sbi,
4315 encoding_flags = le16_to_cpu(sbi->raw_super->s_encoding_flags);
4318 f2fs_err(sbi,
4328 f2fs_info(sbi, "Using encoding defined by superblock: "
4335 sbi->sb->s_encoding = encoding;
4336 sbi->sb->s_encoding_flags = encoding_flags;
4339 if (f2fs_sb_has_casefold(sbi)) {
4340 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
4347 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
4350 if (MAIN_SEGS(sbi) <= SMALL_VOLUME_SEGMENTS) {
4351 if (f2fs_block_unit_discard(sbi))
4352 SM_I(sbi)->dcc_info->discard_granularity =
4354 if (!f2fs_lfs_mode(sbi))
4355 SM_I(sbi)->ipu_policy = BIT(F2FS_IPU_FORCE) |
4359 sbi->readdir_ra = true;
4364 struct f2fs_sb_info *sbi;
4384 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
4385 if (!sbi)
4388 sbi->sb = sb;
4391 init_f2fs_rwsem(&sbi->gc_lock);
4392 mutex_init(&sbi->writepages);
4393 init_f2fs_rwsem(&sbi->cp_global_sem);
4394 init_f2fs_rwsem(&sbi->node_write);
4395 init_f2fs_rwsem(&sbi->node_change);
4396 spin_lock_init(&sbi->stat_lock);
4397 init_f2fs_rwsem(&sbi->cp_rwsem);
4398 init_f2fs_rwsem(&sbi->quota_sem);
4399 init_waitqueue_head(&sbi->cp_wait);
4400 spin_lock_init(&sbi->error_lock);
4403 INIT_LIST_HEAD(&sbi->inode_list[i]);
4404 spin_lock_init(&sbi->inode_lock[i]);
4406 mutex_init(&sbi->flush_lock);
4409 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
4410 if (IS_ERR(sbi->s_chksum_driver)) {
4411 f2fs_err(sbi, "Cannot load crc32 driver.");
4412 err = PTR_ERR(sbi->s_chksum_driver);
4413 sbi->s_chksum_driver = NULL;
4419 f2fs_err(sbi, "unable to set blocksize");
4423 err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
4428 sb->s_fs_info = sbi;
4429 sbi->raw_super = raw_super;
4431 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work);
4432 memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS);
4433 memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON);
4436 if (f2fs_sb_has_inode_chksum(sbi))
4437 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,
4440 default_options(sbi, false);
4456 err = f2fs_setup_casefold(sbi);
4465 if (f2fs_sb_has_quota_ino(sbi)) {
4467 if (f2fs_qf_ino(sbi->sb, i))
4468 sbi->nquota_files++;
4485 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
4490 sbi->valid_super_block = valid_super_block;
4493 set_sbi_flag(sbi, SBI_POR_DOING);
4495 err = f2fs_init_write_merge_io(sbi);
4499 init_sb_info(sbi);
4501 err = f2fs_init_iostat(sbi);
4505 err = init_percpu_info(sbi);
4509 if (F2FS_IO_ALIGNED(sbi)) {
4510 sbi->write_io_dummy =
4511 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
4512 if (!sbi->write_io_dummy) {
4518 /* init per sbi slab cache */
4519 err = f2fs_init_xattr_caches(sbi);
4522 err = f2fs_init_page_array_cache(sbi);
4527 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
4528 if (IS_ERR(sbi->meta_inode)) {
4529 f2fs_err(sbi, "Failed to read F2FS meta data inode");
4530 err = PTR_ERR(sbi->meta_inode);
4534 err = f2fs_get_valid_checkpoint(sbi);
4536 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
4540 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
4541 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
4542 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
4543 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
4544 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
4547 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
4548 set_sbi_flag(sbi, SBI_NEED_FSCK);
4551 err = f2fs_scan_devices(sbi);
4553 f2fs_err(sbi, "Failed to find devices");
4557 err = f2fs_init_post_read_wq(sbi);
4559 f2fs_err(sbi, "Failed to initialize post read workqueue");
4563 sbi->total_valid_node_count =
4564 le32_to_cpu(sbi->ckpt->valid_node_count);
4565 percpu_counter_set(&sbi->total_valid_inode_count,
4566 le32_to_cpu(sbi->ckpt->valid_inode_count));
4567 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
4568 sbi->total_valid_block_count =
4569 le64_to_cpu(sbi->ckpt->valid_block_count);
4570 sbi->last_valid_block_count = sbi->total_valid_block_count;
4571 sbi->reserved_blocks = 0;
4572 sbi->current_reserved_blocks = 0;
4573 limit_reserve_root(sbi);
4574 adjust_unusable_cap_perc(sbi);
4576 f2fs_init_extent_cache_info(sbi);
4578 f2fs_init_ino_entry_info(sbi);
4580 f2fs_init_fsync_node_info(sbi);
4583 f2fs_init_ckpt_req_control(sbi);
4584 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) &&
4585 test_opt(sbi, MERGE_CHECKPOINT)) {
4586 err = f2fs_start_ckpt_thread(sbi);
4588 f2fs_err(sbi,
4596 err = f2fs_build_segment_manager(sbi);
4598 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
4602 err = f2fs_build_node_manager(sbi);
4604 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
4609 err = adjust_reserved_segment(sbi);
4614 sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
4617 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
4618 if (__exist_node_summaries(sbi))
4619 sbi->kbytes_written =
4622 f2fs_build_gc_manager(sbi);
4624 err = f2fs_build_stats(sbi);
4629 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
4630 if (IS_ERR(sbi->node_inode)) {
4631 f2fs_err(sbi, "Failed to read node inode");
4632 err = PTR_ERR(sbi->node_inode);
4637 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
4639 f2fs_err(sbi, "Failed to read root inode");
4656 err = f2fs_init_compress_inode(sbi);
4660 err = f2fs_register_sysfs(sbi);
4666 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
4669 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
4672 quota_enabled = f2fs_recover_quota_begin(sbi);
4675 err = f2fs_recover_orphan_inodes(sbi);
4679 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
4683 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) &&
4684 !test_opt(sbi, NORECOVERY)) {
4689 if (f2fs_hw_is_readonly(sbi)) {
4690 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
4691 err = f2fs_recover_fsync_data(sbi, true);
4694 f2fs_err(sbi, "Need to recover fsync data, but "
4701 f2fs_info(sbi, "write access unavailable, skipping recovery");
4706 set_sbi_flag(sbi, SBI_NEED_FSCK);
4711 err = f2fs_recover_fsync_data(sbi, false);
4716 f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
4721 err = f2fs_recover_fsync_data(sbi, true);
4725 f2fs_err(sbi, "Need to recover fsync data");
4731 f2fs_recover_quota_end(sbi, quota_enabled);
4738 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) {
4739 err = f2fs_check_write_pointer(sbi);
4745 f2fs_init_inmem_curseg(sbi);
4748 clear_sbi_flag(sbi, SBI_POR_DOING);
4750 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
4751 err = f2fs_disable_checkpoint(sbi);
4754 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
4755 f2fs_enable_checkpoint(sbi);
4762 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
4763 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
4765 err = f2fs_start_gc_thread(sbi);
4773 err = f2fs_commit_super(sbi, true);
4774 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
4775 sbi->valid_super_block ? 1 : 2, err);
4778 f2fs_join_shrinker(sbi);
4780 f2fs_tuning_parameters(sbi);
4782 f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
4783 cur_cp_version(F2FS_CKPT(sbi)));
4784 f2fs_update_time(sbi, CP_TIME);
4785 f2fs_update_time(sbi, REQ_TIME);
4786 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
4791 sync_filesystem(sbi->sb);
4797 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb))
4798 f2fs_quota_off_umount(sbi->sb);
4806 truncate_inode_pages_final(META_MAPPING(sbi));
4809 f2fs_unregister_sysfs(sbi);
4811 f2fs_destroy_compress_inode(sbi);
4816 f2fs_release_ino_entry(sbi, true);
4817 truncate_inode_pages_final(NODE_MAPPING(sbi));
4818 iput(sbi->node_inode);
4819 sbi->node_inode = NULL;
4821 f2fs_destroy_stats(sbi);
4824 f2fs_stop_discard_thread(sbi);
4825 f2fs_destroy_node_manager(sbi);
4827 f2fs_destroy_segment_manager(sbi);
4829 f2fs_stop_ckpt_thread(sbi);
4830 /* flush s_error_work before sbi destroy */
4831 flush_work(&sbi->s_error_work);
4832 f2fs_destroy_post_read_wq(sbi);
4834 destroy_device_list(sbi);
4835 kvfree(sbi->ckpt);
4837 make_bad_inode(sbi->meta_inode);
4838 iput(sbi->meta_inode);
4839 sbi->meta_inode = NULL;
4841 f2fs_destroy_page_array_cache(sbi);
4843 f2fs_destroy_xattr_caches(sbi);
4845 mempool_destroy(sbi->write_io_dummy);
4847 destroy_percpu_info(sbi);
4849 f2fs_destroy_iostat(sbi);
4852 kvfree(sbi->write_io[i]);
4861 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4863 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
4868 if (sbi->s_chksum_driver)
4869 crypto_free_shash(sbi->s_chksum_driver);
4870 kfree(sbi);
4890 struct f2fs_sb_info *sbi = F2FS_SB(sb);
4892 set_sbi_flag(sbi, SBI_IS_CLOSE);
4893 f2fs_stop_gc_thread(sbi);
4894 f2fs_stop_discard_thread(sbi);
4901 if (test_opt(sbi, COMPRESS_CACHE))
4902 truncate_inode_pages_final(COMPRESS_MAPPING(sbi));
4905 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
4906 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
4910 stat_inc_cp_call_count(sbi, TOTAL_CALL);
4911 f2fs_write_checkpoint(sbi, &cpc);
4914 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))