7c1a000d46623 (Chao Yu 2018-09-12 09:16:07 +0800 1) // SPDX-License-Identifier: GPL-2.0
0a8165d7c2cf1 (Jaegeuk Kim 2012-11-29 13:28:09 +0900 2) /*
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3) * fs/f2fs/super.c
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4) *
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 5) * Copyright (c) 2012 Samsung Electronics Co., Ltd.
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 6) * http://www.samsung.com/
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 7) */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 8) #include <linux/module.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 9) #include <linux/init.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 10) #include <linux/fs.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 11) #include <linux/statfs.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 12) #include <linux/buffer_head.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 13) #include <linux/backing-dev.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 14) #include <linux/kthread.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 15) #include <linux/parser.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 16) #include <linux/mount.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 17) #include <linux/seq_file.h>
5e176d54a6097 (Jaegeuk Kim 2013-06-28 12:47:01 +0900 18) #include <linux/proc_fs.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 19) #include <linux/random.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 20) #include <linux/exportfs.h>
d3ee456dfbed1 (Namjae Jeon 2013-03-17 17:26:14 +0900 21) #include <linux/blkdev.h>
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 22) #include <linux/quotaops.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 23) #include <linux/f2fs_fs.h>
b59d0bae6ca30 (Namjae Jeon 2013-08-04 23:09:40 +0900 24) #include <linux/sysfs.h>
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 25) #include <linux/quota.h>
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 26) #include <linux/unicode.h>
c6a564ffadc91 (Christoph Hellwig 2020-03-25 16:48:42 +0100 27) #include <linux/part_stat.h>
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 28) #include <linux/zstd.h>
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 29) #include <linux/lz4.h>
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 30)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 31) #include "f2fs.h"
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 32) #include "node.h"
5ec4e49f9bd75 (Jaegeuk Kim 2013-03-31 13:26:03 +0900 33) #include "segment.h"
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 34) #include "xattr.h"
b59d0bae6ca30 (Namjae Jeon 2013-08-04 23:09:40 +0900 35) #include "gc.h"
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 36)
a2a4a7e4abb27 (Namjae Jeon 2013-04-20 01:28:40 +0900 37) #define CREATE_TRACE_POINTS
a2a4a7e4abb27 (Namjae Jeon 2013-04-20 01:28:40 +0900 38) #include <trace/events/f2fs.h>
a2a4a7e4abb27 (Namjae Jeon 2013-04-20 01:28:40 +0900 39)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 40) static struct kmem_cache *f2fs_inode_cachep;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 41)
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 42) #ifdef CONFIG_F2FS_FAULT_INJECTION
2c63fead9e372 (Jaegeuk Kim 2016-04-29 15:49:56 -0700 43)
19880e6e5ff3b (Alexey Dobriyan 2018-11-24 12:06:42 +0300 44) const char *f2fs_fault_name[FAULT_MAX] = {
2c63fead9e372 (Jaegeuk Kim 2016-04-29 15:49:56 -0700 45) [FAULT_KMALLOC] = "kmalloc",
628b3d1438fbc (Chao Yu 2017-11-30 19:28:18 +0800 46) [FAULT_KVMALLOC] = "kvmalloc",
c41f3cc3ae34a (Jaegeuk Kim 2016-04-29 16:17:09 -0700 47) [FAULT_PAGE_ALLOC] = "page alloc",
01eccef7930f1 (Chao Yu 2017-10-28 16:52:30 +0800 48) [FAULT_PAGE_GET] = "page get",
cb78942b82138 (Jaegeuk Kim 2016-04-29 16:29:22 -0700 49) [FAULT_ALLOC_NID] = "alloc nid",
cb78942b82138 (Jaegeuk Kim 2016-04-29 16:29:22 -0700 50) [FAULT_ORPHAN] = "orphan",
cb78942b82138 (Jaegeuk Kim 2016-04-29 16:29:22 -0700 51) [FAULT_BLOCK] = "no more block",
cb78942b82138 (Jaegeuk Kim 2016-04-29 16:29:22 -0700 52) [FAULT_DIR_DEPTH] = "too big dir depth",
53aa6bbfdaae6 (Jaegeuk Kim 2016-05-25 15:24:18 -0700 53) [FAULT_EVICT_INODE] = "evict_inode fail",
14b44d238ce74 (Jaegeuk Kim 2017-03-09 15:24:24 -0800 54) [FAULT_TRUNCATE] = "truncate fail",
6f5c2ed0a26fa (Chao Yu 2018-09-12 09:22:29 +0800 55) [FAULT_READ_IO] = "read IO error",
0f34802858e74 (Chao Yu 2016-09-26 19:45:55 +0800 56) [FAULT_CHECKPOINT] = "checkpoint error",
b83dcfe67142e (Chao Yu 2018-08-06 20:30:18 +0800 57) [FAULT_DISCARD] = "discard error",
6f5c2ed0a26fa (Chao Yu 2018-09-12 09:22:29 +0800 58) [FAULT_WRITE_IO] = "write IO error",
2c63fead9e372 (Jaegeuk Kim 2016-04-29 15:49:56 -0700 59) };
087968974fcd9 (Sheng Yong 2016-05-16 12:38:50 +0800 60)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 61) void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 62) unsigned int type)
087968974fcd9 (Sheng Yong 2016-05-16 12:38:50 +0800 63) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 64) struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
1ecc0c5c50ce8 (Chao Yu 2016-09-23 21:30:09 +0800 65)
087968974fcd9 (Sheng Yong 2016-05-16 12:38:50 +0800 66) if (rate) {
1ecc0c5c50ce8 (Chao Yu 2016-09-23 21:30:09 +0800 67) atomic_set(&ffi->inject_ops, 0);
1ecc0c5c50ce8 (Chao Yu 2016-09-23 21:30:09 +0800 68) ffi->inject_rate = rate;
087968974fcd9 (Sheng Yong 2016-05-16 12:38:50 +0800 69) }
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 70)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 71) if (type)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 72) ffi->inject_type = type;
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 73)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 74) if (!rate && !type)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 75) memset(ffi, 0, sizeof(struct f2fs_fault_info));
087968974fcd9 (Sheng Yong 2016-05-16 12:38:50 +0800 76) }
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 77) #endif
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 78)
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 79) /* f2fs-wide shrinker description */
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 80) static struct shrinker f2fs_shrinker_info = {
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 81) .scan_objects = f2fs_shrink_scan,
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 82) .count_objects = f2fs_shrink_count,
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 83) .seeks = DEFAULT_SEEKS,
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 84) };
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 85)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 86) enum {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 87) Opt_gc_background,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 88) Opt_disable_roll_forward,
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 89) Opt_norecovery,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 90) Opt_discard,
64058be9c8e35 (Chao Yu 2016-07-03 22:05:14 +0800 91) Opt_nodiscard,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 92) Opt_noheap,
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 93) Opt_heap,
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 94) Opt_user_xattr,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 95) Opt_nouser_xattr,
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 96) Opt_acl,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 97) Opt_noacl,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 98) Opt_active_logs,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 99) Opt_disable_ext_identify,
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 100) Opt_inline_xattr,
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 101) Opt_noinline_xattr,
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 102) Opt_inline_xattr_size,
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 103) Opt_inline_data,
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 104) Opt_inline_dentry,
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 105) Opt_noinline_dentry,
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 106) Opt_flush_merge,
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 107) Opt_noflush_merge,
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 108) Opt_nobarrier,
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 109) Opt_fastboot,
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 110) Opt_extent_cache,
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 111) Opt_noextent_cache,
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 112) Opt_noinline_data,
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 113) Opt_data_flush,
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 114) Opt_reserve_root,
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 115) Opt_resgid,
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 116) Opt_resuid,
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 117) Opt_mode,
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 118) Opt_io_size_bits,
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 119) Opt_fault_injection,
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 120) Opt_fault_type,
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 121) Opt_lazytime,
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 122) Opt_nolazytime,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 123) Opt_quota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 124) Opt_noquota,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 125) Opt_usrquota,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 126) Opt_grpquota,
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 127) Opt_prjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 128) Opt_usrjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 129) Opt_grpjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 130) Opt_prjjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 131) Opt_offusrjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 132) Opt_offgrpjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 133) Opt_offprjjquota,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 134) Opt_jqfmt_vfsold,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 135) Opt_jqfmt_vfsv0,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 136) Opt_jqfmt_vfsv1,
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 137) Opt_whint,
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 138) Opt_alloc,
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 139) Opt_fsync,
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 140) Opt_test_dummy_encryption,
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 141) Opt_inlinecrypt,
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 142) Opt_checkpoint_disable,
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 143) Opt_checkpoint_disable_cap,
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 144) Opt_checkpoint_disable_cap_perc,
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 145) Opt_checkpoint_enable,
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 146) Opt_checkpoint_merge,
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 147) Opt_nocheckpoint_merge,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 148) Opt_compress_algorithm,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 149) Opt_compress_log_size,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 150) Opt_compress_extension,
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 151) Opt_compress_chksum,
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 152) Opt_compress_mode,
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 153) Opt_atgc,
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 154) Opt_gc_merge,
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 155) Opt_nogc_merge,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 156) Opt_err,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 157) };
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 158)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 159) static match_table_t f2fs_tokens = {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 160) {Opt_gc_background, "background_gc=%s"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 161) {Opt_disable_roll_forward, "disable_roll_forward"},
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 162) {Opt_norecovery, "norecovery"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 163) {Opt_discard, "discard"},
64058be9c8e35 (Chao Yu 2016-07-03 22:05:14 +0800 164) {Opt_nodiscard, "nodiscard"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 165) {Opt_noheap, "no_heap"},
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 166) {Opt_heap, "heap"},
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 167) {Opt_user_xattr, "user_xattr"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 168) {Opt_nouser_xattr, "nouser_xattr"},
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 169) {Opt_acl, "acl"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 170) {Opt_noacl, "noacl"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 171) {Opt_active_logs, "active_logs=%u"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 172) {Opt_disable_ext_identify, "disable_ext_identify"},
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 173) {Opt_inline_xattr, "inline_xattr"},
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 174) {Opt_noinline_xattr, "noinline_xattr"},
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 175) {Opt_inline_xattr_size, "inline_xattr_size=%u"},
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 176) {Opt_inline_data, "inline_data"},
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 177) {Opt_inline_dentry, "inline_dentry"},
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 178) {Opt_noinline_dentry, "noinline_dentry"},
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 179) {Opt_flush_merge, "flush_merge"},
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 180) {Opt_noflush_merge, "noflush_merge"},
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 181) {Opt_nobarrier, "nobarrier"},
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 182) {Opt_fastboot, "fastboot"},
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 183) {Opt_extent_cache, "extent_cache"},
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 184) {Opt_noextent_cache, "noextent_cache"},
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 185) {Opt_noinline_data, "noinline_data"},
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 186) {Opt_data_flush, "data_flush"},
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 187) {Opt_reserve_root, "reserve_root=%u"},
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 188) {Opt_resgid, "resgid=%u"},
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 189) {Opt_resuid, "resuid=%u"},
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 190) {Opt_mode, "mode=%s"},
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 191) {Opt_io_size_bits, "io_bits=%u"},
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 192) {Opt_fault_injection, "fault_injection=%u"},
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 193) {Opt_fault_type, "fault_type=%u"},
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 194) {Opt_lazytime, "lazytime"},
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 195) {Opt_nolazytime, "nolazytime"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 196) {Opt_quota, "quota"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 197) {Opt_noquota, "noquota"},
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 198) {Opt_usrquota, "usrquota"},
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 199) {Opt_grpquota, "grpquota"},
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 200) {Opt_prjquota, "prjquota"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 201) {Opt_usrjquota, "usrjquota=%s"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 202) {Opt_grpjquota, "grpjquota=%s"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 203) {Opt_prjjquota, "prjjquota=%s"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 204) {Opt_offusrjquota, "usrjquota="},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 205) {Opt_offgrpjquota, "grpjquota="},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 206) {Opt_offprjjquota, "prjjquota="},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 207) {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 208) {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 209) {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 210) {Opt_whint, "whint_mode=%s"},
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 211) {Opt_alloc, "alloc_mode=%s"},
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 212) {Opt_fsync, "fsync_mode=%s"},
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 213) {Opt_test_dummy_encryption, "test_dummy_encryption=%s"},
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 214) {Opt_test_dummy_encryption, "test_dummy_encryption"},
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 215) {Opt_inlinecrypt, "inlinecrypt"},
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 216) {Opt_checkpoint_disable, "checkpoint=disable"},
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 217) {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"},
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 218) {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"},
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 219) {Opt_checkpoint_enable, "checkpoint=enable"},
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 220) {Opt_checkpoint_merge, "checkpoint_merge"},
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 221) {Opt_nocheckpoint_merge, "nocheckpoint_merge"},
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 222) {Opt_compress_algorithm, "compress_algorithm=%s"},
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 223) {Opt_compress_log_size, "compress_log_size=%u"},
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 224) {Opt_compress_extension, "compress_extension=%s"},
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 225) {Opt_compress_chksum, "compress_chksum"},
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 226) {Opt_compress_mode, "compress_mode=%s"},
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 227) {Opt_atgc, "atgc"},
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 228) {Opt_gc_merge, "gc_merge"},
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 229) {Opt_nogc_merge, "nogc_merge"},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 230) {Opt_err, NULL},
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 231) };
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 232)
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 233) void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...)
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 234) {
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 235) struct va_format vaf;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 236) va_list args;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 237) int level;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 238)
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 239) va_start(args, fmt);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 240)
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 241) level = printk_get_level(fmt);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 242) vaf.fmt = printk_skip_level(fmt);
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 243) vaf.va = &args;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 244) printk("%c%cF2FS-fs (%s): %pV\n",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 245) KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 246)
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 247) va_end(args);
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 248) }
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 249)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 250) #ifdef CONFIG_UNICODE
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 251) static const struct f2fs_sb_encodings {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 252) __u16 magic;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 253) char *name;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 254) char *version;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 255) } f2fs_sb_encoding_map[] = {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 256) {F2FS_ENC_UTF8_12_1, "utf8", "12.1.0"},
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 257) };
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 258)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 259) static int f2fs_sb_read_encoding(const struct f2fs_super_block *sb,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 260) const struct f2fs_sb_encodings **encoding,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 261) __u16 *flags)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 262) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 263) __u16 magic = le16_to_cpu(sb->s_encoding);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 264) int i;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 265)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 266) for (i = 0; i < ARRAY_SIZE(f2fs_sb_encoding_map); i++)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 267) if (magic == f2fs_sb_encoding_map[i].magic)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 268) break;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 269)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 270) if (i >= ARRAY_SIZE(f2fs_sb_encoding_map))
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 271) return -EINVAL;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 272)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 273) *encoding = &f2fs_sb_encoding_map[i];
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 274) *flags = le16_to_cpu(sb->s_encoding_flags);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 275)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 276) return 0;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 277) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 278) #endif
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 279)
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 280) static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 281) {
9a9aecaad92d4 (Daniel Rosenberg 2019-05-29 17:49:04 -0700 282) block_t limit = min((sbi->user_block_count << 1) / 1000,
9a9aecaad92d4 (Daniel Rosenberg 2019-05-29 17:49:04 -0700 283) sbi->user_block_count - sbi->reserved_blocks);
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 284)
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 285) /* limit is 0.2% */
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 286) if (test_opt(sbi, RESERVE_ROOT) &&
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 287) F2FS_OPTION(sbi).root_reserved_blocks > limit) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 288) F2FS_OPTION(sbi).root_reserved_blocks = limit;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 289) f2fs_info(sbi, "Reduce reserved blocks for root = %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 290) F2FS_OPTION(sbi).root_reserved_blocks);
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 291) }
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 292) if (!test_opt(sbi, RESERVE_ROOT) &&
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 293) (!uid_eq(F2FS_OPTION(sbi).s_resuid,
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 294) make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 295) !gid_eq(F2FS_OPTION(sbi).s_resgid,
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 296) make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 297) f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 298) from_kuid_munged(&init_user_ns,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 299) F2FS_OPTION(sbi).s_resuid),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 300) from_kgid_munged(&init_user_ns,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 301) F2FS_OPTION(sbi).s_resgid));
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 302) }
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 303)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 304) static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 305) {
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 306) if (!F2FS_OPTION(sbi).unusable_cap_perc)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 307) return;
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 308)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 309) if (F2FS_OPTION(sbi).unusable_cap_perc == 100)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 310) F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count;
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 311) else
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 312) F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) *
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 313) F2FS_OPTION(sbi).unusable_cap_perc;
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 314)
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 315) f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%",
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 316) F2FS_OPTION(sbi).unusable_cap,
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 317) F2FS_OPTION(sbi).unusable_cap_perc);
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 318) }
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 319)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 320) static void init_once(void *foo)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 321) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 322) struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 323)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 324) inode_init_once(&fi->vfs_inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 325) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 326)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 327) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 328) static const char * const quotatypes[] = INITQFNAMES;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 329) #define QTYPE2NAME(t) (quotatypes[t])
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 330) static int f2fs_set_qf_name(struct super_block *sb, int qtype,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 331) substring_t *args)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 332) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 333) struct f2fs_sb_info *sbi = F2FS_SB(sb);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 334) char *qname;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 335) int ret = -EINVAL;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 336)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 337) if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 338) f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 339) return -EINVAL;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 340) }
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 341) if (f2fs_sb_has_quota_ino(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 342) f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name");
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 343) return 0;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 344) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 345)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 346) qname = match_strdup(args);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 347) if (!qname) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 348) f2fs_err(sbi, "Not enough memory for storing quotafile name");
f365c6cc85b1d (Chengguang Xu 2019-01-01 21:33:11 +0800 349) return -ENOMEM;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 350) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 351) if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 352) if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 353) ret = 0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 354) else
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 355) f2fs_err(sbi, "%s quota file already specified",
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 356) QTYPE2NAME(qtype));
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 357) goto errout;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 358) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 359) if (strchr(qname, '/')) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 360) f2fs_err(sbi, "quotafile must be on filesystem root");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 361) goto errout;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 362) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 363) F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 364) set_opt(sbi, QUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 365) return 0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 366) errout:
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 367) kfree(qname);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 368) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 369) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 370)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 371) static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 372) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 373) struct f2fs_sb_info *sbi = F2FS_SB(sb);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 374)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 375) if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 376) f2fs_err(sbi, "Cannot change journaled quota options when quota turned on");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 377) return -EINVAL;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 378) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 379) kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 380) F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 381) return 0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 382) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 383)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 384) static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 385) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 386) /*
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 387) * We do the test below only for project quotas. 'usrquota' and
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 388) * 'grpquota' mount options are allowed even without quota feature
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 389) * to support legacy quotas in quota files.
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 390) */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 391) if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 392) f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement.");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 393) return -1;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 394) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 395) if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 396) F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 397) F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 398) if (test_opt(sbi, USRQUOTA) &&
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 399) F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 400) clear_opt(sbi, USRQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 401)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 402) if (test_opt(sbi, GRPQUOTA) &&
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 403) F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 404) clear_opt(sbi, GRPQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 405)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 406) if (test_opt(sbi, PRJQUOTA) &&
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 407) F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 408) clear_opt(sbi, PRJQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 409)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 410) if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 411) test_opt(sbi, PRJQUOTA)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 412) f2fs_err(sbi, "old and new quota format mixing");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 413) return -1;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 414) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 415)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 416) if (!F2FS_OPTION(sbi).s_jquota_fmt) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 417) f2fs_err(sbi, "journaled quota format not specified");
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 418) return -1;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 419) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 420) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 421)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 422) if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 423) f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 424) F2FS_OPTION(sbi).s_jquota_fmt = 0;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 425) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 426) return 0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 427) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 428) #endif
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 429)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 430) static int f2fs_set_test_dummy_encryption(struct super_block *sb,
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 431) const char *opt,
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 432) const substring_t *arg,
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 433) bool is_remount)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 434) {
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 435) struct f2fs_sb_info *sbi = F2FS_SB(sb);
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 436) #ifdef CONFIG_FS_ENCRYPTION
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 437) int err;
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 438)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 439) if (!f2fs_sb_has_encrypt(sbi)) {
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 440) f2fs_err(sbi, "Encrypt feature is off");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 441) return -EINVAL;
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 442) }
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 443)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 444) /*
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 445) * This mount option is just for testing, and it's not worthwhile to
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 446) * implement the extra complexity (e.g. RCU protection) that would be
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 447) * needed to allow it to be set or changed during remount. We do allow
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 448) * it to be specified during remount, but only if there is no change.
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 449) */
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 450) if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) {
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 451) f2fs_warn(sbi, "Can't set test_dummy_encryption on remount");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 452) return -EINVAL;
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 453) }
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 454) err = fscrypt_set_test_dummy_encryption(
c8c868abc91ff (Eric Biggers 2020-09-16 21:11:36 -0700 455) sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy);
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 456) if (err) {
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 457) if (err == -EEXIST)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 458) f2fs_warn(sbi,
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 459) "Can't change test_dummy_encryption on remount");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 460) else if (err == -EINVAL)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 461) f2fs_warn(sbi, "Value of option \"%s\" is unrecognized",
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 462) opt);
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 463) else
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 464) f2fs_warn(sbi, "Error processing option \"%s\" [%d]",
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 465) opt, err);
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 466) return -EINVAL;
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 467) }
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 468) f2fs_warn(sbi, "Test dummy encryption mode enabled");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 469) #else
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 470) f2fs_warn(sbi, "Test dummy encryption mount option ignored");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 471) #endif
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 472) return 0;
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 473) }
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 474)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 475) #ifdef CONFIG_F2FS_FS_COMPRESSION
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 476) #ifdef CONFIG_F2FS_FS_LZ4
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 477) static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 478) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 479) #ifdef CONFIG_F2FS_FS_LZ4HC
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 480) unsigned int level;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 481) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 482)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 483) if (strlen(str) == 3) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 484) F2FS_OPTION(sbi).compress_level = 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 485) return 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 486) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 487)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 488) #ifdef CONFIG_F2FS_FS_LZ4HC
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 489) str += 3;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 490)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 491) if (str[0] != ':') {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 492) f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 493) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 494) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 495) if (kstrtouint(str + 1, 10, &level))
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 496) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 497)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 498) if (level < LZ4HC_MIN_CLEVEL || level > LZ4HC_MAX_CLEVEL) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 499) f2fs_info(sbi, "invalid lz4hc compress level: %d", level);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 500) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 501) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 502)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 503) F2FS_OPTION(sbi).compress_level = level;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 504) return 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 505) #else
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 506) f2fs_info(sbi, "kernel doesn't support lz4hc compression");
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 507) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 508) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 509) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 510) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 511)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 512) #ifdef CONFIG_F2FS_FS_ZSTD
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 513) static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 514) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 515) unsigned int level;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 516) int len = 4;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 517)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 518) if (strlen(str) == len) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 519) F2FS_OPTION(sbi).compress_level = 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 520) return 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 521) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 522)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 523) str += len;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 524)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 525) if (str[0] != ':') {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 526) f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>");
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 527) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 528) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 529) if (kstrtouint(str + 1, 10, &level))
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 530) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 531)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 532) if (!level || level > ZSTD_maxCLevel()) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 533) f2fs_info(sbi, "invalid zstd compress level: %d", level);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 534) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 535) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 536)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 537) F2FS_OPTION(sbi).compress_level = level;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 538) return 0;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 539) }
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 540) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 541) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 542)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 543) static int parse_options(struct super_block *sb, char *options, bool is_remount)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 544) {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 545) struct f2fs_sb_info *sbi = F2FS_SB(sb);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 546) substring_t args[MAX_OPT_ARGS];
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 547) #ifdef CONFIG_F2FS_FS_COMPRESSION
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 548) unsigned char (*ext)[F2FS_EXTENSION_LEN];
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 549) int ext_cnt;
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 550) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 551) char *p, *name;
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 552) int arg = 0;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 553) kuid_t uid;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 554) kgid_t gid;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 555) int ret;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 556)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 557) if (!options)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 558) return 0;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 559)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 560) while ((p = strsep(&options, ",")) != NULL) {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 561) int token;
5f029c045c948 (Yi Zhuang 2021-04-06 09:47:35 +0800 562)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 563) if (!*p)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 564) continue;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 565) /*
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 566) * Initialize args struct so we know whether arg was
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 567) * found; some options take optional arguments.
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 568) */
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 569) args[0].to = args[0].from = NULL;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 570) token = match_token(p, f2fs_tokens, args);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 571)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 572) switch (token) {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 573) case Opt_gc_background:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 574) name = match_strdup(&args[0]);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 575)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 576) if (!name)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 577) return -ENOMEM;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 578) if (!strcmp(name, "on")) {
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 579) F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 580) } else if (!strcmp(name, "off")) {
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 581) F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 582) } else if (!strcmp(name, "sync")) {
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 583) F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC;
6aefd93b01379 (Jaegeuk Kim 2015-10-05 11:02:54 -0700 584) } else {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 585) kfree(name);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 586) return -EINVAL;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 587) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 588) kfree(name);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 589) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 590) case Opt_disable_roll_forward:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 591) set_opt(sbi, DISABLE_ROLL_FORWARD);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 592) break;
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 593) case Opt_norecovery:
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 594) /* this option mounts f2fs with ro */
a9117eca1de6b (Chao Yu 2020-02-14 17:45:11 +0800 595) set_opt(sbi, NORECOVERY);
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 596) if (!f2fs_readonly(sb))
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 597) return -EINVAL;
2d834bf9ac8e4 (Jaegeuk Kim 2015-01-23 18:33:46 -0800 598) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 599) case Opt_discard:
7d20c8abb2edc (Chao Yu 2018-09-04 03:52:17 +0800 600) set_opt(sbi, DISCARD);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 601) break;
64058be9c8e35 (Chao Yu 2016-07-03 22:05:14 +0800 602) case Opt_nodiscard:
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 603) if (f2fs_sb_has_blkzoned(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 604) f2fs_warn(sbi, "discard is required for zoned block devices");
96ba2decb4241 (Damien Le Moal 2016-10-28 17:45:03 +0900 605) return -EINVAL;
96ba2decb4241 (Damien Le Moal 2016-10-28 17:45:03 +0900 606) }
64058be9c8e35 (Chao Yu 2016-07-03 22:05:14 +0800 607) clear_opt(sbi, DISCARD);
487df616dec33 (Damien Le Moal 2016-10-28 17:44:59 +0900 608) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 609) case Opt_noheap:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 610) set_opt(sbi, NOHEAP);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 611) break;
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 612) case Opt_heap:
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 613) clear_opt(sbi, NOHEAP);
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 614) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 615) #ifdef CONFIG_F2FS_FS_XATTR
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 616) case Opt_user_xattr:
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 617) set_opt(sbi, XATTR_USER);
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 618) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 619) case Opt_nouser_xattr:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 620) clear_opt(sbi, XATTR_USER);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 621) break;
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 622) case Opt_inline_xattr:
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 623) set_opt(sbi, INLINE_XATTR);
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 624) break;
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 625) case Opt_noinline_xattr:
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 626) clear_opt(sbi, INLINE_XATTR);
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 627) break;
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 628) case Opt_inline_xattr_size:
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 629) if (args->from && match_int(args, &arg))
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 630) return -EINVAL;
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 631) set_opt(sbi, INLINE_XATTR_SIZE);
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 632) F2FS_OPTION(sbi).inline_xattr_size = arg;
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 633) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 634) #else
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 635) case Opt_user_xattr:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 636) f2fs_info(sbi, "user_xattr options not supported");
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 637) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 638) case Opt_nouser_xattr:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 639) f2fs_info(sbi, "nouser_xattr options not supported");
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 640) break;
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 641) case Opt_inline_xattr:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 642) f2fs_info(sbi, "inline_xattr options not supported");
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 643) break;
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 644) case Opt_noinline_xattr:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 645) f2fs_info(sbi, "noinline_xattr options not supported");
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 646) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 647) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 648) #ifdef CONFIG_F2FS_FS_POSIX_ACL
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 649) case Opt_acl:
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 650) set_opt(sbi, POSIX_ACL);
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 651) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 652) case Opt_noacl:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 653) clear_opt(sbi, POSIX_ACL);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 654) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 655) #else
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 656) case Opt_acl:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 657) f2fs_info(sbi, "acl options not supported");
4058c5117d6d8 (Kelly Anderson 2013-10-07 11:36:20 +0900 658) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 659) case Opt_noacl:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 660) f2fs_info(sbi, "noacl options not supported");
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 661) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 662) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 663) case Opt_active_logs:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 664) if (args->from && match_int(args, &arg))
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 665) return -EINVAL;
d0b9e42ab6155 (Chao Yu 2020-08-04 21:14:45 +0800 666) if (arg != 2 && arg != 4 &&
d0b9e42ab6155 (Chao Yu 2020-08-04 21:14:45 +0800 667) arg != NR_CURSEG_PERSIST_TYPE)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 668) return -EINVAL;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 669) F2FS_OPTION(sbi).active_logs = arg;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 670) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 671) case Opt_disable_ext_identify:
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 672) set_opt(sbi, DISABLE_EXT_IDENTIFY);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 673) break;
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 674) case Opt_inline_data:
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 675) set_opt(sbi, INLINE_DATA);
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 676) break;
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 677) case Opt_inline_dentry:
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 678) set_opt(sbi, INLINE_DENTRY);
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 679) break;
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 680) case Opt_noinline_dentry:
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 681) clear_opt(sbi, INLINE_DENTRY);
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 682) break;
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 683) case Opt_flush_merge:
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 684) set_opt(sbi, FLUSH_MERGE);
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 685) break;
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 686) case Opt_noflush_merge:
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 687) clear_opt(sbi, FLUSH_MERGE);
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 688) break;
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 689) case Opt_nobarrier:
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 690) set_opt(sbi, NOBARRIER);
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 691) break;
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 692) case Opt_fastboot:
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 693) set_opt(sbi, FASTBOOT);
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 694) break;
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 695) case Opt_extent_cache:
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 696) set_opt(sbi, EXTENT_CACHE);
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 697) break;
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 698) case Opt_noextent_cache:
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 699) clear_opt(sbi, EXTENT_CACHE);
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 700) break;
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 701) case Opt_noinline_data:
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 702) clear_opt(sbi, INLINE_DATA);
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 703) break;
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 704) case Opt_data_flush:
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 705) set_opt(sbi, DATA_FLUSH);
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 706) break;
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 707) case Opt_reserve_root:
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 708) if (args->from && match_int(args, &arg))
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 709) return -EINVAL;
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 710) if (test_opt(sbi, RESERVE_ROOT)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 711) f2fs_info(sbi, "Preserve previous reserve_root=%u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 712) F2FS_OPTION(sbi).root_reserved_blocks);
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 713) } else {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 714) F2FS_OPTION(sbi).root_reserved_blocks = arg;
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 715) set_opt(sbi, RESERVE_ROOT);
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 716) }
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 717) break;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 718) case Opt_resuid:
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 719) if (args->from && match_int(args, &arg))
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 720) return -EINVAL;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 721) uid = make_kuid(current_user_ns(), arg);
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 722) if (!uid_valid(uid)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 723) f2fs_err(sbi, "Invalid uid value %d", arg);
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 724) return -EINVAL;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 725) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 726) F2FS_OPTION(sbi).s_resuid = uid;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 727) break;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 728) case Opt_resgid:
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 729) if (args->from && match_int(args, &arg))
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 730) return -EINVAL;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 731) gid = make_kgid(current_user_ns(), arg);
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 732) if (!gid_valid(gid)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 733) f2fs_err(sbi, "Invalid gid value %d", arg);
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 734) return -EINVAL;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 735) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 736) F2FS_OPTION(sbi).s_resgid = gid;
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 737) break;
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 738) case Opt_mode:
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 739) name = match_strdup(&args[0]);
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 740)
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 741) if (!name)
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 742) return -ENOMEM;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 743) if (!strcmp(name, "adaptive")) {
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 744) if (f2fs_sb_has_blkzoned(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 745) f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature");
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 746) kfree(name);
3adc57e97792e (Damien Le Moal 2016-10-28 17:45:04 +0900 747) return -EINVAL;
3adc57e97792e (Damien Le Moal 2016-10-28 17:45:04 +0900 748) }
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 749) F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 750) } else if (!strcmp(name, "lfs")) {
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 751) F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 752) } else {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 753) kfree(name);
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 754) return -EINVAL;
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 755) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 756) kfree(name);
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 757) break;
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 758) case Opt_io_size_bits:
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 759) if (args->from && match_int(args, &arg))
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 760) return -EINVAL;
a8affc03a9b37 (Christoph Hellwig 2021-03-11 12:01:37 +0100 761) if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_VECS)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 762) f2fs_warn(sbi, "Not support %d, larger than %d",
a8affc03a9b37 (Christoph Hellwig 2021-03-11 12:01:37 +0100 763) 1 << arg, BIO_MAX_VECS);
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 764) return -EINVAL;
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 765) }
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 766) F2FS_OPTION(sbi).write_io_size_bits = arg;
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 767) break;
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 768) #ifdef CONFIG_F2FS_FAULT_INJECTION
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 769) case Opt_fault_injection:
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 770) if (args->from && match_int(args, &arg))
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 771) return -EINVAL;
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 772) f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE);
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 773) set_opt(sbi, FAULT_INJECTION);
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 774) break;
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 775)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 776) case Opt_fault_type:
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 777) if (args->from && match_int(args, &arg))
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 778) return -EINVAL;
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 779) f2fs_build_fault_attr(sbi, 0, arg);
0cc0dec2b6f9b (Kaixu Xia 2017-01-27 09:35:37 +0800 780) set_opt(sbi, FAULT_INJECTION);
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 781) break;
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 782) #else
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 783) case Opt_fault_injection:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 784) f2fs_info(sbi, "fault_injection options not supported");
73faec4d99358 (Jaegeuk Kim 2016-04-29 15:34:32 -0700 785) break;
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 786)
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 787) case Opt_fault_type:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 788) f2fs_info(sbi, "fault_type options not supported");
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 789) break;
4cb037ec3f754 (Chengguang Xu 2018-09-12 13:32:52 +0800 790) #endif
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 791) case Opt_lazytime:
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 792) sb->s_flags |= SB_LAZYTIME;
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 793) break;
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 794) case Opt_nolazytime:
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 795) sb->s_flags &= ~SB_LAZYTIME;
6d94c74ab85fe (Jaegeuk Kim 2016-05-20 21:47:24 -0700 796) break;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 797) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 798) case Opt_quota:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 799) case Opt_usrquota:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 800) set_opt(sbi, USRQUOTA);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 801) break;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 802) case Opt_grpquota:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 803) set_opt(sbi, GRPQUOTA);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 804) break;
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 805) case Opt_prjquota:
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 806) set_opt(sbi, PRJQUOTA);
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 807) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 808) case Opt_usrjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 809) ret = f2fs_set_qf_name(sb, USRQUOTA, &args[0]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 810) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 811) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 812) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 813) case Opt_grpjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 814) ret = f2fs_set_qf_name(sb, GRPQUOTA, &args[0]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 815) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 816) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 817) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 818) case Opt_prjjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 819) ret = f2fs_set_qf_name(sb, PRJQUOTA, &args[0]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 820) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 821) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 822) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 823) case Opt_offusrjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 824) ret = f2fs_clear_qf_name(sb, USRQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 825) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 826) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 827) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 828) case Opt_offgrpjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 829) ret = f2fs_clear_qf_name(sb, GRPQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 830) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 831) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 832) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 833) case Opt_offprjjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 834) ret = f2fs_clear_qf_name(sb, PRJQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 835) if (ret)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 836) return ret;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 837) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 838) case Opt_jqfmt_vfsold:
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 839) F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 840) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 841) case Opt_jqfmt_vfsv0:
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 842) F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 843) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 844) case Opt_jqfmt_vfsv1:
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 845) F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 846) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 847) case Opt_noquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 848) clear_opt(sbi, QUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 849) clear_opt(sbi, USRQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 850) clear_opt(sbi, GRPQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 851) clear_opt(sbi, PRJQUOTA);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 852) break;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 853) #else
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 854) case Opt_quota:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 855) case Opt_usrquota:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 856) case Opt_grpquota:
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 857) case Opt_prjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 858) case Opt_usrjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 859) case Opt_grpjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 860) case Opt_prjjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 861) case Opt_offusrjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 862) case Opt_offgrpjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 863) case Opt_offprjjquota:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 864) case Opt_jqfmt_vfsold:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 865) case Opt_jqfmt_vfsv0:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 866) case Opt_jqfmt_vfsv1:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 867) case Opt_noquota:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 868) f2fs_info(sbi, "quota operations not supported");
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 869) break;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 870) #endif
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 871) case Opt_whint:
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 872) name = match_strdup(&args[0]);
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 873) if (!name)
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 874) return -ENOMEM;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 875) if (!strcmp(name, "user-based")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 876) F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 877) } else if (!strcmp(name, "off")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 878) F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 879) } else if (!strcmp(name, "fs-based")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 880) F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 881) } else {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 882) kfree(name);
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 883) return -EINVAL;
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 884) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 885) kfree(name);
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 886) break;
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 887) case Opt_alloc:
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 888) name = match_strdup(&args[0]);
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 889) if (!name)
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 890) return -ENOMEM;
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 891)
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 892) if (!strcmp(name, "default")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 893) F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 894) } else if (!strcmp(name, "reuse")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 895) F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 896) } else {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 897) kfree(name);
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 898) return -EINVAL;
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 899) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 900) kfree(name);
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 901) break;
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 902) case Opt_fsync:
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 903) name = match_strdup(&args[0]);
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 904) if (!name)
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 905) return -ENOMEM;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 906) if (!strcmp(name, "posix")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 907) F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 908) } else if (!strcmp(name, "strict")) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 909) F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 910) } else if (!strcmp(name, "nobarrier")) {
d6290814b018a (Jaegeuk Kim 2018-05-25 18:02:58 -0700 911) F2FS_OPTION(sbi).fsync_mode =
d6290814b018a (Jaegeuk Kim 2018-05-25 18:02:58 -0700 912) FSYNC_MODE_NOBARRIER;
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 913) } else {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 914) kfree(name);
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 915) return -EINVAL;
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 916) }
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 917) kfree(name);
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 918) break;
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 919) case Opt_test_dummy_encryption:
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 920) ret = f2fs_set_test_dummy_encryption(sb, p, &args[0],
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 921) is_remount);
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 922) if (ret)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 923) return ret;
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 924) break;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 925) case Opt_inlinecrypt:
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 926) #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 927) sb->s_flags |= SB_INLINECRYPT;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 928) #else
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 929) f2fs_info(sbi, "inline encryption not supported");
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 930) #endif
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 931) break;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 932) case Opt_checkpoint_disable_cap_perc:
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 933) if (args->from && match_int(args, &arg))
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 934) return -EINVAL;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 935) if (arg < 0 || arg > 100)
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 936) return -EINVAL;
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 937) F2FS_OPTION(sbi).unusable_cap_perc = arg;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 938) set_opt(sbi, DISABLE_CHECKPOINT);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 939) break;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 940) case Opt_checkpoint_disable_cap:
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 941) if (args->from && match_int(args, &arg))
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 942) return -EINVAL;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 943) F2FS_OPTION(sbi).unusable_cap = arg;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 944) set_opt(sbi, DISABLE_CHECKPOINT);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 945) break;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 946) case Opt_checkpoint_disable:
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 947) set_opt(sbi, DISABLE_CHECKPOINT);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 948) break;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 949) case Opt_checkpoint_enable:
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 950) clear_opt(sbi, DISABLE_CHECKPOINT);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 951) break;
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 952) case Opt_checkpoint_merge:
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 953) set_opt(sbi, MERGE_CHECKPOINT);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 954) break;
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 955) case Opt_nocheckpoint_merge:
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 956) clear_opt(sbi, MERGE_CHECKPOINT);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 957) break;
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 958) #ifdef CONFIG_F2FS_FS_COMPRESSION
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 959) case Opt_compress_algorithm:
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 960) if (!f2fs_sb_has_compression(sbi)) {
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 961) f2fs_info(sbi, "Image doesn't support compression");
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 962) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 963) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 964) name = match_strdup(&args[0]);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 965) if (!name)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 966) return -ENOMEM;
3c57f75182452 (Eric Biggers 2020-05-01 16:35:23 -0700 967) if (!strcmp(name, "lzo")) {
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 968) #ifdef CONFIG_F2FS_FS_LZO
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 969) F2FS_OPTION(sbi).compress_level = 0;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 970) F2FS_OPTION(sbi).compress_algorithm =
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 971) COMPRESS_LZO;
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 972) #else
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 973) f2fs_info(sbi, "kernel doesn't support lzo compression");
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 974) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 975) } else if (!strncmp(name, "lz4", 3)) {
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 976) #ifdef CONFIG_F2FS_FS_LZ4
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 977) ret = f2fs_set_lz4hc_level(sbi, name);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 978) if (ret) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 979) kfree(name);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 980) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 981) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 982) F2FS_OPTION(sbi).compress_algorithm =
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 983) COMPRESS_LZ4;
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 984) #else
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 985) f2fs_info(sbi, "kernel doesn't support lz4 compression");
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 986) #endif
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 987) } else if (!strncmp(name, "zstd", 4)) {
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 988) #ifdef CONFIG_F2FS_FS_ZSTD
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 989) ret = f2fs_set_zstd_level(sbi, name);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 990) if (ret) {
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 991) kfree(name);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 992) return -EINVAL;
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 993) }
50cfa66f0de02 (Chao Yu 2020-03-03 17:46:02 +0800 994) F2FS_OPTION(sbi).compress_algorithm =
50cfa66f0de02 (Chao Yu 2020-03-03 17:46:02 +0800 995) COMPRESS_ZSTD;
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 996) #else
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 997) f2fs_info(sbi, "kernel doesn't support zstd compression");
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 998) #endif
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 999) } else if (!strcmp(name, "lzo-rle")) {
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 1000) #ifdef CONFIG_F2FS_FS_LZORLE
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 1001) F2FS_OPTION(sbi).compress_level = 0;
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 1002) F2FS_OPTION(sbi).compress_algorithm =
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 1003) COMPRESS_LZORLE;
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 1004) #else
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 1005) f2fs_info(sbi, "kernel doesn't support lzorle compression");
32be0e97c7136 (Chao Yu 2021-01-22 17:40:13 +0800 1006) #endif
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1007) } else {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1008) kfree(name);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1009) return -EINVAL;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1010) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1011) kfree(name);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1012) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1013) case Opt_compress_log_size:
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1014) if (!f2fs_sb_has_compression(sbi)) {
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 1015) f2fs_info(sbi, "Image doesn't support compression");
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 1016) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1017) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1018) if (args->from && match_int(args, &arg))
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1019) return -EINVAL;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1020) if (arg < MIN_COMPRESS_LOG_SIZE ||
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1021) arg > MAX_COMPRESS_LOG_SIZE) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1022) f2fs_err(sbi,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1023) "Compress cluster log size is out of range");
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1024) return -EINVAL;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1025) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1026) F2FS_OPTION(sbi).compress_log_size = arg;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1027) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1028) case Opt_compress_extension:
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1029) if (!f2fs_sb_has_compression(sbi)) {
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 1030) f2fs_info(sbi, "Image doesn't support compression");
69c0dd29f7529 (Chao Yu 2020-09-03 10:14:41 +0800 1031) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1032) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1033) name = match_strdup(&args[0]);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1034) if (!name)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1035) return -ENOMEM;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1036)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1037) ext = F2FS_OPTION(sbi).extensions;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1038) ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1039)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1040) if (strlen(name) >= F2FS_EXTENSION_LEN ||
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1041) ext_cnt >= COMPRESS_EXT_NUM) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1042) f2fs_err(sbi,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1043) "invalid extension length/number");
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1044) kfree(name);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1045) return -EINVAL;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1046) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1047)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1048) strcpy(ext[ext_cnt], name);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1049) F2FS_OPTION(sbi).compress_ext_cnt++;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1050) kfree(name);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1051) break;
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1052) case Opt_compress_chksum:
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1053) F2FS_OPTION(sbi).compress_chksum = true;
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1054) break;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1055) case Opt_compress_mode:
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1056) name = match_strdup(&args[0]);
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1057) if (!name)
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1058) return -ENOMEM;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1059) if (!strcmp(name, "fs")) {
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1060) F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1061) } else if (!strcmp(name, "user")) {
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1062) F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1063) } else {
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1064) kfree(name);
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1065) return -EINVAL;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1066) }
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1067) kfree(name);
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1068) break;
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1069) #else
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1070) case Opt_compress_algorithm:
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1071) case Opt_compress_log_size:
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1072) case Opt_compress_extension:
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1073) case Opt_compress_chksum:
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1074) case Opt_compress_mode:
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1075) f2fs_info(sbi, "compression options not supported");
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1076) break;
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1077) #endif
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1078) case Opt_atgc:
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1079) set_opt(sbi, ATGC);
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1080) break;
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1081) case Opt_gc_merge:
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1082) set_opt(sbi, GC_MERGE);
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1083) break;
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1084) case Opt_nogc_merge:
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1085) clear_opt(sbi, GC_MERGE);
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1086) break;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1087) default:
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1088) f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1089) p);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1090) return -EINVAL;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1091) }
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1092) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1093) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1094) if (f2fs_check_quota_options(sbi))
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1095) return -EINVAL;
00960c2cd8f16 (Sheng Yong 2018-07-24 20:17:52 +0800 1096) #else
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 1097) if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1098) f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA");
00960c2cd8f16 (Sheng Yong 2018-07-24 20:17:52 +0800 1099) return -EINVAL;
00960c2cd8f16 (Sheng Yong 2018-07-24 20:17:52 +0800 1100) }
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 1101) if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1102) f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA");
4ddc1b28aac57 (Chao Yu 2018-07-26 07:19:48 +0800 1103) return -EINVAL;
4ddc1b28aac57 (Chao Yu 2018-07-26 07:19:48 +0800 1104) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1105) #endif
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1106) #ifndef CONFIG_UNICODE
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1107) if (f2fs_sb_has_casefold(sbi)) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1108) f2fs_err(sbi,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1109) "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1110) return -EINVAL;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1111) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1112) #endif
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1113) /*
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1114) * The BLKZONED feature indicates that the drive was formatted with
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1115) * zone alignment optimization. This is optional for host-aware
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1116) * devices, but mandatory for host-managed zoned block devices.
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1117) */
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1118) #ifndef CONFIG_BLK_DEV_ZONED
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1119) if (f2fs_sb_has_blkzoned(sbi)) {
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1120) f2fs_err(sbi, "Zoned block device support is not enabled");
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1121) return -EINVAL;
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1122) }
d0660122dced9 (Chao Yu 2020-09-21 20:53:14 +0800 1123) #endif
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 1124)
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1125) if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1126) f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1127) F2FS_IO_SIZE_KB(sbi));
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 1128) return -EINVAL;
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 1129) }
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1130)
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1131) if (test_opt(sbi, INLINE_XATTR_SIZE)) {
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1132) int min_size, max_size;
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1133)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 1134) if (!f2fs_sb_has_extra_attr(sbi) ||
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 1135) !f2fs_sb_has_flexible_inline_xattr(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1136) f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off");
4d817ae099883 (Chao Yu 2018-01-27 17:29:48 +0800 1137) return -EINVAL;
4d817ae099883 (Chao Yu 2018-01-27 17:29:48 +0800 1138) }
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1139) if (!test_opt(sbi, INLINE_XATTR)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1140) f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option");
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1141) return -EINVAL;
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1142) }
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1143)
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1144) min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32);
dd6c89b5f2b93 (Chao Yu 2019-03-04 17:19:04 +0800 1145) max_size = MAX_INLINE_XATTR_SIZE;
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1146)
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1147) if (F2FS_OPTION(sbi).inline_xattr_size < min_size ||
70db5b04cbe19 (Jaegeuk Kim 2019-03-12 11:49:53 -0700 1148) F2FS_OPTION(sbi).inline_xattr_size > max_size) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1149) f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1150) min_size, max_size);
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1151) return -EINVAL;
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1152) }
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1153) }
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 1154)
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1155) if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1156) f2fs_err(sbi, "LFS not compatible with checkpoint=disable\n");
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1157) return -EINVAL;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1158) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1159)
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 1160) /* Not pass down write hints if the number of active logs is lesser
d0b9e42ab6155 (Chao Yu 2020-08-04 21:14:45 +0800 1161) * than NR_CURSEG_PERSIST_TYPE.
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 1162) */
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1163) if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1164) F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1165) return 0;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1166) }
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1167)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1168) static struct inode *f2fs_alloc_inode(struct super_block *sb)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1169) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1170) struct f2fs_inode_info *fi;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1171)
a0acdfe05a954 (Chao Yu 2013-12-05 09:54:00 +0800 1172) fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1173) if (!fi)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1174) return NULL;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1175)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1176) init_once((void *) fi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1177)
434720fa98443 (Masanari Iida 2013-03-19 08:03:35 +0900 1178) /* Initialize f2fs-specific inode info */
204706c7accfa (Jaegeuk Kim 2016-12-02 15:11:32 -0800 1179) atomic_set(&fi->dirty_pages, 0);
c2759ebaf7e8f (Daeho Jeong 2020-09-08 11:44:10 +0900 1180) atomic_set(&fi->i_compr_blocks, 0);
d928bfbfe77aa (Jaegeuk Kim 2014-03-20 19:10:08 +0900 1181) init_rwsem(&fi->i_sem);
c10c98203222f (Chao Yu 2020-02-27 19:30:03 +0800 1182) spin_lock_init(&fi->i_size_lock);
2710fd7e00b4f (Chao Yu 2015-12-15 13:30:45 +0800 1183) INIT_LIST_HEAD(&fi->dirty_list);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1184) INIT_LIST_HEAD(&fi->gdirty_list);
57864ae5ce3ab (Jaegeuk Kim 2017-10-18 19:05:57 -0700 1185) INIT_LIST_HEAD(&fi->inmem_ilist);
88b88a6679715 (Jaegeuk Kim 2014-10-06 17:39:50 -0700 1186) INIT_LIST_HEAD(&fi->inmem_pages);
88b88a6679715 (Jaegeuk Kim 2014-10-06 17:39:50 -0700 1187) mutex_init(&fi->inmem_lock);
b2532c694033f (Chao Yu 2018-04-24 10:55:28 +0800 1188) init_rwsem(&fi->i_gc_rwsem[READ]);
b2532c694033f (Chao Yu 2018-04-24 10:55:28 +0800 1189) init_rwsem(&fi->i_gc_rwsem[WRITE]);
5a3a2d83cda82 (Qiuyang Sun 2017-05-18 11:06:45 +0800 1190) init_rwsem(&fi->i_mmap_sem);
27161f13e3c32 (Yunlei He 2017-09-07 10:40:54 +0800 1191) init_rwsem(&fi->i_xattr_sem);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1192)
ab9fa662e4867 (Jaegeuk Kim 2014-02-27 20:09:05 +0900 1193) /* Will be used by directory only */
ab9fa662e4867 (Jaegeuk Kim 2014-02-27 20:09:05 +0900 1194) fi->i_dir_level = F2FS_SB(sb)->dir_level;
f247037120ecd (Chao Yu 2017-07-19 00:19:05 +0800 1195)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1196) return &fi->vfs_inode;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1197) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1198)
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1199) static int f2fs_drop_inode(struct inode *inode)
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1200) {
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1201) struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
b8d96a30b6f1c (Hou Pengyang 2017-02-27 13:02:58 +0000 1202) int ret;
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1203)
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1204) /*
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1205) * during filesystem shutdown, if checkpoint is disabled,
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1206) * drop useless meta/node dirty pages.
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1207) */
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1208) if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1209) if (inode->i_ino == F2FS_NODE_INO(sbi) ||
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1210) inode->i_ino == F2FS_META_INO(sbi)) {
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1211) trace_f2fs_drop_inode(inode, 1);
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1212) return 1;
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1213) }
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1214) }
a8933b6b68f77 (Chao Yu 2019-07-18 16:39:59 +0800 1215)
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1216) /*
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1217) * This is to avoid a deadlock condition like below.
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1218) * writeback_single_inode(inode)
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1219) * - f2fs_write_data_page
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1220) * - f2fs_gc -> iput -> evict
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1221) * - inode_wait_for_writeback(inode)
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1222) */
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1223) if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) {
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1224) if (!inode->i_nlink && !is_bad_inode(inode)) {
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1225) /* to avoid evict_inode call simultaneously */
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1226) atomic_inc(&inode->i_count);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1227) spin_unlock(&inode->i_lock);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1228)
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1229) /* some remained atomic pages should discarded */
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1230) if (f2fs_is_atomic_file(inode))
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1231) f2fs_drop_inmem_pages(inode);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1232)
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1233) /* should remain fi->extent_tree for writepage */
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1234) f2fs_destroy_extent_node(inode);
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1235)
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1236) sb_start_intwrite(inode->i_sb);
fc9581c809722 (Jaegeuk Kim 2016-05-20 09:22:03 -0700 1237) f2fs_i_size_write(inode, 0);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1238)
a0770e13c8da8 (zhengliang 2019-03-04 09:32:25 +0800 1239) f2fs_submit_merged_write_cond(F2FS_I_SB(inode),
a0770e13c8da8 (zhengliang 2019-03-04 09:32:25 +0800 1240) inode, NULL, 0, DATA);
a0770e13c8da8 (zhengliang 2019-03-04 09:32:25 +0800 1241) truncate_inode_pages_final(inode->i_mapping);
a0770e13c8da8 (zhengliang 2019-03-04 09:32:25 +0800 1242)
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1243) if (F2FS_HAS_BLOCKS(inode))
9a449e9c3b34e (Jaegeuk Kim 2016-06-02 13:49:38 -0700 1244) f2fs_truncate(inode);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1245)
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1246) sb_end_intwrite(inode->i_sb);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1247)
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1248) spin_lock(&inode->i_lock);
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1249) atomic_dec(&inode->i_count);
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1250) }
b8d96a30b6f1c (Hou Pengyang 2017-02-27 13:02:58 +0000 1251) trace_f2fs_drop_inode(inode, 0);
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1252) return 0;
06e1bc05cad8d (Jaegeuk Kim 2015-05-13 14:35:14 -0700 1253) }
b8d96a30b6f1c (Hou Pengyang 2017-02-27 13:02:58 +0000 1254) ret = generic_drop_inode(inode);
8ce589c773180 (Eric Biggers 2019-08-04 19:35:48 -0700 1255) if (!ret)
8ce589c773180 (Eric Biggers 2019-08-04 19:35:48 -0700 1256) ret = fscrypt_drop_inode(inode);
b8d96a30b6f1c (Hou Pengyang 2017-02-27 13:02:58 +0000 1257) trace_f2fs_drop_inode(inode, ret);
b8d96a30b6f1c (Hou Pengyang 2017-02-27 13:02:58 +0000 1258) return ret;
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1259) }
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 1260)
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1261) int f2fs_inode_dirtied(struct inode *inode, bool sync)
b3783873cc221 (Jaegeuk Kim 2013-06-10 09:17:01 +0900 1262) {
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1263) struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1264) int ret = 0;
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1265)
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1266) spin_lock(&sbi->inode_lock[DIRTY_META]);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1267) if (is_inode_flag_set(inode, FI_DIRTY_INODE)) {
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1268) ret = 1;
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1269) } else {
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1270) set_inode_flag(inode, FI_DIRTY_INODE);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1271) stat_inc_dirty_inode(sbi, DIRTY_META);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1272) }
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1273) if (sync && list_empty(&F2FS_I(inode)->gdirty_list)) {
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1274) list_add_tail(&F2FS_I(inode)->gdirty_list,
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1275) &sbi->inode_list[DIRTY_META]);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1276) inc_page_count(sbi, F2FS_DIRTY_IMETA);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1277) }
338bbfa086c34 (Jaegeuk Kim 2016-06-02 11:08:56 -0700 1278) spin_unlock(&sbi->inode_lock[DIRTY_META]);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1279) return ret;
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1280) }
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1281)
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1282) void f2fs_inode_synced(struct inode *inode)
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1283) {
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1284) struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1285)
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1286) spin_lock(&sbi->inode_lock[DIRTY_META]);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1287) if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) {
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1288) spin_unlock(&sbi->inode_lock[DIRTY_META]);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1289) return;
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1290) }
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1291) if (!list_empty(&F2FS_I(inode)->gdirty_list)) {
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1292) list_del_init(&F2FS_I(inode)->gdirty_list);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1293) dec_page_count(sbi, F2FS_DIRTY_IMETA);
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1294) }
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1295) clear_inode_flag(inode, FI_DIRTY_INODE);
26de9b1171305 (Jaegeuk Kim 2016-05-20 20:42:37 -0700 1296) clear_inode_flag(inode, FI_AUTO_RECOVER);
0f18b462b2e5a (Jaegeuk Kim 2016-05-20 11:10:10 -0700 1297) stat_dec_dirty_inode(F2FS_I_SB(inode), DIRTY_META);
338bbfa086c34 (Jaegeuk Kim 2016-06-02 11:08:56 -0700 1298) spin_unlock(&sbi->inode_lock[DIRTY_META]);
b3783873cc221 (Jaegeuk Kim 2013-06-10 09:17:01 +0900 1299) }
b3783873cc221 (Jaegeuk Kim 2013-06-10 09:17:01 +0900 1300)
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1301) /*
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1302) * f2fs_dirty_inode() is called from __mark_inode_dirty()
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1303) *
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1304) * We should call set_dirty_inode to write the dirty inode through write_inode.
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1305) */
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1306) static void f2fs_dirty_inode(struct inode *inode, int flags)
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1307) {
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1308) struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1309)
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1310) if (inode->i_ino == F2FS_NODE_INO(sbi) ||
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1311) inode->i_ino == F2FS_META_INO(sbi))
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1312) return;
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1313)
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1314) if (is_inode_flag_set(inode, FI_AUTO_RECOVER))
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1315) clear_inode_flag(inode, FI_AUTO_RECOVER);
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1316)
7c45729a4d6d1 (Jaegeuk Kim 2016-10-14 11:51:23 -0700 1317) f2fs_inode_dirtied(inode, false);
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1318) }
b56ab837a06f3 (Jaegeuk Kim 2016-06-30 19:09:37 -0700 1319)
d01718a050d06 (Al Viro 2019-04-15 19:29:14 -0400 1320) static void f2fs_free_inode(struct inode *inode)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1321) {
2c58d548f5706 (Eric Biggers 2019-04-10 13:21:15 -0700 1322) fscrypt_free_inode(inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1323) kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1324) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1325)
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1326) static void destroy_percpu_info(struct f2fs_sb_info *sbi)
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1327) {
41382ec43255b (Jaegeuk Kim 2016-05-16 11:06:50 -0700 1328) percpu_counter_destroy(&sbi->alloc_valid_block_count);
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 1329) percpu_counter_destroy(&sbi->total_valid_inode_count);
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1330) }
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1331)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1332) static void destroy_device_list(struct f2fs_sb_info *sbi)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1333) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1334) int i;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1335)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1336) for (i = 0; i < sbi->s_ndevs; i++) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1337) blkdev_put(FDEV(i).bdev, FMODE_EXCL);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1338) #ifdef CONFIG_BLK_DEV_ZONED
95175dafc4399 (Damien Le Moal 2019-03-16 09:13:07 +0900 1339) kvfree(FDEV(i).blkz_seq);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 1340) kfree(FDEV(i).zone_capacity_blocks);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1341) #endif
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1342) }
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 1343) kvfree(sbi->devs);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1344) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1345)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1346) static void f2fs_put_super(struct super_block *sb)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1347) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1348) struct f2fs_sb_info *sbi = F2FS_SB(sb);
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 1349) int i;
cf5c759f927dc (Chao Yu 2017-10-04 09:08:37 +0800 1350) bool dropped;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1351)
99c787cfd2bd0 (Li Guifu 2020-07-24 09:38:11 +0800 1352) /* unregister procfs/sysfs entries in advance to avoid race case */
99c787cfd2bd0 (Li Guifu 2020-07-24 09:38:11 +0800 1353) f2fs_unregister_sysfs(sbi);
99c787cfd2bd0 (Li Guifu 2020-07-24 09:38:11 +0800 1354)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1355) f2fs_quota_off_umount(sb);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1356)
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1357) /* prevent remaining shrinker jobs */
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1358) mutex_lock(&sbi->umount_mutex);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1359)
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1360) /*
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1361) * flush all issued checkpoints and stop checkpoint issue thread.
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1362) * after then, all checkpoints should be done by each process context.
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1363) */
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1364) f2fs_stop_ckpt_thread(sbi);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1365)
85dc2f2c6c84e (Jaegeuk Kim 2015-01-14 17:41:41 -0800 1366) /*
85dc2f2c6c84e (Jaegeuk Kim 2015-01-14 17:41:41 -0800 1367) * We don't need to do checkpoint when superblock is clean.
85dc2f2c6c84e (Jaegeuk Kim 2015-01-14 17:41:41 -0800 1368) * But, the previous checkpoint was not done by umount, it needs to do
85dc2f2c6c84e (Jaegeuk Kim 2015-01-14 17:41:41 -0800 1369) * clean checkpoint again.
85dc2f2c6c84e (Jaegeuk Kim 2015-01-14 17:41:41 -0800 1370) */
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1371) if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1372) !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) {
75ab4cb8301ad (Jaegeuk Kim 2014-09-20 21:57:51 -0700 1373) struct cp_control cpc = {
75ab4cb8301ad (Jaegeuk Kim 2014-09-20 21:57:51 -0700 1374) .reason = CP_UMOUNT,
75ab4cb8301ad (Jaegeuk Kim 2014-09-20 21:57:51 -0700 1375) };
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1376) f2fs_write_checkpoint(sbi, &cpc);
75ab4cb8301ad (Jaegeuk Kim 2014-09-20 21:57:51 -0700 1377) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1378)
4e6a8d9b224f8 (Jaegeuk Kim 2016-12-29 14:07:53 -0800 1379) /* be sure to wait for any on-going discard commands */
03f2c02d8be76 (Jaegeuk Kim 2019-01-14 10:42:11 -0800 1380) dropped = f2fs_issue_discard_timeout(sbi);
4e6a8d9b224f8 (Jaegeuk Kim 2016-12-29 14:07:53 -0800 1381)
7d20c8abb2edc (Chao Yu 2018-09-04 03:52:17 +0800 1382) if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) &&
7d20c8abb2edc (Chao Yu 2018-09-04 03:52:17 +0800 1383) !sbi->discard_blks && !dropped) {
1f43e2ad7bff5 (Chao Yu 2017-04-28 13:56:08 +0800 1384) struct cp_control cpc = {
1f43e2ad7bff5 (Chao Yu 2017-04-28 13:56:08 +0800 1385) .reason = CP_UMOUNT | CP_TRIMMED,
1f43e2ad7bff5 (Chao Yu 2017-04-28 13:56:08 +0800 1386) };
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1387) f2fs_write_checkpoint(sbi, &cpc);
1f43e2ad7bff5 (Chao Yu 2017-04-28 13:56:08 +0800 1388) }
1f43e2ad7bff5 (Chao Yu 2017-04-28 13:56:08 +0800 1389)
cf779cab14d50 (Jaegeuk Kim 2014-08-11 18:37:46 -0700 1390) /*
cf779cab14d50 (Jaegeuk Kim 2014-08-11 18:37:46 -0700 1391) * normally superblock is clean, so we need to release this.
cf779cab14d50 (Jaegeuk Kim 2014-08-11 18:37:46 -0700 1392) * In addition, EIO will skip do checkpoint, we need this as well.
cf779cab14d50 (Jaegeuk Kim 2014-08-11 18:37:46 -0700 1393) */
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1394) f2fs_release_ino_entry(sbi, true);
6f12ac25f0167 (Jaegeuk Kim 2014-08-19 09:48:22 -0700 1395)
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1396) f2fs_leave_shrinker(sbi);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1397) mutex_unlock(&sbi->umount_mutex);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 1398)
17c19120eb7fa (Jaegeuk Kim 2016-01-29 08:57:59 -0800 1399) /* our cp_error case, we can wait for any writeback page */
b9109b0e49b93 (Jaegeuk Kim 2017-05-10 11:28:38 -0700 1400) f2fs_flush_merged_writes(sbi);
17c19120eb7fa (Jaegeuk Kim 2016-01-29 08:57:59 -0800 1401)
bf22c3cc8ce71 (Sahitya Tummala 2020-02-18 09:19:07 +0530 1402) f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
50fa53eccf9f9 (Chao Yu 2018-08-02 23:03:19 +0800 1403)
50fa53eccf9f9 (Chao Yu 2018-08-02 23:03:19 +0800 1404) f2fs_bug_on(sbi, sbi->fsync_node_num);
50fa53eccf9f9 (Chao Yu 2018-08-02 23:03:19 +0800 1405)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1406) iput(sbi->node_inode);
7c77bf7de1574 (Jaegeuk Kim 2019-01-01 00:11:30 -0800 1407) sbi->node_inode = NULL;
7c77bf7de1574 (Jaegeuk Kim 2019-01-01 00:11:30 -0800 1408)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1409) iput(sbi->meta_inode);
7c77bf7de1574 (Jaegeuk Kim 2019-01-01 00:11:30 -0800 1410) sbi->meta_inode = NULL;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1411)
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1412) /*
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1413) * iput() can update stat information, if f2fs_write_checkpoint()
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1414) * above failed with error.
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1415) */
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1416) f2fs_destroy_stats(sbi);
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 1417)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1418) /* destroy f2fs internal modules */
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1419) f2fs_destroy_node_manager(sbi);
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 1420) f2fs_destroy_segment_manager(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1421)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1422) f2fs_destroy_post_read_wq(sbi);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1423)
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 1424) kvfree(sbi->ckpt);
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 1425)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1426) sb->s_fs_info = NULL;
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 1427) if (sbi->s_chksum_driver)
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 1428) crypto_free_shash(sbi->s_chksum_driver);
742532d11d832 (Denis Efremov 2020-06-10 01:14:46 +0300 1429) kfree(sbi->raw_super);
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1430)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 1431) destroy_device_list(sbi);
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 1432) f2fs_destroy_page_array_cache(sbi);
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 1433) f2fs_destroy_xattr_caches(sbi);
b6895e8f99cd8 (Chao Yu 2017-02-27 18:43:12 +0800 1434) mempool_destroy(sbi->write_io_dummy);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1435) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1436) for (i = 0; i < MAXQUOTAS; i++)
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 1437) kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1438) #endif
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 1439) fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 1440) destroy_percpu_info(sbi);
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 1441) for (i = 0; i < NR_PAGE_TYPE; i++)
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 1442) kvfree(sbi->write_io[i]);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1443) #ifdef CONFIG_UNICODE
eca4873ee1b63 (Daniel Rosenberg 2020-07-08 02:12:36 -0700 1444) utf8_unload(sb->s_encoding);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 1445) #endif
742532d11d832 (Denis Efremov 2020-06-10 01:14:46 +0300 1446) kfree(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1447) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1448)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1449) int f2fs_sync_fs(struct super_block *sb, int sync)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1450) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1451) struct f2fs_sb_info *sbi = F2FS_SB(sb);
c34f42e2cb2d2 (Chao Yu 2015-12-23 17:50:30 +0800 1452) int err = 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1453)
1f227a3e215d3 (Jaegeuk Kim 2017-10-23 23:48:49 +0200 1454) if (unlikely(f2fs_cp_error(sbi)))
1f227a3e215d3 (Jaegeuk Kim 2017-10-23 23:48:49 +0200 1455) return 0;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1456) if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1457) return 0;
1f227a3e215d3 (Jaegeuk Kim 2017-10-23 23:48:49 +0200 1458)
a2a4a7e4abb27 (Namjae Jeon 2013-04-20 01:28:40 +0900 1459) trace_f2fs_sync_fs(sb, sync);
a2a4a7e4abb27 (Namjae Jeon 2013-04-20 01:28:40 +0900 1460)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1461) if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1462) return -EAGAIN;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1463)
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1464) if (sync)
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1465) err = f2fs_issue_checkpoint(sbi);
119ee91445341 (Jaegeuk Kim 2015-01-29 11:45:33 -0800 1466)
c34f42e2cb2d2 (Chao Yu 2015-12-23 17:50:30 +0800 1467) return err;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1468) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1469)
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1470) static int f2fs_freeze(struct super_block *sb)
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1471) {
77888c1e42e8c (Jaegeuk Kim 2013-05-20 20:28:47 +0900 1472) if (f2fs_readonly(sb))
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1473) return 0;
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1474)
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1475) /* IO error happened before */
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1476) if (unlikely(f2fs_cp_error(F2FS_SB(sb))))
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1477) return -EIO;
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1478)
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1479) /* must be clean, since sync_filesystem() was already called */
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1480) if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY))
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1481) return -EINVAL;
d50dfc0c7df7b (Jaegeuk Kim 2021-02-08 13:42:21 -0800 1482)
d50dfc0c7df7b (Jaegeuk Kim 2021-02-08 13:42:21 -0800 1483) /* ensure no checkpoint required */
d50dfc0c7df7b (Jaegeuk Kim 2021-02-08 13:42:21 -0800 1484) if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list))
d50dfc0c7df7b (Jaegeuk Kim 2021-02-08 13:42:21 -0800 1485) return -EINVAL;
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 1486) return 0;
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1487) }
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1488)
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1489) static int f2fs_unfreeze(struct super_block *sb)
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1490) {
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1491) return 0;
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1492) }
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 1493)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1494) #ifdef CONFIG_QUOTA
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1495) static int f2fs_statfs_project(struct super_block *sb,
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1496) kprojid_t projid, struct kstatfs *buf)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1497) {
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1498) struct kqid qid;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1499) struct dquot *dquot;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1500) u64 limit;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1501) u64 curblock;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1502)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1503) qid = make_kqid_projid(projid);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1504) dquot = dqget(sb, qid);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1505) if (IS_ERR(dquot))
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1506) return PTR_ERR(dquot);
955ac6e523444 (Sheng Yong 2018-07-24 20:17:53 +0800 1507) spin_lock(&dquot->dq_dqb_lock);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1508)
bf2cbd3c57159 (Chengguang Xu 2020-01-04 22:20:04 +0800 1509) limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit,
bf2cbd3c57159 (Chengguang Xu 2020-01-04 22:20:04 +0800 1510) dquot->dq_dqb.dqb_bhardlimit);
acdf2172172a5 (Chengguang Xu 2020-01-04 22:20:03 +0800 1511) if (limit)
acdf2172172a5 (Chengguang Xu 2020-01-04 22:20:03 +0800 1512) limit >>= sb->s_blocksize_bits;
909110c060f22 (Chengguang Xu 2019-11-25 11:20:36 +0800 1513)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1514) if (limit && buf->f_blocks > limit) {
baaa7ebf25c78 (Konstantin Khlebnikov 2020-05-11 09:15:18 +0300 1515) curblock = (dquot->dq_dqb.dqb_curspace +
baaa7ebf25c78 (Konstantin Khlebnikov 2020-05-11 09:15:18 +0300 1516) dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1517) buf->f_blocks = limit;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1518) buf->f_bfree = buf->f_bavail =
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1519) (buf->f_blocks > curblock) ?
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1520) (buf->f_blocks - curblock) : 0;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1521) }
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1522)
bf2cbd3c57159 (Chengguang Xu 2020-01-04 22:20:04 +0800 1523) limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit,
bf2cbd3c57159 (Chengguang Xu 2020-01-04 22:20:04 +0800 1524) dquot->dq_dqb.dqb_ihardlimit);
909110c060f22 (Chengguang Xu 2019-11-25 11:20:36 +0800 1525)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1526) if (limit && buf->f_files > limit) {
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1527) buf->f_files = limit;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1528) buf->f_ffree =
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1529) (buf->f_files > dquot->dq_dqb.dqb_curinodes) ?
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1530) (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1531) }
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1532)
955ac6e523444 (Sheng Yong 2018-07-24 20:17:53 +0800 1533) spin_unlock(&dquot->dq_dqb_lock);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1534) dqput(dquot);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1535) return 0;
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1536) }
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1537) #endif
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1538)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1539) static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1540) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1541) struct super_block *sb = dentry->d_sb;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1542) struct f2fs_sb_info *sbi = F2FS_SB(sb);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1543) u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
f66c027eaddd3 (Jaegeuk Kim 2018-01-03 10:55:07 -0800 1544) block_t total_count, user_block_count, start_count;
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1545) u64 avail_node_count;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1546)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1547) total_count = le64_to_cpu(sbi->raw_super->block_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1548) user_block_count = sbi->user_block_count;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1549) start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1550) buf->f_type = F2FS_SUPER_MAGIC;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1551) buf->f_bsize = sbi->blocksize;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1552)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1553) buf->f_blocks = total_count - start_count;
f66c027eaddd3 (Jaegeuk Kim 2018-01-03 10:55:07 -0800 1554) buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
80d421450187e (Yunlong Song 2017-10-27 20:45:05 +0800 1555) sbi->current_reserved_blocks;
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1556)
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1557) spin_lock(&sbi->stat_lock);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1558) if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1559) buf->f_bfree = 0;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1560) else
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1561) buf->f_bfree -= sbi->unusable_block_count;
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1562) spin_unlock(&sbi->stat_lock);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1563)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1564) if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1565) buf->f_bavail = buf->f_bfree -
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1566) F2FS_OPTION(sbi).root_reserved_blocks;
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 1567) else
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 1568) buf->f_bavail = 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1569)
27cae0bcc0510 (Chao Yu 2019-08-05 18:27:25 +0800 1570) avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1571)
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1572) if (avail_node_count > user_block_count) {
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1573) buf->f_files = user_block_count;
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1574) buf->f_ffree = buf->f_bavail;
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1575) } else {
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1576) buf->f_files = avail_node_count;
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1577) buf->f_ffree = min(avail_node_count - valid_node_count(sbi),
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1578) buf->f_bavail);
0cc091d0c8c34 (Jaegeuk Kim 2017-06-21 20:55:55 -0700 1579) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1580)
5a20d339c785d (Jaegeuk Kim 2013-03-03 13:58:05 +0900 1581) buf->f_namelen = F2FS_NAME_LEN;
6d1349c769ea2 (Al Viro 2020-09-18 16:45:50 -0400 1582) buf->f_fsid = u64_to_fsid(id);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1583)
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1584) #ifdef CONFIG_QUOTA
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1585) if (is_inode_flag_set(dentry->d_inode, FI_PROJ_INHERIT) &&
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1586) sb_has_quota_limits_enabled(sb, PRJQUOTA)) {
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1587) f2fs_statfs_project(sb, F2FS_I(dentry->d_inode)->i_projid, buf);
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1588) }
ddc34e328d067 (Chao Yu 2017-07-29 00:32:53 +0800 1589) #endif
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1590) return 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1591) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1592)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1593) static inline void f2fs_show_quota_options(struct seq_file *seq,
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1594) struct super_block *sb)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1595) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1596) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1597) struct f2fs_sb_info *sbi = F2FS_SB(sb);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1598)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1599) if (F2FS_OPTION(sbi).s_jquota_fmt) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1600) char *fmtname = "";
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1601)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1602) switch (F2FS_OPTION(sbi).s_jquota_fmt) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1603) case QFMT_VFS_OLD:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1604) fmtname = "vfsold";
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1605) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1606) case QFMT_VFS_V0:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1607) fmtname = "vfsv0";
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1608) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1609) case QFMT_VFS_V1:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1610) fmtname = "vfsv1";
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1611) break;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1612) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1613) seq_printf(seq, ",jqfmt=%s", fmtname);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1614) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1615)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1616) if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1617) seq_show_option(seq, "usrjquota",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1618) F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1619)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1620) if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1621) seq_show_option(seq, "grpjquota",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1622) F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1623)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1624) if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1625) seq_show_option(seq, "prjjquota",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1626) F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1627) #endif
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1628) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1629)
cd6ee739b8ee4 (Chao Yu 2021-02-20 17:38:41 +0800 1630) #ifdef CONFIG_F2FS_FS_COMPRESSION
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1631) static inline void f2fs_show_compress_options(struct seq_file *seq,
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1632) struct super_block *sb)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1633) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1634) struct f2fs_sb_info *sbi = F2FS_SB(sb);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1635) char *algtype = "";
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1636) int i;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1637)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1638) if (!f2fs_sb_has_compression(sbi))
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1639) return;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1640)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1641) switch (F2FS_OPTION(sbi).compress_algorithm) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1642) case COMPRESS_LZO:
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1643) algtype = "lzo";
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1644) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1645) case COMPRESS_LZ4:
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1646) algtype = "lz4";
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1647) break;
50cfa66f0de02 (Chao Yu 2020-03-03 17:46:02 +0800 1648) case COMPRESS_ZSTD:
50cfa66f0de02 (Chao Yu 2020-03-03 17:46:02 +0800 1649) algtype = "zstd";
50cfa66f0de02 (Chao Yu 2020-03-03 17:46:02 +0800 1650) break;
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 1651) case COMPRESS_LZORLE:
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 1652) algtype = "lzo-rle";
6d92b201035df (Chao Yu 2020-04-08 19:56:32 +0800 1653) break;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1654) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1655) seq_printf(seq, ",compress_algorithm=%s", algtype);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1656)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 1657) if (F2FS_OPTION(sbi).compress_level)
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 1658) seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level);
3fde13f817e23 (Chao Yu 2021-01-22 17:46:43 +0800 1659)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1660) seq_printf(seq, ",compress_log_size=%u",
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1661) F2FS_OPTION(sbi).compress_log_size);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1662)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1663) for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1664) seq_printf(seq, ",compress_extension=%s",
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1665) F2FS_OPTION(sbi).extensions[i]);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1666) }
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1667)
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1668) if (F2FS_OPTION(sbi).compress_chksum)
b28f047b28c51 (Chao Yu 2020-11-26 18:32:09 +0800 1669) seq_puts(seq, ",compress_chksum");
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1670)
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1671) if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS)
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1672) seq_printf(seq, ",compress_mode=%s", "fs");
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1673) else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER)
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1674) seq_printf(seq, ",compress_mode=%s", "user");
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1675) }
cd6ee739b8ee4 (Chao Yu 2021-02-20 17:38:41 +0800 1676) #endif
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1677)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1678) static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1679) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1680) struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1681)
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1682) if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC)
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1683) seq_printf(seq, ",background_gc=%s", "sync");
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1684) else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON)
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1685) seq_printf(seq, ",background_gc=%s", "on");
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1686) else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1687) seq_printf(seq, ",background_gc=%s", "off");
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1688)
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1689) if (test_opt(sbi, GC_MERGE))
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1690) seq_puts(seq, ",gc_merge");
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 1691)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1692) if (test_opt(sbi, DISABLE_ROLL_FORWARD))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1693) seq_puts(seq, ",disable_roll_forward");
a9117eca1de6b (Chao Yu 2020-02-14 17:45:11 +0800 1694) if (test_opt(sbi, NORECOVERY))
a9117eca1de6b (Chao Yu 2020-02-14 17:45:11 +0800 1695) seq_puts(seq, ",norecovery");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1696) if (test_opt(sbi, DISCARD))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1697) seq_puts(seq, ",discard");
81621f9761767 (Sahitya Tummala 2019-05-24 14:38:39 +0530 1698) else
81621f9761767 (Sahitya Tummala 2019-05-24 14:38:39 +0530 1699) seq_puts(seq, ",nodiscard");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1700) if (test_opt(sbi, NOHEAP))
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 1701) seq_puts(seq, ",no_heap");
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 1702) else
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 1703) seq_puts(seq, ",heap");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1704) #ifdef CONFIG_F2FS_FS_XATTR
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1705) if (test_opt(sbi, XATTR_USER))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1706) seq_puts(seq, ",user_xattr");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1707) else
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1708) seq_puts(seq, ",nouser_xattr");
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 1709) if (test_opt(sbi, INLINE_XATTR))
444c580f7e9ad (Jaegeuk Kim 2013-08-08 15:16:22 +0900 1710) seq_puts(seq, ",inline_xattr");
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 1711) else
23cf7212a1cae (Chao Yu 2017-02-15 10:34:45 +0800 1712) seq_puts(seq, ",noinline_xattr");
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1713) if (test_opt(sbi, INLINE_XATTR_SIZE))
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 1714) seq_printf(seq, ",inline_xattr_size=%u",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1715) F2FS_OPTION(sbi).inline_xattr_size);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1716) #endif
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1717) #ifdef CONFIG_F2FS_FS_POSIX_ACL
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1718) if (test_opt(sbi, POSIX_ACL))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1719) seq_puts(seq, ",acl");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1720) else
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1721) seq_puts(seq, ",noacl");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1722) #endif
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1723) if (test_opt(sbi, DISABLE_EXT_IDENTIFY))
aa43507f68e44 (Alejandro Martinez Ruiz 2013-01-25 19:08:59 +0100 1724) seq_puts(seq, ",disable_ext_identify");
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 1725) if (test_opt(sbi, INLINE_DATA))
8274de77b7072 (Huajun Li 2013-11-10 23:13:17 +0800 1726) seq_puts(seq, ",inline_data");
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 1727) else
75342797988a0 (Wanpeng Li 2015-03-24 10:20:27 +0800 1728) seq_puts(seq, ",noinline_data");
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 1729) if (test_opt(sbi, INLINE_DENTRY))
5efd3c6f1be9c (Chao Yu 2014-09-24 18:16:13 +0800 1730) seq_puts(seq, ",inline_dentry");
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 1731) else
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 1732) seq_puts(seq, ",noinline_dentry");
b270ad6f0aedd (Gu Zheng 2014-04-11 17:49:55 +0800 1733) if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE))
6b4afdd794783 (Jaegeuk Kim 2014-04-02 15:34:36 +0900 1734) seq_puts(seq, ",flush_merge");
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 1735) if (test_opt(sbi, NOBARRIER))
0f7b2abd18808 (Jaegeuk Kim 2014-07-23 09:57:31 -0700 1736) seq_puts(seq, ",nobarrier");
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 1737) if (test_opt(sbi, FASTBOOT))
d5053a34a9cc7 (Jaegeuk Kim 2014-10-30 22:47:03 -0700 1738) seq_puts(seq, ",fastboot");
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 1739) if (test_opt(sbi, EXTENT_CACHE))
8967215954a50 (Chao Yu 2015-02-05 17:55:51 +0800 1740) seq_puts(seq, ",extent_cache");
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 1741) else
7daaea256de42 (Jaegeuk Kim 2015-06-25 17:43:04 -0700 1742) seq_puts(seq, ",noextent_cache");
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 1743) if (test_opt(sbi, DATA_FLUSH))
343f40f0a70eb (Chao Yu 2015-12-16 13:12:16 +0800 1744) seq_puts(seq, ",data_flush");
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 1745)
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 1746) seq_puts(seq, ",mode=");
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1747) if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE)
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 1748) seq_puts(seq, "adaptive");
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1749) else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS)
36abef4e796d3 (Jaegeuk Kim 2016-06-03 19:29:38 -0700 1750) seq_puts(seq, "lfs");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1751) seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 1752) if (test_opt(sbi, RESERVE_ROOT))
7c2e59632b846 (Jaegeuk Kim 2018-01-04 21:36:09 -0800 1753) seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1754) F2FS_OPTION(sbi).root_reserved_blocks,
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1755) from_kuid_munged(&init_user_ns,
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1756) F2FS_OPTION(sbi).s_resuid),
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1757) from_kgid_munged(&init_user_ns,
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1758) F2FS_OPTION(sbi).s_resgid));
ec91538dccd44 (Jaegeuk Kim 2016-12-21 17:09:19 -0800 1759) if (F2FS_IO_SIZE_BITS(sbi))
c6b1867b1da3b (Chengguang Xu 2018-09-22 22:43:09 +0800 1760) seq_printf(seq, ",io_bits=%u",
c6b1867b1da3b (Chengguang Xu 2018-09-22 22:43:09 +0800 1761) F2FS_OPTION(sbi).write_io_size_bits);
0cc0dec2b6f9b (Kaixu Xia 2017-01-27 09:35:37 +0800 1762) #ifdef CONFIG_F2FS_FAULT_INJECTION
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 1763) if (test_opt(sbi, FAULT_INJECTION)) {
44529f8975b7b (Chao Yu 2017-06-12 09:44:24 +0800 1764) seq_printf(seq, ",fault_injection=%u",
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1765) F2FS_OPTION(sbi).fault_info.inject_rate);
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 1766) seq_printf(seq, ",fault_type=%u",
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 1767) F2FS_OPTION(sbi).fault_info.inject_type);
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 1768) }
0cc0dec2b6f9b (Kaixu Xia 2017-01-27 09:35:37 +0800 1769) #endif
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1770) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1771) if (test_opt(sbi, QUOTA))
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1772) seq_puts(seq, ",quota");
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1773) if (test_opt(sbi, USRQUOTA))
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1774) seq_puts(seq, ",usrquota");
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1775) if (test_opt(sbi, GRPQUOTA))
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1776) seq_puts(seq, ",grpquota");
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 1777) if (test_opt(sbi, PRJQUOTA))
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 1778) seq_puts(seq, ",prjquota");
0cc0dec2b6f9b (Kaixu Xia 2017-01-27 09:35:37 +0800 1779) #endif
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1780) f2fs_show_quota_options(seq, sbi->sb);
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1781) if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER)
0cdd31953967b (Hyunchul Lee 2018-01-31 11:36:57 +0900 1782) seq_printf(seq, ",whint_mode=%s", "user-based");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1783) else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS)
f2e703f9a3caa (Hyunchul Lee 2018-01-31 11:36:58 +0900 1784) seq_printf(seq, ",whint_mode=%s", "fs-based");
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 1785)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 1786) fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1787)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 1788) if (sbi->sb->s_flags & SB_INLINECRYPT)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 1789) seq_puts(seq, ",inlinecrypt");
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 1790)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1791) if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 1792) seq_printf(seq, ",alloc_mode=%s", "default");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1793) else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
079396270b0f1 (Jaegeuk Kim 2018-02-18 08:50:49 -0800 1794) seq_printf(seq, ",alloc_mode=%s", "reuse");
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 1795)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1796) if (test_opt(sbi, DISABLE_CHECKPOINT))
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1797) seq_printf(seq, ",checkpoint=disable:%u",
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1798) F2FS_OPTION(sbi).unusable_cap);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1799) if (test_opt(sbi, MERGE_CHECKPOINT))
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1800) seq_puts(seq, ",checkpoint_merge");
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1801) else
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 1802) seq_puts(seq, ",nocheckpoint_merge");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1803) if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 1804) seq_printf(seq, ",fsync_mode=%s", "posix");
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1805) else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
93cf93f17c8ef (Junling Zheng 2018-03-07 12:07:49 +0800 1806) seq_printf(seq, ",fsync_mode=%s", "strict");
dc1328027b535 (Sahitya Tummala 2018-07-02 11:37:40 +0530 1807) else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER)
dc1328027b535 (Sahitya Tummala 2018-07-02 11:37:40 +0530 1808) seq_printf(seq, ",fsync_mode=%s", "nobarrier");
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1809)
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1810) #ifdef CONFIG_F2FS_FS_COMPRESSION
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1811) f2fs_show_compress_options(seq, sbi->sb);
1f0b067b6e492 (Chao Yu 2020-07-29 21:21:36 +0800 1812) #endif
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1813)
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1814) if (test_opt(sbi, ATGC))
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1815) seq_puts(seq, ",atgc");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1816) return 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1817) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 1818)
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1819) static void default_options(struct f2fs_sb_info *sbi)
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1820) {
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1821) /* init some FS parameters */
d0b9e42ab6155 (Chao Yu 2020-08-04 21:14:45 +0800 1822) F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1823) F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1824) F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1825) F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1826) F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
0aa7e0f8c0a02 (Chao Yu 2018-06-06 23:55:02 +0800 1827) F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
0aa7e0f8c0a02 (Chao Yu 2018-06-06 23:55:02 +0800 1828) F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
91faa5344fd22 (Chao Yu 2020-03-10 20:50:05 +0800 1829) F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1830) F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 1831) F2FS_OPTION(sbi).compress_ext_cnt = 0;
602a16d58e9aa (Daeho Jeong 2020-12-01 13:08:02 +0900 1832) F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS;
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 1833) F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON;
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1834)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 1835) sbi->sb->s_flags &= ~SB_INLINECRYPT;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 1836)
39133a5015e2f (Chao Yu 2017-02-08 17:39:44 +0800 1837) set_opt(sbi, INLINE_XATTR);
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1838) set_opt(sbi, INLINE_DATA);
97c1794a5dc16 (Chao Yu 2016-05-09 19:56:34 +0800 1839) set_opt(sbi, INLINE_DENTRY);
3e72f721390dc (Jaegeuk Kim 2015-06-19 17:53:26 -0700 1840) set_opt(sbi, EXTENT_CACHE);
7a20b8a61eff8 (Jaegeuk Kim 2017-03-24 20:41:45 -0400 1841) set_opt(sbi, NOHEAP);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1842) clear_opt(sbi, DISABLE_CHECKPOINT);
b5d15199a26f6 (Jaegeuk Kim 2021-04-01 17:25:20 -0700 1843) set_opt(sbi, MERGE_CHECKPOINT);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1844) F2FS_OPTION(sbi).unusable_cap = 0;
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 1845) sbi->sb->s_flags |= SB_LAZYTIME;
69e9e4274450c (Jaegeuk Kim 2016-05-20 22:39:20 -0700 1846) set_opt(sbi, FLUSH_MERGE);
7d20c8abb2edc (Chao Yu 2018-09-04 03:52:17 +0800 1847) set_opt(sbi, DISCARD);
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 1848) if (f2fs_sb_has_blkzoned(sbi))
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1849) F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS;
a39e5365835ed (Chao Yu 2018-07-05 14:24:11 +0800 1850) else
b0332a0f957ca (Chao Yu 2020-02-14 17:44:12 +0800 1851) F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE;
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1852)
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1853) #ifdef CONFIG_F2FS_FS_XATTR
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1854) set_opt(sbi, XATTR_USER);
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1855) #endif
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1856) #ifdef CONFIG_F2FS_FS_POSIX_ACL
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1857) set_opt(sbi, POSIX_ACL);
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1858) #endif
36dbd3287fefd (Chao Yu 2016-09-26 19:45:05 +0800 1859)
d494500a70434 (Chao Yu 2018-08-08 17:36:41 +0800 1860) f2fs_build_fault_attr(sbi, 0, 0);
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1861) }
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1862)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 1863) #ifdef CONFIG_QUOTA
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 1864) static int f2fs_enable_quotas(struct super_block *sb);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 1865) #endif
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1866)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1867) static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1868) {
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1869) unsigned int s_flags = sbi->sb->s_flags;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1870) struct cp_control cpc;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1871) int err = 0;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1872) int ret;
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1873) block_t unusable;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1874)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1875) if (s_flags & SB_RDONLY) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1876) f2fs_err(sbi, "checkpoint=disable on readonly fs");
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1877) return -EINVAL;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1878) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1879) sbi->sb->s_flags |= SB_ACTIVE;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1880)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1881) f2fs_update_time(sbi, DISABLE_TIME);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1882)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1883) while (!f2fs_time_over(sbi, DISABLE_TIME)) {
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 1884) down_write(&sbi->gc_lock);
7dede88659df3 (Chao Yu 2021-02-20 17:35:40 +0800 1885) err = f2fs_gc(sbi, true, false, false, NULL_SEGNO);
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1886) if (err == -ENODATA) {
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1887) err = 0;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1888) break;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1889) }
8f31b4665c14f (Jaegeuk Kim 2018-12-17 17:08:26 -0800 1890) if (err && err != -EAGAIN)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1891) break;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1892) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1893)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1894) ret = sync_filesystem(sbi->sb);
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1895) if (ret || err) {
5f029c045c948 (Yi Zhuang 2021-04-06 09:47:35 +0800 1896) err = ret ? ret : err;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1897) goto restore_flag;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1898) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1899)
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1900) unusable = f2fs_get_unusable_blocks(sbi);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1901) if (f2fs_disable_cp_again(sbi, unusable)) {
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1902) err = -EAGAIN;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1903) goto restore_flag;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1904) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1905)
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 1906) down_write(&sbi->gc_lock);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1907) cpc.reason = CP_PAUSE;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1908) set_sbi_flag(sbi, SBI_CP_DISABLED);
896285ad02ea1 (Chao Yu 2019-04-26 17:57:54 +0800 1909) err = f2fs_write_checkpoint(sbi, &cpc);
896285ad02ea1 (Chao Yu 2019-04-26 17:57:54 +0800 1910) if (err)
896285ad02ea1 (Chao Yu 2019-04-26 17:57:54 +0800 1911) goto out_unlock;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1912)
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1913) spin_lock(&sbi->stat_lock);
4d3aed70902f2 (Daniel Rosenberg 2019-05-29 17:49:06 -0700 1914) sbi->unusable_block_count = unusable;
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1915) spin_unlock(&sbi->stat_lock);
c9c8ed50d94c6 (Chao Yu 2019-05-05 11:40:46 +0800 1916)
896285ad02ea1 (Chao Yu 2019-04-26 17:57:54 +0800 1917) out_unlock:
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 1918) up_write(&sbi->gc_lock);
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1919) restore_flag:
7a88ddb56077d (Chao Yu 2020-02-27 19:30:05 +0800 1920) sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 1921) return err;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1922) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1923)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1924) static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1925) {
b0ff4fe746fd0 (Jaegeuk Kim 2021-01-26 17:00:42 -0800 1926) /* we should flush all the data to keep data consistency */
b0ff4fe746fd0 (Jaegeuk Kim 2021-01-26 17:00:42 -0800 1927) sync_inodes_sb(sbi->sb);
b0ff4fe746fd0 (Jaegeuk Kim 2021-01-26 17:00:42 -0800 1928)
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 1929) down_write(&sbi->gc_lock);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1930) f2fs_dirty_to_prefree(sbi);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1931)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1932) clear_sbi_flag(sbi, SBI_CP_DISABLED);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1933) set_sbi_flag(sbi, SBI_IS_DIRTY);
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 1934) up_write(&sbi->gc_lock);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1935)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1936) f2fs_sync_fs(sbi->sb, 1);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1937) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1938)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1939) static int f2fs_remount(struct super_block *sb, int *flags, char *data)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1940) {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1941) struct f2fs_sb_info *sbi = F2FS_SB(sb);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1942) struct f2fs_mount_info org_mount_opt;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1943) unsigned long old_sb_flags;
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1944) int err;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 1945) bool need_restart_gc = false, need_stop_gc = false;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 1946) bool need_restart_ckpt = false, need_stop_ckpt = false;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 1947) bool need_restart_flush = false, need_stop_flush = false;
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 1948) bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1949) bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT);
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 1950) bool no_io_align = !F2FS_IO_ALIGNED(sbi);
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 1951) bool no_atgc = !test_opt(sbi, ATGC);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1952) bool checkpoint_changed;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1953) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1954) int i, j;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1955) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1956)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1957) /*
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1958) * Save the old mount options in case we
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1959) * need to restore them.
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1960) */
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1961) org_mount_opt = sbi->mount_opt;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 1962) old_sb_flags = sb->s_flags;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1963)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1964) #ifdef CONFIG_QUOTA
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1965) org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1966) for (i = 0; i < MAXQUOTAS; i++) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1967) if (F2FS_OPTION(sbi).s_qf_names[i]) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1968) org_mount_opt.s_qf_names[i] =
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1969) kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1970) GFP_KERNEL);
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1971) if (!org_mount_opt.s_qf_names[i]) {
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1972) for (j = 0; j < i; j++)
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 1973) kfree(org_mount_opt.s_qf_names[j]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1974) return -ENOMEM;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1975) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1976) } else {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 1977) org_mount_opt.s_qf_names[i] = NULL;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1978) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1979) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1980) #endif
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 1981)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1982) /* recover superblocks we couldn't write due to previous RO mount */
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 1983) if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) {
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1984) err = f2fs_commit_super(sbi, false);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1985) f2fs_info(sbi, "Try to recover all the superblocks, ret: %d",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 1986) err);
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1987) if (!err)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1988) clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1989) }
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 1990)
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 1991) default_options(sbi);
26666c8a4366d (Chao Yu 2014-09-15 18:04:44 +0800 1992)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1993) /* parse mount options */
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 1994) err = parse_options(sb, data, true);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1995) if (err)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1996) goto restore_opts;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1997) checkpoint_changed =
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 1998) disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 1999)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2000) /*
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2001) * Previous and new state of filesystem is RO,
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2002) * so skip checking GC and FLUSH_MERGE conditions.
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2003) */
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2004) if (f2fs_readonly(sb) && (*flags & SB_RDONLY))
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2005) goto skip;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2006)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2007) #ifdef CONFIG_QUOTA
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2008) if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2009) err = dquot_suspend(sb, -1);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2010) if (err < 0)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2011) goto restore_opts;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2012) } else if (f2fs_readonly(sb) && !(*flags & SB_RDONLY)) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2013) /* dquot_resume needs RW */
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2014) sb->s_flags &= ~SB_RDONLY;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2015) if (sb_any_quota_suspended(sb)) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2016) dquot_resume(sb, -1);
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2017) } else if (f2fs_sb_has_quota_ino(sbi)) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2018) err = f2fs_enable_quotas(sb);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2019) if (err)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2020) goto restore_opts;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2021) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2022) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2023) #endif
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2024) /* disallow enable atgc dynamically */
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2025) if (no_atgc == !!test_opt(sbi, ATGC)) {
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2026) err = -EINVAL;
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2027) f2fs_warn(sbi, "switch atgc option is not allowed");
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2028) goto restore_opts;
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2029) }
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 2030)
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2031) /* disallow enable/disable extent_cache dynamically */
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2032) if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2033) err = -EINVAL;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2034) f2fs_warn(sbi, "switch extent_cache option is not allowed");
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2035) goto restore_opts;
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2036) }
9cd81ce3c2f01 (Chao Yu 2015-09-18 16:55:26 +0800 2037)
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2038) if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) {
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2039) err = -EINVAL;
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2040) f2fs_warn(sbi, "switch io_bits option is not allowed");
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2041) goto restore_opts;
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2042) }
1f78adfab379e (Chao Yu 2019-07-12 16:57:00 +0800 2043)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2044) if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) {
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2045) err = -EINVAL;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2046) f2fs_warn(sbi, "disabling checkpoint not compatible with read-only");
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2047) goto restore_opts;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2048) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 2049)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2050) /*
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2051) * We stop the GC thread if FS is mounted as RO
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2052) * or if background_gc = off is passed in mount
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2053) * option. Also sync the filesystem.
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2054) */
bbbc34fd66625 (Chao Yu 2020-02-14 17:44:13 +0800 2055) if ((*flags & SB_RDONLY) ||
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 2056) (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF &&
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 2057) !test_opt(sbi, GC_MERGE))) {
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2058) if (sbi->gc_thread) {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2059) f2fs_stop_gc_thread(sbi);
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2060) need_restart_gc = true;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2061) }
aba291b3d8d83 (Chao Yu 2014-11-18 11:17:20 +0800 2062) } else if (!sbi->gc_thread) {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2063) err = f2fs_start_gc_thread(sbi);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2064) if (err)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2065) goto restore_opts;
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2066) need_stop_gc = true;
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2067) }
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2068)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2069) if (*flags & SB_RDONLY ||
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2070) F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) {
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2071) sync_inodes_sb(sb);
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2072)
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2073) set_sbi_flag(sbi, SBI_IS_DIRTY);
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2074) set_sbi_flag(sbi, SBI_IS_CLOSE);
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2075) f2fs_sync_fs(sb, 1);
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2076) clear_sbi_flag(sbi, SBI_IS_CLOSE);
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2077) }
faa0e55bba54b (Jaegeuk Kim 2016-03-24 10:29:39 -0700 2078)
3f7070b05052f (Chao Yu 2021-03-17 17:56:03 +0800 2079) if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) ||
3f7070b05052f (Chao Yu 2021-03-17 17:56:03 +0800 2080) !test_opt(sbi, MERGE_CHECKPOINT)) {
3f7070b05052f (Chao Yu 2021-03-17 17:56:03 +0800 2081) f2fs_stop_ckpt_thread(sbi);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2082) need_restart_ckpt = true;
3f7070b05052f (Chao Yu 2021-03-17 17:56:03 +0800 2083) } else {
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2084) err = f2fs_start_ckpt_thread(sbi);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2085) if (err) {
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2086) f2fs_err(sbi,
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2087) "Failed to start F2FS issue_checkpoint_thread (%d)",
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2088) err);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2089) goto restore_gc;
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2090) }
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2091) need_stop_ckpt = true;
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2092) }
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 2093)
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2094) /*
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2095) * We stop issue flush thread if FS is mounted as RO
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2096) * or if flush_merge is not passed in mount option.
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2097) */
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2098) if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) {
5eba8c5d1fb3a (Jaegeuk Kim 2016-12-07 16:23:32 -0800 2099) clear_opt(sbi, FLUSH_MERGE);
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2100) f2fs_destroy_flush_cmd_control(sbi, false);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2101) need_restart_flush = true;
5eba8c5d1fb3a (Jaegeuk Kim 2016-12-07 16:23:32 -0800 2102) } else {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2103) err = f2fs_create_flush_cmd_control(sbi);
2163d19815b3d (Gu Zheng 2014-04-27 14:21:33 +0800 2104) if (err)
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2105) goto restore_ckpt;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2106) need_stop_flush = true;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2107) }
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2108)
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2109) if (checkpoint_changed) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2110) if (test_opt(sbi, DISABLE_CHECKPOINT)) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2111) err = f2fs_disable_checkpoint(sbi);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2112) if (err)
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2113) goto restore_flush;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2114) } else {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2115) f2fs_enable_checkpoint(sbi);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2116) }
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2117) }
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2118)
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2119) skip:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2120) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2121) /* Release old quota file names */
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2122) for (i = 0; i < MAXQUOTAS; i++)
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 2123) kfree(org_mount_opt.s_qf_names[i]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2124) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2125) /* Update the POSIXACL Flag */
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2126) sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 2127) (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 2128)
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 2129) limit_reserve_root(sbi);
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 2130) adjust_unusable_cap_perc(sbi);
095680f24f267 (Jaegeuk Kim 2018-09-28 00:24:39 -0700 2131) *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME);
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2132) return 0;
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2133) restore_flush:
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2134) if (need_restart_flush) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2135) if (f2fs_create_flush_cmd_control(sbi))
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2136) f2fs_warn(sbi, "background flush thread has stopped");
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2137) } else if (need_stop_flush) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2138) clear_opt(sbi, FLUSH_MERGE);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2139) f2fs_destroy_flush_cmd_control(sbi, false);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2140) }
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2141) restore_ckpt:
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2142) if (need_restart_ckpt) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2143) if (f2fs_start_ckpt_thread(sbi))
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2144) f2fs_warn(sbi, "background ckpt thread has stopped");
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2145) } else if (need_stop_ckpt) {
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2146) f2fs_stop_ckpt_thread(sbi);
3fd9735908287 (Chao Yu 2021-03-17 17:56:04 +0800 2147) }
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2148) restore_gc:
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2149) if (need_restart_gc) {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2150) if (f2fs_start_gc_thread(sbi))
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2151) f2fs_warn(sbi, "background gc thread has stopped");
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2152) } else if (need_stop_gc) {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2153) f2fs_stop_gc_thread(sbi);
876dc59eb1f01 (Gu Zheng 2014-04-11 17:50:00 +0800 2154) }
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2155) restore_opts:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2156) #ifdef CONFIG_QUOTA
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2157) F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2158) for (i = 0; i < MAXQUOTAS; i++) {
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 2159) kfree(F2FS_OPTION(sbi).s_qf_names[i]);
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2160) F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2161) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2162) #endif
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2163) sbi->mount_opt = org_mount_opt;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2164) sb->s_flags = old_sb_flags;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2165) return err;
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2166) }
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2167)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2168) #ifdef CONFIG_QUOTA
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2169) /* Read data from quotafile */
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2170) static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2171) size_t len, loff_t off)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2172) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2173) struct inode *inode = sb_dqopt(sb)->files[type];
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2174) struct address_space *mapping = inode->i_mapping;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2175) block_t blkidx = F2FS_BYTES_TO_BLK(off);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2176) int offset = off & (sb->s_blocksize - 1);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2177) int tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2178) size_t toread;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2179) loff_t i_size = i_size_read(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2180) struct page *page;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2181) char *kaddr;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2182)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2183) if (off > i_size)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2184) return 0;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2185)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2186) if (off + len > i_size)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2187) len = i_size - off;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2188) toread = len;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2189) while (toread > 0) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2190) tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2191) repeat:
02117b8ae9c05 (Ritesh Harjani 2018-03-16 18:53:53 +0530 2192) page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2193) if (IS_ERR(page)) {
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2194) if (PTR_ERR(page) == -ENOMEM) {
5df7731f60c2a (Chao Yu 2020-02-17 17:45:44 +0800 2195) congestion_wait(BLK_RW_ASYNC,
5df7731f60c2a (Chao Yu 2020-02-17 17:45:44 +0800 2196) DEFAULT_IO_TIMEOUT);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2197) goto repeat;
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2198) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2199) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2200) return PTR_ERR(page);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2201) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2202)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2203) lock_page(page);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2204)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2205) if (unlikely(page->mapping != mapping)) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2206) f2fs_put_page(page, 1);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2207) goto repeat;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2208) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2209) if (unlikely(!PageUptodate(page))) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2210) f2fs_put_page(page, 1);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2211) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2212) return -EIO;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2213) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2214)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2215) kaddr = kmap_atomic(page);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2216) memcpy(data, kaddr + offset, tocopy);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2217) kunmap_atomic(kaddr);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2218) f2fs_put_page(page, 1);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2219)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2220) offset = 0;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2221) toread -= tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2222) data += tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2223) blkidx++;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2224) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2225) return len;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2226) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2227)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2228) /* Write to quotafile */
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2229) static ssize_t f2fs_quota_write(struct super_block *sb, int type,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2230) const char *data, size_t len, loff_t off)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2231) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2232) struct inode *inode = sb_dqopt(sb)->files[type];
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2233) struct address_space *mapping = inode->i_mapping;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2234) const struct address_space_operations *a_ops = mapping->a_ops;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2235) int offset = off & (sb->s_blocksize - 1);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2236) size_t towrite = len;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2237) struct page *page;
62f63eea291b5 (Chao Yu 2020-03-19 19:58:00 +0800 2238) void *fsdata = NULL;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2239) char *kaddr;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2240) int err = 0;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2241) int tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2242)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2243) while (towrite > 0) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2244) tocopy = min_t(unsigned long, sb->s_blocksize - offset,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2245) towrite);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2246) retry:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2247) err = a_ops->write_begin(NULL, mapping, off, tocopy, 0,
62f63eea291b5 (Chao Yu 2020-03-19 19:58:00 +0800 2248) &page, &fsdata);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2249) if (unlikely(err)) {
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2250) if (err == -ENOMEM) {
5df7731f60c2a (Chao Yu 2020-02-17 17:45:44 +0800 2251) congestion_wait(BLK_RW_ASYNC,
5df7731f60c2a (Chao Yu 2020-02-17 17:45:44 +0800 2252) DEFAULT_IO_TIMEOUT);
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2253) goto retry;
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2254) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2255) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2256) break;
4e46a023c515d (Jaegeuk Kim 2017-10-19 09:43:56 -0700 2257) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2258)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2259) kaddr = kmap_atomic(page);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2260) memcpy(kaddr + offset, data, tocopy);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2261) kunmap_atomic(kaddr);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2262) flush_dcache_page(page);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2263)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2264) a_ops->write_end(NULL, mapping, off, tocopy, tocopy,
62f63eea291b5 (Chao Yu 2020-03-19 19:58:00 +0800 2265) page, fsdata);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2266) offset = 0;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2267) towrite -= tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2268) off += tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2269) data += tocopy;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2270) cond_resched();
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2271) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2272)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2273) if (len == towrite)
6e5b5d41c93ef (Jaegeuk Kim 2017-10-19 12:07:11 -0700 2274) return err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2275) inode->i_mtime = inode->i_ctime = current_time(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2276) f2fs_mark_inode_dirty_sync(inode, false);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2277) return len - towrite;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2278) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2279)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2280) static struct dquot **f2fs_get_dquots(struct inode *inode)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2281) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2282) return F2FS_I(inode)->i_dquot;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2283) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2284)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2285) static qsize_t *f2fs_get_reserved_space(struct inode *inode)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2286) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2287) return &F2FS_I(inode)->i_reserved_quota;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2288) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2289)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2290) static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2291) {
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2292) if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2293) f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it");
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2294) return 0;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2295) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2296)
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2297) return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2298) F2FS_OPTION(sbi).s_jquota_fmt, type);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2299) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2300)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2301) int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2302) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2303) int enabled = 0;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2304) int i, err;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2305)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2306) if (f2fs_sb_has_quota_ino(sbi) && rdonly) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2307) err = f2fs_enable_quotas(sbi->sb);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2308) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2309) f2fs_err(sbi, "Cannot turn on quota_ino: %d", err);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2310) return 0;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2311) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2312) return 1;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2313) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2314)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2315) for (i = 0; i < MAXQUOTAS; i++) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 2316) if (F2FS_OPTION(sbi).s_qf_names[i]) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2317) err = f2fs_quota_on_mount(sbi, i);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2318) if (!err) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2319) enabled = 1;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2320) continue;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2321) }
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2322) f2fs_err(sbi, "Cannot turn on quotas: %d on %d",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2323) err, i);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2324) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2325) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2326) return enabled;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2327) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2328)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2329) static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2330) unsigned int flags)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2331) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2332) struct inode *qf_inode;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2333) unsigned long qf_inum;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2334) int err;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2335)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2336) BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2337)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2338) qf_inum = f2fs_qf_ino(sb, type);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2339) if (!qf_inum)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2340) return -EPERM;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2341)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2342) qf_inode = f2fs_iget(sb, qf_inum);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2343) if (IS_ERR(qf_inode)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2344) f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2345) return PTR_ERR(qf_inode);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2346) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2347)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2348) /* Don't account quota for quota files to avoid recursion */
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2349) qf_inode->i_flags |= S_NOQUOTA;
7212b95e61516 (Jan Kara 2019-11-01 18:55:38 +0100 2350) err = dquot_load_quota_inode(qf_inode, type, format_id, flags);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2351) iput(qf_inode);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2352) return err;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2353) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2354)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2355) static int f2fs_enable_quotas(struct super_block *sb)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2356) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2357) struct f2fs_sb_info *sbi = F2FS_SB(sb);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2358) int type, err = 0;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2359) unsigned long qf_inum;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2360) bool quota_mopt[MAXQUOTAS] = {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2361) test_opt(sbi, USRQUOTA),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2362) test_opt(sbi, GRPQUOTA),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2363) test_opt(sbi, PRJQUOTA),
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2364) };
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2365)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2366) if (is_set_ckpt_flags(F2FS_SB(sb), CP_QUOTA_NEED_FSCK_FLAG)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2367) f2fs_err(sbi, "quota file may be corrupted, skip loading it");
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2368) return 0;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2369) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2370)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2371) sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2372)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2373) for (type = 0; type < MAXQUOTAS; type++) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2374) qf_inum = f2fs_qf_ino(sb, type);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2375) if (qf_inum) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2376) err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2377) DQUOT_USAGE_ENABLED |
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2378) (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2379) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2380) f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2381) type, err);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2382) for (type--; type >= 0; type--)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2383) dquot_quota_off(sb, type);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2384) set_sbi_flag(F2FS_SB(sb),
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2385) SBI_QUOTA_NEED_REPAIR);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2386) return err;
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2387) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2388) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2389) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 2390) return 0;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2391) }
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2392)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2393) int f2fs_quota_sync(struct super_block *sb, int type)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2394) {
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2395) struct f2fs_sb_info *sbi = F2FS_SB(sb);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2396) struct quota_info *dqopt = sb_dqopt(sb);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2397) int cnt;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2398) int ret;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2399)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2400) /*
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2401) * do_quotactl
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2402) * f2fs_quota_sync
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2403) * down_read(quota_sem)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2404) * dquot_writeback_dquots()
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2405) * f2fs_dquot_commit
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2406) * block_operation
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2407) * down_read(quota_sem)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2408) */
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2409) f2fs_lock_op(sbi);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2410)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2411) down_read(&sbi->quota_sem);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2412) ret = dquot_writeback_dquots(sb, type);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2413) if (ret)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2414) goto out;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2415)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2416) /*
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2417) * Now when everything is written we can discard the pagecache so
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2418) * that userspace sees the changes.
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2419) */
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2420) for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2421) struct address_space *mapping;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2422)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2423) if (type != -1 && cnt != type)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2424) continue;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2425) if (!sb_has_quota_active(sb, cnt))
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2426) continue;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2427)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2428) mapping = dqopt->files[cnt]->i_mapping;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2429)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2430) ret = filemap_fdatawrite(mapping);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2431) if (ret)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2432) goto out;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2433)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2434) /* if we are using journalled quota */
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2435) if (is_journalled_quota(sbi))
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2436) continue;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2437)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2438) ret = filemap_fdatawait(mapping);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2439) if (ret)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2440) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2441)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2442) inode_lock(dqopt->files[cnt]);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2443) truncate_inode_pages(&dqopt->files[cnt]->i_data, 0);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2444) inode_unlock(dqopt->files[cnt]);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2445) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2446) out:
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2447) if (ret)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2448) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2449) up_read(&sbi->quota_sem);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2450) f2fs_unlock_op(sbi);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2451) return ret;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2452) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2453)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2454) static int f2fs_quota_on(struct super_block *sb, int type, int format_id,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2455) const struct path *path)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2456) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2457) struct inode *inode;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2458) int err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2459)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2460) /* if quota sysfile exists, deny enabling quota with specific file */
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2461) if (f2fs_sb_has_quota_ino(F2FS_SB(sb))) {
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2462) f2fs_err(F2FS_SB(sb), "quota sysfile already exists");
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2463) return -EBUSY;
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2464) }
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2465)
9a20d391cd099 (Chao Yu 2017-08-07 16:37:59 +0800 2466) err = f2fs_quota_sync(sb, type);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2467) if (err)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2468) return err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2469)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2470) err = dquot_quota_on(sb, type, format_id, path);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2471) if (err)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2472) return err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2473)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2474) inode = d_inode(path->dentry);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2475)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2476) inode_lock(inode);
59c844088b19c (Chao Yu 2018-04-03 15:08:17 +0800 2477) F2FS_I(inode)->i_flags |= F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL;
9149a5eb60615 (Chao Yu 2018-10-07 19:06:15 +0800 2478) f2fs_set_inode_flags(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2479) inode_unlock(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2480) f2fs_mark_inode_dirty_sync(inode, false);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2481)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2482) return 0;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2483) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2484)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2485) static int __f2fs_quota_off(struct super_block *sb, int type)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2486) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2487) struct inode *inode = sb_dqopt(sb)->files[type];
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2488) int err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2489)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2490) if (!inode || !igrab(inode))
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2491) return dquot_quota_off(sb, type);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2492)
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2493) err = f2fs_quota_sync(sb, type);
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2494) if (err)
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2495) goto out_put;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2496)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2497) err = dquot_quota_off(sb, type);
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2498) if (err || f2fs_sb_has_quota_ino(F2FS_SB(sb)))
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2499) goto out_put;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2500)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2501) inode_lock(inode);
59c844088b19c (Chao Yu 2018-04-03 15:08:17 +0800 2502) F2FS_I(inode)->i_flags &= ~(F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL);
9149a5eb60615 (Chao Yu 2018-10-07 19:06:15 +0800 2503) f2fs_set_inode_flags(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2504) inode_unlock(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2505) f2fs_mark_inode_dirty_sync(inode, false);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2506) out_put:
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2507) iput(inode);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2508) return err;
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2509) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2510)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2511) static int f2fs_quota_off(struct super_block *sb, int type)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2512) {
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2513) struct f2fs_sb_info *sbi = F2FS_SB(sb);
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2514) int err;
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2515)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2516) err = __f2fs_quota_off(sb, type);
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2517)
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2518) /*
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2519) * quotactl can shutdown journalled quota, result in inconsistence
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2520) * between quota record and fs data by following updates, tag the
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2521) * flag to let fsck be aware of it.
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2522) */
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2523) if (is_journalled_quota(sbi))
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2524) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2525) return err;
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2526) }
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2527)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2528) void f2fs_quota_off_umount(struct super_block *sb)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2529) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2530) int type;
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2531) int err;
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2532)
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2533) for (type = 0; type < MAXQUOTAS; type++) {
fe973b065bce0 (Chao Yu 2019-07-25 17:33:37 +0800 2534) err = __f2fs_quota_off(sb, type);
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2535) if (err) {
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2536) int ret = dquot_quota_off(sb, type);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2537)
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2538) f2fs_err(F2FS_SB(sb), "Fail to turn off disk quota (type: %d, err: %d, ret:%d), Please run fsck to fix it.",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2539) type, err, ret);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2540) set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR);
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2541) }
cda9cc595f0bb (Yunlei He 2018-06-26 13:12:43 +0800 2542) }
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2543) /*
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2544) * In case of checkpoint=disable, we must flush quota blocks.
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2545) * This can cause NULL exception for node_inode in end_io, since
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2546) * put_super already dropped it.
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2547) */
0e0667b625cf6 (Jaegeuk Kim 2019-01-27 17:59:53 -0800 2548) sync_filesystem(sb);
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2549) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2550)
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2551) static void f2fs_truncate_quota_inode_pages(struct super_block *sb)
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2552) {
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2553) struct quota_info *dqopt = sb_dqopt(sb);
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2554) int type;
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2555)
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2556) for (type = 0; type < MAXQUOTAS; type++) {
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2557) if (!dqopt->files[type])
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2558) continue;
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2559) f2fs_inode_synced(dqopt->files[type]);
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2560) }
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2561) }
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2562)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2563) static int f2fs_dquot_commit(struct dquot *dquot)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2564) {
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2565) struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2566) int ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2567)
2c4e0c528ec29 (Jaegeuk Kim 2019-12-03 17:31:00 -0800 2568) down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2569) ret = dquot_commit(dquot);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2570) if (ret < 0)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2571) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2572) up_read(&sbi->quota_sem);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2573) return ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2574) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2575)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2576) static int f2fs_dquot_acquire(struct dquot *dquot)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2577) {
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2578) struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2579) int ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2580)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2581) down_read(&sbi->quota_sem);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2582) ret = dquot_acquire(dquot);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2583) if (ret < 0)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2584) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2585) up_read(&sbi->quota_sem);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2586) return ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2587) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2588)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2589) static int f2fs_dquot_release(struct dquot *dquot)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2590) {
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2591) struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb);
2c4e0c528ec29 (Jaegeuk Kim 2019-12-03 17:31:00 -0800 2592) int ret = dquot_release(dquot);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2593)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2594) if (ret < 0)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2595) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2596) return ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2597) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2598)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2599) static int f2fs_dquot_mark_dquot_dirty(struct dquot *dquot)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2600) {
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2601) struct super_block *sb = dquot->dq_sb;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2602) struct f2fs_sb_info *sbi = F2FS_SB(sb);
2c4e0c528ec29 (Jaegeuk Kim 2019-12-03 17:31:00 -0800 2603) int ret = dquot_mark_dquot_dirty(dquot);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2604)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2605) /* if we are using journalled quota */
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2606) if (is_journalled_quota(sbi))
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2607) set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2608)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2609) return ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2610) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2611)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2612) static int f2fs_dquot_commit_info(struct super_block *sb, int type)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2613) {
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2614) struct f2fs_sb_info *sbi = F2FS_SB(sb);
2c4e0c528ec29 (Jaegeuk Kim 2019-12-03 17:31:00 -0800 2615) int ret = dquot_commit_info(sb, type);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2616)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2617) if (ret < 0)
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 2618) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2619) return ret;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2620) }
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 2621)
94b1e10e74542 (Wei Yongjun 2018-01-05 09:41:20 +0000 2622) static int f2fs_get_projid(struct inode *inode, kprojid_t *projid)
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2623) {
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2624) *projid = F2FS_I(inode)->i_projid;
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2625) return 0;
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2626) }
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2627)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2628) static const struct dquot_operations f2fs_quota_operations = {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2629) .get_reserved_space = f2fs_get_reserved_space,
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2630) .write_dquot = f2fs_dquot_commit,
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2631) .acquire_dquot = f2fs_dquot_acquire,
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2632) .release_dquot = f2fs_dquot_release,
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2633) .mark_dirty = f2fs_dquot_mark_dquot_dirty,
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2634) .write_info = f2fs_dquot_commit_info,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2635) .alloc_dquot = dquot_alloc,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2636) .destroy_dquot = dquot_destroy,
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 2637) .get_projid = f2fs_get_projid,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2638) .get_next_id = dquot_get_next_id,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2639) };
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2640)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2641) static const struct quotactl_ops f2fs_quotactl_ops = {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2642) .quota_on = f2fs_quota_on,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2643) .quota_off = f2fs_quota_off,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2644) .quota_sync = f2fs_quota_sync,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2645) .get_state = dquot_get_state,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2646) .set_info = dquot_set_dqinfo,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2647) .get_dqblk = dquot_get_dqblk,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2648) .set_dqblk = dquot_set_dqblk,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2649) .get_nextdqblk = dquot_get_next_dqblk,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2650) };
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2651) #else
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2652) int f2fs_quota_sync(struct super_block *sb, int type)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2653) {
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2654) return 0;
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2655) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 2656)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 2657) void f2fs_quota_off_umount(struct super_block *sb)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2658) {
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2659) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2660) #endif
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2661)
f62fc9f97602d (Arvind Yadav 2017-08-31 15:06:24 +0530 2662) static const struct super_operations f2fs_sops = {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2663) .alloc_inode = f2fs_alloc_inode,
d01718a050d06 (Al Viro 2019-04-15 19:29:14 -0400 2664) .free_inode = f2fs_free_inode,
531ad7d58c647 (Jaegeuk Kim 2013-04-30 11:33:27 +0900 2665) .drop_inode = f2fs_drop_inode,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2666) .write_inode = f2fs_write_inode,
b3783873cc221 (Jaegeuk Kim 2013-06-10 09:17:01 +0900 2667) .dirty_inode = f2fs_dirty_inode,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2668) .show_options = f2fs_show_options,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2669) #ifdef CONFIG_QUOTA
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2670) .quota_read = f2fs_quota_read,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2671) .quota_write = f2fs_quota_write,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2672) .get_dquots = f2fs_get_dquots,
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 2673) #endif
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2674) .evict_inode = f2fs_evict_inode,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2675) .put_super = f2fs_put_super,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2676) .sync_fs = f2fs_sync_fs,
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 2677) .freeze_fs = f2fs_freeze,
d6212a5f18c8f (Changman Lee 2013-01-29 18:30:07 +0900 2678) .unfreeze_fs = f2fs_unfreeze,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2679) .statfs = f2fs_statfs,
696c018c7718f (Namjae Jeon 2013-06-16 09:48:48 +0900 2680) .remount_fs = f2fs_remount,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2681) };
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2682)
643fa9612bf1a (Chandan Rajendra 2018-12-12 15:20:12 +0530 2683) #ifdef CONFIG_FS_ENCRYPTION
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2684) static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2685) {
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2686) return f2fs_getxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2687) F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2688) ctx, len, NULL);
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2689) }
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2690)
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2691) static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2692) void *fs_data)
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2693) {
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2694) struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2695)
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2696) /*
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2697) * Encrypting the root directory is not allowed because fsck
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2698) * expects lost+found directory to exist and remain unencrypted
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2699) * if LOST_FOUND feature is enabled.
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2700) *
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2701) */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2702) if (f2fs_sb_has_lost_found(sbi) &&
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2703) inode->i_ino == F2FS_ROOT_INO(sbi))
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2704) return -EPERM;
b7c409deda6bc (Sheng Yong 2018-03-15 18:51:41 +0800 2705)
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2706) return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2707) F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2708) ctx, len, fs_data, XATTR_CREATE);
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2709) }
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2710)
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 2711) static const union fscrypt_policy *f2fs_get_dummy_policy(struct super_block *sb)
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 2712) {
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 2713) return F2FS_OPTION(F2FS_SB(sb)).dummy_enc_policy.policy;
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 2714) }
ff62af200b94e (Sheng Yong 2018-03-15 18:51:42 +0800 2715)
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2716) static bool f2fs_has_stable_inodes(struct super_block *sb)
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2717) {
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2718) return true;
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2719) }
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2720)
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2721) static void f2fs_get_ino_and_lblk_bits(struct super_block *sb,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2722) int *ino_bits_ret, int *lblk_bits_ret)
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2723) {
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2724) *ino_bits_ret = 8 * sizeof(nid_t);
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2725) *lblk_bits_ret = 8 * sizeof(block_t);
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2726) }
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2727)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2728) static int f2fs_get_num_devices(struct super_block *sb)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2729) {
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2730) struct f2fs_sb_info *sbi = F2FS_SB(sb);
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2731)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2732) if (f2fs_is_multi_device(sbi))
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2733) return sbi->s_ndevs;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2734) return 1;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2735) }
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2736)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2737) static void f2fs_get_devices(struct super_block *sb,
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2738) struct request_queue **devs)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2739) {
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2740) struct f2fs_sb_info *sbi = F2FS_SB(sb);
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2741) int i;
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2742)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2743) for (i = 0; i < sbi->s_ndevs; i++)
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2744) devs[i] = bdev_get_queue(FDEV(i).bdev);
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2745) }
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2746)
6f69f0ed6136c (Eric Biggers 2017-02-07 12:42:10 -0800 2747) static const struct fscrypt_operations f2fs_cryptops = {
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2748) .key_prefix = "f2fs:",
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2749) .get_context = f2fs_get_context,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2750) .set_context = f2fs_set_context,
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 2751) .get_dummy_policy = f2fs_get_dummy_policy,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2752) .empty_dir = f2fs_empty_dir,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2753) .max_namelen = F2FS_NAME_LEN,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2754) .has_stable_inodes = f2fs_has_stable_inodes,
0eee17e332262 (Eric Biggers 2019-10-24 14:54:38 -0700 2755) .get_ino_and_lblk_bits = f2fs_get_ino_and_lblk_bits,
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2756) .get_num_devices = f2fs_get_num_devices,
27aacd28ea3b8 (Satya Tangirala 2020-07-02 01:56:06 +0000 2757) .get_devices = f2fs_get_devices,
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2758) };
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2759) #endif
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 2760)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2761) static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2762) u64 ino, u32 generation)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2763) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2764) struct f2fs_sb_info *sbi = F2FS_SB(sb);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2765) struct inode *inode;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2766)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 2767) if (f2fs_check_nid_range(sbi, ino))
910bb12d29cc6 (Chao Yu 2014-03-12 17:08:36 +0800 2768) return ERR_PTR(-ESTALE);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2769)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2770) /*
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2771) * f2fs_iget isn't quite right if the inode is currently unallocated!
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2772) * However f2fs_iget currently does appropriate checks to handle stale
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2773) * inodes so everything is OK.
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2774) */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2775) inode = f2fs_iget(sb, ino);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2776) if (IS_ERR(inode))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2777) return ERR_CAST(inode);
6bacf52fb58ae (Jaegeuk Kim 2013-12-06 15:00:58 +0900 2778) if (unlikely(generation && inode->i_generation != generation)) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2779) /* we didn't find the right inode.. */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2780) iput(inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2781) return ERR_PTR(-ESTALE);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2782) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2783) return inode;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2784) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2785)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2786) static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2787) int fh_len, int fh_type)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2788) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2789) return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2790) f2fs_nfs_get_inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2791) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2792)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2793) static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2794) int fh_len, int fh_type)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2795) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2796) return generic_fh_to_parent(sb, fid, fh_len, fh_type,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2797) f2fs_nfs_get_inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2798) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2799)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2800) static const struct export_operations f2fs_export_ops = {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2801) .fh_to_dentry = f2fs_fh_to_dentry,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2802) .fh_to_parent = f2fs_fh_to_parent,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2803) .get_parent = f2fs_get_parent,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2804) };
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2805)
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2806) loff_t max_file_blocks(struct inode *inode)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2807) {
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2808) loff_t result = 0;
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2809) loff_t leaf_count;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2810)
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2811) /*
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2812) * note: previously, result is equal to (DEF_ADDRS_PER_INODE -
6afc662e68b5f (Chao Yu 2017-09-06 21:59:50 +0800 2813) * DEFAULT_INLINE_XATTR_ADDRS), but now f2fs try to reserve more
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2814) * space in inode.i_addr, it will be more safe to reassign
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2815) * result as zero.
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2816) */
7a2af766af158 (Chao Yu 2017-07-19 00:19:06 +0800 2817)
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2818) if (inode && f2fs_compressed_file(inode))
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2819) leaf_count = ADDRS_PER_BLOCK(inode);
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2820) else
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2821) leaf_count = DEF_ADDRS_PER_BLOCK;
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 2822)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2823) /* two direct node blocks */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2824) result += (leaf_count * 2);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2825)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2826) /* two indirect node blocks */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2827) leaf_count *= NIDS_PER_BLOCK;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2828) result += (leaf_count * 2);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2829)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2830) /* one double indirect node block */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2831) leaf_count *= NIDS_PER_BLOCK;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2832) result += leaf_count;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2833)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2834) return result;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2835) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2836)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2837) static int __f2fs_commit_super(struct buffer_head *bh,
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2838) struct f2fs_super_block *super)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2839) {
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2840) lock_buffer(bh);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2841) if (super)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2842) memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2843) set_buffer_dirty(bh);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2844) unlock_buffer(bh);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2845)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2846) /* it's rare case, we can do fua all the time */
3adc5fcb7edf5 (Jan Kara 2017-05-02 17:03:47 +0200 2847) return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2848) }
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2849)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 2850) static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2851) struct buffer_head *bh)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2852) {
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2853) struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2854) (bh->b_data + F2FS_SUPER_OFFSET);
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 2855) struct super_block *sb = sbi->sb;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2856) u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2857) u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2858) u32 sit_blkaddr = le32_to_cpu(raw_super->sit_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2859) u32 nat_blkaddr = le32_to_cpu(raw_super->nat_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2860) u32 ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2861) u32 main_blkaddr = le32_to_cpu(raw_super->main_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2862) u32 segment_count_ckpt = le32_to_cpu(raw_super->segment_count_ckpt);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2863) u32 segment_count_sit = le32_to_cpu(raw_super->segment_count_sit);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2864) u32 segment_count_nat = le32_to_cpu(raw_super->segment_count_nat);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2865) u32 segment_count_ssa = le32_to_cpu(raw_super->segment_count_ssa);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2866) u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2867) u32 segment_count = le32_to_cpu(raw_super->segment_count);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2868) u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2869) u64 main_end_blkaddr = main_blkaddr +
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2870) (segment_count_main << log_blocks_per_seg);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2871) u64 seg_end_blkaddr = segment0_blkaddr +
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2872) (segment_count << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2873)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2874) if (segment0_blkaddr != cp_blkaddr) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2875) f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2876) segment0_blkaddr, cp_blkaddr);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2877) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2878) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2879)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2880) if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) !=
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2881) sit_blkaddr) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2882) f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2883) cp_blkaddr, sit_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2884) segment_count_ckpt << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2885) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2886) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2887)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2888) if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) !=
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2889) nat_blkaddr) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2890) f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2891) sit_blkaddr, nat_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2892) segment_count_sit << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2893) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2894) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2895)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2896) if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) !=
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2897) ssa_blkaddr) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2898) f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2899) nat_blkaddr, ssa_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2900) segment_count_nat << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2901) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2902) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2903)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2904) if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) !=
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2905) main_blkaddr) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2906) f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2907) ssa_blkaddr, main_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2908) segment_count_ssa << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2909) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2910) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2911)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2912) if (main_end_blkaddr > seg_end_blkaddr) {
d89f589130160 (Wang Xiaojun 2020-09-18 08:31:24 +0800 2913) f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)",
d89f589130160 (Wang Xiaojun 2020-09-18 08:31:24 +0800 2914) main_blkaddr, seg_end_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2915) segment_count_main << log_blocks_per_seg);
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2916) return true;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2917) } else if (main_end_blkaddr < seg_end_blkaddr) {
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2918) int err = 0;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2919) char *res;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2920)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2921) /* fix in-memory information all the time */
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2922) raw_super->segment_count = cpu_to_le32((main_end_blkaddr -
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2923) segment0_blkaddr) >> log_blocks_per_seg);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2924)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2925) if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) {
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 2926) set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2927) res = "internally";
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2928) } else {
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2929) err = __f2fs_commit_super(bh, NULL);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2930) res = err ? "failed" : "done";
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2931) }
d89f589130160 (Wang Xiaojun 2020-09-18 08:31:24 +0800 2932) f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)",
d89f589130160 (Wang Xiaojun 2020-09-18 08:31:24 +0800 2933) res, main_blkaddr, seg_end_blkaddr,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2934) segment_count_main << log_blocks_per_seg);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2935) if (err)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2936) return true;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2937) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2938) return false;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2939) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2940)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 2941) static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2942) struct buffer_head *bh)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2943) {
f99ba9add67ce (Wang Xiaojun 2020-09-17 19:11:58 +0800 2944) block_t segment_count, segs_per_sec, secs_per_zone, segment_count_main;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 2945) block_t total_sections, blocks_per_seg;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2946) struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 2947) (bh->b_data + F2FS_SUPER_OFFSET);
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2948) size_t crc_offset = 0;
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2949) __u32 crc = 0;
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2950)
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2951) if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) {
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2952) f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)",
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2953) F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2954) return -EINVAL;
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2955) }
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2956)
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2957) /* Check checksum_offset and crc in superblock */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 2958) if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) {
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2959) crc_offset = le32_to_cpu(raw_super->checksum_offset);
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2960) if (crc_offset !=
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2961) offsetof(struct f2fs_super_block, crc)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2962) f2fs_info(sbi, "Invalid SB checksum offset: %zu",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2963) crc_offset);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2964) return -EFSCORRUPTED;
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2965) }
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2966) crc = le32_to_cpu(raw_super->crc);
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2967) if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2968) f2fs_info(sbi, "Invalid SB checksum value: %u", crc);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2969) return -EFSCORRUPTED;
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2970) }
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 2971) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2972)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 2973) /* Currently, support only 4KB block size */
e584bbe821229 (Chao Yu 2020-12-09 16:49:36 +0800 2974) if (le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE_BITS) {
e584bbe821229 (Chao Yu 2020-12-09 16:49:36 +0800 2975) f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u",
e584bbe821229 (Chao Yu 2020-12-09 16:49:36 +0800 2976) le32_to_cpu(raw_super->log_blocksize),
e584bbe821229 (Chao Yu 2020-12-09 16:49:36 +0800 2977) F2FS_BLKSIZE_BITS);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2978) return -EFSCORRUPTED;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 2979) }
5c9b469295fb6 (majianpeng 2013-02-01 19:07:57 +0800 2980)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2981) /* check log blocks per segment */
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2982) if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2983) f2fs_info(sbi, "Invalid log blocks per segment (%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2984) le32_to_cpu(raw_super->log_blocks_per_seg));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2985) return -EFSCORRUPTED;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2986) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 2987)
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2988) /* Currently, support 512/1024/2048/4096 bytes sector size */
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2989) if (le32_to_cpu(raw_super->log_sectorsize) >
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2990) F2FS_MAX_LOG_SECTOR_SIZE ||
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2991) le32_to_cpu(raw_super->log_sectorsize) <
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2992) F2FS_MIN_LOG_SECTOR_SIZE) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2993) f2fs_info(sbi, "Invalid log sectorsize (%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 2994) le32_to_cpu(raw_super->log_sectorsize));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 2995) return -EFSCORRUPTED;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 2996) }
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2997) if (le32_to_cpu(raw_super->log_sectors_per_block) +
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2998) le32_to_cpu(raw_super->log_sectorsize) !=
55cf9cb63f0e5 (Chao Yu 2014-09-15 18:01:10 +0800 2999) F2FS_MAX_LOG_SECTOR_SIZE) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3000) f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3001) le32_to_cpu(raw_super->log_sectors_per_block),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3002) le32_to_cpu(raw_super->log_sectorsize));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3003) return -EFSCORRUPTED;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3004) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3005)
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3006) segment_count = le32_to_cpu(raw_super->segment_count);
f99ba9add67ce (Wang Xiaojun 2020-09-17 19:11:58 +0800 3007) segment_count_main = le32_to_cpu(raw_super->segment_count_main);
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3008) segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3009) secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3010) total_sections = le32_to_cpu(raw_super->section_count);
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3011)
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3012) /* blocks_per_seg should be 512, given the above check */
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3013) blocks_per_seg = 1 << le32_to_cpu(raw_super->log_blocks_per_seg);
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3014)
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3015) if (segment_count > F2FS_MAX_SEGMENT ||
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3016) segment_count < F2FS_MIN_SEGMENTS) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3017) f2fs_info(sbi, "Invalid segment count (%u)", segment_count);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3018) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3019) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3020)
f99ba9add67ce (Wang Xiaojun 2020-09-17 19:11:58 +0800 3021) if (total_sections > segment_count_main || total_sections < 1 ||
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3022) segs_per_sec > segment_count || !segs_per_sec) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3023) f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3024) segment_count, total_sections, segs_per_sec);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3025) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3026) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3027)
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3028) if (segment_count_main != total_sections * segs_per_sec) {
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3029) f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)",
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3030) segment_count_main, total_sections, segs_per_sec);
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3031) return -EFSCORRUPTED;
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3032) }
3a22e9ac71585 (Chao Yu 2020-09-29 09:23:34 +0800 3033)
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3034) if ((segment_count / segs_per_sec) < total_sections) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3035) f2fs_info(sbi, "Small segment_count (%u < %u * %u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3036) segment_count, segs_per_sec, total_sections);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3037) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3038) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3039)
88960068f25fc (Martin Blumenstingl 2018-12-22 11:22:26 +0100 3040) if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3041) f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3042) segment_count, le64_to_cpu(raw_super->block_count));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3043) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3044) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3045)
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3046) if (RDEV(0).path[0]) {
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3047) block_t dev_seg_count = le32_to_cpu(RDEV(0).total_segments);
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3048) int i = 1;
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3049)
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3050) while (i < MAX_DEVICES && RDEV(i).path[0]) {
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3051) dev_seg_count += le32_to_cpu(RDEV(i).total_segments);
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3052) i++;
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3053) }
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3054) if (segment_count != dev_seg_count) {
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3055) f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)",
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3056) segment_count, dev_seg_count);
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3057) return -EFSCORRUPTED;
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3058) }
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3059) } else {
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3060) if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_BLKZONED) &&
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3061) !bdev_is_zoned(sbi->sb->s_bdev)) {
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3062) f2fs_info(sbi, "Zoned block device path is missing");
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3063) return -EFSCORRUPTED;
07eb1d699452d (Chao Yu 2020-09-21 20:53:13 +0800 3064) }
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3065) }
9f701f6c772b1 (Qiuyang Sun 2019-09-23 12:22:35 +0800 3066)
42bf546c1fe3f (Chao Yu 2018-06-23 00:12:36 +0800 3067) if (secs_per_zone > total_sections || !secs_per_zone) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3068) f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3069) secs_per_zone, total_sections);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3070) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3071) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3072) if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION ||
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3073) raw_super->hot_ext_count > F2FS_MAX_EXTENSION ||
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3074) (le32_to_cpu(raw_super->extension_count) +
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3075) raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3076) f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3077) le32_to_cpu(raw_super->extension_count),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3078) raw_super->hot_ext_count,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3079) F2FS_MAX_EXTENSION);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3080) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3081) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3082)
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3083) if (le32_to_cpu(raw_super->cp_payload) >
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3084) (blocks_per_seg - F2FS_CP_PACKS)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3085) f2fs_info(sbi, "Insane cp_payload (%u > %u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3086) le32_to_cpu(raw_super->cp_payload),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3087) blocks_per_seg - F2FS_CP_PACKS);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3088) return -EFSCORRUPTED;
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3089) }
0cfe75c5b0119 (Jaegeuk Kim 2018-04-27 19:03:22 -0700 3090)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3091) /* check reserved ino info */
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3092) if (le32_to_cpu(raw_super->node_ino) != 1 ||
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3093) le32_to_cpu(raw_super->meta_ino) != 2 ||
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3094) le32_to_cpu(raw_super->root_ino) != 3) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3095) f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3096) le32_to_cpu(raw_super->node_ino),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3097) le32_to_cpu(raw_super->meta_ino),
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3098) le32_to_cpu(raw_super->root_ino));
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3099) return -EFSCORRUPTED;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3100) }
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3101)
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3102) /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3103) if (sanity_check_area_boundary(sbi, bh))
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3104) return -EFSCORRUPTED;
9a59b62fd8819 (Chao Yu 2015-12-15 09:58:18 +0800 3105)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3106) return 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3107) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3108)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3109) int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3110) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3111) unsigned int total, fsmeta;
577e349514452 (Jaegeuk Kim 2013-01-24 19:56:11 +0900 3112) struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
577e349514452 (Jaegeuk Kim 2013-01-24 19:56:11 +0900 3113) struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3114) unsigned int ovp_segments, reserved_segments;
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3115) unsigned int main_segs, blocks_per_seg;
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3116) unsigned int sit_segs, nat_segs;
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3117) unsigned int sit_bitmap_size, nat_bitmap_size;
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3118) unsigned int log_blocks_per_seg;
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3119) unsigned int segment_count_main;
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3120) unsigned int cp_pack_start_sum, cp_payload;
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3121) block_t user_block_count, valid_user_blocks;
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3122) block_t avail_node_count, valid_node_count;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3123) int i, j;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3124)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3125) total = le32_to_cpu(raw_super->segment_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3126) fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3127) sit_segs = le32_to_cpu(raw_super->segment_count_sit);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3128) fsmeta += sit_segs;
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3129) nat_segs = le32_to_cpu(raw_super->segment_count_nat);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3130) fsmeta += nat_segs;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3131) fsmeta += le32_to_cpu(ckpt->rsvd_segment_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3132) fsmeta += le32_to_cpu(raw_super->segment_count_ssa);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3133)
6bacf52fb58ae (Jaegeuk Kim 2013-12-06 15:00:58 +0900 3134) if (unlikely(fsmeta >= total))
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3135) return 1;
577e349514452 (Jaegeuk Kim 2013-01-24 19:56:11 +0900 3136)
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3137) ovp_segments = le32_to_cpu(ckpt->overprov_segment_count);
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3138) reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count);
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3139)
f99ba9add67ce (Wang Xiaojun 2020-09-17 19:11:58 +0800 3140) if (unlikely(fsmeta < F2FS_MIN_META_SEGMENTS ||
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3141) ovp_segments == 0 || reserved_segments == 0)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3142) f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version");
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3143) return 1;
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3144) }
2040fce83fe17 (Jaegeuk Kim 2016-12-05 13:56:04 -0800 3145)
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3146) user_block_count = le64_to_cpu(ckpt->user_block_count);
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3147) segment_count_main = le32_to_cpu(raw_super->segment_count_main);
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3148) log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3149) if (!user_block_count || user_block_count >=
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3150) segment_count_main << log_blocks_per_seg) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3151) f2fs_err(sbi, "Wrong user_block_count: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3152) user_block_count);
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3153) return 1;
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3154) }
9dc956b2c8523 (Chao Yu 2018-06-27 18:05:54 +0800 3155)
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3156) valid_user_blocks = le64_to_cpu(ckpt->valid_block_count);
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3157) if (valid_user_blocks > user_block_count) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3158) f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3159) valid_user_blocks, user_block_count);
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3160) return 1;
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3161) }
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3162)
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3163) valid_node_count = le32_to_cpu(ckpt->valid_node_count);
27cae0bcc0510 (Chao Yu 2019-08-05 18:27:25 +0800 3164) avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3165) if (valid_node_count > avail_node_count) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3166) f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3167) valid_node_count, avail_node_count);
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3168) return 1;
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3169) }
7b63f72f73af5 (Chao Yu 2019-04-15 15:30:50 +0800 3170)
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3171) main_segs = le32_to_cpu(raw_super->segment_count_main);
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3172) blocks_per_seg = sbi->blocks_per_seg;
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3173)
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3174) for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3175) if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3176) le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3177) return 1;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3178) for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) {
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3179) if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3180) le32_to_cpu(ckpt->cur_node_segno[j])) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3181) f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3182) i, j,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3183) le32_to_cpu(ckpt->cur_node_segno[i]));
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3184) return 1;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3185) }
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3186) }
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3187) }
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3188) for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3189) if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3190) le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3191) return 1;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3192) for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) {
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3193) if (le32_to_cpu(ckpt->cur_data_segno[i]) ==
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3194) le32_to_cpu(ckpt->cur_data_segno[j])) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3195) f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3196) i, j,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3197) le32_to_cpu(ckpt->cur_data_segno[i]));
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3198) return 1;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3199) }
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3200) }
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3201) }
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3202) for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
1166c1f2f6911 (Surbhi Palande 2019-08-23 15:40:45 -0700 3203) for (j = 0; j < NR_CURSEG_DATA_TYPE; j++) {
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3204) if (le32_to_cpu(ckpt->cur_node_segno[i]) ==
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3205) le32_to_cpu(ckpt->cur_data_segno[j])) {
1166c1f2f6911 (Surbhi Palande 2019-08-23 15:40:45 -0700 3206) f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3207) i, j,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3208) le32_to_cpu(ckpt->cur_node_segno[i]));
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3209) return 1;
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3210) }
042be0f849e5f (Chao Yu 2018-09-06 20:34:12 +0800 3211) }
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3212) }
15d3042a937c1 (Jin Qian 2017-05-15 10:45:08 -0700 3213)
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3214) sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3215) nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3216)
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3217) if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 ||
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3218) nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3219) f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3220) sit_bitmap_size, nat_bitmap_size);
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3221) return 1;
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3222) }
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3223)
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3224) cp_pack_start_sum = __start_sum_addr(sbi);
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3225) cp_payload = __cp_payload(sbi);
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3226) if (cp_pack_start_sum < cp_payload + 1 ||
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3227) cp_pack_start_sum > blocks_per_seg - 1 -
d0b9e42ab6155 (Chao Yu 2020-08-04 21:14:45 +0800 3228) NR_CURSEG_PERSIST_TYPE) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3229) f2fs_err(sbi, "Wrong cp_pack_start_sum: %u",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3230) cp_pack_start_sum);
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3231) return 1;
e494c2f995d61 (Chao Yu 2018-08-01 19:16:11 +0800 3232) }
c77ec61ca0a49 (Chao Yu 2018-06-23 11:25:19 +0800 3233)
5dae2d39074dd (Chao Yu 2019-05-20 10:09:22 +0800 3234) if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) &&
5dae2d39074dd (Chao Yu 2019-05-20 10:09:22 +0800 3235) le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) {
2d008835ec2fc (Chao Yu 2019-07-11 09:29:15 +0800 3236) f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, "
2d008835ec2fc (Chao Yu 2019-07-11 09:29:15 +0800 3237) "please run fsck v1.13.0 or higher to repair, chksum_offset: %u, "
2d008835ec2fc (Chao Yu 2019-07-11 09:29:15 +0800 3238) "fixed with patch: \"f2fs-tools: relocate chksum_offset for large_nat_bitmap feature\"",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3239) le32_to_cpu(ckpt->checksum_offset));
5dae2d39074dd (Chao Yu 2019-05-20 10:09:22 +0800 3240) return 1;
5dae2d39074dd (Chao Yu 2019-05-20 10:09:22 +0800 3241) }
5dae2d39074dd (Chao Yu 2019-05-20 10:09:22 +0800 3242)
1e968fdfe69e4 (Jaegeuk Kim 2014-08-11 16:49:25 -0700 3243) if (unlikely(f2fs_cp_error(sbi))) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3244) f2fs_err(sbi, "A bug case: need to run fsck");
577e349514452 (Jaegeuk Kim 2013-01-24 19:56:11 +0900 3245) return 1;
577e349514452 (Jaegeuk Kim 2013-01-24 19:56:11 +0900 3246) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3247) return 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3248) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3249)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3250) static void init_sb_info(struct f2fs_sb_info *sbi)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3251) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3252) struct f2fs_super_block *raw_super = sbi->raw_super;
089842de5750f (Yunlong Song 2018-10-24 16:09:42 +0800 3253) int i;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3254)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3255) sbi->log_sectors_per_block =
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3256) le32_to_cpu(raw_super->log_sectors_per_block);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3257) sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3258) sbi->blocksize = 1 << sbi->log_blocksize;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3259) sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3260) sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3261) sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3262) sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3263) sbi->total_sections = le32_to_cpu(raw_super->section_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3264) sbi->total_node_count =
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3265) (le32_to_cpu(raw_super->segment_count_nat) / 2)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3266) * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK;
b9ec10948ff66 (Yangtao Li 2020-12-07 18:59:33 +0800 3267) F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino);
b9ec10948ff66 (Yangtao Li 2020-12-07 18:59:33 +0800 3268) F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino);
b9ec10948ff66 (Yangtao Li 2020-12-07 18:59:33 +0800 3269) F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino);
5ec4e49f9bd75 (Jaegeuk Kim 2013-03-31 13:26:03 +0900 3270) sbi->cur_victim_sec = NULL_SECNO;
e3080b0120a15 (Chao Yu 2018-10-24 18:37:27 +0800 3271) sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
e3080b0120a15 (Chao Yu 2018-10-24 18:37:27 +0800 3272) sbi->next_victim_seg[FG_GC] = NULL_SEGNO;
b1c57c1caa753 (Jaegeuk Kim 2014-01-08 13:45:08 +0900 3273) sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH;
e3080b0120a15 (Chao Yu 2018-10-24 18:37:27 +0800 3274) sbi->migration_granularity = sbi->segs_per_sec;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3275)
ab9fa662e4867 (Jaegeuk Kim 2014-02-27 20:09:05 +0900 3276) sbi->dir_level = DEF_DIR_LEVEL;
6beceb5427aa8 (Jaegeuk Kim 2016-01-08 15:51:50 -0800 3277) sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL;
d0239e1bf5204 (Jaegeuk Kim 2016-01-08 16:57:48 -0800 3278) sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL;
a7d10cf3e4e3e (Sahitya Tummala 2018-09-19 14:18:47 +0530 3279) sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL;
a7d10cf3e4e3e (Sahitya Tummala 2018-09-19 14:18:47 +0530 3280) sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 3281) sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL;
03f2c02d8be76 (Jaegeuk Kim 2019-01-14 10:42:11 -0800 3282) sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] =
03f2c02d8be76 (Jaegeuk Kim 2019-01-14 10:42:11 -0800 3283) DEF_UMOUNT_DISCARD_TIMEOUT;
caf0047e7e1e6 (Chao Yu 2015-01-28 17:48:42 +0800 3284) clear_sbi_flag(sbi, SBI_NEED_FSCK);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 3285)
35782b233f37e (Jaegeuk Kim 2016-10-20 19:09:57 -0700 3286) for (i = 0; i < NR_COUNT_TYPE; i++)
35782b233f37e (Jaegeuk Kim 2016-10-20 19:09:57 -0700 3287) atomic_set(&sbi->nr_pages[i], 0);
35782b233f37e (Jaegeuk Kim 2016-10-20 19:09:57 -0700 3288)
c29fd0c0e26da (Chao Yu 2018-06-04 23:20:36 +0800 3289) for (i = 0; i < META; i++)
c29fd0c0e26da (Chao Yu 2018-06-04 23:20:36 +0800 3290) atomic_set(&sbi->wb_sync_req[i], 0);
687de7f1010cb (Jaegeuk Kim 2017-03-28 18:07:38 -0700 3291)
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 3292) INIT_LIST_HEAD(&sbi->s_list);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 3293) mutex_init(&sbi->umount_mutex);
107a805de87ec (Chao Yu 2018-05-26 09:00:13 +0800 3294) init_rwsem(&sbi->io_order_lock);
aaec2b1d18792 (Chao Yu 2016-09-20 11:04:18 +0800 3295) spin_lock_init(&sbi->cp_lock);
1228b482c4ee2 (Chao Yu 2017-09-29 13:59:39 +0800 3296)
1228b482c4ee2 (Chao Yu 2017-09-29 13:59:39 +0800 3297) sbi->dirty_device = 0;
1228b482c4ee2 (Chao Yu 2017-09-29 13:59:39 +0800 3298) spin_lock_init(&sbi->dev_lock);
d0d3f1b329b01 (Chao Yu 2018-02-11 22:53:20 +0800 3299)
846ae671ad368 (Chao Yu 2018-02-26 22:04:13 +0800 3300) init_rwsem(&sbi->sb_lock);
f5a53edcf01ea (Jaegeuk Kim 2019-10-18 10:06:40 -0700 3301) init_rwsem(&sbi->pin_sem);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3302) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3303)
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3304) static int init_percpu_info(struct f2fs_sb_info *sbi)
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3305) {
35782b233f37e (Jaegeuk Kim 2016-10-20 19:09:57 -0700 3306) int err;
41382ec43255b (Jaegeuk Kim 2016-05-16 11:06:50 -0700 3307)
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3308) err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL);
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3309) if (err)
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3310) return err;
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3311)
4a70e255449c9 (Chao Yu 2018-09-05 14:54:02 +0800 3312) err = percpu_counter_init(&sbi->total_valid_inode_count, 0,
41382ec43255b (Jaegeuk Kim 2016-05-16 11:06:50 -0700 3313) GFP_KERNEL);
4a70e255449c9 (Chao Yu 2018-09-05 14:54:02 +0800 3314) if (err)
4a70e255449c9 (Chao Yu 2018-09-05 14:54:02 +0800 3315) percpu_counter_destroy(&sbi->alloc_valid_block_count);
4a70e255449c9 (Chao Yu 2018-09-05 14:54:02 +0800 3316)
4a70e255449c9 (Chao Yu 2018-09-05 14:54:02 +0800 3317) return err;
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3318) }
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3319)
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3320) #ifdef CONFIG_BLK_DEV_ZONED
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3321)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3322) struct f2fs_report_zones_args {
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3323) struct f2fs_dev_info *dev;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3324) bool zone_cap_mismatch;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3325) };
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3326)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3327) static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx,
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3328) void *data)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3329) {
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3330) struct f2fs_report_zones_args *rz_args = data;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3331)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3332) if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3333) return 0;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3334)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3335) set_bit(idx, rz_args->dev->blkz_seq);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3336) rz_args->dev->zone_capacity_blocks[idx] = zone->capacity >>
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3337) F2FS_LOG_SECTORS_PER_BLOCK;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3338) if (zone->len != zone->capacity && !rz_args->zone_cap_mismatch)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3339) rz_args->zone_cap_mismatch = true;
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3340)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3341) return 0;
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3342) }
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3343)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3344) static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3345) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3346) struct block_device *bdev = FDEV(devi).bdev;
a782483cc1f87 (Christoph Hellwig 2020-11-26 18:43:37 +0100 3347) sector_t nr_sectors = bdev_nr_sectors(bdev);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3348) struct f2fs_report_zones_args rep_zone_arg;
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3349) int ret;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3350)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3351) if (!f2fs_sb_has_blkzoned(sbi))
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3352) return 0;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3353)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3354) if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
f99e86485cc32 (Damien Le Moal 2017-01-12 07:58:32 -0700 3355) SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)))
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3356) return -EINVAL;
f99e86485cc32 (Damien Le Moal 2017-01-12 07:58:32 -0700 3357) sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev));
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3358) if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz !=
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3359) __ilog2_u32(sbi->blocks_per_blkz))
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3360) return -EINVAL;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3361) sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3362) FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3363) sbi->log_blocks_per_blkz;
f99e86485cc32 (Damien Le Moal 2017-01-12 07:58:32 -0700 3364) if (nr_sectors & (bdev_zone_sectors(bdev) - 1))
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3365) FDEV(devi).nr_blkz++;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3366)
0b6d4ca04a86b (Eric Biggers 2020-06-04 21:57:48 -0700 3367) FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
95175dafc4399 (Damien Le Moal 2019-03-16 09:13:07 +0900 3368) BITS_TO_LONGS(FDEV(devi).nr_blkz)
95175dafc4399 (Damien Le Moal 2019-03-16 09:13:07 +0900 3369) * sizeof(unsigned long),
95175dafc4399 (Damien Le Moal 2019-03-16 09:13:07 +0900 3370) GFP_KERNEL);
95175dafc4399 (Damien Le Moal 2019-03-16 09:13:07 +0900 3371) if (!FDEV(devi).blkz_seq)
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3372) return -ENOMEM;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3373)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3374) /* Get block zones type and zone-capacity */
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3375) FDEV(devi).zone_capacity_blocks = f2fs_kzalloc(sbi,
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3376) FDEV(devi).nr_blkz * sizeof(block_t),
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3377) GFP_KERNEL);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3378) if (!FDEV(devi).zone_capacity_blocks)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3379) return -ENOMEM;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3380)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3381) rep_zone_arg.dev = &FDEV(devi);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3382) rep_zone_arg.zone_cap_mismatch = false;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3383)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3384) ret = blkdev_report_zones(bdev, 0, BLK_ALL_ZONES, f2fs_report_zone_cb,
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3385) &rep_zone_arg);
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3386) if (ret < 0)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3387) return ret;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3388)
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3389) if (!rep_zone_arg.zone_cap_mismatch) {
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3390) kfree(FDEV(devi).zone_capacity_blocks);
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3391) FDEV(devi).zone_capacity_blocks = NULL;
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3392) }
de881df97768d (Aravind Ramesh 2020-07-16 18:26:56 +0530 3393)
d41003513e61d (Christoph Hellwig 2019-11-11 11:39:30 +0900 3394) return 0;
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3395) }
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3396) #endif
178053e2f1f9c (Damien Le Moal 2016-10-28 17:45:05 +0900 3397)
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3398) /*
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3399) * Read f2fs raw super block.
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3400) * Because we have two copies of super block, so read both of them
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3401) * to get the first valid one. If any one of them is broken, we pass
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3402) * them recovery flag back to the caller.
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3403) */
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3404) static int read_raw_super_block(struct f2fs_sb_info *sbi,
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3405) struct f2fs_super_block **raw_super,
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3406) int *valid_super_block, int *recovery)
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3407) {
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3408) struct super_block *sb = sbi->sb;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3409) int block;
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3410) struct buffer_head *bh;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3411) struct f2fs_super_block *super;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3412) int err = 0;
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3413)
b39f0de23d8f2 (Yunlei He 2015-12-15 17:17:20 +0800 3414) super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL);
b39f0de23d8f2 (Yunlei He 2015-12-15 17:17:20 +0800 3415) if (!super)
b39f0de23d8f2 (Yunlei He 2015-12-15 17:17:20 +0800 3416) return -ENOMEM;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3417)
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3418) for (block = 0; block < 2; block++) {
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3419) bh = sb_bread(sb, block);
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3420) if (!bh) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3421) f2fs_err(sbi, "Unable to read %dth superblock",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3422) block + 1);
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3423) err = -EIO;
ed3520427f573 (Chengguang Xu via Linux-f2fs-devel 2019-09-27 09:35:48 +0800 3424) *recovery = 1;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3425) continue;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3426) }
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3427)
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3428) /* sanity checking of raw super */
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3429) err = sanity_check_raw_super(sbi, bh);
38fb6d0ea3429 (Icenowy Zheng 2019-07-25 11:08:52 +0800 3430) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3431) f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3432) block + 1);
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3433) brelse(bh);
ed3520427f573 (Chengguang Xu via Linux-f2fs-devel 2019-09-27 09:35:48 +0800 3434) *recovery = 1;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3435) continue;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3436) }
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3437)
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3438) if (!*raw_super) {
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3439) memcpy(super, bh->b_data + F2FS_SUPER_OFFSET,
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3440) sizeof(*super));
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3441) *valid_super_block = block;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3442) *raw_super = super;
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3443) }
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3444) brelse(bh);
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3445) }
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3446)
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3447) /* No valid superblock */
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3448) if (!*raw_super)
742532d11d832 (Denis Efremov 2020-06-10 01:14:46 +0300 3449) kfree(super);
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3450) else
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3451) err = 0;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3452)
2b39e9072d79a (Shawn Lin 2016-02-17 08:59:01 +0800 3453) return err;
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3454) }
14d7e9de0500e (majianpeng 2013-02-01 19:07:03 +0800 3455)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3456) int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3457) {
5d909cdbbba24 (Jaegeuk Kim 2015-12-07 10:16:58 -0800 3458) struct buffer_head *bh;
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3459) __u32 crc = 0;
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3460) int err;
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3461)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3462) if ((recover && f2fs_readonly(sbi->sb)) ||
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3463) bdev_read_only(sbi->sb->s_bdev)) {
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3464) set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
f2353d7bd4221 (Jaegeuk Kim 2016-03-23 10:42:01 -0700 3465) return -EROFS;
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3466) }
f2353d7bd4221 (Jaegeuk Kim 2016-03-23 10:42:01 -0700 3467)
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3468) /* we should update superblock crc here */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3469) if (!recover && f2fs_sb_has_sb_chksum(sbi)) {
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3470) crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi),
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3471) offsetof(struct f2fs_super_block, crc));
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3472) F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc);
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3473) }
d440c52d3151a (Junling Zheng 2018-09-28 20:25:56 +0800 3474)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3475) /* write back-up superblock first */
0964fc1a82a31 (Sheng Yong 2018-01-29 19:13:15 +0800 3476) bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
5d909cdbbba24 (Jaegeuk Kim 2015-12-07 10:16:58 -0800 3477) if (!bh)
5d909cdbbba24 (Jaegeuk Kim 2015-12-07 10:16:58 -0800 3478) return -EIO;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3479) err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
5d909cdbbba24 (Jaegeuk Kim 2015-12-07 10:16:58 -0800 3480) brelse(bh);
c5bda1c8b13ad (Chao Yu 2015-06-08 13:28:03 +0800 3481)
c5bda1c8b13ad (Chao Yu 2015-06-08 13:28:03 +0800 3482) /* if we are in recovery path, skip writing valid superblock */
c5bda1c8b13ad (Chao Yu 2015-06-08 13:28:03 +0800 3483) if (recover || err)
5d909cdbbba24 (Jaegeuk Kim 2015-12-07 10:16:58 -0800 3484) return err;
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3485)
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3486) /* write current valid superblock */
0964fc1a82a31 (Sheng Yong 2018-01-29 19:13:15 +0800 3487) bh = sb_bread(sbi->sb, sbi->valid_super_block);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3488) if (!bh)
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3489) return -EIO;
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3490) err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3491) brelse(bh);
fd694733d523d (Jaegeuk Kim 2016-03-20 15:33:20 -0700 3492) return err;
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3493) }
26d815ad75156 (Jaegeuk Kim 2015-04-20 18:49:51 -0700 3494)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3495) static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3496) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3497) struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3498) unsigned int max_devices = MAX_DEVICES;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3499) int i;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3500)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3501) /* Initialize single device information */
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3502) if (!RDEV(0).path[0]) {
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3503) if (!bdev_is_zoned(sbi->sb->s_bdev))
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3504) return 0;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3505) max_devices = 1;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3506) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3507)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3508) /*
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3509) * Initialize multiple devices information, or single
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3510) * zoned block device information.
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3511) */
026f05079b00a (Kees Cook 2018-06-12 14:28:23 -0700 3512) sbi->devs = f2fs_kzalloc(sbi,
026f05079b00a (Kees Cook 2018-06-12 14:28:23 -0700 3513) array_size(max_devices,
026f05079b00a (Kees Cook 2018-06-12 14:28:23 -0700 3514) sizeof(struct f2fs_dev_info)),
026f05079b00a (Kees Cook 2018-06-12 14:28:23 -0700 3515) GFP_KERNEL);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3516) if (!sbi->devs)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3517) return -ENOMEM;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3518)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3519) for (i = 0; i < max_devices; i++) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3520)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3521) if (i > 0 && !RDEV(i).path[0])
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3522) break;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3523)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3524) if (max_devices == 1) {
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3525) /* Single zoned block device mount */
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3526) FDEV(0).bdev =
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3527) blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev,
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3528) sbi->sb->s_mode, sbi->sb->s_type);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3529) } else {
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3530) /* Multi-device mount */
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3531) memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3532) FDEV(i).total_segments =
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3533) le32_to_cpu(RDEV(i).total_segments);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3534) if (i == 0) {
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3535) FDEV(i).start_blk = 0;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3536) FDEV(i).end_blk = FDEV(i).start_blk +
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3537) (FDEV(i).total_segments <<
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3538) sbi->log_blocks_per_seg) - 1 +
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3539) le32_to_cpu(raw_super->segment0_blkaddr);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3540) } else {
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3541) FDEV(i).start_blk = FDEV(i - 1).end_blk + 1;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3542) FDEV(i).end_blk = FDEV(i).start_blk +
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3543) (FDEV(i).total_segments <<
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3544) sbi->log_blocks_per_seg) - 1;
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3545) }
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3546) FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path,
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3547) sbi->sb->s_mode, sbi->sb->s_type);
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3548) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3549) if (IS_ERR(FDEV(i).bdev))
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3550) return PTR_ERR(FDEV(i).bdev);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3551)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3552) /* to release errored devices */
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3553) sbi->s_ndevs = i + 1;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3554)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3555) #ifdef CONFIG_BLK_DEV_ZONED
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3556) if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3557) !f2fs_sb_has_blkzoned(sbi)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3558) f2fs_err(sbi, "Zoned block device feature not enabled\n");
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3559) return -EINVAL;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3560) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3561) if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3562) if (init_blkz_info(sbi, i)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3563) f2fs_err(sbi, "Failed to initialize F2FS blkzone information");
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3564) return -EINVAL;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3565) }
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3566) if (max_devices == 1)
7bb3a371d1991 (Masato Suzuki 2017-02-27 20:52:49 +0900 3567) break;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3568) f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3569) i, FDEV(i).path,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3570) FDEV(i).total_segments,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3571) FDEV(i).start_blk, FDEV(i).end_blk,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3572) bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3573) "Host-aware" : "Host-managed");
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3574) continue;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3575) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3576) #endif
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3577) f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3578) i, FDEV(i).path,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3579) FDEV(i).total_segments,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3580) FDEV(i).start_blk, FDEV(i).end_blk);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3581) }
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3582) f2fs_info(sbi,
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3583) "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi));
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3584) return 0;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3585) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3586)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3587) static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3588) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3589) #ifdef CONFIG_UNICODE
eca4873ee1b63 (Daniel Rosenberg 2020-07-08 02:12:36 -0700 3590) if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3591) const struct f2fs_sb_encodings *encoding_info;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3592) struct unicode_map *encoding;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3593) __u16 encoding_flags;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3594)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3595) if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3596) &encoding_flags)) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3597) f2fs_err(sbi,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3598) "Encoding requested by superblock is unknown");
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3599) return -EINVAL;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3600) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3601)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3602) encoding = utf8_load(encoding_info->version);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3603) if (IS_ERR(encoding)) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3604) f2fs_err(sbi,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3605) "can't mount with superblock charset: %s-%s "
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3606) "not supported by the kernel. flags: 0x%x.",
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3607) encoding_info->name, encoding_info->version,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3608) encoding_flags);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3609) return PTR_ERR(encoding);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3610) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3611) f2fs_info(sbi, "Using encoding defined by superblock: "
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3612) "%s-%s with flags 0x%hx", encoding_info->name,
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3613) encoding_info->version?:"\b", encoding_flags);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3614)
eca4873ee1b63 (Daniel Rosenberg 2020-07-08 02:12:36 -0700 3615) sbi->sb->s_encoding = encoding;
eca4873ee1b63 (Daniel Rosenberg 2020-07-08 02:12:36 -0700 3616) sbi->sb->s_encoding_flags = encoding_flags;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3617) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3618) #else
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3619) if (f2fs_sb_has_casefold(sbi)) {
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3620) f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE");
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3621) return -EINVAL;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3622) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3623) #endif
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3624) return 0;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3625) }
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3626)
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3627) static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3628) {
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3629) struct f2fs_sm_info *sm_i = SM_I(sbi);
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3630)
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3631) /* adjust parameters according to the volume size */
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3632) if (sm_i->main_segments <= SMALL_VOLUME_SEGMENTS) {
63189b785960c (Chao Yu 2018-03-08 14:22:56 +0800 3633) F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3634) sm_i->dcc_info->discard_granularity = 1;
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3635) sm_i->ipu_policy = 1 << F2FS_IPU_FORCE;
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3636) }
4cac90d5491c9 (Chao Yu 2018-06-11 18:02:01 +0800 3637)
4cac90d5491c9 (Chao Yu 2018-06-11 18:02:01 +0800 3638) sbi->readdir_ra = 1;
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3639) }
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 3640)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3641) static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3642) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3643) struct f2fs_sb_info *sbi;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3644) struct f2fs_super_block *raw_super;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3645) struct inode *root;
99e3e858a486c (Sheng Yong 2016-05-11 17:08:14 +0800 3646) int err;
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3647) bool skip_recovery = false, need_fsck = false;
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3648) char *options = NULL;
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3649) int recovery, i, valid_super_block;
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3650) struct curseg_info *seg_i;
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3651) int retry_cnt = 1;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3652)
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 3653) try_onemore:
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3654) err = -EINVAL;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3655) raw_super = NULL;
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3656) valid_super_block = -1;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3657) recovery = 0;
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 3658)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3659) /* allocate memory for f2fs-specific super block info */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3660) sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3661) if (!sbi)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3662) return -ENOMEM;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3663)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3664) sbi->sb = sb;
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3665)
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3666) /* Load the checksum driver */
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3667) sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0);
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3668) if (IS_ERR(sbi->s_chksum_driver)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3669) f2fs_err(sbi, "Cannot load crc32 driver.");
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3670) err = PTR_ERR(sbi->s_chksum_driver);
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3671) sbi->s_chksum_driver = NULL;
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3672) goto free_sbi;
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3673) }
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 3674)
ff9234ad4e974 (Namjae Jeon 2013-01-12 14:41:13 +0900 3675) /* set a block size */
6bacf52fb58ae (Jaegeuk Kim 2013-12-06 15:00:58 +0900 3676) if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3677) f2fs_err(sbi, "unable to set blocksize");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3678) goto free_sbi;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3679) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3680)
df728b0f6954c (Jaegeuk Kim 2016-03-23 17:05:27 -0700 3681) err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3682) &recovery);
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3683) if (err)
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3684) goto free_sbi;
9076a75f8e0f2 (Gu Zheng 2013-10-14 18:47:11 +0800 3685)
5fb08372a6893 (Gu Zheng 2013-06-07 14:16:53 +0800 3686) sb->s_fs_info = sbi;
52763a4b7a211 (Jaegeuk Kim 2016-06-13 09:47:48 -0700 3687) sbi->raw_super = raw_super;
52763a4b7a211 (Jaegeuk Kim 2016-06-13 09:47:48 -0700 3688)
704956ecf5bcd (Chao Yu 2017-07-31 20:19:09 +0800 3689) /* precompute checksum seed for metadata */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3690) if (f2fs_sb_has_inode_chksum(sbi))
704956ecf5bcd (Chao Yu 2017-07-31 20:19:09 +0800 3691) sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid,
704956ecf5bcd (Chao Yu 2017-07-31 20:19:09 +0800 3692) sizeof(raw_super->uuid));
704956ecf5bcd (Chao Yu 2017-07-31 20:19:09 +0800 3693)
498c5e9fcd10c (Yunlei He 2015-05-07 18:11:37 +0800 3694) default_options(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3695) /* parse mount options */
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3696) options = kstrdup((const char *)data, GFP_KERNEL);
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3697) if (data && !options) {
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3698) err = -ENOMEM;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3699) goto free_sb_buf;
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3700) }
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3701)
ed318a6cc0b62 (Eric Biggers 2020-05-12 16:32:50 -0700 3702) err = parse_options(sb, options, false);
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3703) if (err)
dabc4a5c60f79 (Jaegeuk Kim 2015-01-23 17:41:39 -0800 3704) goto free_options;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3705)
6d1451bf7f84e (Chengguang Xu 2021-01-13 13:21:54 +0800 3706) sb->s_maxbytes = max_file_blocks(NULL) <<
e0afc4d6d0d3e (Chao Yu 2015-12-31 14:35:37 +0800 3707) le32_to_cpu(raw_super->log_blocksize);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3708) sb->s_max_links = F2FS_LINK_MAX;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3709)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3710) err = f2fs_setup_casefold(sbi);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3711) if (err)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3712) goto free_options;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 3713)
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 3714) #ifdef CONFIG_QUOTA
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 3715) sb->dq_op = &f2fs_quota_operations;
bc88ac96a9acf (Jaegeuk Kim 2019-05-20 16:17:56 -0700 3716) sb->s_qcop = &f2fs_quotactl_ops;
5c57132eaf526 (Chao Yu 2017-07-26 00:01:41 +0800 3717) sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3718)
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3719) if (f2fs_sb_has_quota_ino(sbi)) {
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3720) for (i = 0; i < MAXQUOTAS; i++) {
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3721) if (f2fs_qf_ino(sbi->sb, i))
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3722) sbi->nquota_files++;
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3723) }
292c196a3695e (Chao Yu 2017-11-16 16:59:14 +0800 3724) }
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 3725) #endif
0abd675e97e60 (Chao Yu 2017-07-09 00:13:07 +0800 3726)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3727) sb->s_op = &f2fs_sops;
643fa9612bf1a (Chandan Rajendra 2018-12-12 15:20:12 +0530 3728) #ifdef CONFIG_FS_ENCRYPTION
0b81d07790726 (Jaegeuk Kim 2015-05-15 16:26:10 -0700 3729) sb->s_cop = &f2fs_cryptops;
95ae251fe8283 (Eric Biggers 2019-07-22 09:26:24 -0700 3730) #endif
95ae251fe8283 (Eric Biggers 2019-07-22 09:26:24 -0700 3731) #ifdef CONFIG_FS_VERITY
95ae251fe8283 (Eric Biggers 2019-07-22 09:26:24 -0700 3732) sb->s_vop = &f2fs_verityops;
ffcc41829ae04 (Eric Biggers 2017-10-09 12:15:38 -0700 3733) #endif
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3734) sb->s_xattr = f2fs_xattr_handlers;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3735) sb->s_export_op = &f2fs_export_ops;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3736) sb->s_magic = F2FS_SUPER_MAGIC;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3737) sb->s_time_gran = 1;
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 3738) sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
1751e8a6cb935 (Linus Torvalds 2017-11-27 13:05:09 -0800 3739) (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
85787090a21eb (Christoph Hellwig 2017-05-10 15:06:33 +0200 3740) memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
578c647879f74 (Yufen Yu 2018-01-09 19:33:39 +0800 3741) sb->s_iflags |= SB_I_CGROUPWB;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3742)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3743) /* init f2fs-specific super block info */
e8240f656d4d5 (Chao Yu 2015-12-15 17:19:26 +0800 3744) sbi->valid_super_block = valid_super_block;
fb24fea75ca5c (Chao Yu 2020-01-14 19:36:50 +0800 3745) init_rwsem(&sbi->gc_lock);
853137cef46cc (Jaegeuk Kim 2018-08-09 17:53:34 -0700 3746) mutex_init(&sbi->writepages);
8769918bf06c9 (Sahitya Tummala 2020-11-23 10:58:32 +0530 3747) init_rwsem(&sbi->cp_global_sem);
b3582c6892010 (Chao Yu 2014-07-03 18:58:39 +0800 3748) init_rwsem(&sbi->node_write);
59c9081bc86ef (Yunlei He 2017-03-13 20:22:18 +0800 3749) init_rwsem(&sbi->node_change);
315df8398e363 (Jaegeuk Kim 2015-08-11 12:45:39 -0700 3750)
315df8398e363 (Jaegeuk Kim 2015-08-11 12:45:39 -0700 3751) /* disallow all the data/node/meta page writes */
315df8398e363 (Jaegeuk Kim 2015-08-11 12:45:39 -0700 3752) set_sbi_flag(sbi, SBI_POR_DOING);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3753) spin_lock_init(&sbi->stat_lock);
971767caf6321 (Jaegeuk Kim 2013-11-18 17:16:17 +0900 3754)
b0af6d491a6b5 (Chao Yu 2017-08-02 23:21:48 +0800 3755) /* init iostat info */
b0af6d491a6b5 (Chao Yu 2017-08-02 23:21:48 +0800 3756) spin_lock_init(&sbi->iostat_lock);
b0af6d491a6b5 (Chao Yu 2017-08-02 23:21:48 +0800 3757) sbi->iostat_enable = false;
2bc4bea33848e (Daeho Jeong 2020-03-30 03:30:59 +0000 3758) sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS;
b0af6d491a6b5 (Chao Yu 2017-08-02 23:21:48 +0800 3759)
458e6197c37de (Jaegeuk Kim 2013-12-11 13:54:01 +0900 3760) for (i = 0; i < NR_PAGE_TYPE; i++) {
5f029c045c948 (Yi Zhuang 2021-04-06 09:47:35 +0800 3761) int n = (i == META) ? 1 : NR_TEMP_TYPE;
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3762) int j;
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3763)
c86065938aab5 (Kees Cook 2018-06-12 14:28:16 -0700 3764) sbi->write_io[i] =
c86065938aab5 (Kees Cook 2018-06-12 14:28:16 -0700 3765) f2fs_kmalloc(sbi,
c86065938aab5 (Kees Cook 2018-06-12 14:28:16 -0700 3766) array_size(n,
c86065938aab5 (Kees Cook 2018-06-12 14:28:16 -0700 3767) sizeof(struct f2fs_bio_info)),
c86065938aab5 (Kees Cook 2018-06-12 14:28:16 -0700 3768) GFP_KERNEL);
b63def9112cd8 (Christophe JAILLET 2017-06-11 09:21:11 +0200 3769) if (!sbi->write_io[i]) {
b63def9112cd8 (Christophe JAILLET 2017-06-11 09:21:11 +0200 3770) err = -ENOMEM;
0b2103e886e6d (Chao Yu 2018-09-05 14:54:01 +0800 3771) goto free_bio_info;
b63def9112cd8 (Christophe JAILLET 2017-06-11 09:21:11 +0200 3772) }
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3773)
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3774) for (j = HOT; j < n; j++) {
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3775) init_rwsem(&sbi->write_io[i][j].io_rwsem);
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3776) sbi->write_io[i][j].sbi = sbi;
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3777) sbi->write_io[i][j].bio = NULL;
fb830fc5cfc90 (Chao Yu 2017-05-19 23:37:01 +0800 3778) spin_lock_init(&sbi->write_io[i][j].io_lock);
fb830fc5cfc90 (Chao Yu 2017-05-19 23:37:01 +0800 3779) INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 3780) INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list);
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 3781) init_rwsem(&sbi->write_io[i][j].bio_list_lock);
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 3782) }
458e6197c37de (Jaegeuk Kim 2013-12-11 13:54:01 +0900 3783) }
971767caf6321 (Jaegeuk Kim 2013-11-18 17:16:17 +0900 3784)
b873b798af638 (Jaegeuk Kim 2016-08-04 11:38:25 -0700 3785) init_rwsem(&sbi->cp_rwsem);
db6ec53b7e032 (Jaegeuk Kim 2019-05-29 10:58:45 -0700 3786) init_rwsem(&sbi->quota_sem);
fb51b5ef9c078 (Changman Lee 2013-11-07 12:48:25 +0900 3787) init_waitqueue_head(&sbi->cp_wait);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3788) init_sb_info(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3789)
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3790) err = init_percpu_info(sbi);
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3791) if (err)
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 3792) goto free_bio_info;
523be8a6b3418 (Jaegeuk Kim 2016-05-13 12:36:58 -0700 3793)
c72db71ed61ff (Chao Yu 2019-07-12 16:55:42 +0800 3794) if (F2FS_IO_ALIGNED(sbi)) {
0a595ebaaa6b5 (Jaegeuk Kim 2016-12-14 10:12:56 -0800 3795) sbi->write_io_dummy =
a3ebfe4fd8979 (Chao Yu 2017-02-27 18:43:13 +0800 3796) mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
1727f317219bf (Chao Yu 2017-06-12 09:44:27 +0800 3797) if (!sbi->write_io_dummy) {
1727f317219bf (Chao Yu 2017-06-12 09:44:27 +0800 3798) err = -ENOMEM;
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 3799) goto free_percpu;
1727f317219bf (Chao Yu 2017-06-12 09:44:27 +0800 3800) }
0a595ebaaa6b5 (Jaegeuk Kim 2016-12-14 10:12:56 -0800 3801) }
0a595ebaaa6b5 (Jaegeuk Kim 2016-12-14 10:12:56 -0800 3802)
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 3803) /* init per sbi slab cache */
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 3804) err = f2fs_init_xattr_caches(sbi);
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 3805) if (err)
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 3806) goto free_io_dummy;
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 3807) err = f2fs_init_page_array_cache(sbi);
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 3808) if (err)
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 3809) goto free_xattr_cache;
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 3810)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3811) /* get an inode for meta space */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3812) sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3813) if (IS_ERR(sbi->meta_inode)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3814) f2fs_err(sbi, "Failed to read F2FS meta data inode");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3815) err = PTR_ERR(sbi->meta_inode);
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 3816) goto free_page_array_cache;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3817) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3818)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3819) err = f2fs_get_valid_checkpoint(sbi);
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3820) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3821) f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3822) goto free_meta_inode;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3823) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3824)
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 3825) if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 3826) set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
db610a640eeeb (Jaegeuk Kim 2019-01-24 17:48:38 -0800 3827) if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) {
db610a640eeeb (Jaegeuk Kim 2019-01-24 17:48:38 -0800 3828) set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
db610a640eeeb (Jaegeuk Kim 2019-01-24 17:48:38 -0800 3829) sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL;
db610a640eeeb (Jaegeuk Kim 2019-01-24 17:48:38 -0800 3830) }
af033b2aa8a87 (Chao Yu 2018-09-20 20:05:00 +0800 3831)
04f0b2eaa3b3e (Qiuyang Sun 2019-06-05 11:33:25 +0800 3832) if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG))
04f0b2eaa3b3e (Qiuyang Sun 2019-06-05 11:33:25 +0800 3833) set_sbi_flag(sbi, SBI_NEED_FSCK);
04f0b2eaa3b3e (Qiuyang Sun 2019-06-05 11:33:25 +0800 3834)
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3835) /* Initialize device list */
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3836) err = f2fs_scan_devices(sbi);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3837) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3838) f2fs_err(sbi, "Failed to find devices");
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3839) goto free_devices;
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3840) }
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 3841)
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3842) err = f2fs_init_post_read_wq(sbi);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3843) if (err) {
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3844) f2fs_err(sbi, "Failed to initialize post read workqueue");
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3845) goto free_devices;
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3846) }
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 3847)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3848) sbi->total_valid_node_count =
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3849) le32_to_cpu(sbi->ckpt->valid_node_count);
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3850) percpu_counter_set(&sbi->total_valid_inode_count,
513c5f3735a9b (Jaegeuk Kim 2016-05-16 11:42:32 -0700 3851) le32_to_cpu(sbi->ckpt->valid_inode_count));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3852) sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3853) sbi->total_valid_block_count =
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3854) le64_to_cpu(sbi->ckpt->valid_block_count);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3855) sbi->last_valid_block_count = sbi->total_valid_block_count;
daeb433e42de9 (Chao Yu 2017-06-26 16:24:41 +0800 3856) sbi->reserved_blocks = 0;
80d421450187e (Yunlong Song 2017-10-27 20:45:05 +0800 3857) sbi->current_reserved_blocks = 0;
7e65be49ed94f (Jaegeuk Kim 2017-12-27 15:05:52 -0800 3858) limit_reserve_root(sbi);
1ae18f71cb522 (Jaegeuk Kim 2020-05-15 17:20:50 -0700 3859) adjust_unusable_cap_perc(sbi);
41382ec43255b (Jaegeuk Kim 2016-05-16 11:06:50 -0700 3860)
c227f912732f2 (Chao Yu 2015-12-16 13:09:20 +0800 3861) for (i = 0; i < NR_INODE_TYPE; i++) {
c227f912732f2 (Chao Yu 2015-12-16 13:09:20 +0800 3862) INIT_LIST_HEAD(&sbi->inode_list[i]);
c227f912732f2 (Chao Yu 2015-12-16 13:09:20 +0800 3863) spin_lock_init(&sbi->inode_lock[i]);
c227f912732f2 (Chao Yu 2015-12-16 13:09:20 +0800 3864) }
040d2bb318d1a (Chao Yu 2019-05-20 17:36:59 +0800 3865) mutex_init(&sbi->flush_lock);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3866)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3867) f2fs_init_extent_cache_info(sbi);
1dcc336b02bff (Chao Yu 2015-02-05 17:57:31 +0800 3868)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3869) f2fs_init_ino_entry_info(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3870)
50fa53eccf9f9 (Chao Yu 2018-08-02 23:03:19 +0800 3871) f2fs_init_fsync_node_info(sbi);
50fa53eccf9f9 (Chao Yu 2018-08-02 23:03:19 +0800 3872)
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3873) /* setup checkpoint request control and start checkpoint issue thread */
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3874) f2fs_init_ckpt_req_control(sbi);
3f7070b05052f (Chao Yu 2021-03-17 17:56:03 +0800 3875) if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) &&
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3876) test_opt(sbi, MERGE_CHECKPOINT)) {
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3877) err = f2fs_start_ckpt_thread(sbi);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3878) if (err) {
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3879) f2fs_err(sbi,
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3880) "Failed to start F2FS issue_checkpoint_thread (%d)",
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3881) err);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3882) goto stop_ckpt_thread;
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3883) }
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3884) }
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 3885)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3886) /* setup f2fs internal modules */
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3887) err = f2fs_build_segment_manager(sbi);
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3888) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3889) f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3890) err);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3891) goto free_sm;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3892) }
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3893) err = f2fs_build_node_manager(sbi);
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3894) if (err) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3895) f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3896) err);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3897) goto free_nm;
a07ef784356cf (Namjae Jeon 2012-12-30 14:52:05 +0900 3898) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3899)
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3900) /* For write statistics */
3a0a9cbc44bbb (Chao Yu 2020-11-27 21:20:06 +0800 3901) sbi->sectors_written_start = f2fs_get_sectors_written(sbi);
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3902)
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3903) /* Read accumulated write IO statistics if exists */
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3904) seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3905) if (__exist_node_summaries(sbi))
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3906) sbi->kbytes_written =
b2dde6fca37e9 (Shuoran Liu 2016-03-29 18:00:15 +0800 3907) le64_to_cpu(seg_i->journal->info.kbytes_written);
8f1dbbbbdfe9b (Shuoran Liu 2016-01-27 09:57:30 +0800 3908)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3909) f2fs_build_gc_manager(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3910)
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3911) err = f2fs_build_stats(sbi);
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3912) if (err)
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3913) goto free_nm;
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3914)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3915) /* get an inode for node space */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3916) sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3917) if (IS_ERR(sbi->node_inode)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3918) f2fs_err(sbi, "Failed to read node inode");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3919) err = PTR_ERR(sbi->node_inode);
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3920) goto free_stats;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3921) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3922)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3923) /* read root inode and dentry */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3924) root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3925) if (IS_ERR(root)) {
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3926) f2fs_err(sbi, "Failed to read root inode");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3927) err = PTR_ERR(root);
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3928) goto free_node_inode;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3929) }
bcbfbd604dcba (Chao Yu 2018-06-29 00:19:25 +0800 3930) if (!S_ISDIR(root->i_mode) || !root->i_blocks ||
bcbfbd604dcba (Chao Yu 2018-06-29 00:19:25 +0800 3931) !root->i_size || !root->i_nlink) {
9d847950770da (Chao Yu 2014-07-25 12:55:09 +0800 3932) iput(root);
8f99a946f360c (Chao Yu 2013-11-28 15:43:43 +0800 3933) err = -EINVAL;
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 3934) goto free_node_inode;
8f99a946f360c (Chao Yu 2013-11-28 15:43:43 +0800 3935) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3936)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3937) sb->s_root = d_make_root(root); /* allocate root dentry */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3938) if (!sb->s_root) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3939) err = -ENOMEM;
025cdb166c1e6 (Chengguang Xu 2019-01-23 15:49:44 +0800 3940) goto free_node_inode;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3941) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 3942)
dc6b20551044a (Jaegeuk Kim 2017-07-26 11:24:13 -0700 3943) err = f2fs_register_sysfs(sbi);
b59d0bae6ca30 (Namjae Jeon 2013-08-04 23:09:40 +0900 3944) if (err)
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 3945) goto free_root_inode;
b59d0bae6ca30 (Namjae Jeon 2013-08-04 23:09:40 +0900 3946)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 3947) #ifdef CONFIG_QUOTA
76cf05d79c9ef (Sheng Yong 2018-07-26 19:24:25 +0800 3948) /* Enable quota usage during mount */
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 3949) if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) {
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 3950) err = f2fs_enable_quotas(sb);
730746ce88da9 (Jaegeuk Kim 2018-10-02 17:20:58 -0700 3951) if (err)
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3952) f2fs_err(sbi, "Cannot turn on quotas: error %d", err);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 3953) }
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 3954) #endif
7a88ddb56077d (Chao Yu 2020-02-27 19:30:05 +0800 3955) /* if there are any orphan inodes, free them */
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3956) err = f2fs_recover_orphan_inodes(sbi);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 3957) if (err)
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 3958) goto free_meta;
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 3959)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 3960) if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)))
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3961) goto reset_checkpoint;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 3962)
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 3963) /* recover fsynced data */
a9117eca1de6b (Chao Yu 2020-02-14 17:45:11 +0800 3964) if (!test_opt(sbi, DISABLE_ROLL_FORWARD) &&
a9117eca1de6b (Chao Yu 2020-02-14 17:45:11 +0800 3965) !test_opt(sbi, NORECOVERY)) {
081d78c2fc4ab (Jaegeuk Kim 2015-01-23 19:16:59 -0800 3966) /*
081d78c2fc4ab (Jaegeuk Kim 2015-01-23 19:16:59 -0800 3967) * mount should be failed, when device has readonly mode, and
081d78c2fc4ab (Jaegeuk Kim 2015-01-23 19:16:59 -0800 3968) * previous checkpoint was not done by clean system shutdown.
081d78c2fc4ab (Jaegeuk Kim 2015-01-23 19:16:59 -0800 3969) */
b61af314c9b8c (Chao Yu 2019-04-22 20:22:37 +0800 3970) if (f2fs_hw_is_readonly(sbi)) {
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3971) if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3972) err = f2fs_recover_fsync_data(sbi, true);
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3973) if (err > 0) {
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3974) err = -EROFS;
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3975) f2fs_err(sbi, "Need to recover fsync data, but "
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3976) "write access unavailable, please try "
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3977) "mount w/ disable_roll_forward or norecovery");
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3978) }
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3979) if (err < 0)
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3980) goto free_meta;
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3981) }
23738e74472f9 (Chao Yu 2021-03-31 11:16:32 +0800 3982) f2fs_info(sbi, "write access unavailable, skipping recovery");
b61af314c9b8c (Chao Yu 2019-04-22 20:22:37 +0800 3983) goto reset_checkpoint;
081d78c2fc4ab (Jaegeuk Kim 2015-01-23 19:16:59 -0800 3984) }
2adc3505cfb81 (Chao Yu 2015-03-16 21:08:44 +0800 3985)
2adc3505cfb81 (Chao Yu 2015-03-16 21:08:44 +0800 3986) if (need_fsck)
2adc3505cfb81 (Chao Yu 2015-03-16 21:08:44 +0800 3987) set_sbi_flag(sbi, SBI_NEED_FSCK);
2adc3505cfb81 (Chao Yu 2015-03-16 21:08:44 +0800 3988)
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3989) if (skip_recovery)
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3990) goto reset_checkpoint;
a468f0ef516fd (Jaegeuk Kim 2016-09-19 17:55:10 -0700 3991)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 3992) err = f2fs_recover_fsync_data(sbi, false);
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 3993) if (err < 0) {
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3994) if (err != -ENOMEM)
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 3995) skip_recovery = true;
2adc3505cfb81 (Chao Yu 2015-03-16 21:08:44 +0800 3996) need_fsck = true;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3997) f2fs_err(sbi, "Cannot recover all fsync data errno=%d",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 3998) err);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 3999) goto free_meta;
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4000) }
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 4001) } else {
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4002) err = f2fs_recover_fsync_data(sbi, true);
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 4003)
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 4004) if (!f2fs_readonly(sb) && err > 0) {
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 4005) err = -EINVAL;
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 4006) f2fs_err(sbi, "Need to recover fsync data");
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 4007) goto free_meta;
6781eabba1bdb (Jaegeuk Kim 2016-03-23 16:12:58 -0700 4008) }
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4009) }
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4010)
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4011) /*
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4012) * If the f2fs is not readonly and fsync data recovery succeeds,
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4013) * check zoned block devices' write pointer consistency.
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4014) */
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4015) if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) {
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4016) err = f2fs_check_write_pointer(sbi);
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4017) if (err)
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4018) goto free_meta;
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4019) }
d508c94e45fcd (Shin'ichiro Kawasaki 2019-12-09 19:44:45 +0900 4020)
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 4021) reset_checkpoint:
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4022) f2fs_init_inmem_curseg(sbi);
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4023)
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4024) /* f2fs_recover_fsync_data() cleared this already */
315df8398e363 (Jaegeuk Kim 2015-08-11 12:45:39 -0700 4025) clear_sbi_flag(sbi, SBI_POR_DOING);
b59d0bae6ca30 (Namjae Jeon 2013-08-04 23:09:40 +0900 4026)
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4027) if (test_opt(sbi, DISABLE_CHECKPOINT)) {
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4028) err = f2fs_disable_checkpoint(sbi);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4029) if (err)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4030) goto sync_free_meta;
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4031) } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4032) f2fs_enable_checkpoint(sbi);
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4033) }
4354994f097d0 (Daniel Rosenberg 2018-08-20 19:21:43 -0700 4034)
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4035) /*
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4036) * If filesystem is not mounted as read-only then
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4037) * do start the gc_thread.
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4038) */
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 4039) if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF ||
5911d2d1d1a38 (Chao Yu 2021-03-27 17:57:06 +0800 4040) test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) {
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4041) /* After POR, we can run background GC thread.*/
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4042) err = f2fs_start_gc_thread(sbi);
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4043) if (err)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4044) goto sync_free_meta;
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4045) }
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 4046) kvfree(options);
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 4047)
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 4048) /* recover broken superblock */
f2353d7bd4221 (Jaegeuk Kim 2016-03-23 10:42:01 -0700 4049) if (recovery) {
41214b3c77e09 (Chao Yu 2016-02-22 18:33:20 +0800 4050) err = f2fs_commit_super(sbi, true);
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 4051) f2fs_info(sbi, "Try to recover %dth superblock, ret: %d",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 4052) sbi->valid_super_block ? 1 : 2, err);
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 4053) }
da554e48caab9 (hujianyang 2015-05-21 14:42:53 +0800 4054)
bae01eda8e6ef (Chao Yu 2017-11-30 19:28:20 +0800 4055) f2fs_join_shrinker(sbi);
bae01eda8e6ef (Chao Yu 2017-11-30 19:28:20 +0800 4056)
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 4057) f2fs_tuning_parameters(sbi);
84b89e5d943d8 (Jaegeuk Kim 2018-02-22 14:09:30 -0800 4058)
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 4059) f2fs_notice(sbi, "Mounted with checkpoint version = %llx",
dcbb4c10e6d96 (Joe Perches 2019-06-18 17:48:42 +0800 4060) cur_cp_version(F2FS_CKPT(sbi)));
6beceb5427aa8 (Jaegeuk Kim 2016-01-08 15:51:50 -0800 4061) f2fs_update_time(sbi, CP_TIME);
d0239e1bf5204 (Jaegeuk Kim 2016-01-08 16:57:48 -0800 4062) f2fs_update_time(sbi, REQ_TIME);
db610a640eeeb (Jaegeuk Kim 2019-01-24 17:48:38 -0800 4063) clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4064) return 0;
6437d1b0adb46 (Jaegeuk Kim 2014-02-19 18:23:32 +0900 4065)
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4066) sync_free_meta:
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4067) /* safe to flush all the data */
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4068) sync_filesystem(sbi->sb);
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 4069) retry_cnt = 0;
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4070)
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4071) free_meta:
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 4072) #ifdef CONFIG_QUOTA
26b5a079197c8 (Sheng Yong 2018-10-12 18:49:26 +0800 4073) f2fs_truncate_quota_inode_pages(sb);
7beb01f74415c (Chao Yu 2018-10-24 18:34:26 +0800 4074) if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb))
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 4075) f2fs_quota_off_umount(sbi->sb);
ea6767337f863 (Jaegeuk Kim 2017-10-06 09:14:28 -0700 4076) #endif
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4077) /*
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4078) * Some dirty meta pages can be produced by f2fs_recover_orphan_inodes()
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4079) * failed by EIO. Then, iput(node_inode) can trigger balance_fs_bg()
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4080) * followed by f2fs_write_checkpoint() through f2fs_write_node_pages(), which
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4081) * falls into an infinite loop in f2fs_sync_meta_pages().
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4082) */
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4083) truncate_inode_pages_final(META_MAPPING(sbi));
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4084) /* evict some inodes being cached by GC */
812a95977fd2f (Jaegeuk Kim 2019-01-22 14:04:33 -0800 4085) evict_inodes(sb);
dc6b20551044a (Jaegeuk Kim 2017-07-26 11:24:13 -0700 4086) f2fs_unregister_sysfs(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4087) free_root_inode:
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4088) dput(sb->s_root);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4089) sb->s_root = NULL;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4090) free_node_inode:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4091) f2fs_release_ino_entry(sbi, true);
bae01eda8e6ef (Chao Yu 2017-11-30 19:28:20 +0800 4092) truncate_inode_pages_final(NODE_MAPPING(sbi));
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4093) iput(sbi->node_inode);
7c77bf7de1574 (Jaegeuk Kim 2019-01-01 00:11:30 -0800 4094) sbi->node_inode = NULL;
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 4095) free_stats:
60aa4d5536ab7 (Sahitya Tummala 2018-12-26 11:20:29 +0530 4096) f2fs_destroy_stats(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4097) free_nm:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4098) f2fs_destroy_node_manager(sbi);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4099) free_sm:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4100) f2fs_destroy_segment_manager(sbi);
4c8ff7095bef6 (Chao Yu 2019-11-01 18:07:14 +0800 4101) f2fs_destroy_post_read_wq(sbi);
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 4102) stop_ckpt_thread:
261eeb9c1585d (Daeho Jeong 2021-01-19 09:00:42 +0900 4103) f2fs_stop_ckpt_thread(sbi);
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 4104) free_devices:
3c62be17d4f56 (Jaegeuk Kim 2016-10-06 19:02:05 -0700 4105) destroy_device_list(sbi);
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 4106) kvfree(sbi->ckpt);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4107) free_meta_inode:
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4108) make_bad_inode(sbi->meta_inode);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4109) iput(sbi->meta_inode);
7c77bf7de1574 (Jaegeuk Kim 2019-01-01 00:11:30 -0800 4110) sbi->meta_inode = NULL;
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 4111) free_page_array_cache:
31083031709ee (Chao Yu 2020-09-14 17:05:13 +0800 4112) f2fs_destroy_page_array_cache(sbi);
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 4113) free_xattr_cache:
a999150f4fe3a (Chao Yu 2020-02-25 18:17:10 +0800 4114) f2fs_destroy_xattr_caches(sbi);
0a595ebaaa6b5 (Jaegeuk Kim 2016-12-14 10:12:56 -0800 4115) free_io_dummy:
0a595ebaaa6b5 (Jaegeuk Kim 2016-12-14 10:12:56 -0800 4116) mempool_destroy(sbi->write_io_dummy);
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 4117) free_percpu:
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 4118) destroy_percpu_info(sbi);
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 4119) free_bio_info:
a912b54d3aaa0 (Jaegeuk Kim 2017-05-10 11:18:25 -0700 4120) for (i = 0; i < NR_PAGE_TYPE; i++)
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 4121) kvfree(sbi->write_io[i]);
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 4122)
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 4123) #ifdef CONFIG_UNICODE
eca4873ee1b63 (Daniel Rosenberg 2020-07-08 02:12:36 -0700 4124) utf8_unload(sb->s_encoding);
89ff6005039a8 (Hyeongseok Kim 2020-11-12 18:14:54 +0900 4125) sb->s_encoding = NULL;
5aba54302a46f (Daniel Rosenberg 2019-07-23 16:05:28 -0700 4126) #endif
d7997e63684c9 (Chao Yu 2018-01-17 16:31:35 +0800 4127) free_options:
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4128) #ifdef CONFIG_QUOTA
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4129) for (i = 0; i < MAXQUOTAS; i++)
ba87a45c23d64 (Wang Xiaojun 2020-06-17 20:30:12 +0800 4130) kfree(F2FS_OPTION(sbi).s_qf_names[i]);
4b2414d04e991 (Chao Yu 2017-08-08 10:54:31 +0800 4131) #endif
ac4acb1f4b2b6 (Eric Biggers 2020-09-16 21:11:35 -0700 4132) fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy);
5222595d093eb (Jaegeuk Kim 2018-12-13 18:38:33 -0800 4133) kvfree(options);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4134) free_sb_buf:
742532d11d832 (Denis Efremov 2020-06-10 01:14:46 +0300 4135) kfree(raw_super);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4136) free_sbi:
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 4137) if (sbi->s_chksum_driver)
43b6573bac95d (Keith Mok 2016-03-02 12:04:24 -0800 4138) crypto_free_shash(sbi->s_chksum_driver);
742532d11d832 (Denis Efremov 2020-06-10 01:14:46 +0300 4139) kfree(sbi);
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4140)
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4141) /* give only one another chance */
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 4142) if (retry_cnt > 0 && skip_recovery) {
aa2c8c43e4a5c (Chao Yu 2019-02-19 16:23:53 +0800 4143) retry_cnt--;
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4144) shrink_dcache_sb(sb);
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4145) goto try_onemore;
ed2e621a95d70 (Jaegeuk Kim 2014-08-08 15:37:41 -0700 4146) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4147) return err;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4148) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4149)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4150) static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4151) const char *dev_name, void *data)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4152) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4153) return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4154) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4155)
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4156) static void kill_f2fs_super(struct super_block *sb)
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4157) {
cce1325247b9f (Chao Yu 2017-06-29 23:17:45 +0800 4158) if (sb->s_root) {
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4159) struct f2fs_sb_info *sbi = F2FS_SB(sb);
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4160)
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4161) set_sbi_flag(sbi, SBI_IS_CLOSE);
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4162) f2fs_stop_gc_thread(sbi);
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4163) f2fs_stop_discard_thread(sbi);
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4164)
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4165) if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) ||
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4166) !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4167) struct cp_control cpc = {
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4168) .reason = CP_UMOUNT,
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4169) };
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4170) f2fs_write_checkpoint(sbi, &cpc);
1cb50f87e1069 (Jaegeuk Kim 2018-07-06 16:47:34 -0700 4171) }
1378752b9921e (Chao Yu 2018-08-22 17:11:05 +0800 4172)
1378752b9921e (Chao Yu 2018-08-22 17:11:05 +0800 4173) if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb))
1378752b9921e (Chao Yu 2018-08-22 17:11:05 +0800 4174) sb->s_flags &= ~SB_RDONLY;
cce1325247b9f (Chao Yu 2017-06-29 23:17:45 +0800 4175) }
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4176) kill_block_super(sb);
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4177) }
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4178)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4179) static struct file_system_type f2fs_fs_type = {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4180) .owner = THIS_MODULE,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4181) .name = "f2fs",
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4182) .mount = f2fs_mount,
30a5537f9a9e9 (Jaegeuk Kim 2015-01-14 16:34:24 -0800 4183) .kill_sb = kill_f2fs_super,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4184) .fs_flags = FS_REQUIRES_DEV,
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4185) };
7f78e03513940 (Eric W. Biederman 2013-03-02 19:39:14 -0800 4186) MODULE_ALIAS_FS("f2fs");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4187)
6e6093a8f1444 (Namjae Jeon 2013-01-17 00:08:30 +0900 4188) static int __init init_inodecache(void)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4189) {
5d097056c9a01 (Vladimir Davydov 2016-01-14 15:18:21 -0800 4190) f2fs_inode_cachep = kmem_cache_create("f2fs_inode_cache",
5d097056c9a01 (Vladimir Davydov 2016-01-14 15:18:21 -0800 4191) sizeof(struct f2fs_inode_info), 0,
5d097056c9a01 (Vladimir Davydov 2016-01-14 15:18:21 -0800 4192) SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL);
6bacf52fb58ae (Jaegeuk Kim 2013-12-06 15:00:58 +0900 4193) if (!f2fs_inode_cachep)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4194) return -ENOMEM;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4195) return 0;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4196) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4197)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4198) static void destroy_inodecache(void)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4199) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4200) /*
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4201) * Make sure all delayed rcu free inodes are flushed before we
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4202) * destroy cache.
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4203) */
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4204) rcu_barrier();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4205) kmem_cache_destroy(f2fs_inode_cachep);
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4206) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4207)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4208) static int __init init_f2fs_fs(void)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4209) {
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4210) int err;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4211)
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4212) if (PAGE_SIZE != F2FS_BLKSIZE) {
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4213) printk("F2FS not supported on PAGE_SIZE(%lu) != %d\n",
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4214) PAGE_SIZE, F2FS_BLKSIZE);
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4215) return -EINVAL;
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4216) }
4071e67cffcc5 (Anatoly Pugachev 2018-05-28 02:06:37 +0300 4217)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4218) err = init_inodecache();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4219) if (err)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4220) goto fail;
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4221) err = f2fs_create_node_manager_caches();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4222) if (err)
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4223) goto free_inodecache;
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4224) err = f2fs_create_segment_manager_caches();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4225) if (err)
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4226) goto free_node_manager_caches;
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4227) err = f2fs_create_checkpoint_caches();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4228) if (err)
062920734c0de (Chao Yu 2014-12-29 15:56:18 +0800 4229) goto free_segment_manager_caches;
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4230) err = f2fs_create_recovery_cache();
1dcc336b02bff (Chao Yu 2015-02-05 17:57:31 +0800 4231) if (err)
1dcc336b02bff (Chao Yu 2015-02-05 17:57:31 +0800 4232) goto free_checkpoint_caches;
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4233) err = f2fs_create_extent_cache();
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4234) if (err)
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4235) goto free_recovery_cache;
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4236) err = f2fs_create_garbage_collection_cache();
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 4237) if (err)
1dcc336b02bff (Chao Yu 2015-02-05 17:57:31 +0800 4238) goto free_extent_cache;
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4239) err = f2fs_init_sysfs();
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4240) if (err)
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4241) goto free_garbage_collection_cache;
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4242) err = register_shrinker(&f2fs_shrinker_info);
cfc4d971df411 (Jaegeuk Kim 2015-05-15 15:37:24 -0700 4243) if (err)
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 4244) goto free_sysfs;
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4245) err = register_filesystem(&f2fs_fs_type);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4246) if (err)
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4247) goto free_shrinker;
21acc07d33a96 (Greg Kroah-Hartman 2019-01-04 14:26:18 +0100 4248) f2fs_create_root_stats();
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4249) err = f2fs_init_post_read_processing();
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4250) if (err)
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4251) goto free_root_stats;
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4252) err = f2fs_init_bio_entry_cache();
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4253) if (err)
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4254) goto free_post_read;
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4255) err = f2fs_init_bioset();
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4256) if (err)
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4257) goto free_bio_enrty_cache;
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4258) err = f2fs_init_compress_mempool();
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4259) if (err)
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4260) goto free_bioset;
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4261) err = f2fs_init_compress_cache();
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4262) if (err)
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4263) goto free_compress_mempool;
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4264) return 0;
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4265) free_compress_mempool:
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4266) f2fs_destroy_compress_mempool();
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4267) free_bioset:
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4268) f2fs_destroy_bioset();
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4269) free_bio_enrty_cache:
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4270) f2fs_destroy_bio_entry_cache();
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4271) free_post_read:
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4272) f2fs_destroy_post_read_processing();
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4273) free_root_stats:
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4274) f2fs_destroy_root_stats();
787c7b8cb3c51 (Chao Yu 2015-10-29 09:13:04 +0800 4275) unregister_filesystem(&f2fs_fs_type);
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4276) free_shrinker:
2658e50de6142 (Jaegeuk Kim 2015-06-19 12:01:21 -0700 4277) unregister_shrinker(&f2fs_shrinker_info);
a398101aa1133 (Chao Yu 2017-06-14 17:39:46 +0800 4278) free_sysfs:
dc6b20551044a (Jaegeuk Kim 2017-07-26 11:24:13 -0700 4279) f2fs_exit_sysfs();
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4280) free_garbage_collection_cache:
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4281) f2fs_destroy_garbage_collection_cache();
1dcc336b02bff (Chao Yu 2015-02-05 17:57:31 +0800 4282) free_extent_cache:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4283) f2fs_destroy_extent_cache();
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4284) free_recovery_cache:
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4285) f2fs_destroy_recovery_cache();
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4286) free_checkpoint_caches:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4287) f2fs_destroy_checkpoint_caches();
7fd9e544fbb10 (Jaegeuk Kim 2013-11-15 13:55:58 +0900 4288) free_segment_manager_caches:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4289) f2fs_destroy_segment_manager_caches();
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4290) free_node_manager_caches:
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4291) f2fs_destroy_node_manager_caches();
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4292) free_inodecache:
9890ff3f23ed7 (Zhao Hongjiang 2013-08-20 16:49:51 +0800 4293) destroy_inodecache();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4294) fail:
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4295) return err;
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4296) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4297)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4298) static void __exit exit_f2fs_fs(void)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4299) {
c68d6c8830225 (Chao Yu 2020-09-14 17:05:14 +0800 4300) f2fs_destroy_compress_cache();
5e6bbde959823 (Chao Yu 2020-04-08 19:56:05 +0800 4301) f2fs_destroy_compress_mempool();
f543805fcd60f (Chao Yu 2019-12-04 09:52:58 +0800 4302) f2fs_destroy_bioset();
0b20fcec86515 (Chao Yu 2019-09-30 18:53:25 +0800 4303) f2fs_destroy_bio_entry_cache();
6dbb17961f46b (Eric Biggers 2018-04-18 11:09:48 -0700 4304) f2fs_destroy_post_read_processing();
4589d25d015c2 (Namjae Jeon 2013-01-15 19:58:47 +0900 4305) f2fs_destroy_root_stats();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4306) unregister_filesystem(&f2fs_fs_type);
b8bef79df7095 (Tiezhu Yang 2016-05-18 08:02:25 +0800 4307) unregister_shrinker(&f2fs_shrinker_info);
dc6b20551044a (Jaegeuk Kim 2017-07-26 11:24:13 -0700 4308) f2fs_exit_sysfs();
093749e296e29 (Chao Yu 2020-08-04 21:14:49 +0800 4309) f2fs_destroy_garbage_collection_cache();
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4310) f2fs_destroy_extent_cache();
e472b276a0d21 (Chao Yu 2021-05-07 18:10:38 +0800 4311) f2fs_destroy_recovery_cache();
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4312) f2fs_destroy_checkpoint_caches();
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4313) f2fs_destroy_segment_manager_caches();
4d57b86dd8640 (Chao Yu 2018-05-30 00:20:41 +0800 4314) f2fs_destroy_node_manager_caches();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4315) destroy_inodecache();
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4316) }
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4317)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4318) module_init(init_f2fs_fs)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4319) module_exit(exit_f2fs_fs)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4320)
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4321) MODULE_AUTHOR("Samsung Electronics's Praesto Team");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4322) MODULE_DESCRIPTION("Flash Friendly File System");
aff063e266cbf (Jaegeuk Kim 2012-11-02 17:07:47 +0900 4323) MODULE_LICENSE("GPL");
c3988657d3703 (Chao Yu 2021-05-18 09:57:54 +0800 4324) MODULE_SOFTDEP("pre: crc32");
b4b9d34c855ef (Jaegeuk Kim 2016-11-04 14:59:15 -0700 4325)