super.c (8dd06ef34b6e2f41b29fbf5fc1663780f2524285) super.c (0b6d4ca04a86b9dababbb76e58d33c437e127b77)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

--- 10 unchanged lines hidden (view full) ---

19#include <linux/random.h>
20#include <linux/exportfs.h>
21#include <linux/blkdev.h>
22#include <linux/quotaops.h>
23#include <linux/f2fs_fs.h>
24#include <linux/sysfs.h>
25#include <linux/quota.h>
26#include <linux/unicode.h>
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * fs/f2fs/super.c
4 *
5 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * http://www.samsung.com/
7 */
8#include <linux/module.h>

--- 10 unchanged lines hidden (view full) ---

19#include <linux/random.h>
20#include <linux/exportfs.h>
21#include <linux/blkdev.h>
22#include <linux/quotaops.h>
23#include <linux/f2fs_fs.h>
24#include <linux/sysfs.h>
25#include <linux/quota.h>
26#include <linux/unicode.h>
27#include <linux/part_stat.h>
27
28#include "f2fs.h"
29#include "node.h"
30#include "segment.h"
31#include "xattr.h"
32#include "gc.h"
33#include "trace.h"
34

--- 243 unchanged lines hidden (view full) ---

278 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
279 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
280 from_kuid_munged(&init_user_ns,
281 F2FS_OPTION(sbi).s_resuid),
282 from_kgid_munged(&init_user_ns,
283 F2FS_OPTION(sbi).s_resgid));
284}
285
28
29#include "f2fs.h"
30#include "node.h"
31#include "segment.h"
32#include "xattr.h"
33#include "gc.h"
34#include "trace.h"
35

--- 243 unchanged lines hidden (view full) ---

279 make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
280 f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
281 from_kuid_munged(&init_user_ns,
282 F2FS_OPTION(sbi).s_resuid),
283 from_kgid_munged(&init_user_ns,
284 F2FS_OPTION(sbi).s_resgid));
285}
286
287static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
288{
289 if (!F2FS_OPTION(sbi).unusable_cap_perc)
290 return;
291
292 if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
293 F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
294 else
295 F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) *
296 F2FS_OPTION(sbi).unusable_cap_perc;
297
298 f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%",
299 F2FS_OPTION(sbi).unusable_cap,
300 F2FS_OPTION(sbi).unusable_cap_perc);
301}
302
286static void init_once(void *foo)
287{
288 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
289
290 inode_init_once(&fi->vfs_inode);
291}
292
293#ifdef CONFIG_QUOTA

--- 127 unchanged lines hidden (view full) ---

