Lines Matching full:sbi
67 int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,
70 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
88 f2fs_info(sbi,
259 void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate,
273 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
276 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
320 static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
322 block_t limit = min((sbi->user_block_count >> 3),
323 sbi->user_block_count - sbi->reserved_blocks);
326 if (test_opt(sbi, RESERVE_ROOT) &&
327 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
328 F2FS_OPTION(sbi).root_reserved_blocks = limit;
329 f2fs_info(sbi, "Reduce reserved blocks for root = %u",
330 F2FS_OPTION(sbi).root_reserved_blocks);
332 if (!test_opt(sbi, RESERVE_ROOT) &&
333 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
335 !gid_eq(F2FS_OPTION(sbi).s_resgid,
337 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
339 F2FS_OPTION(sbi).s_resuid),
341 F2FS_OPTION(sbi).s_resgid));
344 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
346 if (!F2FS_OPTION(sbi).unusable_cap_perc)
349 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
350 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
352 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) *
353 F2FS_OPTION(sbi).unusable_cap_perc;
355 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%",
356 F2FS_OPTION(sbi).unusable_cap,
357 F2FS_OPTION(sbi).unusable_cap_perc);
373 struct f2fs_sb_info *sbi = F2FS_SB(sb);
377 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
378 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
381 if (f2fs_sb_has_quota_ino(sbi)) {
382 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
388 f2fs_err(sbi, "Not enough memory for storing quotafile name");
391 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
392 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
395 f2fs_err(sbi, "%s quota file already specified",
400 f2fs_err(sbi, "quotafile must be on filesystem root");
403 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
404 set_opt(sbi, QUOTA);
413 struct f2fs_sb_info *sbi = F2FS_SB(sb);
415 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
416 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
419 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
420 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
424 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
431 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
432 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
435 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
436 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
437 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
438 if (test_opt(sbi, USRQUOTA) &&
439 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
440 clear_opt(sbi, USRQUOTA);
442 if (test_opt(sbi, GRPQUOTA) &&
443 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
444 clear_opt(sbi, GRPQUOTA);
446 if (test_opt(sbi, PRJQUOTA) &&
447 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
448 clear_opt(sbi, PRJQUOTA);
450 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
451 test_opt(sbi, PRJQUOTA)) {
452 f2fs_err(sbi, "old and new quota format mixing");
456 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
457 f2fs_err(sbi, "journaled quota format not specified");
462 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
463 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
464 F2FS_OPTION(sbi).s_jquota_fmt = 0;
475 struct f2fs_sb_info *sbi = F2FS_SB(sb);
481 &F2FS_OPTION(sbi).dummy_enc_policy;
485 f2fs_warn(sbi, "test_dummy_encryption option not supported");
489 if (!f2fs_sb_has_encrypt(sbi)) {
490 f2fs_err(sbi, "Encrypt feature is off");
501 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount");
508 f2fs_warn(sbi,
511 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized",
514 f2fs_warn(sbi, "Error processing option \"%s\" [%d]",
518 f2fs_warn(sbi, "Test dummy encryption mode enabled");
523 static bool is_compress_extension_exist(struct f2fs_sb_info *sbi,
531 ext = F2FS_OPTION(sbi).extensions;
532 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
534 ext = F2FS_OPTION(sbi).noextensions;
535 ext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
553 static int f2fs_test_compress_extension(struct f2fs_sb_info *sbi)
559 ext = F2FS_OPTION(sbi).extensions;
560 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
561 noext = F2FS_OPTION(sbi).noextensions;
562 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
569 f2fs_info(sbi, "Don't allow the nocompress extension specifies all files");
574 f2fs_info(sbi, "Don't allow the same extension %s appear in both compress and nocompress extension",
584 static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
590 F2FS_OPTION(sbi).compress_level = 0;
597 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
604 f2fs_info(sbi, "invalid lz4hc compress level: %d", level);
608 F2FS_OPTION(sbi).compress_level = level;
612 F2FS_OPTION(sbi).compress_level = 0;
615 f2fs_info(sbi, "kernel doesn't support lz4hc compression");
622 static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
628 F2FS_OPTION(sbi).compress_level = F2FS_ZSTD_DEFAULT_CLEVEL;
635 f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
643 f2fs_info(sbi, "do not support negative compress level: %d", level);
648 f2fs_info(sbi, "invalid zstd compress level: %d", level);
652 F2FS_OPTION(sbi).compress_level = level;
660 struct f2fs_sb_info *sbi = F2FS_SB(sb);
695 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
697 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
699 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
707 set_opt(sbi, DISABLE_ROLL_FORWARD);
711 set_opt(sbi, NORECOVERY);
716 if (!f2fs_hw_support_discard(sbi)) {
717 f2fs_warn(sbi, "device does not support discard");
720 set_opt(sbi, DISCARD);
723 if (f2fs_hw_should_discard(sbi)) {
724 f2fs_warn(sbi, "discard is required for zoned block devices");
727 clear_opt(sbi, DISCARD);
731 f2fs_warn(sbi, "heap/no_heap options were deprecated");
735 set_opt(sbi, XATTR_USER);
738 clear_opt(sbi, XATTR_USER);
741 set_opt(sbi, INLINE_XATTR);
744 clear_opt(sbi, INLINE_XATTR);
749 set_opt(sbi, INLINE_XATTR_SIZE);
750 F2FS_OPTION(sbi).inline_xattr_size = arg;
754 f2fs_info(sbi, "user_xattr options not supported");
757 f2fs_info(sbi, "nouser_xattr options not supported");
760 f2fs_info(sbi, "inline_xattr options not supported");
763 f2fs_info(sbi, "noinline_xattr options not supported");
768 set_opt(sbi, POSIX_ACL);
771 clear_opt(sbi, POSIX_ACL);
775 f2fs_info(sbi, "acl options not supported");
778 f2fs_info(sbi, "noacl options not supported");
787 F2FS_OPTION(sbi).active_logs = arg;
790 set_opt(sbi, DISABLE_EXT_IDENTIFY);
793 set_opt(sbi, INLINE_DATA);
796 set_opt(sbi, INLINE_DENTRY);
799 clear_opt(sbi, INLINE_DENTRY);
802 set_opt(sbi, FLUSH_MERGE);
805 clear_opt(sbi, FLUSH_MERGE);
808 set_opt(sbi, NOBARRIER);
811 clear_opt(sbi, NOBARRIER);
814 set_opt(sbi, FASTBOOT);
817 set_opt(sbi, READ_EXTENT_CACHE);
820 clear_opt(sbi, READ_EXTENT_CACHE);
823 clear_opt(sbi, INLINE_DATA);
826 set_opt(sbi, DATA_FLUSH);
831 if (test_opt(sbi, RESERVE_ROOT)) {
832 f2fs_info(sbi, "Preserve previous reserve_root=%u",
833 F2FS_OPTION(sbi).root_reserved_blocks);
835 F2FS_OPTION(sbi).root_reserved_blocks = arg;
836 set_opt(sbi, RESERVE_ROOT);
844 f2fs_err(sbi, "Invalid uid value %d", arg);
847 F2FS_OPTION(sbi).s_resuid = uid;
854 f2fs_err(sbi, "Invalid gid value %d", arg);
857 F2FS_OPTION(sbi).s_resgid = gid;
865 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
867 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
869 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_SEG;
871 F2FS_OPTION(sbi).fs_mode = FS_MODE_FRAGMENT_BLK;
882 if (f2fs_build_fault_attr(sbi, arg,
885 set_opt(sbi, FAULT_INJECTION);
891 if (f2fs_build_fault_attr(sbi, 0, arg))
893 set_opt(sbi, FAULT_INJECTION);
897 f2fs_info(sbi, "fault_injection options not supported");
901 f2fs_info(sbi, "fault_type options not supported");
913 set_opt(sbi, USRQUOTA);
916 set_opt(sbi, GRPQUOTA);
919 set_opt(sbi, PRJQUOTA);
952 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
955 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
958 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
961 clear_opt(sbi, QUOTA);
962 clear_opt(sbi, USRQUOTA);
963 clear_opt(sbi, GRPQUOTA);
964 clear_opt(sbi, PRJQUOTA);
981 f2fs_info(sbi, "quota operations not supported");
990 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
992 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
1004 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1006 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
1008 F2FS_OPTION(sbi).fsync_mode =
1026 f2fs_info(sbi, "inline encryption not supported");
1034 F2FS_OPTION(sbi).unusable_cap_perc = arg;
1035 set_opt(sbi, DISABLE_CHECKPOINT);
1040 F2FS_OPTION(sbi).unusable_cap = arg;
1041 set_opt(sbi, DISABLE_CHECKPOINT);
1044 set_opt(sbi, DISABLE_CHECKPOINT);
1047 clear_opt(sbi, DISABLE_CHECKPOINT);
1050 set_opt(sbi, MERGE_CHECKPOINT);
1053 clear_opt(sbi, MERGE_CHECKPOINT);
1057 if (!f2fs_sb_has_compression(sbi)) {
1058 f2fs_info(sbi, "Image doesn't support compression");
1066 F2FS_OPTION(sbi).compress_level = 0;
1067 F2FS_OPTION(sbi).compress_algorithm =
1070 f2fs_info(sbi, "kernel doesn't support lzo compression");
1074 ret = f2fs_set_lz4hc_level(sbi, name);
1079 F2FS_OPTION(sbi).compress_algorithm =
1082 f2fs_info(sbi, "kernel doesn't support lz4 compression");
1086 ret = f2fs_set_zstd_level(sbi, name);
1091 F2FS_OPTION(sbi).compress_algorithm =
1094 f2fs_info(sbi, "kernel doesn't support zstd compression");
1098 F2FS_OPTION(sbi).compress_level = 0;
1099 F2FS_OPTION(sbi).compress_algorithm =
1102 f2fs_info(sbi, "kernel doesn't support lzorle compression");
1111 if (!f2fs_sb_has_compression(sbi)) {
1112 f2fs_info(sbi, "Image doesn't support compression");
1119 f2fs_err(sbi,
1123 F2FS_OPTION(sbi).compress_log_size = arg;
1126 if (!f2fs_sb_has_compression(sbi)) {
1127 f2fs_info(sbi, "Image doesn't support compression");
1134 ext = F2FS_OPTION(sbi).extensions;
1135 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
1139 f2fs_err(sbi,
1145 if (is_compress_extension_exist(sbi, name, true)) {
1151 F2FS_OPTION(sbi).compress_ext_cnt++;
1155 if (!f2fs_sb_has_compression(sbi)) {
1156 f2fs_info(sbi, "Image doesn't support compression");
1163 noext = F2FS_OPTION(sbi).noextensions;
1164 noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
1168 f2fs_err(sbi,
1174 if (is_compress_extension_exist(sbi, name, false)) {
1180 F2FS_OPTION(sbi).nocompress_ext_cnt++;
1184 if (!f2fs_sb_has_compression(sbi)) {
1185 f2fs_info(sbi, "Image doesn't support compression");
1188 F2FS_OPTION(sbi).compress_chksum = true;
1191 if (!f2fs_sb_has_compression(sbi)) {
1192 f2fs_info(sbi, "Image doesn't support compression");
1199 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
1201 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER;
1209 if (!f2fs_sb_has_compression(sbi)) {
1210 f2fs_info(sbi, "Image doesn't support compression");
1213 set_opt(sbi, COMPRESS_CACHE);
1223 f2fs_info(sbi, "compression options not supported");
1227 set_opt(sbi, ATGC);
1230 set_opt(sbi, GC_MERGE);
1233 clear_opt(sbi, GC_MERGE);
1240 F2FS_OPTION(sbi).discard_unit =
1243 F2FS_OPTION(sbi).discard_unit =
1246 F2FS_OPTION(sbi).discard_unit =
1259 F2FS_OPTION(sbi).memory_mode =
1262 F2FS_OPTION(sbi).memory_mode =
1271 set_opt(sbi, AGE_EXTENT_CACHE);
1278 F2FS_OPTION(sbi).errors =
1281 F2FS_OPTION(sbi).errors =
1284 F2FS_OPTION(sbi).errors =
1293 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
1300 if (f2fs_check_quota_options(sbi))
1303 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
1304 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1307 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
1308 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1313 if (f2fs_sb_has_casefold(sbi)) {
1314 f2fs_err(sbi,
1324 if (f2fs_sb_has_blkzoned(sbi)) {
1326 if (F2FS_OPTION(sbi).discard_unit !=
1328 f2fs_info(sbi, "Zoned block device doesn't need small discard, set discard_unit=section by default");
1329 F2FS_OPTION(sbi).discard_unit =
1333 if (F2FS_OPTION(sbi).fs_mode != FS_MODE_LFS) {
1334 f2fs_info(sbi, "Only lfs mode is allowed with zoned block device feature");
1338 f2fs_err(sbi, "Zoned block device support is not enabled");
1344 if (f2fs_test_compress_extension(sbi)) {
1345 f2fs_err(sbi, "invalid compress or nocompress extension");
1350 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
1353 if (!f2fs_sb_has_extra_attr(sbi) ||
1354 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
1355 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
1358 if (!test_opt(sbi, INLINE_XATTR)) {
1359 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
1366 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
1367 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
1368 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
1374 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
1375 f2fs_err(sbi, "LFS is not compatible with checkpoint=disable");
1379 if (test_opt(sbi, ATGC) && f2fs_lfs_mode(sbi)) {
1380 f2fs_err(sbi, "LFS is not compatible with ATGC");
1384 if (f2fs_is_readonly(sbi) && test_opt(sbi, FLUSH_MERGE)) {
1385 f2fs_err(sbi, "FLUSH_MERGE not compatible with readonly mode");
1389 if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) {
1390 f2fs_err(sbi, "Allow to mount readonly mode only");
1428 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1435 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
1436 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1437 inode->i_ino == F2FS_META_INO(sbi)) {
1486 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1489 spin_lock(&sbi->inode_lock[DIRTY_META]);
1494 stat_inc_dirty_inode(sbi, DIRTY_META);
1498 &sbi->inode_list[DIRTY_META]);
1499 inc_page_count(sbi, F2FS_DIRTY_IMETA);
1501 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1507 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1509 spin_lock(&sbi->inode_lock[DIRTY_META]);
1511 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1516 dec_page_count(sbi, F2FS_DIRTY_IMETA);
1521 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1531 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1533 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1534 inode->i_ino == F2FS_META_INO(sbi))
1549 static void destroy_percpu_info(struct f2fs_sb_info *sbi)
1551 percpu_counter_destroy(&sbi->total_valid_inode_count);
1552 percpu_counter_destroy(&sbi->rf_node_block_count);
1553 percpu_counter_destroy(&sbi->alloc_valid_block_count);
1556 static void destroy_device_list(struct f2fs_sb_info *sbi)
1560 for (i = 0; i < sbi->s_ndevs; i++) {
1562 blkdev_put(FDEV(i).bdev, sbi->sb);
1567 kvfree(sbi->devs);
1572 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1578 f2fs_unregister_sysfs(sbi);
1583 mutex_lock(&sbi->umount_mutex);
1589 f2fs_stop_ckpt_thread(sbi);
1596 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
1597 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) {
1601 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1602 err = f2fs_write_checkpoint(sbi, &cpc);
1606 done = f2fs_issue_discard_timeout(sbi);
1607 if (f2fs_realtime_discard_enable(sbi) && !sbi->discard_blks && done) {
1611 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1612 err = f2fs_write_checkpoint(sbi, &cpc);
1619 f2fs_release_ino_entry(sbi, true);
1621 f2fs_leave_shrinker(sbi);
1622 mutex_unlock(&sbi->umount_mutex);
1625 f2fs_flush_merged_writes(sbi);
1627 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
1629 if (err || f2fs_cp_error(sbi)) {
1630 truncate_inode_pages_final(NODE_MAPPING(sbi));
1631 truncate_inode_pages_final(META_MAPPING(sbi));
1635 if (!get_pages(sbi, i))
1637 f2fs_err(sbi, "detect filesystem reference count leak during "
1638 "umount, type: %d, count: %lld", i, get_pages(sbi, i));
1639 f2fs_bug_on(sbi, 1);
1642 f2fs_bug_on(sbi, sbi->fsync_node_num);
1644 f2fs_destroy_compress_inode(sbi);
1646 iput(sbi->node_inode);
1647 sbi->node_inode = NULL;
1649 iput(sbi->meta_inode);
1650 sbi->meta_inode = NULL;
1656 f2fs_destroy_stats(sbi);
1659 f2fs_destroy_node_manager(sbi);
1660 f2fs_destroy_segment_manager(sbi);
1662 /* flush s_error_work before sbi destroy */
1663 flush_work(&sbi->s_error_work);
1665 f2fs_destroy_post_read_wq(sbi);
1667 kvfree(sbi->ckpt);
1670 if (sbi->s_chksum_driver)
1671 crypto_free_shash(sbi->s_chksum_driver);
1672 kfree(sbi->raw_super);
1674 destroy_device_list(sbi);
1675 f2fs_destroy_page_array_cache(sbi);
1676 f2fs_destroy_xattr_caches(sbi);
1679 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1681 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
1682 destroy_percpu_info(sbi);
1683 f2fs_destroy_iostat(sbi);
1685 kvfree(sbi->write_io[i]);
1689 kfree(sbi);
1694 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1697 if (unlikely(f2fs_cp_error(sbi)))
1699 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
1704 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1708 stat_inc_cp_call_count(sbi, TOTAL_CALL);
1709 err = f2fs_issue_checkpoint(sbi);
1738 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1747 if (test_opt(sbi, DISCARD) && !f2fs_hw_support_discard(sbi))
1748 f2fs_issue_discard_timeout(sbi);
1802 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1808 total_count = le64_to_cpu(sbi->raw_super->block_count);
1809 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
1811 buf->f_bsize = sbi->blocksize;
1815 spin_lock(&sbi->stat_lock);
1817 user_block_count = sbi->user_block_count;
1818 total_valid_node_count = valid_node_count(sbi);
1819 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
1820 buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
1821 sbi->current_reserved_blocks;
1823 if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
1826 buf->f_bfree -= sbi->unusable_block_count;
1827 spin_unlock(&sbi->stat_lock);
1829 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
1831 F2FS_OPTION(sbi).root_reserved_blocks;
1860 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1862 if (F2FS_OPTION(sbi).s_jquota_fmt) {
1865 switch (F2FS_OPTION(sbi).s_jquota_fmt) {
1879 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
1881 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
1883 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
1885 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
1887 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
1889 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
1897 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1901 if (!f2fs_sb_has_compression(sbi))
1904 switch (F2FS_OPTION(sbi).compress_algorithm) {
1920 if (F2FS_OPTION(sbi).compress_level)
1921 seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level);
1924 F2FS_OPTION(sbi).compress_log_size);
1926 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
1928 F2FS_OPTION(sbi).extensions[i]);
1931 for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
1933 F2FS_OPTION(sbi).noextensions[i]);
1936 if (F2FS_OPTION(sbi).compress_chksum)
1939 if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS)
1941 else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER)
1944 if (test_opt(sbi, COMPRESS_CACHE))
1951 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
1953 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
1955 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
1957 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
1960 if (test_opt(sbi, GC_MERGE))
1965 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
1967 if (test_opt(sbi, NORECOVERY))
1969 if (test_opt(sbi, DISCARD)) {
1971 if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK)
1973 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SEGMENT)
1975 else if (F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_SECTION)
1981 if (test_opt(sbi, XATTR_USER))
1985 if (test_opt(sbi, INLINE_XATTR))
1989 if (test_opt(sbi, INLINE_XATTR_SIZE))
1991 F2FS_OPTION(sbi).inline_xattr_size);
1994 if (test_opt(sbi, POSIX_ACL))
1999 if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
2001 if (test_opt(sbi, INLINE_DATA))
2005 if (test_opt(sbi, INLINE_DENTRY))
2009 if (test_opt(sbi, FLUSH_MERGE))
2013 if (test_opt(sbi, NOBARRIER))
2017 if (test_opt(sbi, FASTBOOT))
2019 if (test_opt(sbi, READ_EXTENT_CACHE))
2023 if (test_opt(sbi, AGE_EXTENT_CACHE))
2025 if (test_opt(sbi, DATA_FLUSH))
2029 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE)
2031 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS)
2033 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG)
2035 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK)
2037 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
2038 if (test_opt(sbi, RESERVE_ROOT))
2040 F2FS_OPTION(sbi).root_reserved_blocks,
2042 F2FS_OPTION(sbi).s_resuid),
2044 F2FS_OPTION(sbi).s_resgid));
2046 if (test_opt(sbi, FAULT_INJECTION)) {
2048 F2FS_OPTION(sbi).fault_info.inject_rate);
2050 F2FS_OPTION(sbi).fault_info.inject_type);
2054 if (test_opt(sbi, QUOTA))
2056 if (test_opt(sbi, USRQUOTA))
2058 if (test_opt(sbi, GRPQUOTA))
2060 if (test_opt(sbi, PRJQUOTA))
2063 f2fs_show_quota_options(seq, sbi->sb);
2065 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb);
2067 if (sbi->sb->s_flags & SB_INLINECRYPT)
2070 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
2072 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
2075 if (test_opt(sbi, DISABLE_CHECKPOINT))
2077 F2FS_OPTION(sbi).unusable_cap);
2078 if (test_opt(sbi, MERGE_CHECKPOINT))
2082 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
2084 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
2086 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER)
2090 f2fs_show_compress_options(seq, sbi->sb);
2093 if (test_opt(sbi, ATGC))
2096 if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_NORMAL)
2098 else if (F2FS_OPTION(sbi).memory_mode == MEMORY_MODE_LOW)
2101 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY)
2103 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE)
2105 else if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC)
2111 static void default_options(struct f2fs_sb_info *sbi, bool remount)
2115 set_opt(sbi, READ_EXTENT_CACHE);
2116 clear_opt(sbi, DISABLE_CHECKPOINT);
2118 if (f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi))
2119 set_opt(sbi, DISCARD);
2121 if (f2fs_sb_has_blkzoned(sbi))
2122 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_SECTION;
2124 F2FS_OPTION(sbi).discard_unit = DISCARD_UNIT_BLOCK;
2127 if (f2fs_sb_has_readonly(sbi))
2128 F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE;
2130 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
2132 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
2133 if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main) <=
2135 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
2137 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
2138 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
2139 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
2140 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
2141 if (f2fs_sb_has_compression(sbi)) {
2142 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
2143 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
2144 F2FS_OPTION(sbi).compress_ext_cnt = 0;
2145 F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
2147 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
2148 F2FS_OPTION(sbi).memory_mode = MEMORY_MODE_NORMAL;
2149 F2FS_OPTION(sbi).errors = MOUNT_ERRORS_CONTINUE;
2151 set_opt(sbi, INLINE_XATTR);
2152 set_opt(sbi, INLINE_DATA);
2153 set_opt(sbi, INLINE_DENTRY);
2154 set_opt(sbi, MERGE_CHECKPOINT);
2155 F2FS_OPTION(sbi).unusable_cap = 0;
2156 sbi->sb->s_flags |= SB_LAZYTIME;
2157 if (!f2fs_is_readonly(sbi))
2158 set_opt(sbi, FLUSH_MERGE);
2159 if (f2fs_sb_has_blkzoned(sbi))
2160 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
2162 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
2165 set_opt(sbi, XATTR_USER);
2168 set_opt(sbi, POSIX_ACL);
2171 f2fs_build_fault_attr(sbi, 0, 0);
2178 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
2180 unsigned int s_flags = sbi->sb->s_flags;
2182 unsigned int gc_mode = sbi->gc_mode;
2188 f2fs_err(sbi, "checkpoint=disable on readonly fs");
2191 sbi->sb->s_flags |= SB_ACTIVE;
2194 unusable = f2fs_get_unusable_blocks(sbi);
2195 if (!f2fs_disable_cp_again(sbi, unusable))
2198 f2fs_update_time(sbi, DISABLE_TIME);
2200 sbi->gc_mode = GC_URGENT_HIGH;
2202 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
2210 f2fs_down_write(&sbi->gc_lock);
2211 stat_inc_gc_call_count(sbi, FOREGROUND);
2212 err = f2fs_gc(sbi, &gc_control);
2221 ret = sync_filesystem(sbi->sb);
2227 unusable = f2fs_get_unusable_blocks(sbi);
2228 if (f2fs_disable_cp_again(sbi, unusable)) {
2234 f2fs_down_write(&sbi->gc_lock);
2236 set_sbi_flag(sbi, SBI_CP_DISABLED);
2237 stat_inc_cp_call_count(sbi, TOTAL_CALL);
2238 err = f2fs_write_checkpoint(sbi, &cpc);
2242 spin_lock(&sbi->stat_lock);
2243 sbi->unusable_block_count = unusable;
2244 spin_unlock(&sbi->stat_lock);
2247 f2fs_up_write(&sbi->gc_lock);
2249 sbi->gc_mode = gc_mode;
2250 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
2254 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
2260 sync_inodes_sb(sbi->sb);
2262 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--);
2265 f2fs_warn(sbi, "checkpoint=enable has some unwritten data.");
2267 f2fs_down_write(&sbi->gc_lock);
2268 f2fs_dirty_to_prefree(sbi);
2270 clear_sbi_flag(sbi, SBI_CP_DISABLED);
2271 set_sbi_flag(sbi, SBI_IS_DIRTY);
2272 f2fs_up_write(&sbi->gc_lock);
2274 f2fs_sync_fs(sbi->sb, 1);
2277 f2fs_flush_ckpt_thread(sbi);
2282 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2290 bool no_read_extent_cache = !test_opt(sbi, READ_EXTENT_CACHE);
2291 bool no_age_extent_cache = !test_opt(sbi, AGE_EXTENT_CACHE);
2292 bool enable_checkpoint = !test_opt(sbi, DISABLE_CHECKPOINT);
2293 bool no_atgc = !test_opt(sbi, ATGC);
2294 bool no_discard = !test_opt(sbi, DISCARD);
2295 bool no_compress_cache = !test_opt(sbi, COMPRESS_CACHE);
2296 bool block_unit_discard = f2fs_block_unit_discard(sbi);
2305 org_mount_opt = sbi->mount_opt;
2309 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
2311 if (F2FS_OPTION(sbi).s_qf_names[i]) {
2313 kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
2327 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
2328 err = f2fs_commit_super(sbi, false);
2329 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
2332 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
2335 default_options(sbi, true);
2343 flush_work(&sbi->s_error_work);
2352 if (f2fs_dev_is_readonly(sbi) && !(*flags & SB_RDONLY)) {
2367 } else if (f2fs_sb_has_quota_ino(sbi)) {
2374 if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
2376 f2fs_warn(sbi, "LFS is not compatible with IPU");
2381 if (no_atgc == !!test_opt(sbi, ATGC)) {
2383 f2fs_warn(sbi, "switch atgc option is not allowed");
2388 if (no_read_extent_cache == !!test_opt(sbi, READ_EXTENT_CACHE)) {
2390 f2fs_warn(sbi, "switch extent_cache option is not allowed");
2394 if (no_age_extent_cache == !!test_opt(sbi, AGE_EXTENT_CACHE)) {
2396 f2fs_warn(sbi, "switch age_extent_cache option is not allowed");
2400 if (no_compress_cache == !!test_opt(sbi, COMPRESS_CACHE)) {
2402 f2fs_warn(sbi, "switch compress_cache option is not allowed");
2406 if (block_unit_discard != f2fs_block_unit_discard(sbi)) {
2408 f2fs_warn(sbi, "switch discard_unit option is not allowed");
2412 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
2414 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
2424 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
2425 !test_opt(sbi, GC_MERGE))) {
2426 if (sbi->gc_thread) {
2427 f2fs_stop_gc_thread(sbi);
2430 } else if (!sbi->gc_thread) {
2431 err = f2fs_start_gc_thread(sbi);
2440 set_sbi_flag(sbi, SBI_IS_DIRTY);
2441 set_sbi_flag(sbi, SBI_IS_CLOSE);
2443 clear_sbi_flag(sbi, SBI_IS_CLOSE);
2446 if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) ||
2447 !test_opt(sbi, MERGE_CHECKPOINT)) {
2448 f2fs_stop_ckpt_thread(sbi);
2452 f2fs_flush_ckpt_thread(sbi);
2454 err = f2fs_start_ckpt_thread(sbi);
2456 f2fs_err(sbi,
2468 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
2469 clear_opt(sbi, FLUSH_MERGE);
2470 f2fs_destroy_flush_cmd_control(sbi, false);
2473 err = f2fs_create_flush_cmd_control(sbi);
2479 if (no_discard == !!test_opt(sbi, DISCARD)) {
2480 if (test_opt(sbi, DISCARD)) {
2481 err = f2fs_start_discard_thread(sbi);
2486 f2fs_stop_discard_thread(sbi);
2487 f2fs_issue_discard_timeout(sbi);
2492 if (enable_checkpoint == !!test_opt(sbi, DISABLE_CHECKPOINT)) {
2493 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
2494 err = f2fs_disable_checkpoint(sbi);
2498 f2fs_enable_checkpoint(sbi);
2510 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
2512 limit_reserve_root(sbi);
2513 adjust_unusable_cap_perc(sbi);
2518 if (f2fs_start_discard_thread(sbi))
2519 f2fs_warn(sbi, "discard has been stopped");
2521 f2fs_stop_discard_thread(sbi);
2525 if (f2fs_create_flush_cmd_control(sbi))
2526 f2fs_warn(sbi, "background flush thread has stopped");
2528 clear_opt(sbi, FLUSH_MERGE);
2529 f2fs_destroy_flush_cmd_control(sbi, false);
2533 if (f2fs_start_ckpt_thread(sbi))
2534 f2fs_warn(sbi, "background ckpt thread has stopped");
2536 f2fs_stop_ckpt_thread(sbi);
2540 if (f2fs_start_gc_thread(sbi))
2541 f2fs_warn(sbi, "background gc thread has stopped");
2543 f2fs_stop_gc_thread(sbi);
2547 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
2549 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
2550 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
2553 sbi->mount_opt = org_mount_opt;
2564 static bool f2fs_need_recovery(struct f2fs_sb_info *sbi)
2567 if (is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
2570 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
2572 if (test_opt(sbi, NORECOVERY))
2574 return !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG);
2577 static bool f2fs_recover_quota_begin(struct f2fs_sb_info *sbi)
2579 bool readonly = f2fs_readonly(sbi->sb);
2581 if (!f2fs_need_recovery(sbi))
2585 if (f2fs_hw_is_readonly(sbi))
2589 sbi->sb->s_flags &= ~SB_RDONLY;
2590 set_sbi_flag(sbi, SBI_IS_WRITABLE);
2597 return f2fs_enable_quota_files(sbi, readonly);
2600 static void f2fs_recover_quota_end(struct f2fs_sb_info *sbi,
2604 f2fs_quota_off_umount(sbi->sb);
2606 if (is_sbi_flag_set(sbi, SBI_IS_WRITABLE)) {
2607 clear_sbi_flag(sbi, SBI_IS_WRITABLE);
2608 sbi->sb->s_flags |= SB_RDONLY;
2732 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
2734 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
2735 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
2739 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
2740 F2FS_OPTION(sbi).s_jquota_fmt, type);
2743 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
2748 if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
2749 err = f2fs_enable_quotas(sbi->sb);
2751 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
2758 if (F2FS_OPTION(sbi).s_qf_names[i]) {
2759 err = f2fs_quota_on_mount(sbi, i);
2764 f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
2808 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2812 test_opt(sbi, USRQUOTA),
2813 test_opt(sbi, GRPQUOTA),
2814 test_opt(sbi, PRJQUOTA),
2818 f2fs_err(sbi, "quota file may be corrupted, skip loading it");
2831 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
2844 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type)
2846 struct quota_info *dqopt = sb_dqopt(sbi->sb);
2850 ret = dquot_writeback_dquots(sbi->sb, type);
2859 if (is_journalled_quota(sbi))
2867 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2873 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2890 if (!f2fs_sb_has_quota_ino(sbi))
2902 f2fs_lock_op(sbi);
2903 f2fs_down_read(&sbi->quota_sem);
2905 ret = f2fs_quota_sync_file(sbi, cnt);
2907 f2fs_up_read(&sbi->quota_sem);
2908 f2fs_unlock_op(sbi);
2910 if (!f2fs_sb_has_quota_ino(sbi))
2989 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2999 if (is_journalled_quota(sbi))
3000 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3041 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3044 f2fs_down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING);
3047 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3048 f2fs_up_read(&sbi->quota_sem);
3054 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3057 f2fs_down_read(&sbi->quota_sem);
3060 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3061 f2fs_up_read(&sbi->quota_sem);
3067 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
3071 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3078 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3082 if (is_journalled_quota(sbi))
3083 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
3090 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3094 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3176 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
3184 if (f2fs_sb_has_lost_found(sbi) &&
3185 inode->i_ino == F2FS_ROOT_INO(sbi))
3213 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3217 if (!f2fs_is_multi_device(sbi))
3220 devs = kmalloc_array(sbi->s_ndevs, sizeof(*devs), GFP_KERNEL);
3224 for (i = 0; i < sbi->s_ndevs; i++)
3226 *num_devs = sbi->s_ndevs;
3245 struct f2fs_sb_info *sbi = F2FS_SB(sb);
3248 if (f2fs_check_nid_range(sbi, ino))
3331 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
3336 struct super_block *sb = sbi->sb;
3356 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
3363 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
3371 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
3379 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
3387 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
3394 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)",
3406 if (f2fs_readonly(sb) || f2fs_hw_is_readonly(sbi)) {
3407 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
3413 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)",
3422 static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
3433 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
3443 f2fs_info(sbi, "Invalid SB checksum offset: %zu",
3448 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
3449 f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
3456 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u",
3464 f2fs_info(sbi, "Invalid log blocks per segment (%u)",
3474 f2fs_info(sbi, "Invalid log sectorsize (%u)",
3481 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
3498 f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
3504 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
3510 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)",
3516 f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
3522 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
3536 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)",
3542 !bdev_is_zoned(sbi->sb->s_bdev)) {
3543 f2fs_info(sbi, "Zoned block device path is missing");
3549 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
3557 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
3567 f2fs_info(sbi, "Insane cp_payload (%u >= %u)",
3578 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
3586 if (sanity_check_area_boundary(sbi, bh))
3592 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
3595 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
3596 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
3624 if (!f2fs_sb_has_readonly(sbi) &&
3627 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
3632 (f2fs_sb_has_readonly(sbi) ? 1 : 0);
3636 f2fs_err(sbi, "Wrong user_block_count: %u",
3643 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
3649 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
3651 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
3657 blocks_per_seg = BLKS_PER_SEG(sbi);
3664 if (f2fs_sb_has_readonly(sbi))
3670 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
3683 if (f2fs_sb_has_readonly(sbi))
3689 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
3700 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u",
3713 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
3718 cp_pack_start_sum = __start_sum_addr(sbi);
3719 cp_payload = __cp_payload(sbi);
3723 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
3730 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
3743 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)",
3748 if (unlikely(f2fs_cp_error(sbi))) {
3749 f2fs_err(sbi, "A bug case: need to run fsck");
3755 static void init_sb_info(struct f2fs_sb_info *sbi)
3757 struct f2fs_super_block *raw_super = sbi->raw_super;
3760 sbi->log_sectors_per_block =
3762 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
3763 sbi->blocksize = BIT(sbi->log_blocksize);
3764 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
3765 sbi->blocks_per_seg = BIT(sbi->log_blocks_per_seg);
3766 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
3767 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
3768 sbi->total_sections = le32_to_cpu(raw_super->section_count);
3769 sbi->total_node_count =
3771 NAT_ENTRY_PER_BLOCK) << sbi->log_blocks_per_seg;
3772 F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino);
3773 F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino);
3774 F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino);
3775 sbi->cur_victim_sec = NULL_SECNO;
3776 sbi->gc_mode = GC_NORMAL;
3777 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
3778 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
3779 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
3780 sbi->migration_granularity = SEGS_PER_SEC(sbi);
3781 sbi->seq_file_ra_mul = MIN_RA_MUL;
3782 sbi->max_fragment_chunk = DEF_FRAGMENT_SIZE;
3783 sbi->max_fragment_hole = DEF_FRAGMENT_SIZE;
3784 spin_lock_init(&sbi->gc_remaining_trials_lock);
3785 atomic64_set(&sbi->current_atomic_write, 0);
3787 sbi->dir_level = DEF_DIR_LEVEL;
3788 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
3789 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
3790 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
3791 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
3792 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
3793 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =
3795 clear_sbi_flag(sbi, SBI_NEED_FSCK);
3798 atomic_set(&sbi->nr_pages[i], 0);
3801 atomic_set(&sbi->wb_sync_req[i], 0);
3803 INIT_LIST_HEAD(&sbi->s_list);
3804 mutex_init(&sbi->umount_mutex);
3805 init_f2fs_rwsem(&sbi->io_order_lock);
3806 spin_lock_init(&sbi->cp_lock);
3808 sbi->dirty_device = 0;
3809 spin_lock_init(&sbi->dev_lock);
3811 init_f2fs_rwsem(&sbi->sb_lock);
3812 init_f2fs_rwsem(&sbi->pin_sem);
3815 static int init_percpu_info(struct f2fs_sb_info *sbi)
3819 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
3823 err = percpu_counter_init(&sbi->rf_node_block_count, 0, GFP_KERNEL);
3827 err = percpu_counter_init(&sbi->total_valid_inode_count, 0,
3834 percpu_counter_destroy(&sbi->rf_node_block_count);
3836 percpu_counter_destroy(&sbi->alloc_valid_block_count);
3843 struct f2fs_sb_info *sbi;
3858 if (!rz_args->sbi->unusable_blocks_per_sec) {
3859 rz_args->sbi->unusable_blocks_per_sec = unusable_blocks;
3862 if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) {
3863 f2fs_err(rz_args->sbi, "F2FS supports single zone capacity\n");
3869 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
3877 if (!f2fs_sb_has_blkzoned(sbi))
3881 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
3884 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(zone_sectors);
3886 sbi->blocks_per_blkz);
3890 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
3897 rep_zone_arg.sbi = sbi;
3914 static int read_raw_super_block(struct f2fs_sb_info *sbi,
3918 struct super_block *sb = sbi->sb;
3931 f2fs_err(sbi, "Unable to read %dth superblock",
3939 err = sanity_check_raw_super(sbi, bh);
3941 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
3966 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
3972 if ((recover && f2fs_readonly(sbi->sb)) ||
3973 f2fs_hw_is_readonly(sbi)) {
3974 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
3979 if (!recover && f2fs_sb_has_sb_chksum(sbi)) {
3980 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi),
3982 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc);
3986 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
3989 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
3997 bh = sb_bread(sbi->sb, sbi->valid_super_block);
4000 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
4005 static void save_stop_reason(struct f2fs_sb_info *sbi, unsigned char reason)
4009 spin_lock_irqsave(&sbi->error_lock, flags);
4010 if (sbi->stop_reason[reason] < GENMASK(BITS_PER_BYTE - 1, 0))
4011 sbi->stop_reason[reason]++;
4012 spin_unlock_irqrestore(&sbi->error_lock, flags);
4015 static void f2fs_record_stop_reason(struct f2fs_sb_info *sbi)
4017 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
4021 f2fs_down_write(&sbi->sb_lock);
4023 spin_lock_irqsave(&sbi->error_lock, flags);
4024 if (sbi->error_dirty) {
4025 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors,
4027 sbi->error_dirty = false;
4029 memcpy(raw_super->s_stop_reason, sbi->stop_reason, MAX_STOP_REASON);
4030 spin_unlock_irqrestore(&sbi->error_lock, flags);
4032 err = f2fs_commit_super(sbi, false);
4034 f2fs_up_write(&sbi->sb_lock);
4036 f2fs_err(sbi, "f2fs_commit_super fails to record err:%d", err);
4039 void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag)
4043 spin_lock_irqsave(&sbi->error_lock, flags);
4044 if (!test_bit(flag, (unsigned long *)sbi->errors)) {
4045 set_bit(flag, (unsigned long *)sbi->errors);
4046 sbi->error_dirty = true;
4048 spin_unlock_irqrestore(&sbi->error_lock, flags);
4051 static bool f2fs_update_errors(struct f2fs_sb_info *sbi)
4056 spin_lock_irqsave(&sbi->error_lock, flags);
4057 if (sbi->error_dirty) {
4058 memcpy(F2FS_RAW_SUPER(sbi)->s_errors, sbi->errors,
4060 sbi->error_dirty = false;
4063 spin_unlock_irqrestore(&sbi->error_lock, flags);
4068 static void f2fs_record_errors(struct f2fs_sb_info *sbi, unsigned char error)
4072 f2fs_down_write(&sbi->sb_lock);
4074 if (!f2fs_update_errors(sbi))
4077 err = f2fs_commit_super(sbi, false);
4079 f2fs_err(sbi, "f2fs_commit_super fails to record errors:%u, err:%d",
4082 f2fs_up_write(&sbi->sb_lock);
4085 void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error)
4087 f2fs_save_errors(sbi, error);
4088 f2fs_record_errors(sbi, error);
4091 void f2fs_handle_error_async(struct f2fs_sb_info *sbi, unsigned char error)
4093 f2fs_save_errors(sbi, error);
4095 if (!sbi->error_dirty)
4097 if (!test_bit(error, (unsigned long *)sbi->errors))
4099 schedule_work(&sbi->s_error_work);
4108 void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason)
4110 struct super_block *sb = sbi->sb;
4113 F2FS_OPTION(sbi).errors == MOUNT_ERRORS_CONTINUE;
4115 set_ckpt_flags(sbi, CP_ERROR_FLAG);
4117 if (!f2fs_hw_is_readonly(sbi)) {
4118 save_stop_reason(sbi, reason);
4125 schedule_work(&sbi->s_error_work);
4133 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC &&
4135 !is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN))
4140 set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
4148 f2fs_warn(sbi, "Stopped filesystem due to reason: %d", reason);
4152 f2fs_warn(sbi, "Remounting filesystem read-only");
4165 struct f2fs_sb_info *sbi = container_of(work,
4168 f2fs_record_stop_reason(sbi);
4171 static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
4173 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
4176 blk_mode_t mode = sb_open_mode(sbi->sb->s_flags);
4181 if (!bdev_is_zoned(sbi->sb->s_bdev))
4190 sbi->devs = f2fs_kzalloc(sbi,
4194 if (!sbi->devs)
4197 logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
4198 sbi->aligned_blksize = true;
4202 FDEV(0).bdev = sbi->sb->s_bdev;
4215 sbi->log_blocks_per_seg) - 1 +
4221 sbi->log_blocks_per_seg) - 1;
4223 mode, sbi->sb, NULL);
4230 sbi->s_ndevs = i + 1;
4233 sbi->aligned_blksize = false;
4237 !f2fs_sb_has_blkzoned(sbi)) {
4238 f2fs_err(sbi, "Zoned block device feature not enabled");
4242 if (init_blkz_info(sbi, i)) {
4243 f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
4248 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
4257 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
4265 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
4268 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
4273 encoding_info = f2fs_sb_read_encoding(sbi->raw_super);
4275 f2fs_err(sbi,
4280 encoding_flags = le16_to_cpu(sbi->raw_super->s_encoding_flags);
4283 f2fs_err(sbi,
4293 f2fs_info(sbi, "Using encoding defined by superblock: "
4300 sbi->sb->s_encoding = encoding;
4301 sbi->sb->s_encoding_flags = encoding_flags;
4304 if (f2fs_sb_has_casefold(sbi)) {
4305 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
4312 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
4315 if (MAIN_SEGS(sbi) <= SMALL_VOLUME_SEGMENTS) {
4316 if (f2fs_block_unit_discard(sbi))
4317 SM_I(sbi)->dcc_info->discard_granularity =
4319 if (!f2fs_lfs_mode(sbi))
4320 SM_I(sbi)->ipu_policy = BIT(F2FS_IPU_FORCE) |
4324 sbi->readdir_ra = true;
4329 struct f2fs_sb_info *sbi;
4349 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
4350 if (!sbi)
4353 sbi->sb = sb;
4356 init_f2fs_rwsem(&sbi->gc_lock);
4357 mutex_init(&sbi->writepages);
4358 init_f2fs_rwsem(&sbi->cp_global_sem);
4359 init_f2fs_rwsem(&sbi->node_write);
4360 init_f2fs_rwsem(&sbi->node_change);
4361 spin_lock_init(&sbi->stat_lock);
4362 init_f2fs_rwsem(&sbi->cp_rwsem);
4363 init_f2fs_rwsem(&sbi->quota_sem);
4364 init_waitqueue_head(&sbi->cp_wait);
4365 spin_lock_init(&sbi->error_lock);
4368 INIT_LIST_HEAD(&sbi->inode_list[i]);
4369 spin_lock_init(&sbi->inode_lock[i]);
4371 mutex_init(&sbi->flush_lock);
4374 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
4375 if (IS_ERR(sbi->s_chksum_driver)) {
4376 f2fs_err(sbi, "Cannot load crc32 driver.");
4377 err = PTR_ERR(sbi->s_chksum_driver);
4378 sbi->s_chksum_driver = NULL;
4384 f2fs_err(sbi, "unable to set blocksize");
4388 err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
4393 sb->s_fs_info = sbi;
4394 sbi->raw_super = raw_super;
4396 INIT_WORK(&sbi->s_error_work, f2fs_record_error_work);
4397 memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS);
4398 memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON);
4401 if (f2fs_sb_has_inode_chksum(sbi))
4402 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,
4405 default_options(sbi, false);
4421 err = f2fs_setup_casefold(sbi);
4430 if (f2fs_sb_has_quota_ino(sbi)) {
4432 if (f2fs_qf_ino(sbi->sb, i))
4433 sbi->nquota_files++;
4450 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
4455 sbi->valid_super_block = valid_super_block;
4458 set_sbi_flag(sbi, SBI_POR_DOING);
4460 err = f2fs_init_write_merge_io(sbi);
4464 init_sb_info(sbi);
4466 err = f2fs_init_iostat(sbi);
4470 err = init_percpu_info(sbi);
4474 /* init per sbi slab cache */
4475 err = f2fs_init_xattr_caches(sbi);
4478 err = f2fs_init_page_array_cache(sbi);
4483 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
4484 if (IS_ERR(sbi->meta_inode)) {
4485 f2fs_err(sbi, "Failed to read F2FS meta data inode");
4486 err = PTR_ERR(sbi->meta_inode);
4490 err = f2fs_get_valid_checkpoint(sbi);
4492 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
4496 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
4497 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
4498 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
4499 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
4500 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
4503 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
4504 set_sbi_flag(sbi, SBI_NEED_FSCK);
4507 err = f2fs_scan_devices(sbi);
4509 f2fs_err(sbi, "Failed to find devices");
4513 err = f2fs_init_post_read_wq(sbi);
4515 f2fs_err(sbi, "Failed to initialize post read workqueue");
4519 sbi->total_valid_node_count =
4520 le32_to_cpu(sbi->ckpt->valid_node_count);
4521 percpu_counter_set(&sbi->total_valid_inode_count,
4522 le32_to_cpu(sbi->ckpt->valid_inode_count));
4523 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
4524 sbi->total_valid_block_count =
4525 le64_to_cpu(sbi->ckpt->valid_block_count);
4526 sbi->last_valid_block_count = sbi->total_valid_block_count;
4527 sbi->reserved_blocks = 0;
4528 sbi->current_reserved_blocks = 0;
4529 limit_reserve_root(sbi);
4530 adjust_unusable_cap_perc(sbi);
4532 f2fs_init_extent_cache_info(sbi);
4534 f2fs_init_ino_entry_info(sbi);
4536 f2fs_init_fsync_node_info(sbi);
4539 f2fs_init_ckpt_req_control(sbi);
4540 if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) &&
4541 test_opt(sbi, MERGE_CHECKPOINT)) {
4542 err = f2fs_start_ckpt_thread(sbi);
4544 f2fs_err(sbi,
4552 err = f2fs_build_segment_manager(sbi);
4554 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
4558 err = f2fs_build_node_manager(sbi);
4560 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
4566 sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
4569 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
4570 if (__exist_node_summaries(sbi))
4571 sbi->kbytes_written =
4574 f2fs_build_gc_manager(sbi);
4576 err = f2fs_build_stats(sbi);
4581 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
4582 if (IS_ERR(sbi->node_inode)) {
4583 f2fs_err(sbi, "Failed to read node inode");
4584 err = PTR_ERR(sbi->node_inode);
4589 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
4591 f2fs_err(sbi, "Failed to read root inode");
4608 err = f2fs_init_compress_inode(sbi);
4612 err = f2fs_register_sysfs(sbi);
4618 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
4621 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
4624 quota_enabled = f2fs_recover_quota_begin(sbi);
4627 err = f2fs_recover_orphan_inodes(sbi);
4631 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
4635 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) &&
4636 !test_opt(sbi, NORECOVERY)) {
4641 if (f2fs_hw_is_readonly(sbi)) {
4642 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
4643 err = f2fs_recover_fsync_data(sbi, true);
4646 f2fs_err(sbi, "Need to recover fsync data, but "
4653 f2fs_info(sbi, "write access unavailable, skipping recovery");
4658 set_sbi_flag(sbi, SBI_NEED_FSCK);
4663 err = f2fs_recover_fsync_data(sbi, false);
4668 f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
4673 err = f2fs_recover_fsync_data(sbi, true);
4677 f2fs_err(sbi, "Need to recover fsync data");
4683 f2fs_recover_quota_end(sbi, quota_enabled);
4690 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) {
4691 err = f2fs_check_write_pointer(sbi);
4697 f2fs_init_inmem_curseg(sbi);
4700 clear_sbi_flag(sbi, SBI_POR_DOING);
4702 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
4703 err = f2fs_disable_checkpoint(sbi);
4706 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
4707 f2fs_enable_checkpoint(sbi);
4714 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
4715 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
4717 err = f2fs_start_gc_thread(sbi);
4725 err = f2fs_commit_super(sbi, true);
4726 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
4727 sbi->valid_super_block ? 1 : 2, err);
4730 f2fs_join_shrinker(sbi);
4732 f2fs_tuning_parameters(sbi);
4734 f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
4735 cur_cp_version(F2FS_CKPT(sbi)));
4736 f2fs_update_time(sbi, CP_TIME);
4737 f2fs_update_time(sbi, REQ_TIME);
4738 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
4743 sync_filesystem(sbi->sb);
4749 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb))
4750 f2fs_quota_off_umount(sbi->sb);
4758 truncate_inode_pages_final(META_MAPPING(sbi));
4761 f2fs_unregister_sysfs(sbi);
4763 f2fs_destroy_compress_inode(sbi);
4768 f2fs_release_ino_entry(sbi, true);
4769 truncate_inode_pages_final(NODE_MAPPING(sbi));
4770 iput(sbi->node_inode);
4771 sbi->node_inode = NULL;
4773 f2fs_destroy_stats(sbi);
4776 f2fs_stop_discard_thread(sbi);
4777 f2fs_destroy_node_manager(sbi);
4779 f2fs_destroy_segment_manager(sbi);
4781 f2fs_stop_ckpt_thread(sbi);
4782 /* flush s_error_work before sbi destroy */
4783 flush_work(&sbi->s_error_work);
4784 f2fs_destroy_post_read_wq(sbi);
4786 destroy_device_list(sbi);
4787 kvfree(sbi->ckpt);
4789 make_bad_inode(sbi->meta_inode);
4790 iput(sbi->meta_inode);
4791 sbi->meta_inode = NULL;
4793 f2fs_destroy_page_array_cache(sbi);
4795 f2fs_destroy_xattr_caches(sbi);
4797 destroy_percpu_info(sbi);
4799 f2fs_destroy_iostat(sbi);
4802 kvfree(sbi->write_io[i]);
4811 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4813 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
4818 if (sbi->s_chksum_driver)
4819 crypto_free_shash(sbi->s_chksum_driver);
4820 kfree(sbi);
4840 struct f2fs_sb_info *sbi = F2FS_SB(sb);
4842 set_sbi_flag(sbi, SBI_IS_CLOSE);
4843 f2fs_stop_gc_thread(sbi);
4844 f2fs_stop_discard_thread(sbi);
4851 if (test_opt(sbi, COMPRESS_CACHE))
4852 truncate_inode_pages_final(COMPRESS_MAPPING(sbi));
4855 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
4856 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
4860 stat_inc_cp_call_count(sbi, TOTAL_CALL);
4861 f2fs_write_checkpoint(sbi, &cpc);
4864 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))