Lines Matching refs:sbi
74 int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,
77 struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
95 f2fs_info(sbi,
248 void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
260 KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
295 static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
297 block_t limit = min((sbi->user_block_count >> 3),
298 sbi->user_block_count - sbi->reserved_blocks);
301 if (test_opt(sbi, RESERVE_ROOT) &&
302 F2FS_OPTION(sbi).root_reserved_blocks > limit) {
303 F2FS_OPTION(sbi).root_reserved_blocks = limit;
304 f2fs_info(sbi, "Reduce reserved blocks for root = %u",
305 F2FS_OPTION(sbi).root_reserved_blocks);
307 if (!test_opt(sbi, RESERVE_ROOT) &&
308 (!uid_eq(F2FS_OPTION(sbi).s_resuid,
310 !gid_eq(F2FS_OPTION(sbi).s_resgid,
312 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
314 F2FS_OPTION(sbi).s_resuid),
316 F2FS_OPTION(sbi).s_resgid));
319 static inline int adjust_reserved_segment(struct f2fs_sb_info *sbi)
321 unsigned int sec_blks = sbi->blocks_per_seg * sbi->segs_per_sec;
326 if (!F2FS_IO_ALIGNED(sbi))
330 avg_vblocks = sec_blks / F2FS_IO_SIZE(sbi);
335 wanted_reserved_segments = (F2FS_IO_SIZE(sbi) / avg_vblocks) *
336 reserved_segments(sbi);
337 wanted_reserved_segments -= reserved_segments(sbi);
339 avail_user_block_count = sbi->user_block_count -
340 sbi->current_reserved_blocks -
341 F2FS_OPTION(sbi).root_reserved_blocks;
343 if (wanted_reserved_segments * sbi->blocks_per_seg >
345 f2fs_err(sbi, "IO align feature can't grab additional reserved segment: %u, available segments: %u",
347 avail_user_block_count >> sbi->log_blocks_per_seg);
351 SM_I(sbi)->additional_reserved_segments = wanted_reserved_segments;
353 f2fs_info(sbi, "IO align feature needs additional reserved segment: %u",
359 static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
361 if (!F2FS_OPTION(sbi).unusable_cap_perc)
364 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
365 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
367 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) *
368 F2FS_OPTION(sbi).unusable_cap_perc;
370 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%",
371 F2FS_OPTION(sbi).unusable_cap,
372 F2FS_OPTION(sbi).unusable_cap_perc);
388 struct f2fs_sb_info *sbi = F2FS_SB(sb);
392 if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
393 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
396 if (f2fs_sb_has_quota_ino(sbi)) {
397 f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
403 f2fs_err(sbi, "Not enough memory for storing quotafile name");
406 if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
407 if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
410 f2fs_err(sbi, "%s quota file already specified",
415 f2fs_err(sbi, "quotafile must be on filesystem root");
418 F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
419 set_opt(sbi, QUOTA);
428 struct f2fs_sb_info *sbi = F2FS_SB(sb);
430 if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
431 f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
434 kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
435 F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
439 static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
446 if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
447 f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
450 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
451 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
452 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
453 if (test_opt(sbi, USRQUOTA) &&
454 F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
455 clear_opt(sbi, USRQUOTA);
457 if (test_opt(sbi, GRPQUOTA) &&
458 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
459 clear_opt(sbi, GRPQUOTA);
461 if (test_opt(sbi, PRJQUOTA) &&
462 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
463 clear_opt(sbi, PRJQUOTA);
465 if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
466 test_opt(sbi, PRJQUOTA)) {
467 f2fs_err(sbi, "old and new quota format mixing");
471 if (!F2FS_OPTION(sbi).s_jquota_fmt) {
472 f2fs_err(sbi, "journaled quota format not specified");
477 if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
478 f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
479 F2FS_OPTION(sbi).s_jquota_fmt = 0;
490 struct f2fs_sb_info *sbi = F2FS_SB(sb);
494 if (!f2fs_sb_has_encrypt(sbi)) {
495 f2fs_err(sbi, "Encrypt feature is off");
505 if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) {
506 f2fs_warn(sbi, "Can't set test_dummy_encryption on remount");
510 sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy);
513 f2fs_warn(sbi,
516 f2fs_warn(sbi, "Value of option \"%s\" is unrecognized",
519 f2fs_warn(sbi, "Error processing option \"%s\" [%d]",
523 f2fs_warn(sbi, "Test dummy encryption mode enabled");
525 f2fs_warn(sbi, "Test dummy encryption mount option ignored");
532 struct f2fs_sb_info *sbi = F2FS_SB(sb);
565 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
567 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
569 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
577 set_opt(sbi, DISABLE_ROLL_FORWARD);
581 set_opt(sbi, NORECOVERY);
586 set_opt(sbi, DISCARD);
589 if (f2fs_sb_has_blkzoned(sbi)) {
590 f2fs_warn(sbi, "discard is required for zoned block devices");
593 clear_opt(sbi, DISCARD);
596 set_opt(sbi, NOHEAP);
599 clear_opt(sbi, NOHEAP);
603 set_opt(sbi, XATTR_USER);
606 clear_opt(sbi, XATTR_USER);
609 set_opt(sbi, INLINE_XATTR);
612 clear_opt(sbi, INLINE_XATTR);
617 set_opt(sbi, INLINE_XATTR_SIZE);
618 F2FS_OPTION(sbi).inline_xattr_size = arg;
622 f2fs_info(sbi, "user_xattr options not supported");
625 f2fs_info(sbi, "nouser_xattr options not supported");
628 f2fs_info(sbi, "inline_xattr options not supported");
631 f2fs_info(sbi, "noinline_xattr options not supported");
636 set_opt(sbi, POSIX_ACL);
639 clear_opt(sbi, POSIX_ACL);
643 f2fs_info(sbi, "acl options not supported");
646 f2fs_info(sbi, "noacl options not supported");
655 F2FS_OPTION(sbi).active_logs = arg;
658 set_opt(sbi, DISABLE_EXT_IDENTIFY);
661 set_opt(sbi, INLINE_DATA);
664 set_opt(sbi, INLINE_DENTRY);
667 clear_opt(sbi, INLINE_DENTRY);
670 set_opt(sbi, FLUSH_MERGE);
673 clear_opt(sbi, FLUSH_MERGE);
676 set_opt(sbi, NOBARRIER);
679 set_opt(sbi, FASTBOOT);
682 set_opt(sbi, EXTENT_CACHE);
685 clear_opt(sbi, EXTENT_CACHE);
688 clear_opt(sbi, INLINE_DATA);
691 set_opt(sbi, DATA_FLUSH);
696 if (test_opt(sbi, RESERVE_ROOT)) {
697 f2fs_info(sbi, "Preserve previous reserve_root=%u",
698 F2FS_OPTION(sbi).root_reserved_blocks);
700 F2FS_OPTION(sbi).root_reserved_blocks = arg;
701 set_opt(sbi, RESERVE_ROOT);
709 f2fs_err(sbi, "Invalid uid value %d", arg);
712 F2FS_OPTION(sbi).s_resuid = uid;
719 f2fs_err(sbi, "Invalid gid value %d", arg);
722 F2FS_OPTION(sbi).s_resgid = gid;
730 if (f2fs_sb_has_blkzoned(sbi)) {
731 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
735 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
737 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
748 f2fs_warn(sbi, "Not support %d, larger than %d",
752 F2FS_OPTION(sbi).write_io_size_bits = arg;
758 if (f2fs_build_fault_attr(sbi, arg,
761 set_opt(sbi, FAULT_INJECTION);
767 if (f2fs_build_fault_attr(sbi, 0, arg))
769 set_opt(sbi, FAULT_INJECTION);
773 f2fs_info(sbi, "fault_injection options not supported");
777 f2fs_info(sbi, "fault_type options not supported");
789 set_opt(sbi, USRQUOTA);
792 set_opt(sbi, GRPQUOTA);
795 set_opt(sbi, PRJQUOTA);
828 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
831 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
834 F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
837 clear_opt(sbi, QUOTA);
838 clear_opt(sbi, USRQUOTA);
839 clear_opt(sbi, GRPQUOTA);
840 clear_opt(sbi, PRJQUOTA);
857 f2fs_info(sbi, "quota operations not supported");
865 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
867 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
869 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
882 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
884 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
896 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
898 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
900 F2FS_OPTION(sbi).fsync_mode =
918 f2fs_info(sbi, "inline encryption not supported");
926 F2FS_OPTION(sbi).unusable_cap_perc = arg;
927 set_opt(sbi, DISABLE_CHECKPOINT);
932 F2FS_OPTION(sbi).unusable_cap = arg;
933 set_opt(sbi, DISABLE_CHECKPOINT);
936 set_opt(sbi, DISABLE_CHECKPOINT);
939 clear_opt(sbi, DISABLE_CHECKPOINT);
943 if (!f2fs_sb_has_compression(sbi)) {
944 f2fs_info(sbi, "Image doesn't support compression");
951 F2FS_OPTION(sbi).compress_algorithm =
954 F2FS_OPTION(sbi).compress_algorithm =
957 F2FS_OPTION(sbi).compress_algorithm =
960 F2FS_OPTION(sbi).compress_algorithm =
969 if (!f2fs_sb_has_compression(sbi)) {
970 f2fs_info(sbi, "Image doesn't support compression");
977 f2fs_err(sbi,
981 F2FS_OPTION(sbi).compress_log_size = arg;
984 if (!f2fs_sb_has_compression(sbi)) {
985 f2fs_info(sbi, "Image doesn't support compression");
992 ext = F2FS_OPTION(sbi).extensions;
993 ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
997 f2fs_err(sbi,
1004 F2FS_OPTION(sbi).compress_ext_cnt++;
1011 f2fs_info(sbi, "compression options not supported");
1015 set_opt(sbi, ATGC);
1018 set_opt(sbi, GC_MERGE);
1021 clear_opt(sbi, GC_MERGE);
1024 f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
1030 if (f2fs_check_quota_options(sbi))
1033 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
1034 f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1037 if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
1038 f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
1043 if (f2fs_sb_has_casefold(sbi)) {
1044 f2fs_err(sbi,
1055 if (f2fs_sb_has_blkzoned(sbi)) {
1056 f2fs_err(sbi, "Zoned block device support is not enabled");
1061 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
1062 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
1063 F2FS_IO_SIZE_KB(sbi));
1067 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
1070 if (!f2fs_sb_has_extra_attr(sbi) ||
1071 !f2fs_sb_has_flexible_inline_xattr(sbi)) {
1072 f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
1075 if (!test_opt(sbi, INLINE_XATTR)) {
1076 f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
1083 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
1084 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
1085 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
1091 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
1092 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
1099 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_PERSIST_TYPE)
1100 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
1139 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1146 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
1147 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1148 inode->i_ino == F2FS_META_INO(sbi)) {
1201 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1204 spin_lock(&sbi->inode_lock[DIRTY_META]);
1209 stat_inc_dirty_inode(sbi, DIRTY_META);
1213 &sbi->inode_list[DIRTY_META]);
1214 inc_page_count(sbi, F2FS_DIRTY_IMETA);
1216 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1222 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1224 spin_lock(&sbi->inode_lock[DIRTY_META]);
1226 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1231 dec_page_count(sbi, F2FS_DIRTY_IMETA);
1236 spin_unlock(&sbi->inode_lock[DIRTY_META]);
1246 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1248 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
1249 inode->i_ino == F2FS_META_INO(sbi))
1267 static void destroy_percpu_info(struct f2fs_sb_info *sbi)
1269 percpu_counter_destroy(&sbi->alloc_valid_block_count);
1270 percpu_counter_destroy(&sbi->total_valid_inode_count);
1273 static void destroy_device_list(struct f2fs_sb_info *sbi)
1277 for (i = 0; i < sbi->s_ndevs; i++) {
1283 kvfree(sbi->devs);
1288 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1293 f2fs_unregister_sysfs(sbi);
1298 mutex_lock(&sbi->umount_mutex);
1305 if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
1306 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) {
1310 f2fs_write_checkpoint(sbi, &cpc);
1314 dropped = f2fs_issue_discard_timeout(sbi);
1316 if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
1317 !sbi->discard_blks && !dropped) {
1321 f2fs_write_checkpoint(sbi, &cpc);
1328 f2fs_release_ino_entry(sbi, true);
1330 f2fs_leave_shrinker(sbi);
1331 mutex_unlock(&sbi->umount_mutex);
1334 f2fs_flush_merged_writes(sbi);
1336 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
1338 f2fs_bug_on(sbi, sbi->fsync_node_num);
1340 iput(sbi->node_inode);
1341 sbi->node_inode = NULL;
1343 iput(sbi->meta_inode);
1344 sbi->meta_inode = NULL;
1350 f2fs_destroy_stats(sbi);
1353 f2fs_destroy_node_manager(sbi);
1354 f2fs_destroy_segment_manager(sbi);
1356 f2fs_destroy_post_read_wq(sbi);
1358 kvfree(sbi->ckpt);
1361 if (sbi->s_chksum_driver)
1362 crypto_free_shash(sbi->s_chksum_driver);
1363 kfree(sbi->raw_super);
1365 destroy_device_list(sbi);
1366 f2fs_destroy_page_array_cache(sbi);
1367 f2fs_destroy_xattr_caches(sbi);
1368 mempool_destroy(sbi->write_io_dummy);
1371 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
1373 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
1374 destroy_percpu_info(sbi);
1376 kvfree(sbi->write_io[i]);
1380 kfree(sbi);
1385 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1388 if (unlikely(f2fs_cp_error(sbi)))
1390 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
1395 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1401 cpc.reason = __get_cp_reason(sbi);
1403 down_write(&sbi->gc_lock);
1404 err = f2fs_write_checkpoint(sbi, &cpc);
1405 up_write(&sbi->gc_lock);
1480 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1485 total_count = le64_to_cpu(sbi->raw_super->block_count);
1486 user_block_count = sbi->user_block_count;
1487 start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
1489 buf->f_bsize = sbi->blocksize;
1492 buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
1493 sbi->current_reserved_blocks;
1495 spin_lock(&sbi->stat_lock);
1496 if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
1499 buf->f_bfree -= sbi->unusable_block_count;
1500 spin_unlock(&sbi->stat_lock);
1502 if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
1504 F2FS_OPTION(sbi).root_reserved_blocks;
1508 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
1515 buf->f_ffree = min(avail_node_count - valid_node_count(sbi),
1535 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1537 if (F2FS_OPTION(sbi).s_jquota_fmt) {
1540 switch (F2FS_OPTION(sbi).s_jquota_fmt) {
1554 if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
1556 F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
1558 if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
1560 F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
1562 if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
1564 F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
1571 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1575 if (!f2fs_sb_has_compression(sbi))
1578 switch (F2FS_OPTION(sbi).compress_algorithm) {
1595 F2FS_OPTION(sbi).compress_log_size);
1597 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
1599 F2FS_OPTION(sbi).extensions[i]);
1605 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
1607 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
1609 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
1611 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
1614 if (test_opt(sbi, GC_MERGE))
1617 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
1619 if (test_opt(sbi, NORECOVERY))
1621 if (test_opt(sbi, DISCARD))
1625 if (test_opt(sbi, NOHEAP))
1630 if (test_opt(sbi, XATTR_USER))
1634 if (test_opt(sbi, INLINE_XATTR))
1638 if (test_opt(sbi, INLINE_XATTR_SIZE))
1640 F2FS_OPTION(sbi).inline_xattr_size);
1643 if (test_opt(sbi, POSIX_ACL))
1648 if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
1650 if (test_opt(sbi, INLINE_DATA))
1654 if (test_opt(sbi, INLINE_DENTRY))
1658 if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE))
1660 if (test_opt(sbi, NOBARRIER))
1662 if (test_opt(sbi, FASTBOOT))
1664 if (test_opt(sbi, EXTENT_CACHE))
1668 if (test_opt(sbi, DATA_FLUSH))
1672 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE)
1674 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS)
1676 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
1677 if (test_opt(sbi, RESERVE_ROOT))
1679 F2FS_OPTION(sbi).root_reserved_blocks,
1681 F2FS_OPTION(sbi).s_resuid),
1683 F2FS_OPTION(sbi).s_resgid));
1684 if (F2FS_IO_SIZE_BITS(sbi))
1686 F2FS_OPTION(sbi).write_io_size_bits);
1688 if (test_opt(sbi, FAULT_INJECTION)) {
1690 F2FS_OPTION(sbi).fault_info.inject_rate);
1692 F2FS_OPTION(sbi).fault_info.inject_type);
1696 if (test_opt(sbi, QUOTA))
1698 if (test_opt(sbi, USRQUOTA))
1700 if (test_opt(sbi, GRPQUOTA))
1702 if (test_opt(sbi, PRJQUOTA))
1705 f2fs_show_quota_options(seq, sbi->sb);
1706 if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER)
1708 else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS)
1711 fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb);
1713 if (sbi->sb->s_flags & SB_INLINECRYPT)
1716 if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
1718 else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
1721 if (test_opt(sbi, DISABLE_CHECKPOINT))
1723 F2FS_OPTION(sbi).unusable_cap);
1724 if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
1726 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
1728 else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER)
1732 f2fs_show_compress_options(seq, sbi->sb);
1735 if (test_opt(sbi, ATGC))
1740 static void default_options(struct f2fs_sb_info *sbi)
1743 F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
1744 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
1745 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
1746 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
1747 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1748 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
1749 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
1750 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
1751 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
1752 F2FS_OPTION(sbi).compress_ext_cnt = 0;
1753 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
1755 set_opt(sbi, INLINE_XATTR);
1756 set_opt(sbi, INLINE_DATA);
1757 set_opt(sbi, INLINE_DENTRY);
1758 set_opt(sbi, EXTENT_CACHE);
1759 set_opt(sbi, NOHEAP);
1760 clear_opt(sbi, DISABLE_CHECKPOINT);
1761 F2FS_OPTION(sbi).unusable_cap = 0;
1762 sbi->sb->s_flags |= SB_LAZYTIME;
1763 set_opt(sbi, FLUSH_MERGE);
1764 set_opt(sbi, DISCARD);
1765 if (f2fs_sb_has_blkzoned(sbi))
1766 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
1768 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
1771 set_opt(sbi, XATTR_USER);
1774 set_opt(sbi, POSIX_ACL);
1777 f2fs_build_fault_attr(sbi, 0, 0);
1784 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
1786 unsigned int s_flags = sbi->sb->s_flags;
1793 f2fs_err(sbi, "checkpoint=disable on readonly fs");
1796 sbi->sb->s_flags |= SB_ACTIVE;
1798 f2fs_update_time(sbi, DISABLE_TIME);
1800 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
1801 down_write(&sbi->gc_lock);
1802 err = f2fs_gc(sbi, true, false, false, NULL_SEGNO);
1811 ret = sync_filesystem(sbi->sb);
1817 unusable = f2fs_get_unusable_blocks(sbi);
1818 if (f2fs_disable_cp_again(sbi, unusable)) {
1823 down_write(&sbi->gc_lock);
1825 set_sbi_flag(sbi, SBI_CP_DISABLED);
1826 err = f2fs_write_checkpoint(sbi, &cpc);
1830 spin_lock(&sbi->stat_lock);
1831 sbi->unusable_block_count = unusable;
1832 spin_unlock(&sbi->stat_lock);
1835 up_write(&sbi->gc_lock);
1837 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
1841 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
1847 sync_inodes_sb(sbi->sb);
1850 } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--);
1853 f2fs_warn(sbi, "checkpoint=enable has some unwritten data.");
1855 down_write(&sbi->gc_lock);
1856 f2fs_dirty_to_prefree(sbi);
1858 clear_sbi_flag(sbi, SBI_CP_DISABLED);
1859 set_sbi_flag(sbi, SBI_IS_DIRTY);
1860 up_write(&sbi->gc_lock);
1862 f2fs_sync_fs(sbi->sb, 1);
1867 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1873 bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
1874 bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT);
1875 bool no_io_align = !F2FS_IO_ALIGNED(sbi);
1876 bool no_atgc = !test_opt(sbi, ATGC);
1886 org_mount_opt = sbi->mount_opt;
1890 org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
1892 if (F2FS_OPTION(sbi).s_qf_names[i]) {
1894 kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
1908 if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
1909 err = f2fs_commit_super(sbi, false);
1910 f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
1913 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
1916 default_options(sbi);
1923 disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
1942 } else if (f2fs_sb_has_quota_ino(sbi)) {
1950 if (no_atgc == !!test_opt(sbi, ATGC)) {
1952 f2fs_warn(sbi, "switch atgc option is not allowed");
1957 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
1959 f2fs_warn(sbi, "switch extent_cache option is not allowed");
1963 if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) {
1965 f2fs_warn(sbi, "switch io_bits option is not allowed");
1969 if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
1971 f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
1981 (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
1982 !test_opt(sbi, GC_MERGE))) {
1983 if (sbi->gc_thread) {
1984 f2fs_stop_gc_thread(sbi);
1987 } else if (!sbi->gc_thread) {
1988 err = f2fs_start_gc_thread(sbi);
1995 F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) {
1999 set_sbi_flag(sbi, SBI_IS_DIRTY);
2000 set_sbi_flag(sbi, SBI_IS_CLOSE);
2002 clear_sbi_flag(sbi, SBI_IS_CLOSE);
2006 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
2007 err = f2fs_disable_checkpoint(sbi);
2011 f2fs_enable_checkpoint(sbi);
2019 if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
2020 clear_opt(sbi, FLUSH_MERGE);
2021 f2fs_destroy_flush_cmd_control(sbi, false);
2023 err = f2fs_create_flush_cmd_control(sbi);
2035 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
2037 limit_reserve_root(sbi);
2038 adjust_unusable_cap_perc(sbi);
2043 if (f2fs_start_gc_thread(sbi))
2044 f2fs_warn(sbi, "background gc thread has stopped");
2046 f2fs_stop_gc_thread(sbi);
2050 F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
2052 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
2053 F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
2056 sbi->mount_opt = org_mount_opt;
2176 static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
2178 if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
2179 f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
2183 return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
2184 F2FS_OPTION(sbi).s_jquota_fmt, type);
2187 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
2192 if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
2193 err = f2fs_enable_quotas(sbi->sb);
2195 f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
2202 if (F2FS_OPTION(sbi).s_qf_names[i]) {
2203 err = f2fs_quota_on_mount(sbi, i);
2208 f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
2243 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2247 test_opt(sbi, USRQUOTA),
2248 test_opt(sbi, GRPQUOTA),
2249 test_opt(sbi, PRJQUOTA),
2253 f2fs_err(sbi, "quota file may be corrupted, skip loading it");
2266 f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
2279 static int f2fs_quota_sync_file(struct f2fs_sb_info *sbi, int type)
2281 struct quota_info *dqopt = sb_dqopt(sbi->sb);
2285 ret = dquot_writeback_dquots(sbi->sb, type);
2294 if (is_journalled_quota(sbi))
2302 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2308 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2325 if (!f2fs_sb_has_quota_ino(sbi))
2337 f2fs_lock_op(sbi);
2338 down_read(&sbi->quota_sem);
2340 ret = f2fs_quota_sync_file(sbi, cnt);
2342 up_read(&sbi->quota_sem);
2343 f2fs_unlock_op(sbi);
2345 if (!f2fs_sb_has_quota_ino(sbi))
2413 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2423 if (is_journalled_quota(sbi))
2424 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2465 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
2468 down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING);
2471 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2472 up_read(&sbi->quota_sem);
2478 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
2481 down_read(&sbi->quota_sem);
2484 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2485 up_read(&sbi->quota_sem);
2491 struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
2495 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2502 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2506 if (is_journalled_quota(sbi))
2507 set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
2514 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2518 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
2594 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2602 if (f2fs_sb_has_lost_found(sbi) &&
2603 inode->i_ino == F2FS_ROOT_INO(sbi))
2630 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2632 if (f2fs_is_multi_device(sbi))
2633 return sbi->s_ndevs;
2640 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2643 for (i = 0; i < sbi->s_ndevs; i++)
2664 struct f2fs_sb_info *sbi = F2FS_SB(sb);
2667 if (f2fs_check_nid_range(sbi, ino))
2745 static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
2750 struct super_block *sb = sbi->sb;
2770 f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
2777 f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
2785 f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
2793 f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
2801 f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
2808 f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)",
2821 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
2827 f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)",
2836 static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
2847 f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
2857 f2fs_info(sbi, "Invalid SB checksum offset: %zu",
2862 if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
2863 f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
2870 f2fs_info(sbi, "Invalid page_cache_size (%lu), supports only 4KB",
2877 f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u",
2885 f2fs_info(sbi, "Invalid log blocks per segment (%u)",
2895 f2fs_info(sbi, "Invalid log sectorsize (%u)",
2902 f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
2919 f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
2925 f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
2931 f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)",
2937 f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
2943 f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
2957 f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)",
2963 !bdev_is_zoned(sbi->sb->s_bdev)) {
2964 f2fs_info(sbi, "Zoned block device path is missing");
2970 f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
2978 f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
2988 f2fs_info(sbi, "Insane cp_payload (%u >= %u)",
2999 f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
3007 if (sanity_check_area_boundary(sbi, bh))
3013 int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
3016 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
3017 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
3047 f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
3056 f2fs_err(sbi, "Wrong user_block_count: %u",
3063 f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
3069 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
3071 f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
3077 blocks_per_seg = sbi->blocks_per_seg;
3086 f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
3100 f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
3111 f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u",
3124 f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
3129 cp_pack_start_sum = __start_sum_addr(sbi);
3130 cp_payload = __cp_payload(sbi);
3134 f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
3141 f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
3154 f2fs_warn(sbi, "Insane cp_payload: %u, nat_bits_blocks: %u)",
3159 if (unlikely(f2fs_cp_error(sbi))) {
3160 f2fs_err(sbi, "A bug case: need to run fsck");
3166 static void init_sb_info(struct f2fs_sb_info *sbi)
3168 struct f2fs_super_block *raw_super = sbi->raw_super;
3171 sbi->log_sectors_per_block =
3173 sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
3174 sbi->blocksize = 1 << sbi->log_blocksize;
3175 sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
3176 sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg;
3177 sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
3178 sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
3179 sbi->total_sections = le32_to_cpu(raw_super->section_count);
3180 sbi->total_node_count =
3182 * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
3183 sbi->root_ino_num = le32_to_cpu(raw_super->root_ino);
3184 sbi->node_ino_num = le32_to_cpu(raw_super->node_ino);
3185 sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino);
3186 sbi->cur_victim_sec = NULL_SECNO;
3187 sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
3188 sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
3189 sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
3190 sbi->migration_granularity = sbi->segs_per_sec;
3192 sbi->dir_level = DEF_DIR_LEVEL;
3193 sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
3194 sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
3195 sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
3196 sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
3197 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
3198 sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =
3200 clear_sbi_flag(sbi, SBI_NEED_FSCK);
3203 atomic_set(&sbi->nr_pages[i], 0);
3206 atomic_set(&sbi->wb_sync_req[i], 0);
3208 INIT_LIST_HEAD(&sbi->s_list);
3209 mutex_init(&sbi->umount_mutex);
3210 init_rwsem(&sbi->io_order_lock);
3211 spin_lock_init(&sbi->cp_lock);
3213 sbi->dirty_device = 0;
3214 spin_lock_init(&sbi->dev_lock);
3216 init_rwsem(&sbi->sb_lock);
3217 init_rwsem(&sbi->pin_sem);
3220 static int init_percpu_info(struct f2fs_sb_info *sbi)
3224 err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
3228 err = percpu_counter_init(&sbi->total_valid_inode_count, 0,
3231 percpu_counter_destroy(&sbi->alloc_valid_block_count);
3239 struct f2fs_sb_info *sbi;
3254 if (!rz_args->sbi->unusable_blocks_per_sec) {
3255 rz_args->sbi->unusable_blocks_per_sec = unusable_blocks;
3258 if (rz_args->sbi->unusable_blocks_per_sec != unusable_blocks) {
3259 f2fs_err(rz_args->sbi, "F2FS supports single zone capacity\n");
3265 static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
3272 if (!f2fs_sb_has_blkzoned(sbi))
3275 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
3278 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev));
3279 if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz !=
3280 __ilog2_u32(sbi->blocks_per_blkz))
3282 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
3284 sbi->log_blocks_per_blkz;
3288 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
3295 rep_zone_arg.sbi = sbi;
3312 static int read_raw_super_block(struct f2fs_sb_info *sbi,
3316 struct super_block *sb = sbi->sb;
3329 f2fs_err(sbi, "Unable to read %dth superblock",
3337 err = sanity_check_raw_super(sbi, bh);
3339 f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
3364 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
3370 if ((recover && f2fs_readonly(sbi->sb)) ||
3371 bdev_read_only(sbi->sb->s_bdev)) {
3372 set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
3377 if (!recover && f2fs_sb_has_sb_chksum(sbi)) {
3378 crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi),
3380 F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc);
3384 bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
3387 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
3395 bh = sb_bread(sbi->sb, sbi->valid_super_block);
3398 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
3403 static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
3405 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
3411 if (!bdev_is_zoned(sbi->sb->s_bdev))
3420 sbi->devs = f2fs_kzalloc(sbi,
3424 if (!sbi->devs)
3435 blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev,
3436 sbi->sb->s_mode, sbi->sb->s_type);
3446 sbi->log_blocks_per_seg) - 1 +
3452 sbi->log_blocks_per_seg) - 1;
3455 sbi->sb->s_mode, sbi->sb->s_type);
3461 sbi->s_ndevs = i + 1;
3465 !f2fs_sb_has_blkzoned(sbi)) {
3466 f2fs_err(sbi, "Zoned block device feature not enabled\n");
3470 if (init_blkz_info(sbi, i)) {
3471 f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
3476 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
3485 f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
3490 f2fs_info(sbi,
3491 "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3495 static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
3498 if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
3503 if (f2fs_sb_has_encrypt(sbi)) {
3504 f2fs_err(sbi,
3509 if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info,
3511 f2fs_err(sbi,
3518 f2fs_err(sbi,
3525 f2fs_info(sbi, "Using encoding defined by superblock: "
3529 sbi->sb->s_encoding = encoding;
3530 sbi->sb->s_encoding_flags = encoding_flags;
3531 sbi->sb->s_d_op = &f2fs_dentry_ops;
3534 if (f2fs_sb_has_casefold(sbi)) {
3535 f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
3542 static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
3544 struct f2fs_sm_info *sm_i = SM_I(sbi);
3548 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
3553 sbi->readdir_ra = 1;
3557 static void f2fs_init_grading_ssr(struct f2fs_sb_info *sbi)
3559 u32 total_blocks = le64_to_cpu(sbi->raw_super->block_count) >> 18;
3562 sbi->hot_cold_params.hot_data_lower_limit = SSR_HD_SAPCE_LIMIT_128G;
3563 sbi->hot_cold_params.hot_data_waterline = SSR_HD_WATERLINE_128G;
3564 sbi->hot_cold_params.warm_data_lower_limit = SSR_WD_SAPCE_LIMIT_128G;
3565 sbi->hot_cold_params.warm_data_waterline = SSR_WD_WATERLINE_128G;
3566 sbi->hot_cold_params.hot_node_lower_limit = SSR_HD_SAPCE_LIMIT_128G;
3567 sbi->hot_cold_params.hot_node_waterline = SSR_HN_WATERLINE_128G;
3568 sbi->hot_cold_params.warm_node_lower_limit = SSR_WN_SAPCE_LIMIT_128G;
3569 sbi->hot_cold_params.warm_node_waterline = SSR_WN_WATERLINE_128G;
3570 sbi->hot_cold_params.enable = GRADING_SSR_OFF;
3572 sbi->hot_cold_params.hot_data_lower_limit = SSR_DEFALT_SPACE_LIMIT;
3573 sbi->hot_cold_params.hot_data_waterline = SSR_DEFALT_WATERLINE;
3574 sbi->hot_cold_params.warm_data_lower_limit = SSR_DEFALT_SPACE_LIMIT;
3575 sbi->hot_cold_params.warm_data_waterline = SSR_DEFALT_WATERLINE;
3576 sbi->hot_cold_params.hot_node_lower_limit = SSR_DEFALT_SPACE_LIMIT;
3577 sbi->hot_cold_params.hot_node_waterline = SSR_DEFALT_WATERLINE;
3578 sbi->hot_cold_params.warm_node_lower_limit = SSR_DEFALT_SPACE_LIMIT;
3579 sbi->hot_cold_params.warm_node_waterline = SSR_DEFALT_WATERLINE;
3580 sbi->hot_cold_params.enable = GRADING_SSR_OFF;
3587 struct f2fs_sb_info *sbi;
3604 sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
3605 if (!sbi)
3608 sbi->sb = sb;
3611 sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
3612 if (IS_ERR(sbi->s_chksum_driver)) {
3613 f2fs_err(sbi, "Cannot load crc32 driver.");
3614 err = PTR_ERR(sbi->s_chksum_driver);
3615 sbi->s_chksum_driver = NULL;
3621 f2fs_err(sbi, "unable to set blocksize");
3625 err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
3630 sb->s_fs_info = sbi;
3631 sbi->raw_super = raw_super;
3634 if (f2fs_sb_has_inode_chksum(sbi))
3635 sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,
3638 default_options(sbi);
3650 sbi->max_file_blocks = max_file_blocks();
3651 sb->s_maxbytes = sbi->max_file_blocks <<
3655 err = f2fs_setup_casefold(sbi);
3664 if (f2fs_sb_has_quota_ino(sbi)) {
3666 if (f2fs_qf_ino(sbi->sb, i))
3667 sbi->nquota_files++;
3684 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
3689 sbi->valid_super_block = valid_super_block;
3690 init_rwsem(&sbi->gc_lock);
3691 mutex_init(&sbi->writepages);
3692 mutex_init(&sbi->cp_mutex);
3693 init_rwsem(&sbi->node_write);
3694 init_rwsem(&sbi->node_change);
3697 set_sbi_flag(sbi, SBI_POR_DOING);
3698 spin_lock_init(&sbi->stat_lock);
3701 spin_lock_init(&sbi->iostat_lock);
3702 sbi->iostat_enable = false;
3703 sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS;
3709 sbi->write_io[i] =
3710 f2fs_kmalloc(sbi,
3714 if (!sbi->write_io[i]) {
3720 init_rwsem(&sbi->write_io[i][j].io_rwsem);
3721 sbi->write_io[i][j].sbi = sbi;
3722 sbi->write_io[i][j].bio = NULL;
3723 spin_lock_init(&sbi->write_io[i][j].io_lock);
3724 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
3725 INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
3726 init_rwsem(&sbi->write_io[i][j].bio_list_lock);
3730 init_rwsem(&sbi->cp_rwsem);
3731 init_rwsem(&sbi->quota_sem);
3732 init_waitqueue_head(&sbi->cp_wait);
3733 init_sb_info(sbi);
3735 err = init_percpu_info(sbi);
3739 if (F2FS_IO_ALIGNED(sbi)) {
3740 sbi->write_io_dummy =
3741 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
3742 if (!sbi->write_io_dummy) {
3748 /* init per sbi slab cache */
3749 err = f2fs_init_xattr_caches(sbi);
3752 err = f2fs_init_page_array_cache(sbi);
3757 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
3758 if (IS_ERR(sbi->meta_inode)) {
3759 f2fs_err(sbi, "Failed to read F2FS meta data inode");
3760 err = PTR_ERR(sbi->meta_inode);
3764 err = f2fs_get_valid_checkpoint(sbi);
3766 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
3770 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
3771 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
3772 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
3773 set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
3774 sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
3777 if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
3778 set_sbi_flag(sbi, SBI_NEED_FSCK);
3781 err = f2fs_scan_devices(sbi);
3783 f2fs_err(sbi, "Failed to find devices");
3787 err = f2fs_init_post_read_wq(sbi);
3789 f2fs_err(sbi, "Failed to initialize post read workqueue");
3793 sbi->total_valid_node_count =
3794 le32_to_cpu(sbi->ckpt->valid_node_count);
3795 percpu_counter_set(&sbi->total_valid_inode_count,
3796 le32_to_cpu(sbi->ckpt->valid_inode_count));
3797 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
3798 sbi->total_valid_block_count =
3799 le64_to_cpu(sbi->ckpt->valid_block_count);
3800 sbi->last_valid_block_count = sbi->total_valid_block_count;
3801 sbi->reserved_blocks = 0;
3802 sbi->current_reserved_blocks = 0;
3803 limit_reserve_root(sbi);
3804 adjust_unusable_cap_perc(sbi);
3807 INIT_LIST_HEAD(&sbi->inode_list[i]);
3808 spin_lock_init(&sbi->inode_lock[i]);
3810 mutex_init(&sbi->flush_lock);
3812 f2fs_init_extent_cache_info(sbi);
3814 f2fs_init_ino_entry_info(sbi);
3816 f2fs_init_fsync_node_info(sbi);
3819 err = f2fs_build_segment_manager(sbi);
3821 f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
3825 err = f2fs_build_node_manager(sbi);
3827 f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
3832 err = adjust_reserved_segment(sbi);
3838 sbi->sectors_written_start =
3843 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
3844 if (__exist_node_summaries(sbi))
3845 sbi->kbytes_written =
3848 f2fs_build_gc_manager(sbi);
3850 err = f2fs_build_stats(sbi);
3855 sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
3856 if (IS_ERR(sbi->node_inode)) {
3857 f2fs_err(sbi, "Failed to read node inode");
3858 err = PTR_ERR(sbi->node_inode);
3863 root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
3865 f2fs_err(sbi, "Failed to read root inode");
3882 f2fs_init_grading_ssr(sbi);
3884 err = f2fs_register_sysfs(sbi);
3890 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
3893 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
3897 err = f2fs_recover_orphan_inodes(sbi);
3901 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3905 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) &&
3906 !test_opt(sbi, NORECOVERY)) {
3911 if (f2fs_hw_is_readonly(sbi)) {
3912 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3914 f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");
3917 f2fs_info(sbi, "write access unavailable, skipping recovery");
3922 set_sbi_flag(sbi, SBI_NEED_FSCK);
3927 err = f2fs_recover_fsync_data(sbi, false);
3932 f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
3937 err = f2fs_recover_fsync_data(sbi, true);
3941 f2fs_err(sbi, "Need to recover fsync data");
3950 if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) {
3951 err = f2fs_check_write_pointer(sbi);
3957 f2fs_init_inmem_curseg(sbi);
3960 clear_sbi_flag(sbi, SBI_POR_DOING);
3962 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
3963 err = f2fs_disable_checkpoint(sbi);
3966 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
3967 f2fs_enable_checkpoint(sbi);
3974 if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
3975 test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
3977 err = f2fs_start_gc_thread(sbi);
3985 err = f2fs_commit_super(sbi, true);
3986 f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
3987 sbi->valid_super_block ? 1 : 2, err);
3990 f2fs_join_shrinker(sbi);
3992 f2fs_tuning_parameters(sbi);
3994 f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
3995 cur_cp_version(F2FS_CKPT(sbi)));
3996 f2fs_update_time(sbi, CP_TIME);
3997 f2fs_update_time(sbi, REQ_TIME);
3998 clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
4003 sync_filesystem(sbi->sb);
4009 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb))
4010 f2fs_quota_off_umount(sbi->sb);
4018 truncate_inode_pages_final(META_MAPPING(sbi));
4021 f2fs_unregister_sysfs(sbi);
4026 f2fs_release_ino_entry(sbi, true);
4027 truncate_inode_pages_final(NODE_MAPPING(sbi));
4028 iput(sbi->node_inode);
4029 sbi->node_inode = NULL;
4031 f2fs_destroy_stats(sbi);
4033 f2fs_destroy_node_manager(sbi);
4035 f2fs_destroy_segment_manager(sbi);
4036 f2fs_destroy_post_read_wq(sbi);
4038 destroy_device_list(sbi);
4039 kvfree(sbi->ckpt);
4041 make_bad_inode(sbi->meta_inode);
4042 iput(sbi->meta_inode);
4043 sbi->meta_inode = NULL;
4045 f2fs_destroy_page_array_cache(sbi);
4047 f2fs_destroy_xattr_caches(sbi);
4049 mempool_destroy(sbi->write_io_dummy);
4051 destroy_percpu_info(sbi);
4054 kvfree(sbi->write_io[i]);
4063 kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4065 fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
4070 if (sbi->s_chksum_driver)
4071 crypto_free_shash(sbi->s_chksum_driver);
4072 kfree(sbi);
4092 struct f2fs_sb_info *sbi = F2FS_SB(sb);
4094 set_sbi_flag(sbi, SBI_IS_CLOSE);
4095 f2fs_stop_gc_thread(sbi);
4096 f2fs_stop_discard_thread(sbi);
4098 if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
4099 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
4103 f2fs_write_checkpoint(sbi, &cpc);
4106 if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))