421 token = match_token(p, f2fs_tokens, args);
422
423 switch (token) {
424 case Opt_gc_background:
425 name = match_strdup(&args[0]);
426
427 if (!name)
428 return -ENOMEM;
303static void init_once(void *foo)
304{
305 struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
306
307 inode_init_once(&fi->vfs_inode);
308}
309
310#ifdef CONFIG_QUOTA

--- 127 unchanged lines hidden (view full) ---

438 token = match_token(p, f2fs_tokens, args);
439
440 switch (token) {
441 case Opt_gc_background:
442 name = match_strdup(&args[0]);
443
444 if (!name)
445 return -ENOMEM;
429 if (strlen(name) == 2 && !strncmp(name, "on", 2)) {
430 set_opt(sbi, BG_GC);
431 clear_opt(sbi, FORCE_FG_GC);
432 } else if (strlen(name) == 3 && !strncmp(name, "off", 3)) {
433 clear_opt(sbi, BG_GC);
434 clear_opt(sbi, FORCE_FG_GC);
435 } else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) {
436 set_opt(sbi, BG_GC);
437 set_opt(sbi, FORCE_FG_GC);
446 if (!strcmp(name, "on")) {
447 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
448 } else if (!strcmp(name, "off")) {
449 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
450 } else if (!strcmp(name, "sync")) {
451 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
438 } else {
439 kvfree(name);
440 return -EINVAL;
441 }
442 kvfree(name);
443 break;
444 case Opt_disable_roll_forward:
445 set_opt(sbi, DISABLE_ROLL_FORWARD);
446 break;
447 case Opt_norecovery:
448 /* this option mounts f2fs with ro */
452 } else {
453 kvfree(name);
454 return -EINVAL;
455 }
456 kvfree(name);
457 break;
458 case Opt_disable_roll_forward:
459 set_opt(sbi, DISABLE_ROLL_FORWARD);
460 break;
461 case Opt_norecovery:
462 /* this option mounts f2fs with ro */
449 set_opt(sbi, DISABLE_ROLL_FORWARD);
463 set_opt(sbi, NORECOVERY);
450 if (!f2fs_readonly(sb))
451 return -EINVAL;
452 break;
453 case Opt_discard:
454 set_opt(sbi, DISCARD);
455 break;
456 case Opt_nodiscard:
457 if (f2fs_sb_has_blkzoned(sbi)) {

--- 130 unchanged lines hidden (view full) ---

588 }
589 F2FS_OPTION(sbi).s_resgid = gid;
590 break;
591 case Opt_mode:
592 name = match_strdup(&args[0]);
593
594 if (!name)
595 return -ENOMEM;
464 if (!f2fs_readonly(sb))
465 return -EINVAL;
466 break;
467 case Opt_discard:
468 set_opt(sbi, DISCARD);
469 break;
470 case Opt_nodiscard:
471 if (f2fs_sb_has_blkzoned(sbi)) {

--- 130 unchanged lines hidden (view full) ---

602 }
603 F2FS_OPTION(sbi).s_resgid = gid;
604 break;
605 case Opt_mode:
606 name = match_strdup(&args[0]);
607
608 if (!name)
609 return -ENOMEM;
596 if (strlen(name) == 8 &&
597 !strncmp(name, "adaptive", 8)) {
610 if (!strcmp(name, "adaptive")) {
598 if (f2fs_sb_has_blkzoned(sbi)) {
599 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
600 kvfree(name);
601 return -EINVAL;
602 }
611 if (f2fs_sb_has_blkzoned(sbi)) {
612 f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
613 kvfree(name);
614 return -EINVAL;
615 }
603 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
604 } else if (strlen(name) == 3 &&
605 !strncmp(name, "lfs", 3)) {
606 set_opt_mode(sbi, F2FS_MOUNT_LFS);
616 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
617 } else if (!strcmp(name, "lfs")) {
618 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
607 } else {
608 kvfree(name);
609 return -EINVAL;
610 }
611 kvfree(name);
612 break;
613 case Opt_io_size_bits:
614 if (args->from && match_int(args, &arg))

--- 107 unchanged lines hidden (view full) ---

722 case Opt_noquota:
723 f2fs_info(sbi, "quota operations not supported");
724 break;
725#endif
726 case Opt_whint:
727 name = match_strdup(&args[0]);
728 if (!name)
729 return -ENOMEM;
619 } else {
620 kvfree(name);
621 return -EINVAL;
622 }
623 kvfree(name);
624 break;
625 case Opt_io_size_bits:
626 if (args->from && match_int(args, &arg))

--- 107 unchanged lines hidden (view full) ---

734 case Opt_noquota:
735 f2fs_info(sbi, "quota operations not supported");
736 break;
737#endif
738 case Opt_whint:
739 name = match_strdup(&args[0]);
740 if (!name)
741 return -ENOMEM;
730 if (strlen(name) == 10 &&
731 !strncmp(name, "user-based", 10)) {
742 if (!strcmp(name, "user-based")) {
732 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
743 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
733 } else if (strlen(name) == 3 &&
734 !strncmp(name, "off", 3)) {
744 } else if (!strcmp(name, "off")) {
735 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
745 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
736 } else if (strlen(name) == 8 &&
737 !strncmp(name, "fs-based", 8)) {
746 } else if (!strcmp(name, "fs-based")) {
738 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
739 } else {
740 kvfree(name);
741 return -EINVAL;
742 }
743 kvfree(name);
744 break;
745 case Opt_alloc:
746 name = match_strdup(&args[0]);
747 if (!name)
748 return -ENOMEM;
749
747 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
748 } else {
749 kvfree(name);
750 return -EINVAL;
751 }
752 kvfree(name);
753 break;
754 case Opt_alloc:
755 name = match_strdup(&args[0]);
756 if (!name)
757 return -ENOMEM;
758
750 if (strlen(name) == 7 &&
751 !strncmp(name, "default", 7)) {
759 if (!strcmp(name, "default")) {
752 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
760 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
753 } else if (strlen(name) == 5 &&
754 !strncmp(name, "reuse", 5)) {
761 } else if (!strcmp(name, "reuse")) {
755 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
756 } else {
757 kvfree(name);
758 return -EINVAL;
759 }
760 kvfree(name);
761 break;
762 case Opt_fsync:
763 name = match_strdup(&args[0]);
764 if (!name)
765 return -ENOMEM;
762 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
763 } else {
764 kvfree(name);
765 return -EINVAL;
766 }
767 kvfree(name);
768 break;
769 case Opt_fsync:
770 name = match_strdup(&args[0]);
771 if (!name)
772 return -ENOMEM;
766 if (strlen(name) == 5 &&
767 !strncmp(name, "posix", 5)) {
773 if (!strcmp(name, "posix")) {
768 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
774 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
769 } else if (strlen(name) == 6 &&
770 !strncmp(name, "strict", 6)) {
775 } else if (!strcmp(name, "strict")) {
771 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
776 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
772 } else if (strlen(name) == 9 &&
773 !strncmp(name, "nobarrier", 9)) {
777 } else if (!strcmp(name, "nobarrier")) {
774 F2FS_OPTION(sbi).fsync_mode =
775 FSYNC_MODE_NOBARRIER;
776 } else {
777 kvfree(name);
778 return -EINVAL;
779 }
780 kvfree(name);
781 break;

--- 10 unchanged lines hidden (view full) ---

792 f2fs_info(sbi, "Test dummy encryption mount option ignored");
793#endif
794 break;
795 case Opt_checkpoint_disable_cap_perc:
796 if (args->from && match_int(args, &arg))
797 return -EINVAL;
798 if (arg < 0 || arg > 100)
799 return -EINVAL;
778 F2FS_OPTION(sbi).fsync_mode =
779 FSYNC_MODE_NOBARRIER;
780 } else {
781 kvfree(name);
782 return -EINVAL;
783 }
784 kvfree(name);
785 break;

--- 10 unchanged lines hidden (view full) ---

796 f2fs_info(sbi, "Test dummy encryption mount option ignored");
797#endif
798 break;
799 case Opt_checkpoint_disable_cap_perc:
800 if (args->from && match_int(args, &arg))
801 return -EINVAL;
802 if (arg < 0 || arg > 100)
803 return -EINVAL;
800 if (arg == 100)
801 F2FS_OPTION(sbi).unusable_cap =
802 sbi->user_block_count;
803 else
804 F2FS_OPTION(sbi).unusable_cap =
805 (sbi->user_block_count / 100) * arg;
804 F2FS_OPTION(sbi).unusable_cap_perc = arg;
806 set_opt(sbi, DISABLE_CHECKPOINT);
807 break;
808 case Opt_checkpoint_disable_cap:
809 if (args->from && match_int(args, &arg))
810 return -EINVAL;
811 F2FS_OPTION(sbi).unusable_cap = arg;
812 set_opt(sbi, DISABLE_CHECKPOINT);
813 break;

--- 6 unchanged lines hidden (view full) ---

820 case Opt_compress_algorithm:
821 if (!f2fs_sb_has_compression(sbi)) {
822 f2fs_err(sbi, "Compression feature if off");
823 return -EINVAL;
824 }
825 name = match_strdup(&args[0]);
826 if (!name)
827 return -ENOMEM;
805 set_opt(sbi, DISABLE_CHECKPOINT);
806 break;
807 case Opt_checkpoint_disable_cap:
808 if (args->from && match_int(args, &arg))
809 return -EINVAL;
810 F2FS_OPTION(sbi).unusable_cap = arg;
811 set_opt(sbi, DISABLE_CHECKPOINT);
812 break;

--- 6 unchanged lines hidden (view full) ---

819 case Opt_compress_algorithm:
820 if (!f2fs_sb_has_compression(sbi)) {
821 f2fs_err(sbi, "Compression feature if off");
822 return -EINVAL;
823 }
824 name = match_strdup(&args[0]);
825 if (!name)
826 return -ENOMEM;
828 if (strlen(name) == 3 && !strcmp(name, "lzo")) {
827 if (!strcmp(name, "lzo")) {
829 F2FS_OPTION(sbi).compress_algorithm =
830 COMPRESS_LZO;
828 F2FS_OPTION(sbi).compress_algorithm =
829 COMPRESS_LZO;
831 } else if (strlen(name) == 3 &&
832 !strcmp(name, "lz4")) {
830 } else if (!strcmp(name, "lz4")) {
833 F2FS_OPTION(sbi).compress_algorithm =
834 COMPRESS_LZ4;
831 F2FS_OPTION(sbi).compress_algorithm =
832 COMPRESS_LZ4;
833 } else if (!strcmp(name, "zstd")) {
834 F2FS_OPTION(sbi).compress_algorithm =
835 COMPRESS_ZSTD;
836 } else if (!strcmp(name, "lzo-rle")) {
837 F2FS_OPTION(sbi).compress_algorithm =
838 COMPRESS_LZORLE;
835 } else {
836 kfree(name);
837 return -EINVAL;
838 }
839 kfree(name);
840 break;
841 case Opt_compress_log_size:
842 if (!f2fs_sb_has_compression(sbi)) {

--- 56 unchanged lines hidden (view full) ---

899#ifndef CONFIG_UNICODE
900 if (f2fs_sb_has_casefold(sbi)) {
901 f2fs_err(sbi,
902 "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
903 return -EINVAL;
904 }
905#endif
906
839 } else {
840 kfree(name);
841 return -EINVAL;
842 }
843 kfree(name);
844 break;
845 case Opt_compress_log_size:
846 if (!f2fs_sb_has_compression(sbi)) {

--- 56 unchanged lines hidden (view full) ---

903#ifndef CONFIG_UNICODE
904 if (f2fs_sb_has_casefold(sbi)) {
905 f2fs_err(sbi,
906 "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
907 return -EINVAL;
908 }
909#endif
910
907 if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) {
911 if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
908 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
909 F2FS_IO_SIZE_KB(sbi));
910 return -EINVAL;
911 }
912
913 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
914 int min_size, max_size;
915

--- 13 unchanged lines hidden (view full) ---

929 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
930 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
931 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
932 min_size, max_size);
933 return -EINVAL;
934 }
935 }
936
912 f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
913 F2FS_IO_SIZE_KB(sbi));
914 return -EINVAL;
915 }
916
917 if (test_opt(sbi, INLINE_XATTR_SIZE)) {
918 int min_size, max_size;
919

--- 13 unchanged lines hidden (view full) ---

933 if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
934 F2FS_OPTION(sbi).inline_xattr_size > max_size) {
935 f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
936 min_size, max_size);
937 return -EINVAL;
938 }
939 }
940
937 if (test_opt(sbi, DISABLE_CHECKPOINT) && test_opt(sbi, LFS)) {
941 if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
938 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
939 return -EINVAL;
940 }
941
942 /* Not pass down write hints if the number of active logs is lesser
943 * than NR_CURSEG_TYPE.
944 */
945 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)

--- 9 unchanged lines hidden (view full) ---

955 if (!fi)
956 return NULL;
957
958 init_once((void *) fi);
959
960 /* Initialize f2fs-specific inode info */
961 atomic_set(&fi->dirty_pages, 0);
962 init_rwsem(&fi->i_sem);
942 f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
943 return -EINVAL;
944 }
945
946 /* Not pass down write hints if the number of active logs is lesser
947 * than NR_CURSEG_TYPE.
948 */
949 if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)

--- 9 unchanged lines hidden (view full) ---

959 if (!fi)
960 return NULL;
961
962 init_once((void *) fi);
963
964 /* Initialize f2fs-specific inode info */
965 atomic_set(&fi->dirty_pages, 0);
966 init_rwsem(&fi->i_sem);
967 spin_lock_init(&fi->i_size_lock);
963 INIT_LIST_HEAD(&fi->dirty_list);
964 INIT_LIST_HEAD(&fi->gdirty_list);
965 INIT_LIST_HEAD(&fi->inmem_ilist);
966 INIT_LIST_HEAD(&fi->inmem_pages);
967 mutex_init(&fi->inmem_lock);
968 init_rwsem(&fi->i_gc_rwsem[READ]);
969 init_rwsem(&fi->i_gc_rwsem[WRITE]);
970 init_rwsem(&fi->i_mmap_sem);

--- 196 unchanged lines hidden (view full) ---

1167 f2fs_release_ino_entry(sbi, true);
1168
1169 f2fs_leave_shrinker(sbi);
1170 mutex_unlock(&sbi->umount_mutex);
1171
1172 /* our cp_error case, we can wait for any writeback page */
1173 f2fs_flush_merged_writes(sbi);
1174
968 INIT_LIST_HEAD(&fi->dirty_list);
969 INIT_LIST_HEAD(&fi->gdirty_list);
970 INIT_LIST_HEAD(&fi->inmem_ilist);
971 INIT_LIST_HEAD(&fi->inmem_pages);
972 mutex_init(&fi->inmem_lock);
973 init_rwsem(&fi->i_gc_rwsem[READ]);
974 init_rwsem(&fi->i_gc_rwsem[WRITE]);
975 init_rwsem(&fi->i_mmap_sem);

--- 196 unchanged lines hidden (view full) ---

1172 f2fs_release_ino_entry(sbi, true);
1173
1174 f2fs_leave_shrinker(sbi);
1175 mutex_unlock(&sbi->umount_mutex);
1176
1177 /* our cp_error case, we can wait for any writeback page */
1178 f2fs_flush_merged_writes(sbi);
1179
1175 f2fs_wait_on_all_pages_writeback(sbi);
1180 f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
1176
1177 f2fs_bug_on(sbi, sbi->fsync_node_num);
1178
1179 iput(sbi->node_inode);
1180 sbi->node_inode = NULL;
1181
1182 iput(sbi->meta_inode);
1183 sbi->meta_inode = NULL;

--- 15 unchanged lines hidden (view full) ---

1199 f2fs_unregister_sysfs(sbi);
1200
1201 sb->s_fs_info = NULL;
1202 if (sbi->s_chksum_driver)
1203 crypto_free_shash(sbi->s_chksum_driver);
1204 kvfree(sbi->raw_super);
1205
1206 destroy_device_list(sbi);
1181
1182 f2fs_bug_on(sbi, sbi->fsync_node_num);
1183
1184 iput(sbi->node_inode);
1185 sbi->node_inode = NULL;
1186
1187 iput(sbi->meta_inode);
1188 sbi->meta_inode = NULL;

--- 15 unchanged lines hidden (view full) ---

1204 f2fs_unregister_sysfs(sbi);
1205
1206 sb->s_fs_info = NULL;
1207 if (sbi->s_chksum_driver)
1208 crypto_free_shash(sbi->s_chksum_driver);
1209 kvfree(sbi->raw_super);
1210
1211 destroy_device_list(sbi);
1212 f2fs_destroy_xattr_caches(sbi);
1207 mempool_destroy(sbi->write_io_dummy);
1208#ifdef CONFIG_QUOTA
1209 for (i = 0; i < MAXQUOTAS; i++)
1210 kvfree(F2FS_OPTION(sbi).s_qf_names[i]);
1211#endif
1212 destroy_percpu_info(sbi);
1213 for (i = 0; i < NR_PAGE_TYPE; i++)
1214 kvfree(sbi->write_io[i]);

--- 68 unchanged lines hidden (view full) ---

1283 spin_lock(&dquot->dq_dqb_lock);
1284
1285 limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit,
1286 dquot->dq_dqb.dqb_bhardlimit);
1287 if (limit)
1288 limit >>= sb->s_blocksize_bits;
1289
1290 if (limit && buf->f_blocks > limit) {
1213 mempool_destroy(sbi->write_io_dummy);
1214#ifdef CONFIG_QUOTA
1215 for (i = 0; i < MAXQUOTAS; i++)
1216 kvfree(F2FS_OPTION(sbi).s_qf_names[i]);
1217#endif
1218 destroy_percpu_info(sbi);
1219 for (i = 0; i < NR_PAGE_TYPE; i++)
1220 kvfree(sbi->write_io[i]);

--- 68 unchanged lines hidden (view full) ---

1289 spin_lock(&dquot->dq_dqb_lock);
1290
1291 limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit,
1292 dquot->dq_dqb.dqb_bhardlimit);
1293 if (limit)
1294 limit >>= sb->s_blocksize_bits;
1295
1296 if (limit && buf->f_blocks > limit) {
1291 curblock = dquot->dq_dqb.dqb_curspace >> sb->s_blocksize_bits;
1297 curblock = (dquot->dq_dqb.dqb_curspace +
1298 dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
1292 buf->f_blocks = limit;
1293 buf->f_bfree = buf->f_bavail =
1294 (buf->f_blocks > curblock) ?
1295 (buf->f_blocks - curblock) : 0;
1296 }
1297
1298 limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
1299 dquot->dq_dqb.dqb_ihardlimit);

--- 115 unchanged lines hidden (view full) ---

1415
1416 switch (F2FS_OPTION(sbi).compress_algorithm) {
1417 case COMPRESS_LZO:
1418 algtype = "lzo";
1419 break;
1420 case COMPRESS_LZ4:
1421 algtype = "lz4";
1422 break;
1299 buf->f_blocks = limit;
1300 buf->f_bfree = buf->f_bavail =
1301 (buf->f_blocks > curblock) ?
1302 (buf->f_blocks - curblock) : 0;
1303 }
1304
1305 limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
1306 dquot->dq_dqb.dqb_ihardlimit);

--- 115 unchanged lines hidden (view full) ---

1422
1423 switch (F2FS_OPTION(sbi).compress_algorithm) {
1424 case COMPRESS_LZO:
1425 algtype = "lzo";
1426 break;
1427 case COMPRESS_LZ4:
1428 algtype = "lz4";
1429 break;
1430 case COMPRESS_ZSTD:
1431 algtype = "zstd";
1432 break;
1433 case COMPRESS_LZORLE:
1434 algtype = "lzo-rle";
1435 break;
1423 }
1424 seq_printf(seq, ",compress_algorithm=%s", algtype);
1425
1426 seq_printf(seq, ",compress_log_size=%u",
1427 F2FS_OPTION(sbi).compress_log_size);
1428
1429 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
1430 seq_printf(seq, ",compress_extension=%s",
1431 F2FS_OPTION(sbi).extensions[i]);
1432 }
1433}
1434
1435static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
1436{
1437 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
1438
1436 }
1437 seq_printf(seq, ",compress_algorithm=%s", algtype);
1438
1439 seq_printf(seq, ",compress_log_size=%u",
1440 F2FS_OPTION(sbi).compress_log_size);
1441
1442 for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
1443 seq_printf(seq, ",compress_extension=%s",
1444 F2FS_OPTION(sbi).extensions[i]);
1445 }
1446}
1447
1448static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
1449{
1450 struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
1451
1439 if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) {
1440 if (test_opt(sbi, FORCE_FG_GC))
1441 seq_printf(seq, ",background_gc=%s", "sync");
1442 else
1443 seq_printf(seq, ",background_gc=%s", "on");
1444 } else {
1452 if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
1453 seq_printf(seq, ",background_gc=%s", "sync");
1454 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
1455 seq_printf(seq, ",background_gc=%s", "on");
1456 else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
1445 seq_printf(seq, ",background_gc=%s", "off");
1457 seq_printf(seq, ",background_gc=%s", "off");
1446 }
1458
1447 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
1448 seq_puts(seq, ",disable_roll_forward");
1459 if (test_opt(sbi, DISABLE_ROLL_FORWARD))
1460 seq_puts(seq, ",disable_roll_forward");
1461 if (test_opt(sbi, NORECOVERY))
1462 seq_puts(seq, ",norecovery");
1449 if (test_opt(sbi, DISCARD))
1450 seq_puts(seq, ",discard");
1451 else
1452 seq_puts(seq, ",nodiscard");
1453 if (test_opt(sbi, NOHEAP))
1454 seq_puts(seq, ",no_heap");
1455 else
1456 seq_puts(seq, ",heap");

--- 35 unchanged lines hidden (view full) ---

1492 if (test_opt(sbi, EXTENT_CACHE))
1493 seq_puts(seq, ",extent_cache");
1494 else
1495 seq_puts(seq, ",noextent_cache");
1496 if (test_opt(sbi, DATA_FLUSH))
1497 seq_puts(seq, ",data_flush");
1498
1499 seq_puts(seq, ",mode=");
1463 if (test_opt(sbi, DISCARD))
1464 seq_puts(seq, ",discard");
1465 else
1466 seq_puts(seq, ",nodiscard");
1467 if (test_opt(sbi, NOHEAP))
1468 seq_puts(seq, ",no_heap");
1469 else
1470 seq_puts(seq, ",heap");

--- 35 unchanged lines hidden (view full) ---

1506 if (test_opt(sbi, EXTENT_CACHE))
1507 seq_puts(seq, ",extent_cache");
1508 else
1509 seq_puts(seq, ",noextent_cache");
1510 if (test_opt(sbi, DATA_FLUSH))
1511 seq_puts(seq, ",data_flush");
1512
1513 seq_puts(seq, ",mode=");
1500 if (test_opt(sbi, ADAPTIVE))
1514 if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE)
1501 seq_puts(seq, "adaptive");
1515 seq_puts(seq, "adaptive");
1502 else if (test_opt(sbi, LFS))
1516 else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS)
1503 seq_puts(seq, "lfs");
1504 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
1505 if (test_opt(sbi, RESERVE_ROOT))
1506 seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u",
1507 F2FS_OPTION(sbi).root_reserved_blocks,
1508 from_kuid_munged(&init_user_ns,
1509 F2FS_OPTION(sbi).s_resuid),
1510 from_kgid_munged(&init_user_ns,

--- 54 unchanged lines hidden (view full) ---

1565 F2FS_OPTION(sbi).active_logs = NR_CURSEG_TYPE;
1566 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
1567 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
1568 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
1569 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1570 F2FS_OPTION(sbi).test_dummy_encryption = false;
1571 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
1572 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
1517 seq_puts(seq, "lfs");
1518 seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
1519 if (test_opt(sbi, RESERVE_ROOT))
1520 seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u",
1521 F2FS_OPTION(sbi).root_reserved_blocks,
1522 from_kuid_munged(&init_user_ns,
1523 F2FS_OPTION(sbi).s_resuid),
1524 from_kgid_munged(&init_user_ns,

--- 54 unchanged lines hidden (view full) ---

1579 F2FS_OPTION(sbi).active_logs = NR_CURSEG_TYPE;
1580 F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
1581 F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
1582 F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
1583 F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
1584 F2FS_OPTION(sbi).test_dummy_encryption = false;
1585 F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
1586 F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
1573 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZO;
1587 F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
1574 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
1575 F2FS_OPTION(sbi).compress_ext_cnt = 0;
1588 F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
1589 F2FS_OPTION(sbi).compress_ext_cnt = 0;
1590 F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
1576
1591
1577 set_opt(sbi, BG_GC);
1578 set_opt(sbi, INLINE_XATTR);
1579 set_opt(sbi, INLINE_DATA);
1580 set_opt(sbi, INLINE_DENTRY);
1581 set_opt(sbi, EXTENT_CACHE);
1582 set_opt(sbi, NOHEAP);
1583 clear_opt(sbi, DISABLE_CHECKPOINT);
1584 F2FS_OPTION(sbi).unusable_cap = 0;
1585 sbi->sb->s_flags |= SB_LAZYTIME;
1586 set_opt(sbi, FLUSH_MERGE);
1587 set_opt(sbi, DISCARD);
1588 if (f2fs_sb_has_blkzoned(sbi))
1592 set_opt(sbi, INLINE_XATTR);
1593 set_opt(sbi, INLINE_DATA);
1594 set_opt(sbi, INLINE_DENTRY);
1595 set_opt(sbi, EXTENT_CACHE);
1596 set_opt(sbi, NOHEAP);
1597 clear_opt(sbi, DISABLE_CHECKPOINT);
1598 F2FS_OPTION(sbi).unusable_cap = 0;
1599 sbi->sb->s_flags |= SB_LAZYTIME;
1600 set_opt(sbi, FLUSH_MERGE);
1601 set_opt(sbi, DISCARD);
1602 if (f2fs_sb_has_blkzoned(sbi))
1589 set_opt_mode(sbi, F2FS_MOUNT_LFS);
1603 F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
1590 else
1604 else
1591 set_opt_mode(sbi, F2FS_MOUNT_ADAPTIVE);
1605 F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
1592
1593#ifdef CONFIG_F2FS_FS_XATTR
1594 set_opt(sbi, XATTR_USER);
1595#endif
1596#ifdef CONFIG_F2FS_FS_POSIX_ACL
1597 set_opt(sbi, POSIX_ACL);
1598#endif
1599

--- 52 unchanged lines hidden (view full) ---

1652
1653 spin_lock(&sbi->stat_lock);
1654 sbi->unusable_block_count = unusable;
1655 spin_unlock(&sbi->stat_lock);
1656
1657out_unlock:
1658 up_write(&sbi->gc_lock);
1659restore_flag:
1606
1607#ifdef CONFIG_F2FS_FS_XATTR
1608 set_opt(sbi, XATTR_USER);
1609#endif
1610#ifdef CONFIG_F2FS_FS_POSIX_ACL
1611 set_opt(sbi, POSIX_ACL);
1612#endif
1613

--- 52 unchanged lines hidden (view full) ---

1666
1667 spin_lock(&sbi->stat_lock);
1668 sbi->unusable_block_count = unusable;
1669 spin_unlock(&sbi->stat_lock);
1670
1671out_unlock:
1672 up_write(&sbi->gc_lock);
1673restore_flag:
1660 sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1674 sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
1661 return err;
1662}
1663
1664static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
1665{
1666 down_write(&sbi->gc_lock);
1667 f2fs_dirty_to_prefree(sbi);
1668

--- 106 unchanged lines hidden (view full) ---

1775 goto restore_opts;
1776 }
1777
1778 /*
1779 * We stop the GC thread if FS is mounted as RO
1780 * or if background_gc = off is passed in mount
1781 * option. Also sync the filesystem.
1782 */
1675 return err;
1676}
1677
1678static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
1679{
1680 down_write(&sbi->gc_lock);
1681 f2fs_dirty_to_prefree(sbi);
1682

--- 106 unchanged lines hidden (view full) ---

1789 goto restore_opts;
1790 }
1791
1792 /*
1793 * We stop the GC thread if FS is mounted as RO
1794 * or if background_gc = off is passed in mount
1795 * option. Also sync the filesystem.
1796 */
1783 if ((*flags & SB_RDONLY) || !test_opt(sbi, BG_GC)) {
1797 if ((*flags & SB_RDONLY) ||
1798 F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) {
1784 if (sbi->gc_thread) {
1785 f2fs_stop_gc_thread(sbi);
1786 need_restart_gc = true;
1787 }
1788 } else if (!sbi->gc_thread) {
1789 err = f2fs_start_gc_thread(sbi);
1790 if (err)
1791 goto restore_opts;

--- 39 unchanged lines hidden (view full) ---

1831 for (i = 0; i < MAXQUOTAS; i++)
1832 kvfree(org_mount_opt.s_qf_names[i]);
1833#endif
1834 /* Update the POSIXACL Flag */
1835 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
1836 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
1837
1838 limit_reserve_root(sbi);
1799 if (sbi->gc_thread) {
1800 f2fs_stop_gc_thread(sbi);
1801 need_restart_gc = true;
1802 }
1803 } else if (!sbi->gc_thread) {
1804 err = f2fs_start_gc_thread(sbi);
1805 if (err)
1806 goto restore_opts;

--- 39 unchanged lines hidden (view full) ---

1846 for (i = 0; i < MAXQUOTAS; i++)
1847 kvfree(org_mount_opt.s_qf_names[i]);
1848#endif
1849 /* Update the POSIXACL Flag */
1850 sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
1851 (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
1852
1853 limit_reserve_root(sbi);
1854 adjust_unusable_cap_perc(sbi);
1839 *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
1840 return 0;
1841restore_gc:
1842 if (need_restart_gc) {
1843 if (f2fs_start_gc_thread(sbi))
1844 f2fs_warn(sbi, "background gc thread has stopped");
1845 } else if (need_stop_gc) {
1846 f2fs_stop_gc_thread(sbi);

--- 33 unchanged lines hidden (view full) ---

1880 len = i_size - off;
1881 toread = len;
1882 while (toread > 0) {
1883 tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
1884repeat:
1885 page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
1886 if (IS_ERR(page)) {
1887 if (PTR_ERR(page) == -ENOMEM) {
1855 *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
1856 return 0;
1857restore_gc:
1858 if (need_restart_gc) {
1859 if (f2fs_start_gc_thread(sbi))
1860 f2fs_warn(sbi, "background gc thread has stopped");
1861 } else if (need_stop_gc) {
1862 f2fs_stop_gc_thread(sbi);

--- 33 unchanged lines hidden (view full) ---

1896 len = i_size - off;
1897 toread = len;
1898 while (toread > 0) {
1899 tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
1900repeat:
1901 page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
1902 if (IS_ERR(page)) {
1903 if (PTR_ERR(page) == -ENOMEM) {
1888 congestion_wait(BLK_RW_ASYNC, HZ/50);
1904 congestion_wait(BLK_RW_ASYNC,
1905 DEFAULT_IO_TIMEOUT);
1889 goto repeat;
1890 }
1891 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
1892 return PTR_ERR(page);
1893 }
1894
1895 lock_page(page);
1896

--- 25 unchanged lines hidden (view full) ---

1922 const char *data, size_t len, loff_t off)
1923{
1924 struct inode *inode = sb_dqopt(sb)->files[type];
1925 struct address_space *mapping = inode->i_mapping;
1926 const struct address_space_operations *a_ops = mapping->a_ops;
1927 int offset = off & (sb->s_blocksize - 1);
1928 size_t towrite = len;
1929 struct page *page;
1906 goto repeat;
1907 }
1908 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
1909 return PTR_ERR(page);
1910 }
1911
1912 lock_page(page);
1913

--- 25 unchanged lines hidden (view full) ---

1939 const char *data, size_t len, loff_t off)
1940{
1941 struct inode *inode = sb_dqopt(sb)->files[type];
1942 struct address_space *mapping = inode->i_mapping;
1943 const struct address_space_operations *a_ops = mapping->a_ops;
1944 int offset = off & (sb->s_blocksize - 1);
1945 size_t towrite = len;
1946 struct page *page;
1947 void *fsdata = NULL;
1930 char *kaddr;
1931 int err = 0;
1932 int tocopy;
1933
1934 while (towrite > 0) {
1935 tocopy = min_t(unsigned long, sb->s_blocksize - offset,
1936 towrite);
1937retry:
1938 err = a_ops->write_begin(NULL, mapping, off, tocopy, 0,
1948 char *kaddr;
1949 int err = 0;
1950 int tocopy;
1951
1952 while (towrite > 0) {
1953 tocopy = min_t(unsigned long, sb->s_blocksize - offset,
1954 towrite);
1955retry:
1956 err = a_ops->write_begin(NULL, mapping, off, tocopy, 0,
1939 &page, NULL);
1957 &page, &fsdata);
1940 if (unlikely(err)) {
1941 if (err == -ENOMEM) {
1958 if (unlikely(err)) {
1959 if (err == -ENOMEM) {
1942 congestion_wait(BLK_RW_ASYNC, HZ/50);
1960 congestion_wait(BLK_RW_ASYNC,
1961 DEFAULT_IO_TIMEOUT);
1943 goto retry;
1944 }
1945 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
1946 break;
1947 }
1948
1949 kaddr = kmap_atomic(page);
1950 memcpy(kaddr + offset, data, tocopy);
1951 kunmap_atomic(kaddr);
1952 flush_dcache_page(page);
1953
1954 a_ops->write_end(NULL, mapping, off, tocopy, tocopy,
1962 goto retry;
1963 }
1964 set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
1965 break;
1966 }
1967
1968 kaddr = kmap_atomic(page);
1969 memcpy(kaddr + offset, data, tocopy);
1970 kunmap_atomic(kaddr);
1971 flush_dcache_page(page);
1972
1973 a_ops->write_end(NULL, mapping, off, tocopy, tocopy,
1955 page, NULL);
1974 page, fsdata);
1956 offset = 0;
1957 towrite -= tocopy;
1958 off += tocopy;
1959 data += tocopy;
1960 cond_resched();
1961 }
1962
1963 if (len == towrite)

--- 1045 unchanged lines hidden (view full) ---

3009 __ilog2_u32(sbi->blocks_per_blkz))
3010 return -EINVAL;
3011 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
3012 FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
3013 sbi->log_blocks_per_blkz;
3014 if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
3015 FDEV(devi).nr_blkz++;
3016
1975 offset = 0;
1976 towrite -= tocopy;
1977 off += tocopy;
1978 data += tocopy;
1979 cond_resched();
1980 }
1981
1982 if (len == towrite)

--- 1045 unchanged lines hidden (view full) ---

3028 __ilog2_u32(sbi->blocks_per_blkz))
3029 return -EINVAL;
3030 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
3031 FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
3032 sbi->log_blocks_per_blkz;
3033 if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
3034 FDEV(devi).nr_blkz++;
3035
3017 FDEV(devi).blkz_seq = f2fs_kzalloc(sbi,
3036 FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
3018 BITS_TO_LONGS(FDEV(devi).nr_blkz)
3019 * sizeof(unsigned long),
3020 GFP_KERNEL);
3021 if (!FDEV(devi).blkz_seq)
3022 return -ENOMEM;
3023
3024 /* Get block zones type */
3025 ret = blkdev_report_zones(bdev, 0, BLK_ALL_ZONES, f2fs_report_zone_cb,

--- 370 unchanged lines hidden (view full) ---

3396 memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
3397 sb->s_iflags |= SB_I_CGROUPWB;
3398
3399 /* init f2fs-specific super block info */
3400 sbi->valid_super_block = valid_super_block;
3401 init_rwsem(&sbi->gc_lock);
3402 mutex_init(&sbi->writepages);
3403 mutex_init(&sbi->cp_mutex);
3037 BITS_TO_LONGS(FDEV(devi).nr_blkz)
3038 * sizeof(unsigned long),
3039 GFP_KERNEL);
3040 if (!FDEV(devi).blkz_seq)
3041 return -ENOMEM;
3042
3043 /* Get block zones type */
3044 ret = blkdev_report_zones(bdev, 0, BLK_ALL_ZONES, f2fs_report_zone_cb,

--- 370 unchanged lines hidden (view full) ---

3415 memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
3416 sb->s_iflags |= SB_I_CGROUPWB;
3417
3418 /* init f2fs-specific super block info */
3419 sbi->valid_super_block = valid_super_block;
3420 init_rwsem(&sbi->gc_lock);
3421 mutex_init(&sbi->writepages);
3422 mutex_init(&sbi->cp_mutex);
3404 mutex_init(&sbi->resize_mutex);
3405 init_rwsem(&sbi->node_write);
3406 init_rwsem(&sbi->node_change);
3407
3408 /* disallow all the data/node/meta page writes */
3409 set_sbi_flag(sbi, SBI_POR_DOING);
3410 spin_lock_init(&sbi->stat_lock);
3411
3412 /* init iostat info */
3413 spin_lock_init(&sbi->iostat_lock);
3414 sbi->iostat_enable = false;
3423 init_rwsem(&sbi->node_write);
3424 init_rwsem(&sbi->node_change);
3425
3426 /* disallow all the data/node/meta page writes */
3427 set_sbi_flag(sbi, SBI_POR_DOING);
3428 spin_lock_init(&sbi->stat_lock);
3429
3430 /* init iostat info */
3431 spin_lock_init(&sbi->iostat_lock);
3432 sbi->iostat_enable = false;
3433 sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS;
3415
3416 for (i = 0; i < NR_PAGE_TYPE; i++) {
3417 int n = (i == META) ? 1: NR_TEMP_TYPE;
3418 int j;
3419
3420 sbi->write_io[i] =
3421 f2fs_kmalloc(sbi,
3422 array_size(n,

--- 28 unchanged lines hidden (view full) ---

3451 sbi->write_io_dummy =
3452 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
3453 if (!sbi->write_io_dummy) {
3454 err = -ENOMEM;
3455 goto free_percpu;
3456 }
3457 }
3458
3434
3435 for (i = 0; i < NR_PAGE_TYPE; i++) {
3436 int n = (i == META) ? 1: NR_TEMP_TYPE;
3437 int j;
3438
3439 sbi->write_io[i] =
3440 f2fs_kmalloc(sbi,
3441 array_size(n,

--- 28 unchanged lines hidden (view full) ---

3470 sbi->write_io_dummy =
3471 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
3472 if (!sbi->write_io_dummy) {
3473 err = -ENOMEM;
3474 goto free_percpu;
3475 }
3476 }
3477
3478 /* init per sbi slab cache */
3479 err = f2fs_init_xattr_caches(sbi);
3480 if (err)
3481 goto free_io_dummy;
3482
3459 /* get an inode for meta space */
3460 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
3461 if (IS_ERR(sbi->meta_inode)) {
3462 f2fs_err(sbi, "Failed to read F2FS meta data inode");
3463 err = PTR_ERR(sbi->meta_inode);
3483 /* get an inode for meta space */
3484 sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
3485 if (IS_ERR(sbi->meta_inode)) {
3486 f2fs_err(sbi, "Failed to read F2FS meta data inode");
3487 err = PTR_ERR(sbi->meta_inode);
3464 goto free_io_dummy;
3488 goto free_xattr_cache;
3465 }
3466
3467 err = f2fs_get_valid_checkpoint(sbi);
3468 if (err) {
3469 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
3470 goto free_meta_inode;
3471 }
3472

--- 26 unchanged lines hidden (view full) ---

3499 le32_to_cpu(sbi->ckpt->valid_inode_count));
3500 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
3501 sbi->total_valid_block_count =
3502 le64_to_cpu(sbi->ckpt->valid_block_count);
3503 sbi->last_valid_block_count = sbi->total_valid_block_count;
3504 sbi->reserved_blocks = 0;
3505 sbi->current_reserved_blocks = 0;
3506 limit_reserve_root(sbi);
3489 }
3490
3491 err = f2fs_get_valid_checkpoint(sbi);
3492 if (err) {
3493 f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
3494 goto free_meta_inode;
3495 }
3496

--- 26 unchanged lines hidden (view full) ---

3523 le32_to_cpu(sbi->ckpt->valid_inode_count));
3524 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
3525 sbi->total_valid_block_count =
3526 le64_to_cpu(sbi->ckpt->valid_block_count);
3527 sbi->last_valid_block_count = sbi->total_valid_block_count;
3528 sbi->reserved_blocks = 0;
3529 sbi->current_reserved_blocks = 0;
3530 limit_reserve_root(sbi);
3531 adjust_unusable_cap_perc(sbi);
3507
3508 for (i = 0; i < NR_INODE_TYPE; i++) {
3509 INIT_LIST_HEAD(&sbi->inode_list[i]);
3510 spin_lock_init(&sbi->inode_lock[i]);
3511 }
3512 mutex_init(&sbi->flush_lock);
3513
3514 f2fs_init_extent_cache_info(sbi);

--- 69 unchanged lines hidden (view full) ---

3584#ifdef CONFIG_QUOTA
3585 /* Enable quota usage during mount */
3586 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
3587 err = f2fs_enable_quotas(sb);
3588 if (err)
3589 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
3590 }
3591#endif
3532
3533 for (i = 0; i < NR_INODE_TYPE; i++) {
3534 INIT_LIST_HEAD(&sbi->inode_list[i]);
3535 spin_lock_init(&sbi->inode_lock[i]);
3536 }
3537 mutex_init(&sbi->flush_lock);
3538
3539 f2fs_init_extent_cache_info(sbi);

--- 69 unchanged lines hidden (view full) ---

3609#ifdef CONFIG_QUOTA
3610 /* Enable quota usage during mount */
3611 if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
3612 err = f2fs_enable_quotas(sb);
3613 if (err)
3614 f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
3615 }
3616#endif
3592 /* if there are nt orphan nodes free them */
3617 /* if there are any orphan inodes, free them */
3593 err = f2fs_recover_orphan_inodes(sbi);
3594 if (err)
3595 goto free_meta;
3596
3597 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3598 goto reset_checkpoint;
3599
3600 /* recover fsynced data */
3618 err = f2fs_recover_orphan_inodes(sbi);
3619 if (err)
3620 goto free_meta;
3621
3622 if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
3623 goto reset_checkpoint;
3624
3625 /* recover fsynced data */
3601 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
3626 if (!test_opt(sbi, DISABLE_ROLL_FORWARD) &&
3627 !test_opt(sbi, NORECOVERY)) {
3602 /*
3603 * mount should be failed, when device has readonly mode, and
3604 * previous checkpoint was not done by clean system shutdown.
3605 */
3606 if (f2fs_hw_is_readonly(sbi)) {
3607 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3608 err = -EROFS;
3609 f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");

--- 49 unchanged lines hidden (view full) ---

3659 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
3660 f2fs_enable_checkpoint(sbi);
3661 }
3662
3663 /*
3664 * If filesystem is not mounted as read-only then
3665 * do start the gc_thread.
3666 */
3628 /*
3629 * mount should be failed, when device has readonly mode, and
3630 * previous checkpoint was not done by clean system shutdown.
3631 */
3632 if (f2fs_hw_is_readonly(sbi)) {
3633 if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
3634 err = -EROFS;
3635 f2fs_err(sbi, "Need to recover fsync data, but write access unavailable");

--- 49 unchanged lines hidden (view full) ---

3685 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
3686 f2fs_enable_checkpoint(sbi);
3687 }
3688
3689 /*
3690 * If filesystem is not mounted as read-only then
3691 * do start the gc_thread.
3692 */
3667 if (test_opt(sbi, BG_GC) && !f2fs_readonly(sb)) {
3693 if (F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF && !f2fs_readonly(sb)) {
3668 /* After POR, we can run background GC thread.*/
3669 err = f2fs_start_gc_thread(sbi);
3670 if (err)
3671 goto sync_free_meta;
3672 }
3673 kvfree(options);
3674
3675 /* recover broken superblock */

--- 52 unchanged lines hidden (view full) ---

3728 f2fs_destroy_post_read_wq(sbi);
3729free_devices:
3730 destroy_device_list(sbi);
3731 kvfree(sbi->ckpt);
3732free_meta_inode:
3733 make_bad_inode(sbi->meta_inode);
3734 iput(sbi->meta_inode);
3735 sbi->meta_inode = NULL;
3694 /* After POR, we can run background GC thread.*/
3695 err = f2fs_start_gc_thread(sbi);
3696 if (err)
3697 goto sync_free_meta;
3698 }
3699 kvfree(options);
3700
3701 /* recover broken superblock */

--- 52 unchanged lines hidden (view full) ---

3754 f2fs_destroy_post_read_wq(sbi);
3755free_devices:
3756 destroy_device_list(sbi);
3757 kvfree(sbi->ckpt);
3758free_meta_inode:
3759 make_bad_inode(sbi->meta_inode);
3760 iput(sbi->meta_inode);
3761 sbi->meta_inode = NULL;
3762free_xattr_cache:
3763 f2fs_destroy_xattr_caches(sbi);
3736free_io_dummy:
3737 mempool_destroy(sbi->write_io_dummy);
3738free_percpu:
3739 destroy_percpu_info(sbi);
3740free_bio_info:
3741 for (i = 0; i < NR_PAGE_TYPE; i++)
3742 kvfree(sbi->write_io[i]);
3743

--- 121 unchanged lines hidden (view full) ---

3865 if (err)
3866 goto free_root_stats;
3867 err = f2fs_init_bio_entry_cache();
3868 if (err)
3869 goto free_post_read;
3870 err = f2fs_init_bioset();
3871 if (err)
3872 goto free_bio_enrty_cache;
3764free_io_dummy:
3765 mempool_destroy(sbi->write_io_dummy);
3766free_percpu:
3767 destroy_percpu_info(sbi);
3768free_bio_info:
3769 for (i = 0; i < NR_PAGE_TYPE; i++)
3770 kvfree(sbi->write_io[i]);
3771

--- 121 unchanged lines hidden (view full) ---

3893 if (err)
3894 goto free_root_stats;
3895 err = f2fs_init_bio_entry_cache();
3896 if (err)
3897 goto free_post_read;
3898 err = f2fs_init_bioset();
3899 if (err)
3900 goto free_bio_enrty_cache;
3901 err = f2fs_init_compress_mempool();
3902 if (err)
3903 goto free_bioset;
3873 return 0;
3904 return 0;
3905free_bioset:
3906 f2fs_destroy_bioset();
3874free_bio_enrty_cache:
3875 f2fs_destroy_bio_entry_cache();
3876free_post_read:
3877 f2fs_destroy_post_read_processing();
3878free_root_stats:
3879 f2fs_destroy_root_stats();
3880 unregister_filesystem(&f2fs_fs_type);
3881free_shrinker:

--- 11 unchanged lines hidden (view full) ---

3893free_inodecache:
3894 destroy_inodecache();
3895fail:
3896 return err;
3897}
3898
3899static void __exit exit_f2fs_fs(void)
3900{
3907free_bio_enrty_cache:
3908 f2fs_destroy_bio_entry_cache();
3909free_post_read:
3910 f2fs_destroy_post_read_processing();
3911free_root_stats:
3912 f2fs_destroy_root_stats();
3913 unregister_filesystem(&f2fs_fs_type);
3914free_shrinker:

--- 11 unchanged lines hidden (view full) ---

3926free_inodecache:
3927 destroy_inodecache();
3928fail:
3929 return err;
3930}
3931
3932static void __exit exit_f2fs_fs(void)
3933{
3934 f2fs_destroy_compress_mempool();
3901 f2fs_destroy_bioset();
3902 f2fs_destroy_bio_entry_cache();
3903 f2fs_destroy_post_read_processing();
3904 f2fs_destroy_root_stats();
3905 unregister_filesystem(&f2fs_fs_type);
3906 unregister_shrinker(&f2fs_shrinker_info);
3907 f2fs_exit_sysfs();
3908 f2fs_destroy_extent_cache();

--- 14 unchanged lines hidden ---
3935 f2fs_destroy_bioset();
3936 f2fs_destroy_bio_entry_cache();
3937 f2fs_destroy_post_read_processing();
3938 f2fs_destroy_root_stats();
3939 unregister_filesystem(&f2fs_fs_type);
3940 unregister_shrinker(&f2fs_shrinker_info);
3941 f2fs_exit_sysfs();
3942 f2fs_destroy_extent_cache();

--- 14 unchanged lines hidden ---