Chao Yu | 7c1a000 | 2018-09-12 09:16:07 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 2 | /* |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3 | * fs/f2fs/super.c |
| 4 | * |
| 5 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. |
| 6 | * http://www.samsung.com/ |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 7 | */ |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/statfs.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 12 | #include <linux/buffer_head.h> |
| 13 | #include <linux/backing-dev.h> |
| 14 | #include <linux/kthread.h> |
| 15 | #include <linux/parser.h> |
| 16 | #include <linux/mount.h> |
| 17 | #include <linux/seq_file.h> |
Jaegeuk Kim | 5e176d5 | 2013-06-28 12:47:01 +0900 | [diff] [blame] | 18 | #include <linux/proc_fs.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 19 | #include <linux/random.h> |
| 20 | #include <linux/exportfs.h> |
Namjae Jeon | d3ee456 | 2013-03-17 17:26:14 +0900 | [diff] [blame] | 21 | #include <linux/blkdev.h> |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 22 | #include <linux/quotaops.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 23 | #include <linux/f2fs_fs.h> |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 24 | #include <linux/sysfs.h> |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 25 | #include <linux/quota.h> |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 26 | #include <linux/unicode.h> |
Christoph Hellwig | c6a564ff | 2020-03-25 16:48:42 +0100 | [diff] [blame] | 27 | #include <linux/part_stat.h> |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 28 | #include <linux/zstd.h> |
| 29 | #include <linux/lz4.h> |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 30 | |
| 31 | #include "f2fs.h" |
| 32 | #include "node.h" |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 33 | #include "segment.h" |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 34 | #include "xattr.h" |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 35 | #include "gc.h" |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 36 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 37 | #define CREATE_TRACE_POINTS |
| 38 | #include <trace/events/f2fs.h> |
| 39 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 40 | static struct kmem_cache *f2fs_inode_cachep; |
| 41 | |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 42 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 43 | |
Alexey Dobriyan | 19880e6 | 2018-11-24 12:06:42 +0300 | [diff] [blame] | 44 | const char *f2fs_fault_name[FAULT_MAX] = { |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 45 | [FAULT_KMALLOC] = "kmalloc", |
Chao Yu | 628b3d1 | 2017-11-30 19:28:18 +0800 | [diff] [blame] | 46 | [FAULT_KVMALLOC] = "kvmalloc", |
Jaegeuk Kim | c41f3cc3 | 2016-04-29 16:17:09 -0700 | [diff] [blame] | 47 | [FAULT_PAGE_ALLOC] = "page alloc", |
Chao Yu | 01eccef | 2017-10-28 16:52:30 +0800 | [diff] [blame] | 48 | [FAULT_PAGE_GET] = "page get", |
Jaegeuk Kim | cb78942 | 2016-04-29 16:29:22 -0700 | [diff] [blame] | 49 | [FAULT_ALLOC_NID] = "alloc nid", |
| 50 | [FAULT_ORPHAN] = "orphan", |
| 51 | [FAULT_BLOCK] = "no more block", |
| 52 | [FAULT_DIR_DEPTH] = "too big dir depth", |
Jaegeuk Kim | 53aa6bb | 2016-05-25 15:24:18 -0700 | [diff] [blame] | 53 | [FAULT_EVICT_INODE] = "evict_inode fail", |
Jaegeuk Kim | 14b44d2 | 2017-03-09 15:24:24 -0800 | [diff] [blame] | 54 | [FAULT_TRUNCATE] = "truncate fail", |
Chao Yu | 6f5c2ed | 2018-09-12 09:22:29 +0800 | [diff] [blame] | 55 | [FAULT_READ_IO] = "read IO error", |
Chao Yu | 0f34802 | 2016-09-26 19:45:55 +0800 | [diff] [blame] | 56 | [FAULT_CHECKPOINT] = "checkpoint error", |
Chao Yu | b83dcfe | 2018-08-06 20:30:18 +0800 | [diff] [blame] | 57 | [FAULT_DISCARD] = "discard error", |
Chao Yu | 6f5c2ed | 2018-09-12 09:22:29 +0800 | [diff] [blame] | 58 | [FAULT_WRITE_IO] = "write IO error", |
Jaegeuk Kim | 2c63fea | 2016-04-29 15:49:56 -0700 | [diff] [blame] | 59 | }; |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 60 | |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 61 | void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, |
| 62 | unsigned int type) |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 63 | { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 64 | struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 65 | |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 66 | if (rate) { |
Chao Yu | 1ecc0c5 | 2016-09-23 21:30:09 +0800 | [diff] [blame] | 67 | atomic_set(&ffi->inject_ops, 0); |
| 68 | ffi->inject_rate = rate; |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 69 | } |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 70 | |
| 71 | if (type) |
| 72 | ffi->inject_type = type; |
| 73 | |
| 74 | if (!rate && !type) |
| 75 | memset(ffi, 0, sizeof(struct f2fs_fault_info)); |
Sheng Yong | 0879689 | 2016-05-16 12:38:50 +0800 | [diff] [blame] | 76 | } |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 77 | #endif |
| 78 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 79 | /* f2fs-wide shrinker description */ |
| 80 | static struct shrinker f2fs_shrinker_info = { |
| 81 | .scan_objects = f2fs_shrink_scan, |
| 82 | .count_objects = f2fs_shrink_count, |
| 83 | .seeks = DEFAULT_SEEKS, |
| 84 | }; |
| 85 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 86 | enum { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 87 | Opt_gc_background, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 88 | Opt_disable_roll_forward, |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 89 | Opt_norecovery, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 90 | Opt_discard, |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 91 | Opt_nodiscard, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 92 | Opt_noheap, |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 93 | Opt_heap, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 94 | Opt_user_xattr, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 95 | Opt_nouser_xattr, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 96 | Opt_acl, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 97 | Opt_noacl, |
| 98 | Opt_active_logs, |
| 99 | Opt_disable_ext_identify, |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 100 | Opt_inline_xattr, |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 101 | Opt_noinline_xattr, |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 102 | Opt_inline_xattr_size, |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 103 | Opt_inline_data, |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 104 | Opt_inline_dentry, |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 105 | Opt_noinline_dentry, |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 106 | Opt_flush_merge, |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 107 | Opt_noflush_merge, |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 108 | Opt_nobarrier, |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 109 | Opt_fastboot, |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 110 | Opt_extent_cache, |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 111 | Opt_noextent_cache, |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 112 | Opt_noinline_data, |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 113 | Opt_data_flush, |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 114 | Opt_reserve_root, |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 115 | Opt_resgid, |
| 116 | Opt_resuid, |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 117 | Opt_mode, |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 118 | Opt_io_size_bits, |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 119 | Opt_fault_injection, |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 120 | Opt_fault_type, |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 121 | Opt_lazytime, |
| 122 | Opt_nolazytime, |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 123 | Opt_quota, |
| 124 | Opt_noquota, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 125 | Opt_usrquota, |
| 126 | Opt_grpquota, |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 127 | Opt_prjquota, |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 128 | Opt_usrjquota, |
| 129 | Opt_grpjquota, |
| 130 | Opt_prjjquota, |
| 131 | Opt_offusrjquota, |
| 132 | Opt_offgrpjquota, |
| 133 | Opt_offprjjquota, |
| 134 | Opt_jqfmt_vfsold, |
| 135 | Opt_jqfmt_vfsv0, |
| 136 | Opt_jqfmt_vfsv1, |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 137 | Opt_whint, |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 138 | Opt_alloc, |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 139 | Opt_fsync, |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 140 | Opt_test_dummy_encryption, |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 141 | Opt_inlinecrypt, |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 142 | Opt_checkpoint_disable, |
| 143 | Opt_checkpoint_disable_cap, |
| 144 | Opt_checkpoint_disable_cap_perc, |
| 145 | Opt_checkpoint_enable, |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 146 | Opt_checkpoint_merge, |
| 147 | Opt_nocheckpoint_merge, |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 148 | Opt_compress_algorithm, |
| 149 | Opt_compress_log_size, |
| 150 | Opt_compress_extension, |
Chao Yu | b28f047 | 2020-11-26 18:32:09 +0800 | [diff] [blame] | 151 | Opt_compress_chksum, |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 152 | Opt_compress_mode, |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 153 | Opt_atgc, |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 154 | Opt_gc_merge, |
| 155 | Opt_nogc_merge, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 156 | Opt_err, |
| 157 | }; |
| 158 | |
| 159 | static match_table_t f2fs_tokens = { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 160 | {Opt_gc_background, "background_gc=%s"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 161 | {Opt_disable_roll_forward, "disable_roll_forward"}, |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 162 | {Opt_norecovery, "norecovery"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 163 | {Opt_discard, "discard"}, |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 164 | {Opt_nodiscard, "nodiscard"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 165 | {Opt_noheap, "no_heap"}, |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 166 | {Opt_heap, "heap"}, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 167 | {Opt_user_xattr, "user_xattr"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 168 | {Opt_nouser_xattr, "nouser_xattr"}, |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 169 | {Opt_acl, "acl"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 170 | {Opt_noacl, "noacl"}, |
| 171 | {Opt_active_logs, "active_logs=%u"}, |
| 172 | {Opt_disable_ext_identify, "disable_ext_identify"}, |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 173 | {Opt_inline_xattr, "inline_xattr"}, |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 174 | {Opt_noinline_xattr, "noinline_xattr"}, |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 175 | {Opt_inline_xattr_size, "inline_xattr_size=%u"}, |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 176 | {Opt_inline_data, "inline_data"}, |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 177 | {Opt_inline_dentry, "inline_dentry"}, |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 178 | {Opt_noinline_dentry, "noinline_dentry"}, |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 179 | {Opt_flush_merge, "flush_merge"}, |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 180 | {Opt_noflush_merge, "noflush_merge"}, |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 181 | {Opt_nobarrier, "nobarrier"}, |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 182 | {Opt_fastboot, "fastboot"}, |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 183 | {Opt_extent_cache, "extent_cache"}, |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 184 | {Opt_noextent_cache, "noextent_cache"}, |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 185 | {Opt_noinline_data, "noinline_data"}, |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 186 | {Opt_data_flush, "data_flush"}, |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 187 | {Opt_reserve_root, "reserve_root=%u"}, |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 188 | {Opt_resgid, "resgid=%u"}, |
| 189 | {Opt_resuid, "resuid=%u"}, |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 190 | {Opt_mode, "mode=%s"}, |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 191 | {Opt_io_size_bits, "io_bits=%u"}, |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 192 | {Opt_fault_injection, "fault_injection=%u"}, |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 193 | {Opt_fault_type, "fault_type=%u"}, |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 194 | {Opt_lazytime, "lazytime"}, |
| 195 | {Opt_nolazytime, "nolazytime"}, |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 196 | {Opt_quota, "quota"}, |
| 197 | {Opt_noquota, "noquota"}, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 198 | {Opt_usrquota, "usrquota"}, |
| 199 | {Opt_grpquota, "grpquota"}, |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 200 | {Opt_prjquota, "prjquota"}, |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 201 | {Opt_usrjquota, "usrjquota=%s"}, |
| 202 | {Opt_grpjquota, "grpjquota=%s"}, |
| 203 | {Opt_prjjquota, "prjjquota=%s"}, |
| 204 | {Opt_offusrjquota, "usrjquota="}, |
| 205 | {Opt_offgrpjquota, "grpjquota="}, |
| 206 | {Opt_offprjjquota, "prjjquota="}, |
| 207 | {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, |
| 208 | {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, |
| 209 | {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 210 | {Opt_whint, "whint_mode=%s"}, |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 211 | {Opt_alloc, "alloc_mode=%s"}, |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 212 | {Opt_fsync, "fsync_mode=%s"}, |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 213 | {Opt_test_dummy_encryption, "test_dummy_encryption=%s"}, |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 214 | {Opt_test_dummy_encryption, "test_dummy_encryption"}, |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 215 | {Opt_inlinecrypt, "inlinecrypt"}, |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 216 | {Opt_checkpoint_disable, "checkpoint=disable"}, |
| 217 | {Opt_checkpoint_disable_cap, "checkpoint=disable:%u"}, |
| 218 | {Opt_checkpoint_disable_cap_perc, "checkpoint=disable:%u%%"}, |
| 219 | {Opt_checkpoint_enable, "checkpoint=enable"}, |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 220 | {Opt_checkpoint_merge, "checkpoint_merge"}, |
| 221 | {Opt_nocheckpoint_merge, "nocheckpoint_merge"}, |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 222 | {Opt_compress_algorithm, "compress_algorithm=%s"}, |
| 223 | {Opt_compress_log_size, "compress_log_size=%u"}, |
| 224 | {Opt_compress_extension, "compress_extension=%s"}, |
Chao Yu | b28f047 | 2020-11-26 18:32:09 +0800 | [diff] [blame] | 225 | {Opt_compress_chksum, "compress_chksum"}, |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 226 | {Opt_compress_mode, "compress_mode=%s"}, |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 227 | {Opt_atgc, "atgc"}, |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 228 | {Opt_gc_merge, "gc_merge"}, |
| 229 | {Opt_nogc_merge, "nogc_merge"}, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 230 | {Opt_err, NULL}, |
| 231 | }; |
| 232 | |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 233 | void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 234 | { |
| 235 | struct va_format vaf; |
| 236 | va_list args; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 237 | int level; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 238 | |
| 239 | va_start(args, fmt); |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 240 | |
| 241 | level = printk_get_level(fmt); |
| 242 | vaf.fmt = printk_skip_level(fmt); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 243 | vaf.va = &args; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 244 | printk("%c%cF2FS-fs (%s): %pV\n", |
| 245 | KERN_SOH_ASCII, level, sbi->sb->s_id, &vaf); |
| 246 | |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 247 | va_end(args); |
| 248 | } |
| 249 | |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 250 | #ifdef CONFIG_UNICODE |
| 251 | static const struct f2fs_sb_encodings { |
| 252 | __u16 magic; |
| 253 | char *name; |
| 254 | char *version; |
| 255 | } f2fs_sb_encoding_map[] = { |
| 256 | {F2FS_ENC_UTF8_12_1, "utf8", "12.1.0"}, |
| 257 | }; |
| 258 | |
| 259 | static int f2fs_sb_read_encoding(const struct f2fs_super_block *sb, |
| 260 | const struct f2fs_sb_encodings **encoding, |
| 261 | __u16 *flags) |
| 262 | { |
| 263 | __u16 magic = le16_to_cpu(sb->s_encoding); |
| 264 | int i; |
| 265 | |
| 266 | for (i = 0; i < ARRAY_SIZE(f2fs_sb_encoding_map); i++) |
| 267 | if (magic == f2fs_sb_encoding_map[i].magic) |
| 268 | break; |
| 269 | |
| 270 | if (i >= ARRAY_SIZE(f2fs_sb_encoding_map)) |
| 271 | return -EINVAL; |
| 272 | |
| 273 | *encoding = &f2fs_sb_encoding_map[i]; |
| 274 | *flags = le16_to_cpu(sb->s_encoding_flags); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | #endif |
| 279 | |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 280 | static inline void limit_reserve_root(struct f2fs_sb_info *sbi) |
| 281 | { |
Daniel Rosenberg | 9a9aeca | 2019-05-29 17:49:04 -0700 | [diff] [blame] | 282 | block_t limit = min((sbi->user_block_count << 1) / 1000, |
| 283 | sbi->user_block_count - sbi->reserved_blocks); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 284 | |
| 285 | /* limit is 0.2% */ |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 286 | if (test_opt(sbi, RESERVE_ROOT) && |
| 287 | F2FS_OPTION(sbi).root_reserved_blocks > limit) { |
| 288 | F2FS_OPTION(sbi).root_reserved_blocks = limit; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 289 | f2fs_info(sbi, "Reduce reserved blocks for root = %u", |
| 290 | F2FS_OPTION(sbi).root_reserved_blocks); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 291 | } |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 292 | if (!test_opt(sbi, RESERVE_ROOT) && |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 293 | (!uid_eq(F2FS_OPTION(sbi).s_resuid, |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 294 | make_kuid(&init_user_ns, F2FS_DEF_RESUID)) || |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 295 | !gid_eq(F2FS_OPTION(sbi).s_resgid, |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 296 | make_kgid(&init_user_ns, F2FS_DEF_RESGID)))) |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 297 | f2fs_info(sbi, "Ignore s_resuid=%u, s_resgid=%u w/o reserve_root", |
| 298 | from_kuid_munged(&init_user_ns, |
| 299 | F2FS_OPTION(sbi).s_resuid), |
| 300 | from_kgid_munged(&init_user_ns, |
| 301 | F2FS_OPTION(sbi).s_resgid)); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Jaegeuk Kim | 1ae18f7 | 2020-05-15 17:20:50 -0700 | [diff] [blame] | 304 | static inline void adjust_unusable_cap_perc(struct f2fs_sb_info *sbi) |
| 305 | { |
| 306 | if (!F2FS_OPTION(sbi).unusable_cap_perc) |
| 307 | return; |
| 308 | |
| 309 | if (F2FS_OPTION(sbi).unusable_cap_perc == 100) |
| 310 | F2FS_OPTION(sbi).unusable_cap = sbi->user_block_count; |
| 311 | else |
| 312 | F2FS_OPTION(sbi).unusable_cap = (sbi->user_block_count / 100) * |
| 313 | F2FS_OPTION(sbi).unusable_cap_perc; |
| 314 | |
| 315 | f2fs_info(sbi, "Adjust unusable cap for checkpoint=disable = %u / %u%%", |
| 316 | F2FS_OPTION(sbi).unusable_cap, |
| 317 | F2FS_OPTION(sbi).unusable_cap_perc); |
| 318 | } |
| 319 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 320 | static void init_once(void *foo) |
| 321 | { |
| 322 | struct f2fs_inode_info *fi = (struct f2fs_inode_info *) foo; |
| 323 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 324 | inode_init_once(&fi->vfs_inode); |
| 325 | } |
| 326 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 327 | #ifdef CONFIG_QUOTA |
| 328 | static const char * const quotatypes[] = INITQFNAMES; |
| 329 | #define QTYPE2NAME(t) (quotatypes[t]) |
| 330 | static int f2fs_set_qf_name(struct super_block *sb, int qtype, |
| 331 | substring_t *args) |
| 332 | { |
| 333 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 334 | char *qname; |
| 335 | int ret = -EINVAL; |
| 336 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 337 | if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 338 | f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 339 | return -EINVAL; |
| 340 | } |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 341 | if (f2fs_sb_has_quota_ino(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 342 | f2fs_info(sbi, "QUOTA feature is enabled, so ignore qf_name"); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 346 | qname = match_strdup(args); |
| 347 | if (!qname) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 348 | f2fs_err(sbi, "Not enough memory for storing quotafile name"); |
Chengguang Xu | f365c6c | 2019-01-01 21:33:11 +0800 | [diff] [blame] | 349 | return -ENOMEM; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 350 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 351 | if (F2FS_OPTION(sbi).s_qf_names[qtype]) { |
| 352 | if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0) |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 353 | ret = 0; |
| 354 | else |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 355 | f2fs_err(sbi, "%s quota file already specified", |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 356 | QTYPE2NAME(qtype)); |
| 357 | goto errout; |
| 358 | } |
| 359 | if (strchr(qname, '/')) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 360 | f2fs_err(sbi, "quotafile must be on filesystem root"); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 361 | goto errout; |
| 362 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 363 | F2FS_OPTION(sbi).s_qf_names[qtype] = qname; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 364 | set_opt(sbi, QUOTA); |
| 365 | return 0; |
| 366 | errout: |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 367 | kfree(qname); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | static int f2fs_clear_qf_name(struct super_block *sb, int qtype) |
| 372 | { |
| 373 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 374 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 375 | if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 376 | f2fs_err(sbi, "Cannot change journaled quota options when quota turned on"); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 377 | return -EINVAL; |
| 378 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 379 | kfree(F2FS_OPTION(sbi).s_qf_names[qtype]); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 380 | F2FS_OPTION(sbi).s_qf_names[qtype] = NULL; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | static int f2fs_check_quota_options(struct f2fs_sb_info *sbi) |
| 385 | { |
| 386 | /* |
| 387 | * We do the test below only for project quotas. 'usrquota' and |
| 388 | * 'grpquota' mount options are allowed even without quota feature |
| 389 | * to support legacy quotas in quota files. |
| 390 | */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 391 | if (test_opt(sbi, PRJQUOTA) && !f2fs_sb_has_project_quota(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 392 | f2fs_err(sbi, "Project quota feature not enabled. Cannot enable project quota enforcement."); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 393 | return -1; |
| 394 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 395 | if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || |
| 396 | F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || |
| 397 | F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) { |
| 398 | if (test_opt(sbi, USRQUOTA) && |
| 399 | F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 400 | clear_opt(sbi, USRQUOTA); |
| 401 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 402 | if (test_opt(sbi, GRPQUOTA) && |
| 403 | F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 404 | clear_opt(sbi, GRPQUOTA); |
| 405 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 406 | if (test_opt(sbi, PRJQUOTA) && |
| 407 | F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 408 | clear_opt(sbi, PRJQUOTA); |
| 409 | |
| 410 | if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) || |
| 411 | test_opt(sbi, PRJQUOTA)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 412 | f2fs_err(sbi, "old and new quota format mixing"); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 413 | return -1; |
| 414 | } |
| 415 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 416 | if (!F2FS_OPTION(sbi).s_jquota_fmt) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 417 | f2fs_err(sbi, "journaled quota format not specified"); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 418 | return -1; |
| 419 | } |
| 420 | } |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 421 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 422 | if (f2fs_sb_has_quota_ino(sbi) && F2FS_OPTION(sbi).s_jquota_fmt) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 423 | f2fs_info(sbi, "QUOTA feature is enabled, so ignore jquota_fmt"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 424 | F2FS_OPTION(sbi).s_jquota_fmt = 0; |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 425 | } |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | #endif |
| 429 | |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 430 | static int f2fs_set_test_dummy_encryption(struct super_block *sb, |
| 431 | const char *opt, |
| 432 | const substring_t *arg, |
| 433 | bool is_remount) |
| 434 | { |
| 435 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 436 | #ifdef CONFIG_FS_ENCRYPTION |
| 437 | int err; |
| 438 | |
| 439 | if (!f2fs_sb_has_encrypt(sbi)) { |
| 440 | f2fs_err(sbi, "Encrypt feature is off"); |
| 441 | return -EINVAL; |
| 442 | } |
| 443 | |
| 444 | /* |
| 445 | * This mount option is just for testing, and it's not worthwhile to |
| 446 | * implement the extra complexity (e.g. RCU protection) that would be |
| 447 | * needed to allow it to be set or changed during remount. We do allow |
| 448 | * it to be specified during remount, but only if there is no change. |
| 449 | */ |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 450 | if (is_remount && !F2FS_OPTION(sbi).dummy_enc_policy.policy) { |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 451 | f2fs_warn(sbi, "Can't set test_dummy_encryption on remount"); |
| 452 | return -EINVAL; |
| 453 | } |
| 454 | err = fscrypt_set_test_dummy_encryption( |
Eric Biggers | c8c868a | 2020-09-16 21:11:36 -0700 | [diff] [blame] | 455 | sb, arg->from, &F2FS_OPTION(sbi).dummy_enc_policy); |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 456 | if (err) { |
| 457 | if (err == -EEXIST) |
| 458 | f2fs_warn(sbi, |
| 459 | "Can't change test_dummy_encryption on remount"); |
| 460 | else if (err == -EINVAL) |
| 461 | f2fs_warn(sbi, "Value of option \"%s\" is unrecognized", |
| 462 | opt); |
| 463 | else |
| 464 | f2fs_warn(sbi, "Error processing option \"%s\" [%d]", |
| 465 | opt, err); |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | f2fs_warn(sbi, "Test dummy encryption mode enabled"); |
| 469 | #else |
| 470 | f2fs_warn(sbi, "Test dummy encryption mount option ignored"); |
| 471 | #endif |
| 472 | return 0; |
| 473 | } |
| 474 | |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 475 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
| 476 | #ifdef CONFIG_F2FS_FS_LZ4 |
| 477 | static int f2fs_set_lz4hc_level(struct f2fs_sb_info *sbi, const char *str) |
| 478 | { |
| 479 | #ifdef CONFIG_F2FS_FS_LZ4HC |
| 480 | unsigned int level; |
| 481 | #endif |
| 482 | |
| 483 | if (strlen(str) == 3) { |
| 484 | F2FS_OPTION(sbi).compress_level = 0; |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | #ifdef CONFIG_F2FS_FS_LZ4HC |
| 489 | str += 3; |
| 490 | |
| 491 | if (str[0] != ':') { |
| 492 | f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); |
| 493 | return -EINVAL; |
| 494 | } |
| 495 | if (kstrtouint(str + 1, 10, &level)) |
| 496 | return -EINVAL; |
| 497 | |
| 498 | if (level < LZ4HC_MIN_CLEVEL || level > LZ4HC_MAX_CLEVEL) { |
| 499 | f2fs_info(sbi, "invalid lz4hc compress level: %d", level); |
| 500 | return -EINVAL; |
| 501 | } |
| 502 | |
| 503 | F2FS_OPTION(sbi).compress_level = level; |
| 504 | return 0; |
| 505 | #else |
| 506 | f2fs_info(sbi, "kernel doesn't support lz4hc compression"); |
| 507 | return -EINVAL; |
| 508 | #endif |
| 509 | } |
| 510 | #endif |
| 511 | |
| 512 | #ifdef CONFIG_F2FS_FS_ZSTD |
| 513 | static int f2fs_set_zstd_level(struct f2fs_sb_info *sbi, const char *str) |
| 514 | { |
| 515 | unsigned int level; |
| 516 | int len = 4; |
| 517 | |
| 518 | if (strlen(str) == len) { |
| 519 | F2FS_OPTION(sbi).compress_level = 0; |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | str += len; |
| 524 | |
| 525 | if (str[0] != ':') { |
| 526 | f2fs_info(sbi, "wrong format, e.g. <alg_name>:<compr_level>"); |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | if (kstrtouint(str + 1, 10, &level)) |
| 530 | return -EINVAL; |
| 531 | |
| 532 | if (!level || level > ZSTD_maxCLevel()) { |
| 533 | f2fs_info(sbi, "invalid zstd compress level: %d", level); |
| 534 | return -EINVAL; |
| 535 | } |
| 536 | |
| 537 | F2FS_OPTION(sbi).compress_level = level; |
| 538 | return 0; |
| 539 | } |
| 540 | #endif |
| 541 | #endif |
| 542 | |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 543 | static int parse_options(struct super_block *sb, char *options, bool is_remount) |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 544 | { |
| 545 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 546 | substring_t args[MAX_OPT_ARGS]; |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 547 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 548 | unsigned char (*ext)[F2FS_EXTENSION_LEN]; |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 549 | int ext_cnt; |
| 550 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 551 | char *p, *name; |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 552 | int arg = 0; |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 553 | kuid_t uid; |
| 554 | kgid_t gid; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 555 | int ret; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 556 | |
| 557 | if (!options) |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 558 | goto default_check; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 559 | |
| 560 | while ((p = strsep(&options, ",")) != NULL) { |
| 561 | int token; |
Yi Zhuang | 5f029c0 | 2021-04-06 09:47:35 +0800 | [diff] [blame] | 562 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 563 | if (!*p) |
| 564 | continue; |
| 565 | /* |
| 566 | * Initialize args struct so we know whether arg was |
| 567 | * found; some options take optional arguments. |
| 568 | */ |
| 569 | args[0].to = args[0].from = NULL; |
| 570 | token = match_token(p, f2fs_tokens, args); |
| 571 | |
| 572 | switch (token) { |
| 573 | case Opt_gc_background: |
| 574 | name = match_strdup(&args[0]); |
| 575 | |
| 576 | if (!name) |
| 577 | return -ENOMEM; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 578 | if (!strcmp(name, "on")) { |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 579 | F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 580 | } else if (!strcmp(name, "off")) { |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 581 | F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_OFF; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 582 | } else if (!strcmp(name, "sync")) { |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 583 | F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_SYNC; |
Jaegeuk Kim | 6aefd93 | 2015-10-05 11:02:54 -0700 | [diff] [blame] | 584 | } else { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 585 | kfree(name); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 586 | return -EINVAL; |
| 587 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 588 | kfree(name); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 589 | break; |
| 590 | case Opt_disable_roll_forward: |
| 591 | set_opt(sbi, DISABLE_ROLL_FORWARD); |
| 592 | break; |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 593 | case Opt_norecovery: |
| 594 | /* this option mounts f2fs with ro */ |
Chao Yu | a9117ec | 2020-02-14 17:45:11 +0800 | [diff] [blame] | 595 | set_opt(sbi, NORECOVERY); |
Jaegeuk Kim | 2d834bf | 2015-01-23 18:33:46 -0800 | [diff] [blame] | 596 | if (!f2fs_readonly(sb)) |
| 597 | return -EINVAL; |
| 598 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 599 | case Opt_discard: |
Chao Yu | 7d20c8a | 2018-09-04 03:52:17 +0800 | [diff] [blame] | 600 | set_opt(sbi, DISCARD); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 601 | break; |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 602 | case Opt_nodiscard: |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 603 | if (f2fs_sb_has_blkzoned(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 604 | f2fs_warn(sbi, "discard is required for zoned block devices"); |
Damien Le Moal | 96ba2de | 2016-10-28 17:45:03 +0900 | [diff] [blame] | 605 | return -EINVAL; |
| 606 | } |
Chao Yu | 64058be | 2016-07-03 22:05:14 +0800 | [diff] [blame] | 607 | clear_opt(sbi, DISCARD); |
Damien Le Moal | 487df61 | 2016-10-28 17:44:59 +0900 | [diff] [blame] | 608 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 609 | case Opt_noheap: |
| 610 | set_opt(sbi, NOHEAP); |
| 611 | break; |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 612 | case Opt_heap: |
| 613 | clear_opt(sbi, NOHEAP); |
| 614 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 615 | #ifdef CONFIG_F2FS_FS_XATTR |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 616 | case Opt_user_xattr: |
| 617 | set_opt(sbi, XATTR_USER); |
| 618 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 619 | case Opt_nouser_xattr: |
| 620 | clear_opt(sbi, XATTR_USER); |
| 621 | break; |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 622 | case Opt_inline_xattr: |
| 623 | set_opt(sbi, INLINE_XATTR); |
| 624 | break; |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 625 | case Opt_noinline_xattr: |
| 626 | clear_opt(sbi, INLINE_XATTR); |
| 627 | break; |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 628 | case Opt_inline_xattr_size: |
| 629 | if (args->from && match_int(args, &arg)) |
| 630 | return -EINVAL; |
| 631 | set_opt(sbi, INLINE_XATTR_SIZE); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 632 | F2FS_OPTION(sbi).inline_xattr_size = arg; |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 633 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 634 | #else |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 635 | case Opt_user_xattr: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 636 | f2fs_info(sbi, "user_xattr options not supported"); |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 637 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 638 | case Opt_nouser_xattr: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 639 | f2fs_info(sbi, "nouser_xattr options not supported"); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 640 | break; |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 641 | case Opt_inline_xattr: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 642 | f2fs_info(sbi, "inline_xattr options not supported"); |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 643 | break; |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 644 | case Opt_noinline_xattr: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 645 | f2fs_info(sbi, "noinline_xattr options not supported"); |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 646 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 647 | #endif |
| 648 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 649 | case Opt_acl: |
| 650 | set_opt(sbi, POSIX_ACL); |
| 651 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 652 | case Opt_noacl: |
| 653 | clear_opt(sbi, POSIX_ACL); |
| 654 | break; |
| 655 | #else |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 656 | case Opt_acl: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 657 | f2fs_info(sbi, "acl options not supported"); |
Kelly Anderson | 4058c51 | 2013-10-07 11:36:20 +0900 | [diff] [blame] | 658 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 659 | case Opt_noacl: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 660 | f2fs_info(sbi, "noacl options not supported"); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 661 | break; |
| 662 | #endif |
| 663 | case Opt_active_logs: |
| 664 | if (args->from && match_int(args, &arg)) |
| 665 | return -EINVAL; |
Chao Yu | d0b9e42 | 2020-08-04 21:14:45 +0800 | [diff] [blame] | 666 | if (arg != 2 && arg != 4 && |
| 667 | arg != NR_CURSEG_PERSIST_TYPE) |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 668 | return -EINVAL; |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 669 | F2FS_OPTION(sbi).active_logs = arg; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 670 | break; |
| 671 | case Opt_disable_ext_identify: |
| 672 | set_opt(sbi, DISABLE_EXT_IDENTIFY); |
| 673 | break; |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 674 | case Opt_inline_data: |
| 675 | set_opt(sbi, INLINE_DATA); |
| 676 | break; |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 677 | case Opt_inline_dentry: |
| 678 | set_opt(sbi, INLINE_DENTRY); |
| 679 | break; |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 680 | case Opt_noinline_dentry: |
| 681 | clear_opt(sbi, INLINE_DENTRY); |
| 682 | break; |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 683 | case Opt_flush_merge: |
| 684 | set_opt(sbi, FLUSH_MERGE); |
| 685 | break; |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 686 | case Opt_noflush_merge: |
| 687 | clear_opt(sbi, FLUSH_MERGE); |
| 688 | break; |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 689 | case Opt_nobarrier: |
| 690 | set_opt(sbi, NOBARRIER); |
| 691 | break; |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 692 | case Opt_fastboot: |
| 693 | set_opt(sbi, FASTBOOT); |
| 694 | break; |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 695 | case Opt_extent_cache: |
| 696 | set_opt(sbi, EXTENT_CACHE); |
| 697 | break; |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 698 | case Opt_noextent_cache: |
| 699 | clear_opt(sbi, EXTENT_CACHE); |
| 700 | break; |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 701 | case Opt_noinline_data: |
| 702 | clear_opt(sbi, INLINE_DATA); |
| 703 | break; |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 704 | case Opt_data_flush: |
| 705 | set_opt(sbi, DATA_FLUSH); |
| 706 | break; |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 707 | case Opt_reserve_root: |
| 708 | if (args->from && match_int(args, &arg)) |
| 709 | return -EINVAL; |
| 710 | if (test_opt(sbi, RESERVE_ROOT)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 711 | f2fs_info(sbi, "Preserve previous reserve_root=%u", |
| 712 | F2FS_OPTION(sbi).root_reserved_blocks); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 713 | } else { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 714 | F2FS_OPTION(sbi).root_reserved_blocks = arg; |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 715 | set_opt(sbi, RESERVE_ROOT); |
| 716 | } |
| 717 | break; |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 718 | case Opt_resuid: |
| 719 | if (args->from && match_int(args, &arg)) |
| 720 | return -EINVAL; |
| 721 | uid = make_kuid(current_user_ns(), arg); |
| 722 | if (!uid_valid(uid)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 723 | f2fs_err(sbi, "Invalid uid value %d", arg); |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 724 | return -EINVAL; |
| 725 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 726 | F2FS_OPTION(sbi).s_resuid = uid; |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 727 | break; |
| 728 | case Opt_resgid: |
| 729 | if (args->from && match_int(args, &arg)) |
| 730 | return -EINVAL; |
| 731 | gid = make_kgid(current_user_ns(), arg); |
| 732 | if (!gid_valid(gid)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 733 | f2fs_err(sbi, "Invalid gid value %d", arg); |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 734 | return -EINVAL; |
| 735 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 736 | F2FS_OPTION(sbi).s_resgid = gid; |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 737 | break; |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 738 | case Opt_mode: |
| 739 | name = match_strdup(&args[0]); |
| 740 | |
| 741 | if (!name) |
| 742 | return -ENOMEM; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 743 | if (!strcmp(name, "adaptive")) { |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 744 | if (f2fs_sb_has_blkzoned(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 745 | f2fs_warn(sbi, "adaptive mode is not allowed with zoned block device feature"); |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 746 | kfree(name); |
Damien Le Moal | 3adc57e | 2016-10-28 17:45:04 +0900 | [diff] [blame] | 747 | return -EINVAL; |
| 748 | } |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 749 | F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 750 | } else if (!strcmp(name, "lfs")) { |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 751 | F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 752 | } else { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 753 | kfree(name); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 754 | return -EINVAL; |
| 755 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 756 | kfree(name); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 757 | break; |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 758 | case Opt_io_size_bits: |
| 759 | if (args->from && match_int(args, &arg)) |
| 760 | return -EINVAL; |
Christoph Hellwig | a8affc0 | 2021-03-11 12:01:37 +0100 | [diff] [blame] | 761 | if (arg <= 0 || arg > __ilog2_u32(BIO_MAX_VECS)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 762 | f2fs_warn(sbi, "Not support %d, larger than %d", |
Christoph Hellwig | a8affc0 | 2021-03-11 12:01:37 +0100 | [diff] [blame] | 763 | 1 << arg, BIO_MAX_VECS); |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 764 | return -EINVAL; |
| 765 | } |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 766 | F2FS_OPTION(sbi).write_io_size_bits = arg; |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 767 | break; |
Chengguang Xu | 4cb037e | 2018-09-12 13:32:52 +0800 | [diff] [blame] | 768 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 769 | case Opt_fault_injection: |
| 770 | if (args->from && match_int(args, &arg)) |
| 771 | return -EINVAL; |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 772 | f2fs_build_fault_attr(sbi, arg, F2FS_ALL_FAULT_TYPE); |
| 773 | set_opt(sbi, FAULT_INJECTION); |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 774 | break; |
Chengguang Xu | 4cb037e | 2018-09-12 13:32:52 +0800 | [diff] [blame] | 775 | |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 776 | case Opt_fault_type: |
| 777 | if (args->from && match_int(args, &arg)) |
| 778 | return -EINVAL; |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 779 | f2fs_build_fault_attr(sbi, 0, arg); |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 780 | set_opt(sbi, FAULT_INJECTION); |
Jaegeuk Kim | 73faec4d | 2016-04-29 15:34:32 -0700 | [diff] [blame] | 781 | break; |
Chengguang Xu | 4cb037e | 2018-09-12 13:32:52 +0800 | [diff] [blame] | 782 | #else |
| 783 | case Opt_fault_injection: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 784 | f2fs_info(sbi, "fault_injection options not supported"); |
Chengguang Xu | 4cb037e | 2018-09-12 13:32:52 +0800 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case Opt_fault_type: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 788 | f2fs_info(sbi, "fault_type options not supported"); |
Chengguang Xu | 4cb037e | 2018-09-12 13:32:52 +0800 | [diff] [blame] | 789 | break; |
| 790 | #endif |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 791 | case Opt_lazytime: |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 792 | sb->s_flags |= SB_LAZYTIME; |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 793 | break; |
| 794 | case Opt_nolazytime: |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 795 | sb->s_flags &= ~SB_LAZYTIME; |
Jaegeuk Kim | 6d94c74 | 2016-05-20 21:47:24 -0700 | [diff] [blame] | 796 | break; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 797 | #ifdef CONFIG_QUOTA |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 798 | case Opt_quota: |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 799 | case Opt_usrquota: |
| 800 | set_opt(sbi, USRQUOTA); |
| 801 | break; |
| 802 | case Opt_grpquota: |
| 803 | set_opt(sbi, GRPQUOTA); |
| 804 | break; |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 805 | case Opt_prjquota: |
| 806 | set_opt(sbi, PRJQUOTA); |
| 807 | break; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 808 | case Opt_usrjquota: |
| 809 | ret = f2fs_set_qf_name(sb, USRQUOTA, &args[0]); |
| 810 | if (ret) |
| 811 | return ret; |
| 812 | break; |
| 813 | case Opt_grpjquota: |
| 814 | ret = f2fs_set_qf_name(sb, GRPQUOTA, &args[0]); |
| 815 | if (ret) |
| 816 | return ret; |
| 817 | break; |
| 818 | case Opt_prjjquota: |
| 819 | ret = f2fs_set_qf_name(sb, PRJQUOTA, &args[0]); |
| 820 | if (ret) |
| 821 | return ret; |
| 822 | break; |
| 823 | case Opt_offusrjquota: |
| 824 | ret = f2fs_clear_qf_name(sb, USRQUOTA); |
| 825 | if (ret) |
| 826 | return ret; |
| 827 | break; |
| 828 | case Opt_offgrpjquota: |
| 829 | ret = f2fs_clear_qf_name(sb, GRPQUOTA); |
| 830 | if (ret) |
| 831 | return ret; |
| 832 | break; |
| 833 | case Opt_offprjjquota: |
| 834 | ret = f2fs_clear_qf_name(sb, PRJQUOTA); |
| 835 | if (ret) |
| 836 | return ret; |
| 837 | break; |
| 838 | case Opt_jqfmt_vfsold: |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 839 | F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 840 | break; |
| 841 | case Opt_jqfmt_vfsv0: |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 842 | F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 843 | break; |
| 844 | case Opt_jqfmt_vfsv1: |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 845 | F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 846 | break; |
| 847 | case Opt_noquota: |
| 848 | clear_opt(sbi, QUOTA); |
| 849 | clear_opt(sbi, USRQUOTA); |
| 850 | clear_opt(sbi, GRPQUOTA); |
| 851 | clear_opt(sbi, PRJQUOTA); |
| 852 | break; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 853 | #else |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 854 | case Opt_quota: |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 855 | case Opt_usrquota: |
| 856 | case Opt_grpquota: |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 857 | case Opt_prjquota: |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 858 | case Opt_usrjquota: |
| 859 | case Opt_grpjquota: |
| 860 | case Opt_prjjquota: |
| 861 | case Opt_offusrjquota: |
| 862 | case Opt_offgrpjquota: |
| 863 | case Opt_offprjjquota: |
| 864 | case Opt_jqfmt_vfsold: |
| 865 | case Opt_jqfmt_vfsv0: |
| 866 | case Opt_jqfmt_vfsv1: |
| 867 | case Opt_noquota: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 868 | f2fs_info(sbi, "quota operations not supported"); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 869 | break; |
| 870 | #endif |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 871 | case Opt_whint: |
| 872 | name = match_strdup(&args[0]); |
| 873 | if (!name) |
| 874 | return -ENOMEM; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 875 | if (!strcmp(name, "user-based")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 876 | F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 877 | } else if (!strcmp(name, "off")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 878 | F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 879 | } else if (!strcmp(name, "fs-based")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 880 | F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS; |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 881 | } else { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 882 | kfree(name); |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 883 | return -EINVAL; |
| 884 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 885 | kfree(name); |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 886 | break; |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 887 | case Opt_alloc: |
| 888 | name = match_strdup(&args[0]); |
| 889 | if (!name) |
| 890 | return -ENOMEM; |
| 891 | |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 892 | if (!strcmp(name, "default")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 893 | F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 894 | } else if (!strcmp(name, "reuse")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 895 | F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 896 | } else { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 897 | kfree(name); |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 898 | return -EINVAL; |
| 899 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 900 | kfree(name); |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 901 | break; |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 902 | case Opt_fsync: |
| 903 | name = match_strdup(&args[0]); |
| 904 | if (!name) |
| 905 | return -ENOMEM; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 906 | if (!strcmp(name, "posix")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 907 | F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 908 | } else if (!strcmp(name, "strict")) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 909 | F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 910 | } else if (!strcmp(name, "nobarrier")) { |
Jaegeuk Kim | d629081 | 2018-05-25 18:02:58 -0700 | [diff] [blame] | 911 | F2FS_OPTION(sbi).fsync_mode = |
| 912 | FSYNC_MODE_NOBARRIER; |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 913 | } else { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 914 | kfree(name); |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 915 | return -EINVAL; |
| 916 | } |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 917 | kfree(name); |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 918 | break; |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 919 | case Opt_test_dummy_encryption: |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 920 | ret = f2fs_set_test_dummy_encryption(sb, p, &args[0], |
| 921 | is_remount); |
| 922 | if (ret) |
| 923 | return ret; |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 924 | break; |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 925 | case Opt_inlinecrypt: |
| 926 | #ifdef CONFIG_FS_ENCRYPTION_INLINE_CRYPT |
| 927 | sb->s_flags |= SB_INLINECRYPT; |
| 928 | #else |
| 929 | f2fs_info(sbi, "inline encryption not supported"); |
| 930 | #endif |
| 931 | break; |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 932 | case Opt_checkpoint_disable_cap_perc: |
| 933 | if (args->from && match_int(args, &arg)) |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 934 | return -EINVAL; |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 935 | if (arg < 0 || arg > 100) |
| 936 | return -EINVAL; |
Jaegeuk Kim | 1ae18f7 | 2020-05-15 17:20:50 -0700 | [diff] [blame] | 937 | F2FS_OPTION(sbi).unusable_cap_perc = arg; |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 938 | set_opt(sbi, DISABLE_CHECKPOINT); |
| 939 | break; |
| 940 | case Opt_checkpoint_disable_cap: |
| 941 | if (args->from && match_int(args, &arg)) |
| 942 | return -EINVAL; |
| 943 | F2FS_OPTION(sbi).unusable_cap = arg; |
| 944 | set_opt(sbi, DISABLE_CHECKPOINT); |
| 945 | break; |
| 946 | case Opt_checkpoint_disable: |
| 947 | set_opt(sbi, DISABLE_CHECKPOINT); |
| 948 | break; |
| 949 | case Opt_checkpoint_enable: |
| 950 | clear_opt(sbi, DISABLE_CHECKPOINT); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 951 | break; |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 952 | case Opt_checkpoint_merge: |
| 953 | set_opt(sbi, MERGE_CHECKPOINT); |
| 954 | break; |
| 955 | case Opt_nocheckpoint_merge: |
| 956 | clear_opt(sbi, MERGE_CHECKPOINT); |
| 957 | break; |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 958 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 959 | case Opt_compress_algorithm: |
| 960 | if (!f2fs_sb_has_compression(sbi)) { |
Chao Yu | 69c0dd2 | 2020-09-03 10:14:41 +0800 | [diff] [blame] | 961 | f2fs_info(sbi, "Image doesn't support compression"); |
| 962 | break; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 963 | } |
| 964 | name = match_strdup(&args[0]); |
| 965 | if (!name) |
| 966 | return -ENOMEM; |
Eric Biggers | 3c57f75 | 2020-05-01 16:35:23 -0700 | [diff] [blame] | 967 | if (!strcmp(name, "lzo")) { |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 968 | #ifdef CONFIG_F2FS_FS_LZO |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 969 | F2FS_OPTION(sbi).compress_level = 0; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 970 | F2FS_OPTION(sbi).compress_algorithm = |
| 971 | COMPRESS_LZO; |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 972 | #else |
| 973 | f2fs_info(sbi, "kernel doesn't support lzo compression"); |
| 974 | #endif |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 975 | } else if (!strncmp(name, "lz4", 3)) { |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 976 | #ifdef CONFIG_F2FS_FS_LZ4 |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 977 | ret = f2fs_set_lz4hc_level(sbi, name); |
| 978 | if (ret) { |
| 979 | kfree(name); |
| 980 | return -EINVAL; |
| 981 | } |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 982 | F2FS_OPTION(sbi).compress_algorithm = |
| 983 | COMPRESS_LZ4; |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 984 | #else |
| 985 | f2fs_info(sbi, "kernel doesn't support lz4 compression"); |
| 986 | #endif |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 987 | } else if (!strncmp(name, "zstd", 4)) { |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 988 | #ifdef CONFIG_F2FS_FS_ZSTD |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 989 | ret = f2fs_set_zstd_level(sbi, name); |
| 990 | if (ret) { |
| 991 | kfree(name); |
| 992 | return -EINVAL; |
| 993 | } |
Chao Yu | 50cfa66 | 2020-03-03 17:46:02 +0800 | [diff] [blame] | 994 | F2FS_OPTION(sbi).compress_algorithm = |
| 995 | COMPRESS_ZSTD; |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 996 | #else |
| 997 | f2fs_info(sbi, "kernel doesn't support zstd compression"); |
| 998 | #endif |
Chao Yu | 6d92b20 | 2020-04-08 19:56:32 +0800 | [diff] [blame] | 999 | } else if (!strcmp(name, "lzo-rle")) { |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 1000 | #ifdef CONFIG_F2FS_FS_LZORLE |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 1001 | F2FS_OPTION(sbi).compress_level = 0; |
Chao Yu | 6d92b20 | 2020-04-08 19:56:32 +0800 | [diff] [blame] | 1002 | F2FS_OPTION(sbi).compress_algorithm = |
| 1003 | COMPRESS_LZORLE; |
Chao Yu | 32be0e9 | 2021-01-22 17:40:13 +0800 | [diff] [blame] | 1004 | #else |
| 1005 | f2fs_info(sbi, "kernel doesn't support lzorle compression"); |
| 1006 | #endif |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1007 | } else { |
| 1008 | kfree(name); |
| 1009 | return -EINVAL; |
| 1010 | } |
| 1011 | kfree(name); |
| 1012 | break; |
| 1013 | case Opt_compress_log_size: |
| 1014 | if (!f2fs_sb_has_compression(sbi)) { |
Chao Yu | 69c0dd2 | 2020-09-03 10:14:41 +0800 | [diff] [blame] | 1015 | f2fs_info(sbi, "Image doesn't support compression"); |
| 1016 | break; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1017 | } |
| 1018 | if (args->from && match_int(args, &arg)) |
| 1019 | return -EINVAL; |
| 1020 | if (arg < MIN_COMPRESS_LOG_SIZE || |
| 1021 | arg > MAX_COMPRESS_LOG_SIZE) { |
| 1022 | f2fs_err(sbi, |
| 1023 | "Compress cluster log size is out of range"); |
| 1024 | return -EINVAL; |
| 1025 | } |
| 1026 | F2FS_OPTION(sbi).compress_log_size = arg; |
| 1027 | break; |
| 1028 | case Opt_compress_extension: |
| 1029 | if (!f2fs_sb_has_compression(sbi)) { |
Chao Yu | 69c0dd2 | 2020-09-03 10:14:41 +0800 | [diff] [blame] | 1030 | f2fs_info(sbi, "Image doesn't support compression"); |
| 1031 | break; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1032 | } |
| 1033 | name = match_strdup(&args[0]); |
| 1034 | if (!name) |
| 1035 | return -ENOMEM; |
| 1036 | |
| 1037 | ext = F2FS_OPTION(sbi).extensions; |
| 1038 | ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt; |
| 1039 | |
| 1040 | if (strlen(name) >= F2FS_EXTENSION_LEN || |
| 1041 | ext_cnt >= COMPRESS_EXT_NUM) { |
| 1042 | f2fs_err(sbi, |
| 1043 | "invalid extension length/number"); |
| 1044 | kfree(name); |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | strcpy(ext[ext_cnt], name); |
| 1049 | F2FS_OPTION(sbi).compress_ext_cnt++; |
| 1050 | kfree(name); |
| 1051 | break; |
Chao Yu | b28f047 | 2020-11-26 18:32:09 +0800 | [diff] [blame] | 1052 | case Opt_compress_chksum: |
| 1053 | F2FS_OPTION(sbi).compress_chksum = true; |
| 1054 | break; |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 1055 | case Opt_compress_mode: |
| 1056 | name = match_strdup(&args[0]); |
| 1057 | if (!name) |
| 1058 | return -ENOMEM; |
| 1059 | if (!strcmp(name, "fs")) { |
| 1060 | F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; |
| 1061 | } else if (!strcmp(name, "user")) { |
| 1062 | F2FS_OPTION(sbi).compress_mode = COMPR_MODE_USER; |
| 1063 | } else { |
| 1064 | kfree(name); |
| 1065 | return -EINVAL; |
| 1066 | } |
| 1067 | kfree(name); |
| 1068 | break; |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 1069 | #else |
| 1070 | case Opt_compress_algorithm: |
| 1071 | case Opt_compress_log_size: |
| 1072 | case Opt_compress_extension: |
Chao Yu | b28f047 | 2020-11-26 18:32:09 +0800 | [diff] [blame] | 1073 | case Opt_compress_chksum: |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 1074 | case Opt_compress_mode: |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 1075 | f2fs_info(sbi, "compression options not supported"); |
| 1076 | break; |
| 1077 | #endif |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 1078 | case Opt_atgc: |
| 1079 | set_opt(sbi, ATGC); |
| 1080 | break; |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 1081 | case Opt_gc_merge: |
| 1082 | set_opt(sbi, GC_MERGE); |
| 1083 | break; |
| 1084 | case Opt_nogc_merge: |
| 1085 | clear_opt(sbi, GC_MERGE); |
| 1086 | break; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1087 | default: |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1088 | f2fs_err(sbi, "Unrecognized mount option \"%s\" or missing value", |
| 1089 | p); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1090 | return -EINVAL; |
| 1091 | } |
| 1092 | } |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 1093 | default_check: |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1094 | #ifdef CONFIG_QUOTA |
| 1095 | if (f2fs_check_quota_options(sbi)) |
| 1096 | return -EINVAL; |
Sheng Yong | 00960c2cd | 2018-07-24 20:17:52 +0800 | [diff] [blame] | 1097 | #else |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 1098 | if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sbi->sb)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1099 | f2fs_info(sbi, "Filesystem with quota feature cannot be mounted RDWR without CONFIG_QUOTA"); |
Sheng Yong | 00960c2cd | 2018-07-24 20:17:52 +0800 | [diff] [blame] | 1100 | return -EINVAL; |
| 1101 | } |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 1102 | if (f2fs_sb_has_project_quota(sbi) && !f2fs_readonly(sbi->sb)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1103 | f2fs_err(sbi, "Filesystem with project quota feature cannot be mounted RDWR without CONFIG_QUOTA"); |
Chao Yu | 4ddc1b2 | 2018-07-26 07:19:48 +0800 | [diff] [blame] | 1104 | return -EINVAL; |
| 1105 | } |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1106 | #endif |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 1107 | #ifndef CONFIG_UNICODE |
| 1108 | if (f2fs_sb_has_casefold(sbi)) { |
| 1109 | f2fs_err(sbi, |
| 1110 | "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); |
| 1111 | return -EINVAL; |
| 1112 | } |
| 1113 | #endif |
Chao Yu | d066012 | 2020-09-21 20:53:14 +0800 | [diff] [blame] | 1114 | /* |
| 1115 | * The BLKZONED feature indicates that the drive was formatted with |
| 1116 | * zone alignment optimization. This is optional for host-aware |
| 1117 | * devices, but mandatory for host-managed zoned block devices. |
| 1118 | */ |
| 1119 | #ifndef CONFIG_BLK_DEV_ZONED |
| 1120 | if (f2fs_sb_has_blkzoned(sbi)) { |
| 1121 | f2fs_err(sbi, "Zoned block device support is not enabled"); |
| 1122 | return -EINVAL; |
| 1123 | } |
| 1124 | #endif |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 1125 | |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1126 | if (F2FS_IO_SIZE_BITS(sbi) && !f2fs_lfs_mode(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1127 | f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", |
| 1128 | F2FS_IO_SIZE_KB(sbi)); |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 1129 | return -EINVAL; |
| 1130 | } |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 1131 | |
| 1132 | if (test_opt(sbi, INLINE_XATTR_SIZE)) { |
Jaegeuk Kim | 70db5b0 | 2019-03-12 11:49:53 -0700 | [diff] [blame] | 1133 | int min_size, max_size; |
| 1134 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 1135 | if (!f2fs_sb_has_extra_attr(sbi) || |
| 1136 | !f2fs_sb_has_flexible_inline_xattr(sbi)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1137 | f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); |
Chao Yu | 4d817ae | 2018-01-27 17:29:48 +0800 | [diff] [blame] | 1138 | return -EINVAL; |
| 1139 | } |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 1140 | if (!test_opt(sbi, INLINE_XATTR)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1141 | f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 1142 | return -EINVAL; |
| 1143 | } |
Jaegeuk Kim | 70db5b0 | 2019-03-12 11:49:53 -0700 | [diff] [blame] | 1144 | |
| 1145 | min_size = sizeof(struct f2fs_xattr_header) / sizeof(__le32); |
Chao Yu | dd6c89b | 2019-03-04 17:19:04 +0800 | [diff] [blame] | 1146 | max_size = MAX_INLINE_XATTR_SIZE; |
Jaegeuk Kim | 70db5b0 | 2019-03-12 11:49:53 -0700 | [diff] [blame] | 1147 | |
| 1148 | if (F2FS_OPTION(sbi).inline_xattr_size < min_size || |
| 1149 | F2FS_OPTION(sbi).inline_xattr_size > max_size) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1150 | f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", |
| 1151 | min_size, max_size); |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 1152 | return -EINVAL; |
| 1153 | } |
| 1154 | } |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1155 | |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1156 | if (test_opt(sbi, DISABLE_CHECKPOINT) && f2fs_lfs_mode(sbi)) { |
Joe Perches | 833dcd3 | 2021-05-26 13:05:36 -0700 | [diff] [blame] | 1157 | f2fs_err(sbi, "LFS not compatible with checkpoint=disable"); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1158 | return -EINVAL; |
| 1159 | } |
| 1160 | |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1161 | /* Not pass down write hints if the number of active logs is lesser |
Chao Yu | d0b9e42 | 2020-08-04 21:14:45 +0800 | [diff] [blame] | 1162 | * than NR_CURSEG_PERSIST_TYPE. |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1163 | */ |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1164 | if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE) |
| 1165 | F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 1166 | |
| 1167 | if (f2fs_sb_has_readonly(sbi) && !f2fs_readonly(sbi->sb)) { |
| 1168 | f2fs_err(sbi, "Allow to mount readonly mode only"); |
| 1169 | return -EROFS; |
| 1170 | } |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1171 | return 0; |
| 1172 | } |
| 1173 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1174 | static struct inode *f2fs_alloc_inode(struct super_block *sb) |
| 1175 | { |
| 1176 | struct f2fs_inode_info *fi; |
| 1177 | |
Chao Yu | a0acdfe | 2013-12-05 09:54:00 +0800 | [diff] [blame] | 1178 | fi = kmem_cache_alloc(f2fs_inode_cachep, GFP_F2FS_ZERO); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1179 | if (!fi) |
| 1180 | return NULL; |
| 1181 | |
| 1182 | init_once((void *) fi); |
| 1183 | |
Masanari Iida | 434720f | 2013-03-19 08:03:35 +0900 | [diff] [blame] | 1184 | /* Initialize f2fs-specific inode info */ |
Jaegeuk Kim | 204706c | 2016-12-02 15:11:32 -0800 | [diff] [blame] | 1185 | atomic_set(&fi->dirty_pages, 0); |
Daeho Jeong | c2759eb | 2020-09-08 11:44:10 +0900 | [diff] [blame] | 1186 | atomic_set(&fi->i_compr_blocks, 0); |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 1187 | init_rwsem(&fi->i_sem); |
Chao Yu | c10c982 | 2020-02-27 19:30:03 +0800 | [diff] [blame] | 1188 | spin_lock_init(&fi->i_size_lock); |
Chao Yu | 2710fd7 | 2015-12-15 13:30:45 +0800 | [diff] [blame] | 1189 | INIT_LIST_HEAD(&fi->dirty_list); |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 1190 | INIT_LIST_HEAD(&fi->gdirty_list); |
Jaegeuk Kim | 57864ae | 2017-10-18 19:05:57 -0700 | [diff] [blame] | 1191 | INIT_LIST_HEAD(&fi->inmem_ilist); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1192 | INIT_LIST_HEAD(&fi->inmem_pages); |
| 1193 | mutex_init(&fi->inmem_lock); |
Chao Yu | b2532c6 | 2018-04-24 10:55:28 +0800 | [diff] [blame] | 1194 | init_rwsem(&fi->i_gc_rwsem[READ]); |
| 1195 | init_rwsem(&fi->i_gc_rwsem[WRITE]); |
Qiuyang Sun | 5a3a2d8 | 2017-05-18 11:06:45 +0800 | [diff] [blame] | 1196 | init_rwsem(&fi->i_mmap_sem); |
Yunlei He | 27161f1 | 2017-09-07 10:40:54 +0800 | [diff] [blame] | 1197 | init_rwsem(&fi->i_xattr_sem); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1198 | |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 1199 | /* Will be used by directory only */ |
| 1200 | fi->i_dir_level = F2FS_SB(sb)->dir_level; |
Chao Yu | f247037 | 2017-07-19 00:19:05 +0800 | [diff] [blame] | 1201 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1202 | return &fi->vfs_inode; |
| 1203 | } |
| 1204 | |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 1205 | static int f2fs_drop_inode(struct inode *inode) |
| 1206 | { |
Chao Yu | a8933b6 | 2019-07-18 16:39:59 +0800 | [diff] [blame] | 1207 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 1208 | int ret; |
Chao Yu | a8933b6 | 2019-07-18 16:39:59 +0800 | [diff] [blame] | 1209 | |
| 1210 | /* |
| 1211 | * during filesystem shutdown, if checkpoint is disabled, |
| 1212 | * drop useless meta/node dirty pages. |
| 1213 | */ |
| 1214 | if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { |
| 1215 | if (inode->i_ino == F2FS_NODE_INO(sbi) || |
| 1216 | inode->i_ino == F2FS_META_INO(sbi)) { |
| 1217 | trace_f2fs_drop_inode(inode, 1); |
| 1218 | return 1; |
| 1219 | } |
| 1220 | } |
| 1221 | |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 1222 | /* |
| 1223 | * This is to avoid a deadlock condition like below. |
| 1224 | * writeback_single_inode(inode) |
| 1225 | * - f2fs_write_data_page |
| 1226 | * - f2fs_gc -> iput -> evict |
| 1227 | * - inode_wait_for_writeback(inode) |
| 1228 | */ |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 1229 | if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) { |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1230 | if (!inode->i_nlink && !is_bad_inode(inode)) { |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 1231 | /* to avoid evict_inode call simultaneously */ |
| 1232 | atomic_inc(&inode->i_count); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1233 | spin_unlock(&inode->i_lock); |
| 1234 | |
| 1235 | /* some remained atomic pages should discarded */ |
| 1236 | if (f2fs_is_atomic_file(inode)) |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 1237 | f2fs_drop_inmem_pages(inode); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1238 | |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 1239 | /* should remain fi->extent_tree for writepage */ |
| 1240 | f2fs_destroy_extent_node(inode); |
| 1241 | |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1242 | sb_start_intwrite(inode->i_sb); |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 1243 | f2fs_i_size_write(inode, 0); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1244 | |
zhengliang | a0770e1 | 2019-03-04 09:32:25 +0800 | [diff] [blame] | 1245 | f2fs_submit_merged_write_cond(F2FS_I_SB(inode), |
| 1246 | inode, NULL, 0, DATA); |
| 1247 | truncate_inode_pages_final(inode->i_mapping); |
| 1248 | |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1249 | if (F2FS_HAS_BLOCKS(inode)) |
Jaegeuk Kim | 9a449e9 | 2016-06-02 13:49:38 -0700 | [diff] [blame] | 1250 | f2fs_truncate(inode); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1251 | |
| 1252 | sb_end_intwrite(inode->i_sb); |
| 1253 | |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1254 | spin_lock(&inode->i_lock); |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 1255 | atomic_dec(&inode->i_count); |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1256 | } |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 1257 | trace_f2fs_drop_inode(inode, 0); |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 1258 | return 0; |
Jaegeuk Kim | 06e1bc0 | 2015-05-13 14:35:14 -0700 | [diff] [blame] | 1259 | } |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 1260 | ret = generic_drop_inode(inode); |
Eric Biggers | 8ce589c | 2019-08-04 19:35:48 -0700 | [diff] [blame] | 1261 | if (!ret) |
| 1262 | ret = fscrypt_drop_inode(inode); |
Hou Pengyang | b8d96a3 | 2017-02-27 13:02:58 +0000 | [diff] [blame] | 1263 | trace_f2fs_drop_inode(inode, ret); |
| 1264 | return ret; |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 1265 | } |
| 1266 | |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1267 | int f2fs_inode_dirtied(struct inode *inode, bool sync) |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1268 | { |
| 1269 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1270 | int ret = 0; |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1271 | |
| 1272 | spin_lock(&sbi->inode_lock[DIRTY_META]); |
| 1273 | if (is_inode_flag_set(inode, FI_DIRTY_INODE)) { |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1274 | ret = 1; |
| 1275 | } else { |
| 1276 | set_inode_flag(inode, FI_DIRTY_INODE); |
| 1277 | stat_inc_dirty_inode(sbi, DIRTY_META); |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1278 | } |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1279 | if (sync && list_empty(&F2FS_I(inode)->gdirty_list)) { |
| 1280 | list_add_tail(&F2FS_I(inode)->gdirty_list, |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1281 | &sbi->inode_list[DIRTY_META]); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1282 | inc_page_count(sbi, F2FS_DIRTY_IMETA); |
| 1283 | } |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1284 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1285 | return ret; |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | void f2fs_inode_synced(struct inode *inode) |
| 1289 | { |
| 1290 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 1291 | |
| 1292 | spin_lock(&sbi->inode_lock[DIRTY_META]); |
| 1293 | if (!is_inode_flag_set(inode, FI_DIRTY_INODE)) { |
| 1294 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
| 1295 | return; |
| 1296 | } |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1297 | if (!list_empty(&F2FS_I(inode)->gdirty_list)) { |
| 1298 | list_del_init(&F2FS_I(inode)->gdirty_list); |
| 1299 | dec_page_count(sbi, F2FS_DIRTY_IMETA); |
| 1300 | } |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1301 | clear_inode_flag(inode, FI_DIRTY_INODE); |
| 1302 | clear_inode_flag(inode, FI_AUTO_RECOVER); |
Jaegeuk Kim | b56ab83 | 2016-06-30 19:09:37 -0700 | [diff] [blame] | 1303 | stat_dec_dirty_inode(F2FS_I_SB(inode), DIRTY_META); |
| 1304 | spin_unlock(&sbi->inode_lock[DIRTY_META]); |
| 1305 | } |
| 1306 | |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 1307 | /* |
| 1308 | * f2fs_dirty_inode() is called from __mark_inode_dirty() |
| 1309 | * |
| 1310 | * We should call set_dirty_inode to write the dirty inode through write_inode. |
| 1311 | */ |
| 1312 | static void f2fs_dirty_inode(struct inode *inode, int flags) |
| 1313 | { |
Jaegeuk Kim | 0f18b46 | 2016-05-20 11:10:10 -0700 | [diff] [blame] | 1314 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 1315 | |
| 1316 | if (inode->i_ino == F2FS_NODE_INO(sbi) || |
| 1317 | inode->i_ino == F2FS_META_INO(sbi)) |
| 1318 | return; |
| 1319 | |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 1320 | if (is_inode_flag_set(inode, FI_AUTO_RECOVER)) |
| 1321 | clear_inode_flag(inode, FI_AUTO_RECOVER); |
| 1322 | |
Jaegeuk Kim | 7c45729 | 2016-10-14 11:51:23 -0700 | [diff] [blame] | 1323 | f2fs_inode_dirtied(inode, false); |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 1324 | } |
| 1325 | |
Al Viro | d01718a | 2019-04-15 19:29:14 -0400 | [diff] [blame] | 1326 | static void f2fs_free_inode(struct inode *inode) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1327 | { |
Eric Biggers | 2c58d54 | 2019-04-10 13:21:15 -0700 | [diff] [blame] | 1328 | fscrypt_free_inode(inode); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1329 | kmem_cache_free(f2fs_inode_cachep, F2FS_I(inode)); |
| 1330 | } |
| 1331 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1332 | static void destroy_percpu_info(struct f2fs_sb_info *sbi) |
| 1333 | { |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 1334 | percpu_counter_destroy(&sbi->alloc_valid_block_count); |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 1335 | percpu_counter_destroy(&sbi->total_valid_inode_count); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1338 | static void destroy_device_list(struct f2fs_sb_info *sbi) |
| 1339 | { |
| 1340 | int i; |
| 1341 | |
| 1342 | for (i = 0; i < sbi->s_ndevs; i++) { |
| 1343 | blkdev_put(FDEV(i).bdev, FMODE_EXCL); |
| 1344 | #ifdef CONFIG_BLK_DEV_ZONED |
Damien Le Moal | 95175da | 2019-03-16 09:13:07 +0900 | [diff] [blame] | 1345 | kvfree(FDEV(i).blkz_seq); |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 1346 | kfree(FDEV(i).zone_capacity_blocks); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1347 | #endif |
| 1348 | } |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 1349 | kvfree(sbi->devs); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1352 | static void f2fs_put_super(struct super_block *sb) |
| 1353 | { |
| 1354 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 1355 | int i; |
Chao Yu | cf5c759 | 2017-10-04 09:08:37 +0800 | [diff] [blame] | 1356 | bool dropped; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1357 | |
Li Guifu | 99c787c | 2020-07-24 09:38:11 +0800 | [diff] [blame] | 1358 | /* unregister procfs/sysfs entries in advance to avoid race case */ |
| 1359 | f2fs_unregister_sysfs(sbi); |
| 1360 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1361 | f2fs_quota_off_umount(sb); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1362 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1363 | /* prevent remaining shrinker jobs */ |
| 1364 | mutex_lock(&sbi->umount_mutex); |
| 1365 | |
Jaegeuk Kim | 85dc2f2 | 2015-01-14 17:41:41 -0800 | [diff] [blame] | 1366 | /* |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 1367 | * flush all issued checkpoints and stop checkpoint issue thread. |
| 1368 | * after then, all checkpoints should be done by each process context. |
| 1369 | */ |
| 1370 | f2fs_stop_ckpt_thread(sbi); |
| 1371 | |
| 1372 | /* |
Jaegeuk Kim | 85dc2f2 | 2015-01-14 17:41:41 -0800 | [diff] [blame] | 1373 | * We don't need to do checkpoint when superblock is clean. |
| 1374 | * But, the previous checkpoint was not done by umount, it needs to do |
| 1375 | * clean checkpoint again. |
| 1376 | */ |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1377 | if ((is_sbi_flag_set(sbi, SBI_IS_DIRTY) || |
| 1378 | !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG))) { |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 1379 | struct cp_control cpc = { |
| 1380 | .reason = CP_UMOUNT, |
| 1381 | }; |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 1382 | f2fs_write_checkpoint(sbi, &cpc); |
Jaegeuk Kim | 75ab4cb | 2014-09-20 21:57:51 -0700 | [diff] [blame] | 1383 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1384 | |
Jaegeuk Kim | 4e6a8d9 | 2016-12-29 14:07:53 -0800 | [diff] [blame] | 1385 | /* be sure to wait for any on-going discard commands */ |
Jaegeuk Kim | 03f2c02 | 2019-01-14 10:42:11 -0800 | [diff] [blame] | 1386 | dropped = f2fs_issue_discard_timeout(sbi); |
Jaegeuk Kim | 4e6a8d9 | 2016-12-29 14:07:53 -0800 | [diff] [blame] | 1387 | |
Chao Yu | 7d20c8a | 2018-09-04 03:52:17 +0800 | [diff] [blame] | 1388 | if ((f2fs_hw_support_discard(sbi) || f2fs_hw_should_discard(sbi)) && |
| 1389 | !sbi->discard_blks && !dropped) { |
Chao Yu | 1f43e2a | 2017-04-28 13:56:08 +0800 | [diff] [blame] | 1390 | struct cp_control cpc = { |
| 1391 | .reason = CP_UMOUNT | CP_TRIMMED, |
| 1392 | }; |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 1393 | f2fs_write_checkpoint(sbi, &cpc); |
Chao Yu | 1f43e2a | 2017-04-28 13:56:08 +0800 | [diff] [blame] | 1394 | } |
| 1395 | |
Jaegeuk Kim | cf779ca | 2014-08-11 18:37:46 -0700 | [diff] [blame] | 1396 | /* |
| 1397 | * normally superblock is clean, so we need to release this. |
| 1398 | * In addition, EIO will skip do checkpoint, we need this as well. |
| 1399 | */ |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 1400 | f2fs_release_ino_entry(sbi, true); |
Jaegeuk Kim | 6f12ac2 | 2014-08-19 09:48:22 -0700 | [diff] [blame] | 1401 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 1402 | f2fs_leave_shrinker(sbi); |
| 1403 | mutex_unlock(&sbi->umount_mutex); |
| 1404 | |
Jaegeuk Kim | 17c1912 | 2016-01-29 08:57:59 -0800 | [diff] [blame] | 1405 | /* our cp_error case, we can wait for any writeback page */ |
Jaegeuk Kim | b9109b0 | 2017-05-10 11:28:38 -0700 | [diff] [blame] | 1406 | f2fs_flush_merged_writes(sbi); |
Jaegeuk Kim | 17c1912 | 2016-01-29 08:57:59 -0800 | [diff] [blame] | 1407 | |
Sahitya Tummala | bf22c3c | 2020-02-18 09:19:07 +0530 | [diff] [blame] | 1408 | f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); |
Chao Yu | 50fa53e | 2018-08-02 23:03:19 +0800 | [diff] [blame] | 1409 | |
| 1410 | f2fs_bug_on(sbi, sbi->fsync_node_num); |
| 1411 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1412 | iput(sbi->node_inode); |
Jaegeuk Kim | 7c77bf7 | 2019-01-01 00:11:30 -0800 | [diff] [blame] | 1413 | sbi->node_inode = NULL; |
| 1414 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1415 | iput(sbi->meta_inode); |
Jaegeuk Kim | 7c77bf7 | 2019-01-01 00:11:30 -0800 | [diff] [blame] | 1416 | sbi->meta_inode = NULL; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1417 | |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 1418 | /* |
| 1419 | * iput() can update stat information, if f2fs_write_checkpoint() |
| 1420 | * above failed with error. |
| 1421 | */ |
| 1422 | f2fs_destroy_stats(sbi); |
| 1423 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1424 | /* destroy f2fs internal modules */ |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 1425 | f2fs_destroy_node_manager(sbi); |
| 1426 | f2fs_destroy_segment_manager(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1427 | |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1428 | f2fs_destroy_post_read_wq(sbi); |
| 1429 | |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 1430 | kvfree(sbi->ckpt); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 1431 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1432 | sb->s_fs_info = NULL; |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 1433 | if (sbi->s_chksum_driver) |
| 1434 | crypto_free_shash(sbi->s_chksum_driver); |
Denis Efremov | 742532d | 2020-06-10 01:14:46 +0300 | [diff] [blame] | 1435 | kfree(sbi->raw_super); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1436 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 1437 | destroy_device_list(sbi); |
Chao Yu | 3108303 | 2020-09-14 17:05:13 +0800 | [diff] [blame] | 1438 | f2fs_destroy_page_array_cache(sbi); |
Chao Yu | a999150 | 2020-02-25 18:17:10 +0800 | [diff] [blame] | 1439 | f2fs_destroy_xattr_caches(sbi); |
Chao Yu | b6895e8 | 2017-02-27 18:43:12 +0800 | [diff] [blame] | 1440 | mempool_destroy(sbi->write_io_dummy); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1441 | #ifdef CONFIG_QUOTA |
| 1442 | for (i = 0; i < MAXQUOTAS; i++) |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 1443 | kfree(F2FS_OPTION(sbi).s_qf_names[i]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1444 | #endif |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 1445 | fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 1446 | destroy_percpu_info(sbi); |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 1447 | for (i = 0; i < NR_PAGE_TYPE; i++) |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 1448 | kvfree(sbi->write_io[i]); |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 1449 | #ifdef CONFIG_UNICODE |
Daniel Rosenberg | eca4873 | 2020-07-08 02:12:36 -0700 | [diff] [blame] | 1450 | utf8_unload(sb->s_encoding); |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 1451 | #endif |
Denis Efremov | 742532d | 2020-06-10 01:14:46 +0300 | [diff] [blame] | 1452 | kfree(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | int f2fs_sync_fs(struct super_block *sb, int sync) |
| 1456 | { |
| 1457 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | c34f42e | 2015-12-23 17:50:30 +0800 | [diff] [blame] | 1458 | int err = 0; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1459 | |
Jaegeuk Kim | 1f227a3 | 2017-10-23 23:48:49 +0200 | [diff] [blame] | 1460 | if (unlikely(f2fs_cp_error(sbi))) |
| 1461 | return 0; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1462 | if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
| 1463 | return 0; |
Jaegeuk Kim | 1f227a3 | 2017-10-23 23:48:49 +0200 | [diff] [blame] | 1464 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 1465 | trace_f2fs_sync_fs(sb, sync); |
| 1466 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1467 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
| 1468 | return -EAGAIN; |
| 1469 | |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 1470 | if (sync) |
| 1471 | err = f2fs_issue_checkpoint(sbi); |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 1472 | |
Chao Yu | c34f42e | 2015-12-23 17:50:30 +0800 | [diff] [blame] | 1473 | return err; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1474 | } |
| 1475 | |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 1476 | static int f2fs_freeze(struct super_block *sb) |
| 1477 | { |
Jaegeuk Kim | 77888c1 | 2013-05-20 20:28:47 +0900 | [diff] [blame] | 1478 | if (f2fs_readonly(sb)) |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 1479 | return 0; |
| 1480 | |
Jaegeuk Kim | b4b9d34 | 2016-11-04 14:59:15 -0700 | [diff] [blame] | 1481 | /* IO error happened before */ |
| 1482 | if (unlikely(f2fs_cp_error(F2FS_SB(sb)))) |
| 1483 | return -EIO; |
| 1484 | |
| 1485 | /* must be clean, since sync_filesystem() was already called */ |
| 1486 | if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY)) |
| 1487 | return -EINVAL; |
Jaegeuk Kim | d50dfc0c | 2021-02-08 13:42:21 -0800 | [diff] [blame] | 1488 | |
| 1489 | /* ensure no checkpoint required */ |
| 1490 | if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list)) |
| 1491 | return -EINVAL; |
Jaegeuk Kim | b4b9d34 | 2016-11-04 14:59:15 -0700 | [diff] [blame] | 1492 | return 0; |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | static int f2fs_unfreeze(struct super_block *sb) |
| 1496 | { |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1500 | #ifdef CONFIG_QUOTA |
| 1501 | static int f2fs_statfs_project(struct super_block *sb, |
| 1502 | kprojid_t projid, struct kstatfs *buf) |
| 1503 | { |
| 1504 | struct kqid qid; |
| 1505 | struct dquot *dquot; |
| 1506 | u64 limit; |
| 1507 | u64 curblock; |
| 1508 | |
| 1509 | qid = make_kqid_projid(projid); |
| 1510 | dquot = dqget(sb, qid); |
| 1511 | if (IS_ERR(dquot)) |
| 1512 | return PTR_ERR(dquot); |
Sheng Yong | 955ac6e | 2018-07-24 20:17:53 +0800 | [diff] [blame] | 1513 | spin_lock(&dquot->dq_dqb_lock); |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1514 | |
Chengguang Xu | bf2cbd3 | 2020-01-04 22:20:04 +0800 | [diff] [blame] | 1515 | limit = min_not_zero(dquot->dq_dqb.dqb_bsoftlimit, |
| 1516 | dquot->dq_dqb.dqb_bhardlimit); |
Chengguang Xu | acdf217 | 2020-01-04 22:20:03 +0800 | [diff] [blame] | 1517 | if (limit) |
| 1518 | limit >>= sb->s_blocksize_bits; |
Chengguang Xu | 909110c | 2019-11-25 11:20:36 +0800 | [diff] [blame] | 1519 | |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1520 | if (limit && buf->f_blocks > limit) { |
Konstantin Khlebnikov | baaa7eb | 2020-05-11 09:15:18 +0300 | [diff] [blame] | 1521 | curblock = (dquot->dq_dqb.dqb_curspace + |
| 1522 | dquot->dq_dqb.dqb_rsvspace) >> sb->s_blocksize_bits; |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1523 | buf->f_blocks = limit; |
| 1524 | buf->f_bfree = buf->f_bavail = |
| 1525 | (buf->f_blocks > curblock) ? |
| 1526 | (buf->f_blocks - curblock) : 0; |
| 1527 | } |
| 1528 | |
Chengguang Xu | bf2cbd3 | 2020-01-04 22:20:04 +0800 | [diff] [blame] | 1529 | limit = min_not_zero(dquot->dq_dqb.dqb_isoftlimit, |
| 1530 | dquot->dq_dqb.dqb_ihardlimit); |
Chengguang Xu | 909110c | 2019-11-25 11:20:36 +0800 | [diff] [blame] | 1531 | |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1532 | if (limit && buf->f_files > limit) { |
| 1533 | buf->f_files = limit; |
| 1534 | buf->f_ffree = |
| 1535 | (buf->f_files > dquot->dq_dqb.dqb_curinodes) ? |
| 1536 | (buf->f_files - dquot->dq_dqb.dqb_curinodes) : 0; |
| 1537 | } |
| 1538 | |
Sheng Yong | 955ac6e | 2018-07-24 20:17:53 +0800 | [diff] [blame] | 1539 | spin_unlock(&dquot->dq_dqb_lock); |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1540 | dqput(dquot); |
| 1541 | return 0; |
| 1542 | } |
| 1543 | #endif |
| 1544 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1545 | static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 1546 | { |
| 1547 | struct super_block *sb = dentry->d_sb; |
| 1548 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1549 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
Jaegeuk Kim | f66c027 | 2018-01-03 10:55:07 -0800 | [diff] [blame] | 1550 | block_t total_count, user_block_count, start_count; |
Jaegeuk Kim | 0cc091d | 2017-06-21 20:55:55 -0700 | [diff] [blame] | 1551 | u64 avail_node_count; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1552 | |
| 1553 | total_count = le64_to_cpu(sbi->raw_super->block_count); |
| 1554 | user_block_count = sbi->user_block_count; |
| 1555 | start_count = le32_to_cpu(sbi->raw_super->segment0_blkaddr); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1556 | buf->f_type = F2FS_SUPER_MAGIC; |
| 1557 | buf->f_bsize = sbi->blocksize; |
| 1558 | |
| 1559 | buf->f_blocks = total_count - start_count; |
Jaegeuk Kim | f66c027 | 2018-01-03 10:55:07 -0800 | [diff] [blame] | 1560 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) - |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 1561 | sbi->current_reserved_blocks; |
Chao Yu | c9c8ed5 | 2019-05-05 11:40:46 +0800 | [diff] [blame] | 1562 | |
| 1563 | spin_lock(&sbi->stat_lock); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1564 | if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) |
| 1565 | buf->f_bfree = 0; |
| 1566 | else |
| 1567 | buf->f_bfree -= sbi->unusable_block_count; |
Chao Yu | c9c8ed5 | 2019-05-05 11:40:46 +0800 | [diff] [blame] | 1568 | spin_unlock(&sbi->stat_lock); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1569 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1570 | if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) |
| 1571 | buf->f_bavail = buf->f_bfree - |
| 1572 | F2FS_OPTION(sbi).root_reserved_blocks; |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1573 | else |
| 1574 | buf->f_bavail = 0; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1575 | |
Chao Yu | 27cae0b | 2019-08-05 18:27:25 +0800 | [diff] [blame] | 1576 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
Jaegeuk Kim | 0cc091d | 2017-06-21 20:55:55 -0700 | [diff] [blame] | 1577 | |
| 1578 | if (avail_node_count > user_block_count) { |
| 1579 | buf->f_files = user_block_count; |
| 1580 | buf->f_ffree = buf->f_bavail; |
| 1581 | } else { |
| 1582 | buf->f_files = avail_node_count; |
| 1583 | buf->f_ffree = min(avail_node_count - valid_node_count(sbi), |
| 1584 | buf->f_bavail); |
| 1585 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1586 | |
Jaegeuk Kim | 5a20d33 | 2013-03-03 13:58:05 +0900 | [diff] [blame] | 1587 | buf->f_namelen = F2FS_NAME_LEN; |
Al Viro | 6d1349c | 2020-09-18 16:45:50 -0400 | [diff] [blame] | 1588 | buf->f_fsid = u64_to_fsid(id); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1589 | |
Chao Yu | ddc34e3 | 2017-07-29 00:32:53 +0800 | [diff] [blame] | 1590 | #ifdef CONFIG_QUOTA |
| 1591 | if (is_inode_flag_set(dentry->d_inode, FI_PROJ_INHERIT) && |
| 1592 | sb_has_quota_limits_enabled(sb, PRJQUOTA)) { |
| 1593 | f2fs_statfs_project(sb, F2FS_I(dentry->d_inode)->i_projid, buf); |
| 1594 | } |
| 1595 | #endif |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1596 | return 0; |
| 1597 | } |
| 1598 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1599 | static inline void f2fs_show_quota_options(struct seq_file *seq, |
| 1600 | struct super_block *sb) |
| 1601 | { |
| 1602 | #ifdef CONFIG_QUOTA |
| 1603 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1604 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1605 | if (F2FS_OPTION(sbi).s_jquota_fmt) { |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1606 | char *fmtname = ""; |
| 1607 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1608 | switch (F2FS_OPTION(sbi).s_jquota_fmt) { |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1609 | case QFMT_VFS_OLD: |
| 1610 | fmtname = "vfsold"; |
| 1611 | break; |
| 1612 | case QFMT_VFS_V0: |
| 1613 | fmtname = "vfsv0"; |
| 1614 | break; |
| 1615 | case QFMT_VFS_V1: |
| 1616 | fmtname = "vfsv1"; |
| 1617 | break; |
| 1618 | } |
| 1619 | seq_printf(seq, ",jqfmt=%s", fmtname); |
| 1620 | } |
| 1621 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1622 | if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA]) |
| 1623 | seq_show_option(seq, "usrjquota", |
| 1624 | F2FS_OPTION(sbi).s_qf_names[USRQUOTA]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1625 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1626 | if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]) |
| 1627 | seq_show_option(seq, "grpjquota", |
| 1628 | F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1629 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1630 | if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) |
| 1631 | seq_show_option(seq, "prjjquota", |
| 1632 | F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1633 | #endif |
| 1634 | } |
| 1635 | |
Chao Yu | cd6ee73 | 2021-02-20 17:38:41 +0800 | [diff] [blame] | 1636 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1637 | static inline void f2fs_show_compress_options(struct seq_file *seq, |
| 1638 | struct super_block *sb) |
| 1639 | { |
| 1640 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1641 | char *algtype = ""; |
| 1642 | int i; |
| 1643 | |
| 1644 | if (!f2fs_sb_has_compression(sbi)) |
| 1645 | return; |
| 1646 | |
| 1647 | switch (F2FS_OPTION(sbi).compress_algorithm) { |
| 1648 | case COMPRESS_LZO: |
| 1649 | algtype = "lzo"; |
| 1650 | break; |
| 1651 | case COMPRESS_LZ4: |
| 1652 | algtype = "lz4"; |
| 1653 | break; |
Chao Yu | 50cfa66 | 2020-03-03 17:46:02 +0800 | [diff] [blame] | 1654 | case COMPRESS_ZSTD: |
| 1655 | algtype = "zstd"; |
| 1656 | break; |
Chao Yu | 6d92b20 | 2020-04-08 19:56:32 +0800 | [diff] [blame] | 1657 | case COMPRESS_LZORLE: |
| 1658 | algtype = "lzo-rle"; |
| 1659 | break; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1660 | } |
| 1661 | seq_printf(seq, ",compress_algorithm=%s", algtype); |
| 1662 | |
Chao Yu | 3fde13f | 2021-01-22 17:46:43 +0800 | [diff] [blame] | 1663 | if (F2FS_OPTION(sbi).compress_level) |
| 1664 | seq_printf(seq, ":%d", F2FS_OPTION(sbi).compress_level); |
| 1665 | |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1666 | seq_printf(seq, ",compress_log_size=%u", |
| 1667 | F2FS_OPTION(sbi).compress_log_size); |
| 1668 | |
| 1669 | for (i = 0; i < F2FS_OPTION(sbi).compress_ext_cnt; i++) { |
| 1670 | seq_printf(seq, ",compress_extension=%s", |
| 1671 | F2FS_OPTION(sbi).extensions[i]); |
| 1672 | } |
Chao Yu | b28f047 | 2020-11-26 18:32:09 +0800 | [diff] [blame] | 1673 | |
| 1674 | if (F2FS_OPTION(sbi).compress_chksum) |
| 1675 | seq_puts(seq, ",compress_chksum"); |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 1676 | |
| 1677 | if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_FS) |
| 1678 | seq_printf(seq, ",compress_mode=%s", "fs"); |
| 1679 | else if (F2FS_OPTION(sbi).compress_mode == COMPR_MODE_USER) |
| 1680 | seq_printf(seq, ",compress_mode=%s", "user"); |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1681 | } |
Chao Yu | cd6ee73 | 2021-02-20 17:38:41 +0800 | [diff] [blame] | 1682 | #endif |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1683 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1684 | static int f2fs_show_options(struct seq_file *seq, struct dentry *root) |
| 1685 | { |
| 1686 | struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb); |
| 1687 | |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 1688 | if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) |
| 1689 | seq_printf(seq, ",background_gc=%s", "sync"); |
| 1690 | else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_ON) |
| 1691 | seq_printf(seq, ",background_gc=%s", "on"); |
| 1692 | else if (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF) |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1693 | seq_printf(seq, ",background_gc=%s", "off"); |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 1694 | |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 1695 | if (test_opt(sbi, GC_MERGE)) |
| 1696 | seq_puts(seq, ",gc_merge"); |
| 1697 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1698 | if (test_opt(sbi, DISABLE_ROLL_FORWARD)) |
| 1699 | seq_puts(seq, ",disable_roll_forward"); |
Chao Yu | a9117ec | 2020-02-14 17:45:11 +0800 | [diff] [blame] | 1700 | if (test_opt(sbi, NORECOVERY)) |
| 1701 | seq_puts(seq, ",norecovery"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1702 | if (test_opt(sbi, DISCARD)) |
| 1703 | seq_puts(seq, ",discard"); |
Sahitya Tummala | 81621f9 | 2019-05-24 14:38:39 +0530 | [diff] [blame] | 1704 | else |
| 1705 | seq_puts(seq, ",nodiscard"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1706 | if (test_opt(sbi, NOHEAP)) |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 1707 | seq_puts(seq, ",no_heap"); |
| 1708 | else |
| 1709 | seq_puts(seq, ",heap"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1710 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1711 | if (test_opt(sbi, XATTR_USER)) |
| 1712 | seq_puts(seq, ",user_xattr"); |
| 1713 | else |
| 1714 | seq_puts(seq, ",nouser_xattr"); |
Jaegeuk Kim | 444c580 | 2013-08-08 15:16:22 +0900 | [diff] [blame] | 1715 | if (test_opt(sbi, INLINE_XATTR)) |
| 1716 | seq_puts(seq, ",inline_xattr"); |
Chao Yu | 23cf721 | 2017-02-15 10:34:45 +0800 | [diff] [blame] | 1717 | else |
| 1718 | seq_puts(seq, ",noinline_xattr"); |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 1719 | if (test_opt(sbi, INLINE_XATTR_SIZE)) |
| 1720 | seq_printf(seq, ",inline_xattr_size=%u", |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1721 | F2FS_OPTION(sbi).inline_xattr_size); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1722 | #endif |
| 1723 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 1724 | if (test_opt(sbi, POSIX_ACL)) |
| 1725 | seq_puts(seq, ",acl"); |
| 1726 | else |
| 1727 | seq_puts(seq, ",noacl"); |
| 1728 | #endif |
| 1729 | if (test_opt(sbi, DISABLE_EXT_IDENTIFY)) |
Alejandro Martinez Ruiz | aa43507 | 2013-01-25 19:08:59 +0100 | [diff] [blame] | 1730 | seq_puts(seq, ",disable_ext_identify"); |
Huajun Li | 8274de7 | 2013-11-10 23:13:17 +0800 | [diff] [blame] | 1731 | if (test_opt(sbi, INLINE_DATA)) |
| 1732 | seq_puts(seq, ",inline_data"); |
Wanpeng Li | 7534279 | 2015-03-24 10:20:27 +0800 | [diff] [blame] | 1733 | else |
| 1734 | seq_puts(seq, ",noinline_data"); |
Chao Yu | 5efd3c6 | 2014-09-24 18:16:13 +0800 | [diff] [blame] | 1735 | if (test_opt(sbi, INLINE_DENTRY)) |
| 1736 | seq_puts(seq, ",inline_dentry"); |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 1737 | else |
| 1738 | seq_puts(seq, ",noinline_dentry"); |
Gu Zheng | b270ad6 | 2014-04-11 17:49:55 +0800 | [diff] [blame] | 1739 | if (!f2fs_readonly(sbi->sb) && test_opt(sbi, FLUSH_MERGE)) |
Jaegeuk Kim | 6b4afdd | 2014-04-02 15:34:36 +0900 | [diff] [blame] | 1740 | seq_puts(seq, ",flush_merge"); |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 1741 | if (test_opt(sbi, NOBARRIER)) |
| 1742 | seq_puts(seq, ",nobarrier"); |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 1743 | if (test_opt(sbi, FASTBOOT)) |
| 1744 | seq_puts(seq, ",fastboot"); |
Chao Yu | 8967215 | 2015-02-05 17:55:51 +0800 | [diff] [blame] | 1745 | if (test_opt(sbi, EXTENT_CACHE)) |
| 1746 | seq_puts(seq, ",extent_cache"); |
Jaegeuk Kim | 7daaea2 | 2015-06-25 17:43:04 -0700 | [diff] [blame] | 1747 | else |
| 1748 | seq_puts(seq, ",noextent_cache"); |
Chao Yu | 343f40f | 2015-12-16 13:12:16 +0800 | [diff] [blame] | 1749 | if (test_opt(sbi, DATA_FLUSH)) |
| 1750 | seq_puts(seq, ",data_flush"); |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 1751 | |
| 1752 | seq_puts(seq, ",mode="); |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1753 | if (F2FS_OPTION(sbi).fs_mode == FS_MODE_ADAPTIVE) |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 1754 | seq_puts(seq, "adaptive"); |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1755 | else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 1756 | seq_puts(seq, "lfs"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1757 | seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 1758 | if (test_opt(sbi, RESERVE_ROOT)) |
Jaegeuk Kim | 7c2e596 | 2018-01-04 21:36:09 -0800 | [diff] [blame] | 1759 | seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u", |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1760 | F2FS_OPTION(sbi).root_reserved_blocks, |
| 1761 | from_kuid_munged(&init_user_ns, |
| 1762 | F2FS_OPTION(sbi).s_resuid), |
| 1763 | from_kgid_munged(&init_user_ns, |
| 1764 | F2FS_OPTION(sbi).s_resgid)); |
Jaegeuk Kim | ec91538 | 2016-12-21 17:09:19 -0800 | [diff] [blame] | 1765 | if (F2FS_IO_SIZE_BITS(sbi)) |
Chengguang Xu | c6b1867 | 2018-09-22 22:43:09 +0800 | [diff] [blame] | 1766 | seq_printf(seq, ",io_bits=%u", |
| 1767 | F2FS_OPTION(sbi).write_io_size_bits); |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 1768 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 1769 | if (test_opt(sbi, FAULT_INJECTION)) { |
Chao Yu | 44529f8 | 2017-06-12 09:44:24 +0800 | [diff] [blame] | 1770 | seq_printf(seq, ",fault_injection=%u", |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1771 | F2FS_OPTION(sbi).fault_info.inject_rate); |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 1772 | seq_printf(seq, ",fault_type=%u", |
| 1773 | F2FS_OPTION(sbi).fault_info.inject_type); |
| 1774 | } |
Kaixu Xia | 0cc0dec | 2017-01-27 09:35:37 +0800 | [diff] [blame] | 1775 | #endif |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1776 | #ifdef CONFIG_QUOTA |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1777 | if (test_opt(sbi, QUOTA)) |
| 1778 | seq_puts(seq, ",quota"); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1779 | if (test_opt(sbi, USRQUOTA)) |
| 1780 | seq_puts(seq, ",usrquota"); |
| 1781 | if (test_opt(sbi, GRPQUOTA)) |
| 1782 | seq_puts(seq, ",grpquota"); |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 1783 | if (test_opt(sbi, PRJQUOTA)) |
| 1784 | seq_puts(seq, ",prjquota"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1785 | #endif |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1786 | f2fs_show_quota_options(seq, sbi->sb); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1787 | if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) |
Hyunchul Lee | 0cdd319 | 2018-01-31 11:36:57 +0900 | [diff] [blame] | 1788 | seq_printf(seq, ",whint_mode=%s", "user-based"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1789 | else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) |
Hyunchul Lee | f2e703f | 2018-01-31 11:36:58 +0900 | [diff] [blame] | 1790 | seq_printf(seq, ",whint_mode=%s", "fs-based"); |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 1791 | |
| 1792 | fscrypt_show_test_dummy_encryption(seq, ',', sbi->sb); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1793 | |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 1794 | if (sbi->sb->s_flags & SB_INLINECRYPT) |
| 1795 | seq_puts(seq, ",inlinecrypt"); |
| 1796 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1797 | if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT) |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 1798 | seq_printf(seq, ",alloc_mode=%s", "default"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1799 | else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE) |
Jaegeuk Kim | 0793962 | 2018-02-18 08:50:49 -0800 | [diff] [blame] | 1800 | seq_printf(seq, ",alloc_mode=%s", "reuse"); |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 1801 | |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1802 | if (test_opt(sbi, DISABLE_CHECKPOINT)) |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 1803 | seq_printf(seq, ",checkpoint=disable:%u", |
| 1804 | F2FS_OPTION(sbi).unusable_cap); |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 1805 | if (test_opt(sbi, MERGE_CHECKPOINT)) |
| 1806 | seq_puts(seq, ",checkpoint_merge"); |
| 1807 | else |
| 1808 | seq_puts(seq, ",nocheckpoint_merge"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1809 | if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX) |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 1810 | seq_printf(seq, ",fsync_mode=%s", "posix"); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1811 | else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) |
Junling Zheng | 93cf93f | 2018-03-07 12:07:49 +0800 | [diff] [blame] | 1812 | seq_printf(seq, ",fsync_mode=%s", "strict"); |
Sahitya Tummala | dc13280 | 2018-07-02 11:37:40 +0530 | [diff] [blame] | 1813 | else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_NOBARRIER) |
| 1814 | seq_printf(seq, ",fsync_mode=%s", "nobarrier"); |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1815 | |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 1816 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1817 | f2fs_show_compress_options(seq, sbi->sb); |
Chao Yu | 1f0b067 | 2020-07-29 21:21:36 +0800 | [diff] [blame] | 1818 | #endif |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 1819 | |
| 1820 | if (test_opt(sbi, ATGC)) |
| 1821 | seq_puts(seq, ",atgc"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 1822 | return 0; |
| 1823 | } |
| 1824 | |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1825 | static void default_options(struct f2fs_sb_info *sbi) |
| 1826 | { |
| 1827 | /* init some FS parameters */ |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 1828 | if (f2fs_sb_has_readonly(sbi)) |
| 1829 | F2FS_OPTION(sbi).active_logs = NR_CURSEG_RO_TYPE; |
| 1830 | else |
| 1831 | F2FS_OPTION(sbi).active_logs = NR_CURSEG_PERSIST_TYPE; |
| 1832 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1833 | F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS; |
| 1834 | F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF; |
| 1835 | F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT; |
| 1836 | F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX; |
Chao Yu | 0aa7e0f | 2018-06-06 23:55:02 +0800 | [diff] [blame] | 1837 | F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID); |
| 1838 | F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID); |
Chao Yu | 91faa53 | 2020-03-10 20:50:05 +0800 | [diff] [blame] | 1839 | F2FS_OPTION(sbi).compress_algorithm = COMPRESS_LZ4; |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 1840 | F2FS_OPTION(sbi).compress_log_size = MIN_COMPRESS_LOG_SIZE; |
| 1841 | F2FS_OPTION(sbi).compress_ext_cnt = 0; |
Daeho Jeong | 602a16d | 2020-12-01 13:08:02 +0900 | [diff] [blame] | 1842 | F2FS_OPTION(sbi).compress_mode = COMPR_MODE_FS; |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 1843 | F2FS_OPTION(sbi).bggc_mode = BGGC_MODE_ON; |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1844 | |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 1845 | sbi->sb->s_flags &= ~SB_INLINECRYPT; |
| 1846 | |
Chao Yu | 39133a5 | 2017-02-08 17:39:44 +0800 | [diff] [blame] | 1847 | set_opt(sbi, INLINE_XATTR); |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1848 | set_opt(sbi, INLINE_DATA); |
Chao Yu | 97c1794 | 2016-05-09 19:56:34 +0800 | [diff] [blame] | 1849 | set_opt(sbi, INLINE_DENTRY); |
Jaegeuk Kim | 3e72f72 | 2015-06-19 17:53:26 -0700 | [diff] [blame] | 1850 | set_opt(sbi, EXTENT_CACHE); |
Jaegeuk Kim | 7a20b8a | 2017-03-24 20:41:45 -0400 | [diff] [blame] | 1851 | set_opt(sbi, NOHEAP); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1852 | clear_opt(sbi, DISABLE_CHECKPOINT); |
Jaegeuk Kim | b5d1519 | 2021-04-01 17:25:20 -0700 | [diff] [blame] | 1853 | set_opt(sbi, MERGE_CHECKPOINT); |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 1854 | F2FS_OPTION(sbi).unusable_cap = 0; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1855 | sbi->sb->s_flags |= SB_LAZYTIME; |
Jaegeuk Kim | 69e9e42 | 2016-05-20 22:39:20 -0700 | [diff] [blame] | 1856 | set_opt(sbi, FLUSH_MERGE); |
Chao Yu | 7d20c8a | 2018-09-04 03:52:17 +0800 | [diff] [blame] | 1857 | set_opt(sbi, DISCARD); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 1858 | if (f2fs_sb_has_blkzoned(sbi)) |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1859 | F2FS_OPTION(sbi).fs_mode = FS_MODE_LFS; |
Chao Yu | a39e5365 | 2018-07-05 14:24:11 +0800 | [diff] [blame] | 1860 | else |
Chao Yu | b0332a0 | 2020-02-14 17:44:12 +0800 | [diff] [blame] | 1861 | F2FS_OPTION(sbi).fs_mode = FS_MODE_ADAPTIVE; |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1862 | |
| 1863 | #ifdef CONFIG_F2FS_FS_XATTR |
| 1864 | set_opt(sbi, XATTR_USER); |
| 1865 | #endif |
| 1866 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 1867 | set_opt(sbi, POSIX_ACL); |
| 1868 | #endif |
Chao Yu | 36dbd32 | 2016-09-26 19:45:05 +0800 | [diff] [blame] | 1869 | |
Chao Yu | d494500 | 2018-08-08 17:36:41 +0800 | [diff] [blame] | 1870 | f2fs_build_fault_attr(sbi, 0, 0); |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 1871 | } |
| 1872 | |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 1873 | #ifdef CONFIG_QUOTA |
| 1874 | static int f2fs_enable_quotas(struct super_block *sb); |
| 1875 | #endif |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1876 | |
| 1877 | static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) |
| 1878 | { |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1879 | unsigned int s_flags = sbi->sb->s_flags; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1880 | struct cp_control cpc; |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1881 | int err = 0; |
| 1882 | int ret; |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 1883 | block_t unusable; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1884 | |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1885 | if (s_flags & SB_RDONLY) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1886 | f2fs_err(sbi, "checkpoint=disable on readonly fs"); |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1887 | return -EINVAL; |
| 1888 | } |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1889 | sbi->sb->s_flags |= SB_ACTIVE; |
| 1890 | |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1891 | f2fs_update_time(sbi, DISABLE_TIME); |
| 1892 | |
| 1893 | while (!f2fs_time_over(sbi, DISABLE_TIME)) { |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 1894 | down_write(&sbi->gc_lock); |
Chao Yu | 7dede886 | 2021-02-20 17:35:40 +0800 | [diff] [blame] | 1895 | err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1896 | if (err == -ENODATA) { |
| 1897 | err = 0; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1898 | break; |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1899 | } |
Jaegeuk Kim | 8f31b46 | 2018-12-17 17:08:26 -0800 | [diff] [blame] | 1900 | if (err && err != -EAGAIN) |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1901 | break; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1902 | } |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1903 | |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1904 | ret = sync_filesystem(sbi->sb); |
| 1905 | if (ret || err) { |
Yi Zhuang | 5f029c0 | 2021-04-06 09:47:35 +0800 | [diff] [blame] | 1906 | err = ret ? ret : err; |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1907 | goto restore_flag; |
| 1908 | } |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1909 | |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 1910 | unusable = f2fs_get_unusable_blocks(sbi); |
| 1911 | if (f2fs_disable_cp_again(sbi, unusable)) { |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1912 | err = -EAGAIN; |
| 1913 | goto restore_flag; |
| 1914 | } |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1915 | |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 1916 | down_write(&sbi->gc_lock); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1917 | cpc.reason = CP_PAUSE; |
| 1918 | set_sbi_flag(sbi, SBI_CP_DISABLED); |
Chao Yu | 896285a | 2019-04-26 17:57:54 +0800 | [diff] [blame] | 1919 | err = f2fs_write_checkpoint(sbi, &cpc); |
| 1920 | if (err) |
| 1921 | goto out_unlock; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1922 | |
Chao Yu | c9c8ed5 | 2019-05-05 11:40:46 +0800 | [diff] [blame] | 1923 | spin_lock(&sbi->stat_lock); |
Daniel Rosenberg | 4d3aed7 | 2019-05-29 17:49:06 -0700 | [diff] [blame] | 1924 | sbi->unusable_block_count = unusable; |
Chao Yu | c9c8ed5 | 2019-05-05 11:40:46 +0800 | [diff] [blame] | 1925 | spin_unlock(&sbi->stat_lock); |
| 1926 | |
Chao Yu | 896285a | 2019-04-26 17:57:54 +0800 | [diff] [blame] | 1927 | out_unlock: |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 1928 | up_write(&sbi->gc_lock); |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1929 | restore_flag: |
Chao Yu | 7a88ddb | 2020-02-27 19:30:05 +0800 | [diff] [blame] | 1930 | sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */ |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 1931 | return err; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) |
| 1935 | { |
Jaegeuk Kim | b0ff4fe | 2021-01-26 17:00:42 -0800 | [diff] [blame] | 1936 | /* we should flush all the data to keep data consistency */ |
| 1937 | sync_inodes_sb(sbi->sb); |
| 1938 | |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 1939 | down_write(&sbi->gc_lock); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1940 | f2fs_dirty_to_prefree(sbi); |
| 1941 | |
| 1942 | clear_sbi_flag(sbi, SBI_CP_DISABLED); |
| 1943 | set_sbi_flag(sbi, SBI_IS_DIRTY); |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 1944 | up_write(&sbi->gc_lock); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1945 | |
| 1946 | f2fs_sync_fs(sbi->sb, 1); |
| 1947 | } |
| 1948 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1949 | static int f2fs_remount(struct super_block *sb, int *flags, char *data) |
| 1950 | { |
| 1951 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 1952 | struct f2fs_mount_info org_mount_opt; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1953 | unsigned long old_sb_flags; |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1954 | int err; |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 1955 | bool need_restart_gc = false, need_stop_gc = false; |
| 1956 | bool need_restart_ckpt = false, need_stop_ckpt = false; |
| 1957 | bool need_restart_flush = false, need_stop_flush = false; |
Chao Yu | 9cd81ce | 2015-09-18 16:55:26 +0800 | [diff] [blame] | 1958 | bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1959 | bool disable_checkpoint = test_opt(sbi, DISABLE_CHECKPOINT); |
Chao Yu | 1f78adf | 2019-07-12 16:57:00 +0800 | [diff] [blame] | 1960 | bool no_io_align = !F2FS_IO_ALIGNED(sbi); |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 1961 | bool no_atgc = !test_opt(sbi, ATGC); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 1962 | bool checkpoint_changed; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1963 | #ifdef CONFIG_QUOTA |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1964 | int i, j; |
| 1965 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1966 | |
| 1967 | /* |
| 1968 | * Save the old mount options in case we |
| 1969 | * need to restore them. |
| 1970 | */ |
| 1971 | org_mount_opt = sbi->mount_opt; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 1972 | old_sb_flags = sb->s_flags; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 1973 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1974 | #ifdef CONFIG_QUOTA |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1975 | org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1976 | for (i = 0; i < MAXQUOTAS; i++) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1977 | if (F2FS_OPTION(sbi).s_qf_names[i]) { |
| 1978 | org_mount_opt.s_qf_names[i] = |
| 1979 | kstrdup(F2FS_OPTION(sbi).s_qf_names[i], |
| 1980 | GFP_KERNEL); |
| 1981 | if (!org_mount_opt.s_qf_names[i]) { |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1982 | for (j = 0; j < i; j++) |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 1983 | kfree(org_mount_opt.s_qf_names[j]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1984 | return -ENOMEM; |
| 1985 | } |
| 1986 | } else { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 1987 | org_mount_opt.s_qf_names[i] = NULL; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | #endif |
| 1991 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1992 | /* recover superblocks we couldn't write due to previous RO mount */ |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 1993 | if (!(*flags & SB_RDONLY) && is_sbi_flag_set(sbi, SBI_NEED_SB_WRITE)) { |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1994 | err = f2fs_commit_super(sbi, false); |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 1995 | f2fs_info(sbi, "Try to recover all the superblocks, ret: %d", |
| 1996 | err); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 1997 | if (!err) |
| 1998 | clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
| 1999 | } |
| 2000 | |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 2001 | default_options(sbi); |
Chao Yu | 26666c8 | 2014-09-15 18:04:44 +0800 | [diff] [blame] | 2002 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2003 | /* parse mount options */ |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 2004 | err = parse_options(sb, data, true); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2005 | if (err) |
| 2006 | goto restore_opts; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 2007 | checkpoint_changed = |
| 2008 | disable_checkpoint != test_opt(sbi, DISABLE_CHECKPOINT); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2009 | |
| 2010 | /* |
| 2011 | * Previous and new state of filesystem is RO, |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2012 | * so skip checking GC and FLUSH_MERGE conditions. |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2013 | */ |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 2014 | if (f2fs_readonly(sb) && (*flags & SB_RDONLY)) |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2015 | goto skip; |
| 2016 | |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 2017 | if (f2fs_sb_has_readonly(sbi) && !(*flags & SB_RDONLY)) { |
| 2018 | err = -EROFS; |
| 2019 | goto restore_opts; |
| 2020 | } |
| 2021 | |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2022 | #ifdef CONFIG_QUOTA |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 2023 | if (!f2fs_readonly(sb) && (*flags & SB_RDONLY)) { |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2024 | err = dquot_suspend(sb, -1); |
| 2025 | if (err < 0) |
| 2026 | goto restore_opts; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 2027 | } else if (f2fs_readonly(sb) && !(*flags & SB_RDONLY)) { |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2028 | /* dquot_resume needs RW */ |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 2029 | sb->s_flags &= ~SB_RDONLY; |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2030 | if (sb_any_quota_suspended(sb)) { |
| 2031 | dquot_resume(sb, -1); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2032 | } else if (f2fs_sb_has_quota_ino(sbi)) { |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2033 | err = f2fs_enable_quotas(sb); |
| 2034 | if (err) |
| 2035 | goto restore_opts; |
| 2036 | } |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2037 | } |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2038 | #endif |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 2039 | /* disallow enable atgc dynamically */ |
| 2040 | if (no_atgc == !!test_opt(sbi, ATGC)) { |
| 2041 | err = -EINVAL; |
| 2042 | f2fs_warn(sbi, "switch atgc option is not allowed"); |
| 2043 | goto restore_opts; |
| 2044 | } |
| 2045 | |
Chao Yu | 9cd81ce | 2015-09-18 16:55:26 +0800 | [diff] [blame] | 2046 | /* disallow enable/disable extent_cache dynamically */ |
| 2047 | if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { |
| 2048 | err = -EINVAL; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2049 | f2fs_warn(sbi, "switch extent_cache option is not allowed"); |
Chao Yu | 9cd81ce | 2015-09-18 16:55:26 +0800 | [diff] [blame] | 2050 | goto restore_opts; |
| 2051 | } |
| 2052 | |
Chao Yu | 1f78adf | 2019-07-12 16:57:00 +0800 | [diff] [blame] | 2053 | if (no_io_align == !!F2FS_IO_ALIGNED(sbi)) { |
| 2054 | err = -EINVAL; |
| 2055 | f2fs_warn(sbi, "switch io_bits option is not allowed"); |
| 2056 | goto restore_opts; |
| 2057 | } |
| 2058 | |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 2059 | if ((*flags & SB_RDONLY) && test_opt(sbi, DISABLE_CHECKPOINT)) { |
| 2060 | err = -EINVAL; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2061 | f2fs_warn(sbi, "disabling checkpoint not compatible with read-only"); |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 2062 | goto restore_opts; |
| 2063 | } |
| 2064 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2065 | /* |
| 2066 | * We stop the GC thread if FS is mounted as RO |
| 2067 | * or if background_gc = off is passed in mount |
| 2068 | * option. Also sync the filesystem. |
| 2069 | */ |
Chao Yu | bbbc34f | 2020-02-14 17:44:13 +0800 | [diff] [blame] | 2070 | if ((*flags & SB_RDONLY) || |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 2071 | (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_OFF && |
| 2072 | !test_opt(sbi, GC_MERGE))) { |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2073 | if (sbi->gc_thread) { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2074 | f2fs_stop_gc_thread(sbi); |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2075 | need_restart_gc = true; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2076 | } |
Chao Yu | aba291b | 2014-11-18 11:17:20 +0800 | [diff] [blame] | 2077 | } else if (!sbi->gc_thread) { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2078 | err = f2fs_start_gc_thread(sbi); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2079 | if (err) |
| 2080 | goto restore_opts; |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2081 | need_stop_gc = true; |
| 2082 | } |
| 2083 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 2084 | if (*flags & SB_RDONLY || |
| 2085 | F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) { |
Jaegeuk Kim | faa0e55 | 2016-03-24 10:29:39 -0700 | [diff] [blame] | 2086 | sync_inodes_sb(sb); |
| 2087 | |
| 2088 | set_sbi_flag(sbi, SBI_IS_DIRTY); |
| 2089 | set_sbi_flag(sbi, SBI_IS_CLOSE); |
| 2090 | f2fs_sync_fs(sb, 1); |
| 2091 | clear_sbi_flag(sbi, SBI_IS_CLOSE); |
| 2092 | } |
| 2093 | |
Chao Yu | 3f7070b | 2021-03-17 17:56:03 +0800 | [diff] [blame] | 2094 | if ((*flags & SB_RDONLY) || test_opt(sbi, DISABLE_CHECKPOINT) || |
| 2095 | !test_opt(sbi, MERGE_CHECKPOINT)) { |
| 2096 | f2fs_stop_ckpt_thread(sbi); |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2097 | need_restart_ckpt = true; |
Chao Yu | 3f7070b | 2021-03-17 17:56:03 +0800 | [diff] [blame] | 2098 | } else { |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 2099 | err = f2fs_start_ckpt_thread(sbi); |
| 2100 | if (err) { |
| 2101 | f2fs_err(sbi, |
| 2102 | "Failed to start F2FS issue_checkpoint_thread (%d)", |
| 2103 | err); |
| 2104 | goto restore_gc; |
| 2105 | } |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2106 | need_stop_ckpt = true; |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 2107 | } |
| 2108 | |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2109 | /* |
| 2110 | * We stop issue flush thread if FS is mounted as RO |
| 2111 | * or if flush_merge is not passed in mount option. |
| 2112 | */ |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 2113 | if ((*flags & SB_RDONLY) || !test_opt(sbi, FLUSH_MERGE)) { |
Jaegeuk Kim | 5eba8c5 | 2016-12-07 16:23:32 -0800 | [diff] [blame] | 2114 | clear_opt(sbi, FLUSH_MERGE); |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2115 | f2fs_destroy_flush_cmd_control(sbi, false); |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2116 | need_restart_flush = true; |
Jaegeuk Kim | 5eba8c5 | 2016-12-07 16:23:32 -0800 | [diff] [blame] | 2117 | } else { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2118 | err = f2fs_create_flush_cmd_control(sbi); |
Gu Zheng | 2163d19 | 2014-04-27 14:21:33 +0800 | [diff] [blame] | 2119 | if (err) |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2120 | goto restore_ckpt; |
| 2121 | need_stop_flush = true; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2122 | } |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2123 | |
| 2124 | if (checkpoint_changed) { |
| 2125 | if (test_opt(sbi, DISABLE_CHECKPOINT)) { |
| 2126 | err = f2fs_disable_checkpoint(sbi); |
| 2127 | if (err) |
| 2128 | goto restore_flush; |
| 2129 | } else { |
| 2130 | f2fs_enable_checkpoint(sbi); |
| 2131 | } |
| 2132 | } |
| 2133 | |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2134 | skip: |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2135 | #ifdef CONFIG_QUOTA |
| 2136 | /* Release old quota file names */ |
| 2137 | for (i = 0; i < MAXQUOTAS; i++) |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 2138 | kfree(org_mount_opt.s_qf_names[i]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2139 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2140 | /* Update the POSIXACL Flag */ |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 2141 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | |
| 2142 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 2143 | |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 2144 | limit_reserve_root(sbi); |
Jaegeuk Kim | 1ae18f7 | 2020-05-15 17:20:50 -0700 | [diff] [blame] | 2145 | adjust_unusable_cap_perc(sbi); |
Jaegeuk Kim | 095680f | 2018-09-28 00:24:39 -0700 | [diff] [blame] | 2146 | *flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2147 | return 0; |
Chao Yu | 3fd9735 | 2021-03-17 17:56:04 +0800 | [diff] [blame] | 2148 | restore_flush: |
| 2149 | if (need_restart_flush) { |
| 2150 | if (f2fs_create_flush_cmd_control(sbi)) |
| 2151 | f2fs_warn(sbi, "background flush thread has stopped"); |
| 2152 | } else if (need_stop_flush) { |
| 2153 | clear_opt(sbi, FLUSH_MERGE); |
| 2154 | f2fs_destroy_flush_cmd_control(sbi, false); |
| 2155 | } |
| 2156 | restore_ckpt: |
| 2157 | if (need_restart_ckpt) { |
| 2158 | if (f2fs_start_ckpt_thread(sbi)) |
| 2159 | f2fs_warn(sbi, "background ckpt thread has stopped"); |
| 2160 | } else if (need_stop_ckpt) { |
| 2161 | f2fs_stop_ckpt_thread(sbi); |
| 2162 | } |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2163 | restore_gc: |
| 2164 | if (need_restart_gc) { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2165 | if (f2fs_start_gc_thread(sbi)) |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2166 | f2fs_warn(sbi, "background gc thread has stopped"); |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2167 | } else if (need_stop_gc) { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2168 | f2fs_stop_gc_thread(sbi); |
Gu Zheng | 876dc59 | 2014-04-11 17:50:00 +0800 | [diff] [blame] | 2169 | } |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2170 | restore_opts: |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2171 | #ifdef CONFIG_QUOTA |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 2172 | F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2173 | for (i = 0; i < MAXQUOTAS; i++) { |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 2174 | kfree(F2FS_OPTION(sbi).s_qf_names[i]); |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 2175 | F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i]; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2176 | } |
| 2177 | #endif |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2178 | sbi->mount_opt = org_mount_opt; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2179 | sb->s_flags = old_sb_flags; |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2180 | return err; |
| 2181 | } |
| 2182 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2183 | #ifdef CONFIG_QUOTA |
| 2184 | /* Read data from quotafile */ |
| 2185 | static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data, |
| 2186 | size_t len, loff_t off) |
| 2187 | { |
| 2188 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2189 | struct address_space *mapping = inode->i_mapping; |
| 2190 | block_t blkidx = F2FS_BYTES_TO_BLK(off); |
| 2191 | int offset = off & (sb->s_blocksize - 1); |
| 2192 | int tocopy; |
| 2193 | size_t toread; |
| 2194 | loff_t i_size = i_size_read(inode); |
| 2195 | struct page *page; |
| 2196 | char *kaddr; |
| 2197 | |
| 2198 | if (off > i_size) |
| 2199 | return 0; |
| 2200 | |
| 2201 | if (off + len > i_size) |
| 2202 | len = i_size - off; |
| 2203 | toread = len; |
| 2204 | while (toread > 0) { |
| 2205 | tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread); |
| 2206 | repeat: |
Ritesh Harjani | 02117b8 | 2018-03-16 18:53:53 +0530 | [diff] [blame] | 2207 | page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2208 | if (IS_ERR(page)) { |
| 2209 | if (PTR_ERR(page) == -ENOMEM) { |
Chao Yu | 5df7731f | 2020-02-17 17:45:44 +0800 | [diff] [blame] | 2210 | congestion_wait(BLK_RW_ASYNC, |
| 2211 | DEFAULT_IO_TIMEOUT); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2212 | goto repeat; |
| 2213 | } |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2214 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2215 | return PTR_ERR(page); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2216 | } |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2217 | |
| 2218 | lock_page(page); |
| 2219 | |
| 2220 | if (unlikely(page->mapping != mapping)) { |
| 2221 | f2fs_put_page(page, 1); |
| 2222 | goto repeat; |
| 2223 | } |
| 2224 | if (unlikely(!PageUptodate(page))) { |
| 2225 | f2fs_put_page(page, 1); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2226 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2227 | return -EIO; |
| 2228 | } |
| 2229 | |
| 2230 | kaddr = kmap_atomic(page); |
| 2231 | memcpy(data, kaddr + offset, tocopy); |
| 2232 | kunmap_atomic(kaddr); |
| 2233 | f2fs_put_page(page, 1); |
| 2234 | |
| 2235 | offset = 0; |
| 2236 | toread -= tocopy; |
| 2237 | data += tocopy; |
| 2238 | blkidx++; |
| 2239 | } |
| 2240 | return len; |
| 2241 | } |
| 2242 | |
| 2243 | /* Write to quotafile */ |
| 2244 | static ssize_t f2fs_quota_write(struct super_block *sb, int type, |
| 2245 | const char *data, size_t len, loff_t off) |
| 2246 | { |
| 2247 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2248 | struct address_space *mapping = inode->i_mapping; |
| 2249 | const struct address_space_operations *a_ops = mapping->a_ops; |
| 2250 | int offset = off & (sb->s_blocksize - 1); |
| 2251 | size_t towrite = len; |
| 2252 | struct page *page; |
Chao Yu | 62f63ee | 2020-03-19 19:58:00 +0800 | [diff] [blame] | 2253 | void *fsdata = NULL; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2254 | char *kaddr; |
| 2255 | int err = 0; |
| 2256 | int tocopy; |
| 2257 | |
| 2258 | while (towrite > 0) { |
| 2259 | tocopy = min_t(unsigned long, sb->s_blocksize - offset, |
| 2260 | towrite); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2261 | retry: |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2262 | err = a_ops->write_begin(NULL, mapping, off, tocopy, 0, |
Chao Yu | 62f63ee | 2020-03-19 19:58:00 +0800 | [diff] [blame] | 2263 | &page, &fsdata); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2264 | if (unlikely(err)) { |
| 2265 | if (err == -ENOMEM) { |
Chao Yu | 5df7731f | 2020-02-17 17:45:44 +0800 | [diff] [blame] | 2266 | congestion_wait(BLK_RW_ASYNC, |
| 2267 | DEFAULT_IO_TIMEOUT); |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2268 | goto retry; |
| 2269 | } |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2270 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2271 | break; |
Jaegeuk Kim | 4e46a02 | 2017-10-19 09:43:56 -0700 | [diff] [blame] | 2272 | } |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2273 | |
| 2274 | kaddr = kmap_atomic(page); |
| 2275 | memcpy(kaddr + offset, data, tocopy); |
| 2276 | kunmap_atomic(kaddr); |
| 2277 | flush_dcache_page(page); |
| 2278 | |
| 2279 | a_ops->write_end(NULL, mapping, off, tocopy, tocopy, |
Chao Yu | 62f63ee | 2020-03-19 19:58:00 +0800 | [diff] [blame] | 2280 | page, fsdata); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2281 | offset = 0; |
| 2282 | towrite -= tocopy; |
| 2283 | off += tocopy; |
| 2284 | data += tocopy; |
| 2285 | cond_resched(); |
| 2286 | } |
| 2287 | |
| 2288 | if (len == towrite) |
Jaegeuk Kim | 6e5b5d4 | 2017-10-19 12:07:11 -0700 | [diff] [blame] | 2289 | return err; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2290 | inode->i_mtime = inode->i_ctime = current_time(inode); |
| 2291 | f2fs_mark_inode_dirty_sync(inode, false); |
| 2292 | return len - towrite; |
| 2293 | } |
| 2294 | |
| 2295 | static struct dquot **f2fs_get_dquots(struct inode *inode) |
| 2296 | { |
| 2297 | return F2FS_I(inode)->i_dquot; |
| 2298 | } |
| 2299 | |
| 2300 | static qsize_t *f2fs_get_reserved_space(struct inode *inode) |
| 2301 | { |
| 2302 | return &F2FS_I(inode)->i_reserved_quota; |
| 2303 | } |
| 2304 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2305 | static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type) |
| 2306 | { |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2307 | if (is_set_ckpt_flags(sbi, CP_QUOTA_NEED_FSCK_FLAG)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2308 | f2fs_err(sbi, "quota sysfile may be corrupted, skip loading it"); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2309 | return 0; |
| 2310 | } |
| 2311 | |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 2312 | return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type], |
| 2313 | F2FS_OPTION(sbi).s_jquota_fmt, type); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2314 | } |
| 2315 | |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2316 | int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly) |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2317 | { |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2318 | int enabled = 0; |
| 2319 | int i, err; |
| 2320 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2321 | if (f2fs_sb_has_quota_ino(sbi) && rdonly) { |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2322 | err = f2fs_enable_quotas(sbi->sb); |
| 2323 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2324 | f2fs_err(sbi, "Cannot turn on quota_ino: %d", err); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2325 | return 0; |
| 2326 | } |
| 2327 | return 1; |
| 2328 | } |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2329 | |
| 2330 | for (i = 0; i < MAXQUOTAS; i++) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 2331 | if (F2FS_OPTION(sbi).s_qf_names[i]) { |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2332 | err = f2fs_quota_on_mount(sbi, i); |
| 2333 | if (!err) { |
| 2334 | enabled = 1; |
| 2335 | continue; |
| 2336 | } |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2337 | f2fs_err(sbi, "Cannot turn on quotas: %d on %d", |
| 2338 | err, i); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2339 | } |
| 2340 | } |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2341 | return enabled; |
| 2342 | } |
| 2343 | |
| 2344 | static int f2fs_quota_enable(struct super_block *sb, int type, int format_id, |
| 2345 | unsigned int flags) |
| 2346 | { |
| 2347 | struct inode *qf_inode; |
| 2348 | unsigned long qf_inum; |
| 2349 | int err; |
| 2350 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2351 | BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb))); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2352 | |
| 2353 | qf_inum = f2fs_qf_ino(sb, type); |
| 2354 | if (!qf_inum) |
| 2355 | return -EPERM; |
| 2356 | |
| 2357 | qf_inode = f2fs_iget(sb, qf_inum); |
| 2358 | if (IS_ERR(qf_inode)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2359 | f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2360 | return PTR_ERR(qf_inode); |
| 2361 | } |
| 2362 | |
| 2363 | /* Don't account quota for quota files to avoid recursion */ |
| 2364 | qf_inode->i_flags |= S_NOQUOTA; |
Jan Kara | 7212b95 | 2019-11-01 18:55:38 +0100 | [diff] [blame] | 2365 | err = dquot_load_quota_inode(qf_inode, type, format_id, flags); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2366 | iput(qf_inode); |
| 2367 | return err; |
| 2368 | } |
| 2369 | |
| 2370 | static int f2fs_enable_quotas(struct super_block *sb) |
| 2371 | { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2372 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2373 | int type, err = 0; |
| 2374 | unsigned long qf_inum; |
| 2375 | bool quota_mopt[MAXQUOTAS] = { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2376 | test_opt(sbi, USRQUOTA), |
| 2377 | test_opt(sbi, GRPQUOTA), |
| 2378 | test_opt(sbi, PRJQUOTA), |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2379 | }; |
| 2380 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2381 | if (is_set_ckpt_flags(F2FS_SB(sb), CP_QUOTA_NEED_FSCK_FLAG)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2382 | f2fs_err(sbi, "quota file may be corrupted, skip loading it"); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2383 | return 0; |
| 2384 | } |
| 2385 | |
| 2386 | sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE; |
| 2387 | |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2388 | for (type = 0; type < MAXQUOTAS; type++) { |
| 2389 | qf_inum = f2fs_qf_ino(sb, type); |
| 2390 | if (qf_inum) { |
| 2391 | err = f2fs_quota_enable(sb, type, QFMT_VFS_V1, |
| 2392 | DQUOT_USAGE_ENABLED | |
| 2393 | (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0)); |
| 2394 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2395 | f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.", |
| 2396 | type, err); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2397 | for (type--; type >= 0; type--) |
| 2398 | dquot_quota_off(sb, type); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2399 | set_sbi_flag(F2FS_SB(sb), |
| 2400 | SBI_QUOTA_NEED_REPAIR); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 2401 | return err; |
| 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | return 0; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2406 | } |
| 2407 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2408 | int f2fs_quota_sync(struct super_block *sb, int type) |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2409 | { |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2410 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2411 | struct quota_info *dqopt = sb_dqopt(sb); |
| 2412 | int cnt; |
| 2413 | int ret; |
| 2414 | |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2415 | /* |
| 2416 | * do_quotactl |
| 2417 | * f2fs_quota_sync |
| 2418 | * down_read(quota_sem) |
| 2419 | * dquot_writeback_dquots() |
| 2420 | * f2fs_dquot_commit |
| 2421 | * block_operation |
| 2422 | * down_read(quota_sem) |
| 2423 | */ |
| 2424 | f2fs_lock_op(sbi); |
| 2425 | |
| 2426 | down_read(&sbi->quota_sem); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2427 | ret = dquot_writeback_dquots(sb, type); |
| 2428 | if (ret) |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2429 | goto out; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2430 | |
| 2431 | /* |
| 2432 | * Now when everything is written we can discard the pagecache so |
| 2433 | * that userspace sees the changes. |
| 2434 | */ |
| 2435 | for (cnt = 0; cnt < MAXQUOTAS; cnt++) { |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2436 | struct address_space *mapping; |
| 2437 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2438 | if (type != -1 && cnt != type) |
| 2439 | continue; |
| 2440 | if (!sb_has_quota_active(sb, cnt)) |
| 2441 | continue; |
| 2442 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2443 | mapping = dqopt->files[cnt]->i_mapping; |
| 2444 | |
| 2445 | ret = filemap_fdatawrite(mapping); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2446 | if (ret) |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2447 | goto out; |
| 2448 | |
| 2449 | /* if we are using journalled quota */ |
| 2450 | if (is_journalled_quota(sbi)) |
| 2451 | continue; |
| 2452 | |
| 2453 | ret = filemap_fdatawait(mapping); |
| 2454 | if (ret) |
| 2455 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2456 | |
| 2457 | inode_lock(dqopt->files[cnt]); |
| 2458 | truncate_inode_pages(&dqopt->files[cnt]->i_data, 0); |
| 2459 | inode_unlock(dqopt->files[cnt]); |
| 2460 | } |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2461 | out: |
| 2462 | if (ret) |
| 2463 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2464 | up_read(&sbi->quota_sem); |
| 2465 | f2fs_unlock_op(sbi); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2466 | return ret; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | static int f2fs_quota_on(struct super_block *sb, int type, int format_id, |
| 2470 | const struct path *path) |
| 2471 | { |
| 2472 | struct inode *inode; |
| 2473 | int err; |
| 2474 | |
Chao Yu | fe973b0 | 2019-07-25 17:33:37 +0800 | [diff] [blame] | 2475 | /* if quota sysfile exists, deny enabling quota with specific file */ |
| 2476 | if (f2fs_sb_has_quota_ino(F2FS_SB(sb))) { |
| 2477 | f2fs_err(F2FS_SB(sb), "quota sysfile already exists"); |
| 2478 | return -EBUSY; |
| 2479 | } |
| 2480 | |
Chao Yu | 9a20d39 | 2017-08-07 16:37:59 +0800 | [diff] [blame] | 2481 | err = f2fs_quota_sync(sb, type); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2482 | if (err) |
| 2483 | return err; |
| 2484 | |
| 2485 | err = dquot_quota_on(sb, type, format_id, path); |
| 2486 | if (err) |
| 2487 | return err; |
| 2488 | |
| 2489 | inode = d_inode(path->dentry); |
| 2490 | |
| 2491 | inode_lock(inode); |
Chao Yu | 59c8440 | 2018-04-03 15:08:17 +0800 | [diff] [blame] | 2492 | F2FS_I(inode)->i_flags |= F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL; |
Chao Yu | 9149a5e | 2018-10-07 19:06:15 +0800 | [diff] [blame] | 2493 | f2fs_set_inode_flags(inode); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2494 | inode_unlock(inode); |
| 2495 | f2fs_mark_inode_dirty_sync(inode, false); |
| 2496 | |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
Chao Yu | fe973b0 | 2019-07-25 17:33:37 +0800 | [diff] [blame] | 2500 | static int __f2fs_quota_off(struct super_block *sb, int type) |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2501 | { |
| 2502 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2503 | int err; |
| 2504 | |
| 2505 | if (!inode || !igrab(inode)) |
| 2506 | return dquot_quota_off(sb, type); |
| 2507 | |
Yunlei He | cda9cc5 | 2018-06-26 13:12:43 +0800 | [diff] [blame] | 2508 | err = f2fs_quota_sync(sb, type); |
| 2509 | if (err) |
| 2510 | goto out_put; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2511 | |
| 2512 | err = dquot_quota_off(sb, type); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2513 | if (err || f2fs_sb_has_quota_ino(F2FS_SB(sb))) |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2514 | goto out_put; |
| 2515 | |
| 2516 | inode_lock(inode); |
Chao Yu | 59c8440 | 2018-04-03 15:08:17 +0800 | [diff] [blame] | 2517 | F2FS_I(inode)->i_flags &= ~(F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL); |
Chao Yu | 9149a5e | 2018-10-07 19:06:15 +0800 | [diff] [blame] | 2518 | f2fs_set_inode_flags(inode); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2519 | inode_unlock(inode); |
| 2520 | f2fs_mark_inode_dirty_sync(inode, false); |
| 2521 | out_put: |
| 2522 | iput(inode); |
| 2523 | return err; |
| 2524 | } |
| 2525 | |
Chao Yu | fe973b0 | 2019-07-25 17:33:37 +0800 | [diff] [blame] | 2526 | static int f2fs_quota_off(struct super_block *sb, int type) |
| 2527 | { |
| 2528 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 2529 | int err; |
| 2530 | |
| 2531 | err = __f2fs_quota_off(sb, type); |
| 2532 | |
| 2533 | /* |
| 2534 | * quotactl can shutdown journalled quota, result in inconsistence |
| 2535 | * between quota record and fs data by following updates, tag the |
| 2536 | * flag to let fsck be aware of it. |
| 2537 | */ |
| 2538 | if (is_journalled_quota(sbi)) |
| 2539 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
| 2540 | return err; |
| 2541 | } |
| 2542 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2543 | void f2fs_quota_off_umount(struct super_block *sb) |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2544 | { |
| 2545 | int type; |
Yunlei He | cda9cc5 | 2018-06-26 13:12:43 +0800 | [diff] [blame] | 2546 | int err; |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2547 | |
Yunlei He | cda9cc5 | 2018-06-26 13:12:43 +0800 | [diff] [blame] | 2548 | for (type = 0; type < MAXQUOTAS; type++) { |
Chao Yu | fe973b0 | 2019-07-25 17:33:37 +0800 | [diff] [blame] | 2549 | err = __f2fs_quota_off(sb, type); |
Yunlei He | cda9cc5 | 2018-06-26 13:12:43 +0800 | [diff] [blame] | 2550 | if (err) { |
| 2551 | int ret = dquot_quota_off(sb, type); |
| 2552 | |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2553 | f2fs_err(F2FS_SB(sb), "Fail to turn off disk quota (type: %d, err: %d, ret:%d), Please run fsck to fix it.", |
| 2554 | type, err, ret); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2555 | set_sbi_flag(F2FS_SB(sb), SBI_QUOTA_NEED_REPAIR); |
Yunlei He | cda9cc5 | 2018-06-26 13:12:43 +0800 | [diff] [blame] | 2556 | } |
| 2557 | } |
Jaegeuk Kim | 0e0667b | 2019-01-27 17:59:53 -0800 | [diff] [blame] | 2558 | /* |
| 2559 | * In case of checkpoint=disable, we must flush quota blocks. |
| 2560 | * This can cause NULL exception for node_inode in end_io, since |
| 2561 | * put_super already dropped it. |
| 2562 | */ |
| 2563 | sync_filesystem(sb); |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2564 | } |
| 2565 | |
Sheng Yong | 26b5a07 | 2018-10-12 18:49:26 +0800 | [diff] [blame] | 2566 | static void f2fs_truncate_quota_inode_pages(struct super_block *sb) |
| 2567 | { |
| 2568 | struct quota_info *dqopt = sb_dqopt(sb); |
| 2569 | int type; |
| 2570 | |
| 2571 | for (type = 0; type < MAXQUOTAS; type++) { |
| 2572 | if (!dqopt->files[type]) |
| 2573 | continue; |
| 2574 | f2fs_inode_synced(dqopt->files[type]); |
| 2575 | } |
| 2576 | } |
| 2577 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2578 | static int f2fs_dquot_commit(struct dquot *dquot) |
| 2579 | { |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2580 | struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2581 | int ret; |
| 2582 | |
Jaegeuk Kim | 2c4e0c5 | 2019-12-03 17:31:00 -0800 | [diff] [blame] | 2583 | down_read_nested(&sbi->quota_sem, SINGLE_DEPTH_NESTING); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2584 | ret = dquot_commit(dquot); |
| 2585 | if (ret < 0) |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2586 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
| 2587 | up_read(&sbi->quota_sem); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2588 | return ret; |
| 2589 | } |
| 2590 | |
| 2591 | static int f2fs_dquot_acquire(struct dquot *dquot) |
| 2592 | { |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2593 | struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2594 | int ret; |
| 2595 | |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2596 | down_read(&sbi->quota_sem); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2597 | ret = dquot_acquire(dquot); |
| 2598 | if (ret < 0) |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2599 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
| 2600 | up_read(&sbi->quota_sem); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2601 | return ret; |
| 2602 | } |
| 2603 | |
| 2604 | static int f2fs_dquot_release(struct dquot *dquot) |
| 2605 | { |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2606 | struct f2fs_sb_info *sbi = F2FS_SB(dquot->dq_sb); |
Jaegeuk Kim | 2c4e0c5 | 2019-12-03 17:31:00 -0800 | [diff] [blame] | 2607 | int ret = dquot_release(dquot); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2608 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2609 | if (ret < 0) |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2610 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2611 | return ret; |
| 2612 | } |
| 2613 | |
| 2614 | static int f2fs_dquot_mark_dquot_dirty(struct dquot *dquot) |
| 2615 | { |
| 2616 | struct super_block *sb = dquot->dq_sb; |
| 2617 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Jaegeuk Kim | 2c4e0c5 | 2019-12-03 17:31:00 -0800 | [diff] [blame] | 2618 | int ret = dquot_mark_dquot_dirty(dquot); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2619 | |
| 2620 | /* if we are using journalled quota */ |
| 2621 | if (is_journalled_quota(sbi)) |
| 2622 | set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH); |
| 2623 | |
| 2624 | return ret; |
| 2625 | } |
| 2626 | |
| 2627 | static int f2fs_dquot_commit_info(struct super_block *sb, int type) |
| 2628 | { |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2629 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
Jaegeuk Kim | 2c4e0c5 | 2019-12-03 17:31:00 -0800 | [diff] [blame] | 2630 | int ret = dquot_commit_info(sb, type); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2631 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2632 | if (ret < 0) |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 2633 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2634 | return ret; |
| 2635 | } |
Sheng Yong | 26b5a07 | 2018-10-12 18:49:26 +0800 | [diff] [blame] | 2636 | |
Wei Yongjun | 94b1e10 | 2018-01-05 09:41:20 +0000 | [diff] [blame] | 2637 | static int f2fs_get_projid(struct inode *inode, kprojid_t *projid) |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 2638 | { |
| 2639 | *projid = F2FS_I(inode)->i_projid; |
| 2640 | return 0; |
| 2641 | } |
| 2642 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2643 | static const struct dquot_operations f2fs_quota_operations = { |
| 2644 | .get_reserved_space = f2fs_get_reserved_space, |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2645 | .write_dquot = f2fs_dquot_commit, |
| 2646 | .acquire_dquot = f2fs_dquot_acquire, |
| 2647 | .release_dquot = f2fs_dquot_release, |
| 2648 | .mark_dirty = f2fs_dquot_mark_dquot_dirty, |
| 2649 | .write_info = f2fs_dquot_commit_info, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2650 | .alloc_dquot = dquot_alloc, |
| 2651 | .destroy_dquot = dquot_destroy, |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 2652 | .get_projid = f2fs_get_projid, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2653 | .get_next_id = dquot_get_next_id, |
| 2654 | }; |
| 2655 | |
| 2656 | static const struct quotactl_ops f2fs_quotactl_ops = { |
| 2657 | .quota_on = f2fs_quota_on, |
| 2658 | .quota_off = f2fs_quota_off, |
| 2659 | .quota_sync = f2fs_quota_sync, |
| 2660 | .get_state = dquot_get_state, |
| 2661 | .set_info = dquot_set_dqinfo, |
| 2662 | .get_dqblk = dquot_get_dqblk, |
| 2663 | .set_dqblk = dquot_set_dqblk, |
| 2664 | .get_nextdqblk = dquot_get_next_dqblk, |
| 2665 | }; |
| 2666 | #else |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 2667 | int f2fs_quota_sync(struct super_block *sb, int type) |
| 2668 | { |
| 2669 | return 0; |
| 2670 | } |
| 2671 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 2672 | void f2fs_quota_off_umount(struct super_block *sb) |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2673 | { |
| 2674 | } |
| 2675 | #endif |
| 2676 | |
Arvind Yadav | f62fc9f | 2017-08-31 15:06:24 +0530 | [diff] [blame] | 2677 | static const struct super_operations f2fs_sops = { |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2678 | .alloc_inode = f2fs_alloc_inode, |
Al Viro | d01718a | 2019-04-15 19:29:14 -0400 | [diff] [blame] | 2679 | .free_inode = f2fs_free_inode, |
Jaegeuk Kim | 531ad7d | 2013-04-30 11:33:27 +0900 | [diff] [blame] | 2680 | .drop_inode = f2fs_drop_inode, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2681 | .write_inode = f2fs_write_inode, |
Jaegeuk Kim | b378387 | 2013-06-10 09:17:01 +0900 | [diff] [blame] | 2682 | .dirty_inode = f2fs_dirty_inode, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2683 | .show_options = f2fs_show_options, |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 2684 | #ifdef CONFIG_QUOTA |
| 2685 | .quota_read = f2fs_quota_read, |
| 2686 | .quota_write = f2fs_quota_write, |
| 2687 | .get_dquots = f2fs_get_dquots, |
| 2688 | #endif |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2689 | .evict_inode = f2fs_evict_inode, |
| 2690 | .put_super = f2fs_put_super, |
| 2691 | .sync_fs = f2fs_sync_fs, |
Changman Lee | d6212a5 | 2013-01-29 18:30:07 +0900 | [diff] [blame] | 2692 | .freeze_fs = f2fs_freeze, |
| 2693 | .unfreeze_fs = f2fs_unfreeze, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2694 | .statfs = f2fs_statfs, |
Namjae Jeon | 696c018 | 2013-06-16 09:48:48 +0900 | [diff] [blame] | 2695 | .remount_fs = f2fs_remount, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2696 | }; |
| 2697 | |
Chandan Rajendra | 643fa96 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 2698 | #ifdef CONFIG_FS_ENCRYPTION |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 2699 | static int f2fs_get_context(struct inode *inode, void *ctx, size_t len) |
| 2700 | { |
| 2701 | return f2fs_getxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, |
| 2702 | F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, |
| 2703 | ctx, len, NULL); |
| 2704 | } |
| 2705 | |
| 2706 | static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len, |
| 2707 | void *fs_data) |
| 2708 | { |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 2709 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 2710 | |
| 2711 | /* |
| 2712 | * Encrypting the root directory is not allowed because fsck |
| 2713 | * expects lost+found directory to exist and remain unencrypted |
| 2714 | * if LOST_FOUND feature is enabled. |
| 2715 | * |
| 2716 | */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2717 | if (f2fs_sb_has_lost_found(sbi) && |
Sheng Yong | b7c409d | 2018-03-15 18:51:41 +0800 | [diff] [blame] | 2718 | inode->i_ino == F2FS_ROOT_INO(sbi)) |
| 2719 | return -EPERM; |
| 2720 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 2721 | return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION, |
| 2722 | F2FS_XATTR_NAME_ENCRYPTION_CONTEXT, |
| 2723 | ctx, len, fs_data, XATTR_CREATE); |
| 2724 | } |
| 2725 | |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 2726 | static const union fscrypt_policy *f2fs_get_dummy_policy(struct super_block *sb) |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 2727 | { |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 2728 | return F2FS_OPTION(F2FS_SB(sb)).dummy_enc_policy.policy; |
Sheng Yong | ff62af2 | 2018-03-15 18:51:42 +0800 | [diff] [blame] | 2729 | } |
| 2730 | |
Eric Biggers | 0eee17e | 2019-10-24 14:54:38 -0700 | [diff] [blame] | 2731 | static bool f2fs_has_stable_inodes(struct super_block *sb) |
| 2732 | { |
| 2733 | return true; |
| 2734 | } |
| 2735 | |
| 2736 | static void f2fs_get_ino_and_lblk_bits(struct super_block *sb, |
| 2737 | int *ino_bits_ret, int *lblk_bits_ret) |
| 2738 | { |
| 2739 | *ino_bits_ret = 8 * sizeof(nid_t); |
| 2740 | *lblk_bits_ret = 8 * sizeof(block_t); |
| 2741 | } |
| 2742 | |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 2743 | static int f2fs_get_num_devices(struct super_block *sb) |
| 2744 | { |
| 2745 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 2746 | |
| 2747 | if (f2fs_is_multi_device(sbi)) |
| 2748 | return sbi->s_ndevs; |
| 2749 | return 1; |
| 2750 | } |
| 2751 | |
| 2752 | static void f2fs_get_devices(struct super_block *sb, |
| 2753 | struct request_queue **devs) |
| 2754 | { |
| 2755 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 2756 | int i; |
| 2757 | |
| 2758 | for (i = 0; i < sbi->s_ndevs; i++) |
| 2759 | devs[i] = bdev_get_queue(FDEV(i).bdev); |
| 2760 | } |
| 2761 | |
Eric Biggers | 6f69f0e | 2017-02-07 12:42:10 -0800 | [diff] [blame] | 2762 | static const struct fscrypt_operations f2fs_cryptops = { |
Eric Biggers | 0eee17e | 2019-10-24 14:54:38 -0700 | [diff] [blame] | 2763 | .key_prefix = "f2fs:", |
| 2764 | .get_context = f2fs_get_context, |
| 2765 | .set_context = f2fs_set_context, |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 2766 | .get_dummy_policy = f2fs_get_dummy_policy, |
Eric Biggers | 0eee17e | 2019-10-24 14:54:38 -0700 | [diff] [blame] | 2767 | .empty_dir = f2fs_empty_dir, |
| 2768 | .max_namelen = F2FS_NAME_LEN, |
| 2769 | .has_stable_inodes = f2fs_has_stable_inodes, |
| 2770 | .get_ino_and_lblk_bits = f2fs_get_ino_and_lblk_bits, |
Satya Tangirala | 27aacd2 | 2020-07-02 01:56:06 +0000 | [diff] [blame] | 2771 | .get_num_devices = f2fs_get_num_devices, |
| 2772 | .get_devices = f2fs_get_devices, |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 2773 | }; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 2774 | #endif |
| 2775 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2776 | static struct inode *f2fs_nfs_get_inode(struct super_block *sb, |
| 2777 | u64 ino, u32 generation) |
| 2778 | { |
| 2779 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 2780 | struct inode *inode; |
| 2781 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 2782 | if (f2fs_check_nid_range(sbi, ino)) |
Chao Yu | 910bb12 | 2014-03-12 17:08:36 +0800 | [diff] [blame] | 2783 | return ERR_PTR(-ESTALE); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2784 | |
| 2785 | /* |
| 2786 | * f2fs_iget isn't quite right if the inode is currently unallocated! |
| 2787 | * However f2fs_iget currently does appropriate checks to handle stale |
| 2788 | * inodes so everything is OK. |
| 2789 | */ |
| 2790 | inode = f2fs_iget(sb, ino); |
| 2791 | if (IS_ERR(inode)) |
| 2792 | return ERR_CAST(inode); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 2793 | if (unlikely(generation && inode->i_generation != generation)) { |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2794 | /* we didn't find the right inode.. */ |
| 2795 | iput(inode); |
| 2796 | return ERR_PTR(-ESTALE); |
| 2797 | } |
| 2798 | return inode; |
| 2799 | } |
| 2800 | |
| 2801 | static struct dentry *f2fs_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 2802 | int fh_len, int fh_type) |
| 2803 | { |
| 2804 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 2805 | f2fs_nfs_get_inode); |
| 2806 | } |
| 2807 | |
| 2808 | static struct dentry *f2fs_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 2809 | int fh_len, int fh_type) |
| 2810 | { |
| 2811 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 2812 | f2fs_nfs_get_inode); |
| 2813 | } |
| 2814 | |
| 2815 | static const struct export_operations f2fs_export_ops = { |
| 2816 | .fh_to_dentry = f2fs_fh_to_dentry, |
| 2817 | .fh_to_parent = f2fs_fh_to_parent, |
| 2818 | .get_parent = f2fs_get_parent, |
| 2819 | }; |
| 2820 | |
Chengguang Xu | 6d1451b | 2021-01-13 13:21:54 +0800 | [diff] [blame] | 2821 | loff_t max_file_blocks(struct inode *inode) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2822 | { |
Chao Yu | 7a2af76 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2823 | loff_t result = 0; |
Chengguang Xu | 6d1451b | 2021-01-13 13:21:54 +0800 | [diff] [blame] | 2824 | loff_t leaf_count; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2825 | |
Chao Yu | 7a2af76 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2826 | /* |
| 2827 | * note: previously, result is equal to (DEF_ADDRS_PER_INODE - |
Chao Yu | 6afc662 | 2017-09-06 21:59:50 +0800 | [diff] [blame] | 2828 | * DEFAULT_INLINE_XATTR_ADDRS), but now f2fs try to reserve more |
Chao Yu | 7a2af76 | 2017-07-19 00:19:06 +0800 | [diff] [blame] | 2829 | * space in inode.i_addr, it will be more safe to reassign |
| 2830 | * result as zero. |
| 2831 | */ |
| 2832 | |
Chengguang Xu | 6d1451b | 2021-01-13 13:21:54 +0800 | [diff] [blame] | 2833 | if (inode && f2fs_compressed_file(inode)) |
| 2834 | leaf_count = ADDRS_PER_BLOCK(inode); |
| 2835 | else |
| 2836 | leaf_count = DEF_ADDRS_PER_BLOCK; |
| 2837 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2838 | /* two direct node blocks */ |
| 2839 | result += (leaf_count * 2); |
| 2840 | |
| 2841 | /* two indirect node blocks */ |
| 2842 | leaf_count *= NIDS_PER_BLOCK; |
| 2843 | result += (leaf_count * 2); |
| 2844 | |
| 2845 | /* one double indirect node block */ |
| 2846 | leaf_count *= NIDS_PER_BLOCK; |
| 2847 | result += leaf_count; |
| 2848 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2849 | return result; |
| 2850 | } |
| 2851 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2852 | static int __f2fs_commit_super(struct buffer_head *bh, |
| 2853 | struct f2fs_super_block *super) |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2854 | { |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2855 | lock_buffer(bh); |
| 2856 | if (super) |
| 2857 | memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2858 | set_buffer_dirty(bh); |
| 2859 | unlock_buffer(bh); |
| 2860 | |
| 2861 | /* it's rare case, we can do fua all the time */ |
Jan Kara | 3adc5fcb | 2017-05-02 17:03:47 +0200 | [diff] [blame] | 2862 | return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 2865 | static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2866 | struct buffer_head *bh) |
| 2867 | { |
| 2868 | struct f2fs_super_block *raw_super = (struct f2fs_super_block *) |
| 2869 | (bh->b_data + F2FS_SUPER_OFFSET); |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 2870 | struct super_block *sb = sbi->sb; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2871 | u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr); |
| 2872 | u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr); |
| 2873 | u32 sit_blkaddr = le32_to_cpu(raw_super->sit_blkaddr); |
| 2874 | u32 nat_blkaddr = le32_to_cpu(raw_super->nat_blkaddr); |
| 2875 | u32 ssa_blkaddr = le32_to_cpu(raw_super->ssa_blkaddr); |
| 2876 | u32 main_blkaddr = le32_to_cpu(raw_super->main_blkaddr); |
| 2877 | u32 segment_count_ckpt = le32_to_cpu(raw_super->segment_count_ckpt); |
| 2878 | u32 segment_count_sit = le32_to_cpu(raw_super->segment_count_sit); |
| 2879 | u32 segment_count_nat = le32_to_cpu(raw_super->segment_count_nat); |
| 2880 | u32 segment_count_ssa = le32_to_cpu(raw_super->segment_count_ssa); |
| 2881 | u32 segment_count_main = le32_to_cpu(raw_super->segment_count_main); |
| 2882 | u32 segment_count = le32_to_cpu(raw_super->segment_count); |
| 2883 | u32 log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2884 | u64 main_end_blkaddr = main_blkaddr + |
| 2885 | (segment_count_main << log_blocks_per_seg); |
| 2886 | u64 seg_end_blkaddr = segment0_blkaddr + |
| 2887 | (segment_count << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2888 | |
| 2889 | if (segment0_blkaddr != cp_blkaddr) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2890 | f2fs_info(sbi, "Mismatch start address, segment0(%u) cp_blkaddr(%u)", |
| 2891 | segment0_blkaddr, cp_blkaddr); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2892 | return true; |
| 2893 | } |
| 2894 | |
| 2895 | if (cp_blkaddr + (segment_count_ckpt << log_blocks_per_seg) != |
| 2896 | sit_blkaddr) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2897 | f2fs_info(sbi, "Wrong CP boundary, start(%u) end(%u) blocks(%u)", |
| 2898 | cp_blkaddr, sit_blkaddr, |
| 2899 | segment_count_ckpt << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2900 | return true; |
| 2901 | } |
| 2902 | |
| 2903 | if (sit_blkaddr + (segment_count_sit << log_blocks_per_seg) != |
| 2904 | nat_blkaddr) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2905 | f2fs_info(sbi, "Wrong SIT boundary, start(%u) end(%u) blocks(%u)", |
| 2906 | sit_blkaddr, nat_blkaddr, |
| 2907 | segment_count_sit << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2908 | return true; |
| 2909 | } |
| 2910 | |
| 2911 | if (nat_blkaddr + (segment_count_nat << log_blocks_per_seg) != |
| 2912 | ssa_blkaddr) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2913 | f2fs_info(sbi, "Wrong NAT boundary, start(%u) end(%u) blocks(%u)", |
| 2914 | nat_blkaddr, ssa_blkaddr, |
| 2915 | segment_count_nat << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2916 | return true; |
| 2917 | } |
| 2918 | |
| 2919 | if (ssa_blkaddr + (segment_count_ssa << log_blocks_per_seg) != |
| 2920 | main_blkaddr) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2921 | f2fs_info(sbi, "Wrong SSA boundary, start(%u) end(%u) blocks(%u)", |
| 2922 | ssa_blkaddr, main_blkaddr, |
| 2923 | segment_count_ssa << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2924 | return true; |
| 2925 | } |
| 2926 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2927 | if (main_end_blkaddr > seg_end_blkaddr) { |
Wang Xiaojun | d89f589 | 2020-09-18 08:31:24 +0800 | [diff] [blame] | 2928 | f2fs_info(sbi, "Wrong MAIN_AREA boundary, start(%u) end(%llu) block(%u)", |
| 2929 | main_blkaddr, seg_end_blkaddr, |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2930 | segment_count_main << log_blocks_per_seg); |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2931 | return true; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2932 | } else if (main_end_blkaddr < seg_end_blkaddr) { |
| 2933 | int err = 0; |
| 2934 | char *res; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2935 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2936 | /* fix in-memory information all the time */ |
| 2937 | raw_super->segment_count = cpu_to_le32((main_end_blkaddr - |
| 2938 | segment0_blkaddr) >> log_blocks_per_seg); |
| 2939 | |
| 2940 | if (f2fs_readonly(sb) || bdev_read_only(sb->s_bdev)) { |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 2941 | set_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2942 | res = "internally"; |
| 2943 | } else { |
| 2944 | err = __f2fs_commit_super(bh, NULL); |
| 2945 | res = err ? "failed" : "done"; |
| 2946 | } |
Wang Xiaojun | d89f589 | 2020-09-18 08:31:24 +0800 | [diff] [blame] | 2947 | f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)", |
| 2948 | res, main_blkaddr, seg_end_blkaddr, |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2949 | segment_count_main << log_blocks_per_seg); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2950 | if (err) |
| 2951 | return true; |
| 2952 | } |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2953 | return false; |
| 2954 | } |
| 2955 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 2956 | static int sanity_check_raw_super(struct f2fs_sb_info *sbi, |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2957 | struct buffer_head *bh) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2958 | { |
Wang Xiaojun | f99ba9a | 2020-09-17 19:11:58 +0800 | [diff] [blame] | 2959 | block_t segment_count, segs_per_sec, secs_per_zone, segment_count_main; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 2960 | block_t total_sections, blocks_per_seg; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 2961 | struct f2fs_super_block *raw_super = (struct f2fs_super_block *) |
| 2962 | (bh->b_data + F2FS_SUPER_OFFSET); |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 2963 | size_t crc_offset = 0; |
| 2964 | __u32 crc = 0; |
| 2965 | |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 2966 | if (le32_to_cpu(raw_super->magic) != F2FS_SUPER_MAGIC) { |
| 2967 | f2fs_info(sbi, "Magic Mismatch, valid(0x%x) - read(0x%x)", |
| 2968 | F2FS_SUPER_MAGIC, le32_to_cpu(raw_super->magic)); |
| 2969 | return -EINVAL; |
| 2970 | } |
| 2971 | |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 2972 | /* Check checksum_offset and crc in superblock */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 2973 | if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_SB_CHKSUM)) { |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 2974 | crc_offset = le32_to_cpu(raw_super->checksum_offset); |
| 2975 | if (crc_offset != |
| 2976 | offsetof(struct f2fs_super_block, crc)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2977 | f2fs_info(sbi, "Invalid SB checksum offset: %zu", |
| 2978 | crc_offset); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 2979 | return -EFSCORRUPTED; |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 2980 | } |
| 2981 | crc = le32_to_cpu(raw_super->crc); |
| 2982 | if (!f2fs_crc_valid(sbi, crc, raw_super, crc_offset)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2983 | f2fs_info(sbi, "Invalid SB checksum value: %u", crc); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 2984 | return -EFSCORRUPTED; |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 2985 | } |
| 2986 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2987 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 2988 | /* Currently, support only 4KB block size */ |
Chao Yu | e584bbe | 2020-12-09 16:49:36 +0800 | [diff] [blame] | 2989 | if (le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE_BITS) { |
| 2990 | f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", |
| 2991 | le32_to_cpu(raw_super->log_blocksize), |
| 2992 | F2FS_BLKSIZE_BITS); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 2993 | return -EFSCORRUPTED; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 2994 | } |
majianpeng | 5c9b469 | 2013-02-01 19:07:57 +0800 | [diff] [blame] | 2995 | |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 2996 | /* check log blocks per segment */ |
| 2997 | if (le32_to_cpu(raw_super->log_blocks_per_seg) != 9) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 2998 | f2fs_info(sbi, "Invalid log blocks per segment (%u)", |
| 2999 | le32_to_cpu(raw_super->log_blocks_per_seg)); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3000 | return -EFSCORRUPTED; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 3001 | } |
| 3002 | |
Chao Yu | 55cf9cb | 2014-09-15 18:01:10 +0800 | [diff] [blame] | 3003 | /* Currently, support 512/1024/2048/4096 bytes sector size */ |
| 3004 | if (le32_to_cpu(raw_super->log_sectorsize) > |
| 3005 | F2FS_MAX_LOG_SECTOR_SIZE || |
| 3006 | le32_to_cpu(raw_super->log_sectorsize) < |
| 3007 | F2FS_MIN_LOG_SECTOR_SIZE) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3008 | f2fs_info(sbi, "Invalid log sectorsize (%u)", |
| 3009 | le32_to_cpu(raw_super->log_sectorsize)); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3010 | return -EFSCORRUPTED; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3011 | } |
Chao Yu | 55cf9cb | 2014-09-15 18:01:10 +0800 | [diff] [blame] | 3012 | if (le32_to_cpu(raw_super->log_sectors_per_block) + |
| 3013 | le32_to_cpu(raw_super->log_sectorsize) != |
| 3014 | F2FS_MAX_LOG_SECTOR_SIZE) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3015 | f2fs_info(sbi, "Invalid log sectors per block(%u) log sectorsize(%u)", |
| 3016 | le32_to_cpu(raw_super->log_sectors_per_block), |
| 3017 | le32_to_cpu(raw_super->log_sectorsize)); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3018 | return -EFSCORRUPTED; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3019 | } |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 3020 | |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3021 | segment_count = le32_to_cpu(raw_super->segment_count); |
Wang Xiaojun | f99ba9a | 2020-09-17 19:11:58 +0800 | [diff] [blame] | 3022 | segment_count_main = le32_to_cpu(raw_super->segment_count_main); |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3023 | segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); |
| 3024 | secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); |
| 3025 | total_sections = le32_to_cpu(raw_super->section_count); |
| 3026 | |
| 3027 | /* blocks_per_seg should be 512, given the above check */ |
| 3028 | blocks_per_seg = 1 << le32_to_cpu(raw_super->log_blocks_per_seg); |
| 3029 | |
| 3030 | if (segment_count > F2FS_MAX_SEGMENT || |
| 3031 | segment_count < F2FS_MIN_SEGMENTS) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3032 | f2fs_info(sbi, "Invalid segment count (%u)", segment_count); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3033 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Wang Xiaojun | f99ba9a | 2020-09-17 19:11:58 +0800 | [diff] [blame] | 3036 | if (total_sections > segment_count_main || total_sections < 1 || |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3037 | segs_per_sec > segment_count || !segs_per_sec) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3038 | f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)", |
| 3039 | segment_count, total_sections, segs_per_sec); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3040 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Chao Yu | 3a22e9a | 2020-09-29 09:23:34 +0800 | [diff] [blame] | 3043 | if (segment_count_main != total_sections * segs_per_sec) { |
| 3044 | f2fs_info(sbi, "Invalid segment/section count (%u != %u * %u)", |
| 3045 | segment_count_main, total_sections, segs_per_sec); |
| 3046 | return -EFSCORRUPTED; |
| 3047 | } |
| 3048 | |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3049 | if ((segment_count / segs_per_sec) < total_sections) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3050 | f2fs_info(sbi, "Small segment_count (%u < %u * %u)", |
| 3051 | segment_count, segs_per_sec, total_sections); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3052 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
Martin Blumenstingl | 8896006 | 2018-12-22 11:22:26 +0100 | [diff] [blame] | 3055 | if (segment_count > (le64_to_cpu(raw_super->block_count) >> 9)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3056 | f2fs_info(sbi, "Wrong segment_count / block_count (%u > %llu)", |
| 3057 | segment_count, le64_to_cpu(raw_super->block_count)); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3058 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
Qiuyang Sun | 9f701f6 | 2019-09-23 12:22:35 +0800 | [diff] [blame] | 3061 | if (RDEV(0).path[0]) { |
| 3062 | block_t dev_seg_count = le32_to_cpu(RDEV(0).total_segments); |
| 3063 | int i = 1; |
| 3064 | |
| 3065 | while (i < MAX_DEVICES && RDEV(i).path[0]) { |
| 3066 | dev_seg_count += le32_to_cpu(RDEV(i).total_segments); |
| 3067 | i++; |
| 3068 | } |
| 3069 | if (segment_count != dev_seg_count) { |
| 3070 | f2fs_info(sbi, "Segment count (%u) mismatch with total segments from devices (%u)", |
| 3071 | segment_count, dev_seg_count); |
| 3072 | return -EFSCORRUPTED; |
| 3073 | } |
Chao Yu | 07eb1d6 | 2020-09-21 20:53:13 +0800 | [diff] [blame] | 3074 | } else { |
| 3075 | if (__F2FS_HAS_FEATURE(raw_super, F2FS_FEATURE_BLKZONED) && |
| 3076 | !bdev_is_zoned(sbi->sb->s_bdev)) { |
| 3077 | f2fs_info(sbi, "Zoned block device path is missing"); |
| 3078 | return -EFSCORRUPTED; |
| 3079 | } |
Qiuyang Sun | 9f701f6 | 2019-09-23 12:22:35 +0800 | [diff] [blame] | 3080 | } |
| 3081 | |
Chao Yu | 42bf546 | 2018-06-23 00:12:36 +0800 | [diff] [blame] | 3082 | if (secs_per_zone > total_sections || !secs_per_zone) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3083 | f2fs_info(sbi, "Wrong secs_per_zone / total_sections (%u, %u)", |
| 3084 | secs_per_zone, total_sections); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3085 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3086 | } |
| 3087 | if (le32_to_cpu(raw_super->extension_count) > F2FS_MAX_EXTENSION || |
| 3088 | raw_super->hot_ext_count > F2FS_MAX_EXTENSION || |
| 3089 | (le32_to_cpu(raw_super->extension_count) + |
| 3090 | raw_super->hot_ext_count) > F2FS_MAX_EXTENSION) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3091 | f2fs_info(sbi, "Corrupted extension count (%u + %u > %u)", |
| 3092 | le32_to_cpu(raw_super->extension_count), |
| 3093 | raw_super->hot_ext_count, |
| 3094 | F2FS_MAX_EXTENSION); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3095 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | if (le32_to_cpu(raw_super->cp_payload) > |
| 3099 | (blocks_per_seg - F2FS_CP_PACKS)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3100 | f2fs_info(sbi, "Insane cp_payload (%u > %u)", |
| 3101 | le32_to_cpu(raw_super->cp_payload), |
| 3102 | blocks_per_seg - F2FS_CP_PACKS); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3103 | return -EFSCORRUPTED; |
Jaegeuk Kim | 0cfe75c | 2018-04-27 19:03:22 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 3106 | /* check reserved ino info */ |
| 3107 | if (le32_to_cpu(raw_super->node_ino) != 1 || |
| 3108 | le32_to_cpu(raw_super->meta_ino) != 2 || |
| 3109 | le32_to_cpu(raw_super->root_ino) != 3) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3110 | f2fs_info(sbi, "Invalid Fs Meta Ino: node(%u) meta(%u) root(%u)", |
| 3111 | le32_to_cpu(raw_super->node_ino), |
| 3112 | le32_to_cpu(raw_super->meta_ino), |
| 3113 | le32_to_cpu(raw_super->root_ino)); |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3114 | return -EFSCORRUPTED; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3118 | if (sanity_check_area_boundary(sbi, bh)) |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3119 | return -EFSCORRUPTED; |
Chao Yu | 9a59b62 | 2015-12-15 09:58:18 +0800 | [diff] [blame] | 3120 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3121 | return 0; |
| 3122 | } |
| 3123 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3124 | int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3125 | { |
| 3126 | unsigned int total, fsmeta; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 3127 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
| 3128 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 3129 | unsigned int ovp_segments, reserved_segments; |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 3130 | unsigned int main_segs, blocks_per_seg; |
Chao Yu | c77ec61 | 2018-06-23 11:25:19 +0800 | [diff] [blame] | 3131 | unsigned int sit_segs, nat_segs; |
| 3132 | unsigned int sit_bitmap_size, nat_bitmap_size; |
| 3133 | unsigned int log_blocks_per_seg; |
Chao Yu | 9dc956b | 2018-06-27 18:05:54 +0800 | [diff] [blame] | 3134 | unsigned int segment_count_main; |
Chao Yu | e494c2f | 2018-08-01 19:16:11 +0800 | [diff] [blame] | 3135 | unsigned int cp_pack_start_sum, cp_payload; |
Chao Yu | 7b63f72 | 2019-04-15 15:30:50 +0800 | [diff] [blame] | 3136 | block_t user_block_count, valid_user_blocks; |
| 3137 | block_t avail_node_count, valid_node_count; |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3138 | int i, j; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3139 | |
| 3140 | total = le32_to_cpu(raw_super->segment_count); |
| 3141 | fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); |
Chao Yu | c77ec61 | 2018-06-23 11:25:19 +0800 | [diff] [blame] | 3142 | sit_segs = le32_to_cpu(raw_super->segment_count_sit); |
| 3143 | fsmeta += sit_segs; |
| 3144 | nat_segs = le32_to_cpu(raw_super->segment_count_nat); |
| 3145 | fsmeta += nat_segs; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3146 | fsmeta += le32_to_cpu(ckpt->rsvd_segment_count); |
| 3147 | fsmeta += le32_to_cpu(raw_super->segment_count_ssa); |
| 3148 | |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 3149 | if (unlikely(fsmeta >= total)) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3150 | return 1; |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 3151 | |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 3152 | ovp_segments = le32_to_cpu(ckpt->overprov_segment_count); |
| 3153 | reserved_segments = le32_to_cpu(ckpt->rsvd_segment_count); |
| 3154 | |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3155 | if (!f2fs_sb_has_readonly(sbi) && |
| 3156 | unlikely(fsmeta < F2FS_MIN_META_SEGMENTS || |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 3157 | ovp_segments == 0 || reserved_segments == 0)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3158 | f2fs_err(sbi, "Wrong layout: check mkfs.f2fs version"); |
Jaegeuk Kim | 2040fce8 | 2016-12-05 13:56:04 -0800 | [diff] [blame] | 3159 | return 1; |
| 3160 | } |
Chao Yu | 9dc956b | 2018-06-27 18:05:54 +0800 | [diff] [blame] | 3161 | user_block_count = le64_to_cpu(ckpt->user_block_count); |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3162 | segment_count_main = le32_to_cpu(raw_super->segment_count_main) + |
| 3163 | (f2fs_sb_has_readonly(sbi) ? 1 : 0); |
Chao Yu | 9dc956b | 2018-06-27 18:05:54 +0800 | [diff] [blame] | 3164 | log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
| 3165 | if (!user_block_count || user_block_count >= |
| 3166 | segment_count_main << log_blocks_per_seg) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3167 | f2fs_err(sbi, "Wrong user_block_count: %u", |
| 3168 | user_block_count); |
Chao Yu | 9dc956b | 2018-06-27 18:05:54 +0800 | [diff] [blame] | 3169 | return 1; |
| 3170 | } |
| 3171 | |
Chao Yu | 7b63f72 | 2019-04-15 15:30:50 +0800 | [diff] [blame] | 3172 | valid_user_blocks = le64_to_cpu(ckpt->valid_block_count); |
| 3173 | if (valid_user_blocks > user_block_count) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3174 | f2fs_err(sbi, "Wrong valid_user_blocks: %u, user_block_count: %u", |
| 3175 | valid_user_blocks, user_block_count); |
Chao Yu | 7b63f72 | 2019-04-15 15:30:50 +0800 | [diff] [blame] | 3176 | return 1; |
| 3177 | } |
| 3178 | |
| 3179 | valid_node_count = le32_to_cpu(ckpt->valid_node_count); |
Chao Yu | 27cae0b | 2019-08-05 18:27:25 +0800 | [diff] [blame] | 3180 | avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
Chao Yu | 7b63f72 | 2019-04-15 15:30:50 +0800 | [diff] [blame] | 3181 | if (valid_node_count > avail_node_count) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3182 | f2fs_err(sbi, "Wrong valid_node_count: %u, avail_node_count: %u", |
| 3183 | valid_node_count, avail_node_count); |
Chao Yu | 7b63f72 | 2019-04-15 15:30:50 +0800 | [diff] [blame] | 3184 | return 1; |
| 3185 | } |
| 3186 | |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 3187 | main_segs = le32_to_cpu(raw_super->segment_count_main); |
| 3188 | blocks_per_seg = sbi->blocks_per_seg; |
| 3189 | |
| 3190 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { |
| 3191 | if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs || |
| 3192 | le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg) |
| 3193 | return 1; |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3194 | |
| 3195 | if (f2fs_sb_has_readonly(sbi)) |
| 3196 | goto check_data; |
| 3197 | |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3198 | for (j = i + 1; j < NR_CURSEG_NODE_TYPE; j++) { |
| 3199 | if (le32_to_cpu(ckpt->cur_node_segno[i]) == |
| 3200 | le32_to_cpu(ckpt->cur_node_segno[j])) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3201 | f2fs_err(sbi, "Node segment (%u, %u) has the same segno: %u", |
| 3202 | i, j, |
| 3203 | le32_to_cpu(ckpt->cur_node_segno[i])); |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3204 | return 1; |
| 3205 | } |
| 3206 | } |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 3207 | } |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3208 | check_data: |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 3209 | for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { |
| 3210 | if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs || |
| 3211 | le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg) |
| 3212 | return 1; |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3213 | |
| 3214 | if (f2fs_sb_has_readonly(sbi)) |
| 3215 | goto skip_cross; |
| 3216 | |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3217 | for (j = i + 1; j < NR_CURSEG_DATA_TYPE; j++) { |
| 3218 | if (le32_to_cpu(ckpt->cur_data_segno[i]) == |
| 3219 | le32_to_cpu(ckpt->cur_data_segno[j])) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3220 | f2fs_err(sbi, "Data segment (%u, %u) has the same segno: %u", |
| 3221 | i, j, |
| 3222 | le32_to_cpu(ckpt->cur_data_segno[i])); |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3223 | return 1; |
| 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { |
Surbhi Palande | 1166c1f | 2019-08-23 15:40:45 -0700 | [diff] [blame] | 3228 | for (j = 0; j < NR_CURSEG_DATA_TYPE; j++) { |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3229 | if (le32_to_cpu(ckpt->cur_node_segno[i]) == |
| 3230 | le32_to_cpu(ckpt->cur_data_segno[j])) { |
Surbhi Palande | 1166c1f | 2019-08-23 15:40:45 -0700 | [diff] [blame] | 3231 | f2fs_err(sbi, "Node segment (%u) and Data segment (%u) has the same segno: %u", |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3232 | i, j, |
| 3233 | le32_to_cpu(ckpt->cur_node_segno[i])); |
Chao Yu | 042be0f | 2018-09-06 20:34:12 +0800 | [diff] [blame] | 3234 | return 1; |
| 3235 | } |
| 3236 | } |
Jin Qian | 15d3042 | 2017-05-15 10:45:08 -0700 | [diff] [blame] | 3237 | } |
Jaegeuk Kim | a7d9fe3 | 2021-05-21 01:32:53 -0700 | [diff] [blame^] | 3238 | skip_cross: |
Chao Yu | c77ec61 | 2018-06-23 11:25:19 +0800 | [diff] [blame] | 3239 | sit_bitmap_size = le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); |
| 3240 | nat_bitmap_size = le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); |
Chao Yu | c77ec61 | 2018-06-23 11:25:19 +0800 | [diff] [blame] | 3241 | |
| 3242 | if (sit_bitmap_size != ((sit_segs / 2) << log_blocks_per_seg) / 8 || |
| 3243 | nat_bitmap_size != ((nat_segs / 2) << log_blocks_per_seg) / 8) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3244 | f2fs_err(sbi, "Wrong bitmap size: sit: %u, nat:%u", |
| 3245 | sit_bitmap_size, nat_bitmap_size); |
Chao Yu | c77ec61 | 2018-06-23 11:25:19 +0800 | [diff] [blame] | 3246 | return 1; |
| 3247 | } |
| 3248 | |
Chao Yu | e494c2f | 2018-08-01 19:16:11 +0800 | [diff] [blame] | 3249 | cp_pack_start_sum = __start_sum_addr(sbi); |
| 3250 | cp_payload = __cp_payload(sbi); |
| 3251 | if (cp_pack_start_sum < cp_payload + 1 || |
| 3252 | cp_pack_start_sum > blocks_per_seg - 1 - |
Chao Yu | d0b9e42 | 2020-08-04 21:14:45 +0800 | [diff] [blame] | 3253 | NR_CURSEG_PERSIST_TYPE) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3254 | f2fs_err(sbi, "Wrong cp_pack_start_sum: %u", |
| 3255 | cp_pack_start_sum); |
Chao Yu | e494c2f | 2018-08-01 19:16:11 +0800 | [diff] [blame] | 3256 | return 1; |
| 3257 | } |
| 3258 | |
Chao Yu | 5dae2d3 | 2019-05-20 10:09:22 +0800 | [diff] [blame] | 3259 | if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG) && |
| 3260 | le32_to_cpu(ckpt->checksum_offset) != CP_MIN_CHKSUM_OFFSET) { |
Chao Yu | 2d00883 | 2019-07-11 09:29:15 +0800 | [diff] [blame] | 3261 | f2fs_warn(sbi, "using deprecated layout of large_nat_bitmap, " |
| 3262 | "please run fsck v1.13.0 or higher to repair, chksum_offset: %u, " |
| 3263 | "fixed with patch: \"f2fs-tools: relocate chksum_offset for large_nat_bitmap feature\"", |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3264 | le32_to_cpu(ckpt->checksum_offset)); |
Chao Yu | 5dae2d3 | 2019-05-20 10:09:22 +0800 | [diff] [blame] | 3265 | return 1; |
| 3266 | } |
| 3267 | |
Jaegeuk Kim | 1e968fd | 2014-08-11 16:49:25 -0700 | [diff] [blame] | 3268 | if (unlikely(f2fs_cp_error(sbi))) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3269 | f2fs_err(sbi, "A bug case: need to run fsck"); |
Jaegeuk Kim | 577e349 | 2013-01-24 19:56:11 +0900 | [diff] [blame] | 3270 | return 1; |
| 3271 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3272 | return 0; |
| 3273 | } |
| 3274 | |
| 3275 | static void init_sb_info(struct f2fs_sb_info *sbi) |
| 3276 | { |
| 3277 | struct f2fs_super_block *raw_super = sbi->raw_super; |
Yunlong Song | 089842d | 2018-10-24 16:09:42 +0800 | [diff] [blame] | 3278 | int i; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3279 | |
| 3280 | sbi->log_sectors_per_block = |
| 3281 | le32_to_cpu(raw_super->log_sectors_per_block); |
| 3282 | sbi->log_blocksize = le32_to_cpu(raw_super->log_blocksize); |
| 3283 | sbi->blocksize = 1 << sbi->log_blocksize; |
| 3284 | sbi->log_blocks_per_seg = le32_to_cpu(raw_super->log_blocks_per_seg); |
| 3285 | sbi->blocks_per_seg = 1 << sbi->log_blocks_per_seg; |
| 3286 | sbi->segs_per_sec = le32_to_cpu(raw_super->segs_per_sec); |
| 3287 | sbi->secs_per_zone = le32_to_cpu(raw_super->secs_per_zone); |
| 3288 | sbi->total_sections = le32_to_cpu(raw_super->section_count); |
| 3289 | sbi->total_node_count = |
| 3290 | (le32_to_cpu(raw_super->segment_count_nat) / 2) |
| 3291 | * sbi->blocks_per_seg * NAT_ENTRY_PER_BLOCK; |
Yangtao Li | b9ec109 | 2020-12-07 18:59:33 +0800 | [diff] [blame] | 3292 | F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino); |
| 3293 | F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino); |
| 3294 | F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino); |
Jaegeuk Kim | 5ec4e49 | 2013-03-31 13:26:03 +0900 | [diff] [blame] | 3295 | sbi->cur_victim_sec = NULL_SECNO; |
Chao Yu | e3080b0 | 2018-10-24 18:37:27 +0800 | [diff] [blame] | 3296 | sbi->next_victim_seg[BG_GC] = NULL_SEGNO; |
| 3297 | sbi->next_victim_seg[FG_GC] = NULL_SEGNO; |
Jaegeuk Kim | b1c57c1 | 2014-01-08 13:45:08 +0900 | [diff] [blame] | 3298 | sbi->max_victim_search = DEF_MAX_VICTIM_SEARCH; |
Chao Yu | e3080b0 | 2018-10-24 18:37:27 +0800 | [diff] [blame] | 3299 | sbi->migration_granularity = sbi->segs_per_sec; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3300 | |
Jaegeuk Kim | ab9fa66 | 2014-02-27 20:09:05 +0900 | [diff] [blame] | 3301 | sbi->dir_level = DEF_DIR_LEVEL; |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 3302 | sbi->interval_time[CP_TIME] = DEF_CP_INTERVAL; |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 3303 | sbi->interval_time[REQ_TIME] = DEF_IDLE_INTERVAL; |
Sahitya Tummala | a7d10cf | 2018-09-19 14:18:47 +0530 | [diff] [blame] | 3304 | sbi->interval_time[DISCARD_TIME] = DEF_IDLE_INTERVAL; |
| 3305 | sbi->interval_time[GC_TIME] = DEF_IDLE_INTERVAL; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 3306 | sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_INTERVAL; |
Jaegeuk Kim | 03f2c02 | 2019-01-14 10:42:11 -0800 | [diff] [blame] | 3307 | sbi->interval_time[UMOUNT_DISCARD_TIMEOUT] = |
| 3308 | DEF_UMOUNT_DISCARD_TIMEOUT; |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 3309 | clear_sbi_flag(sbi, SBI_NEED_FSCK); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 3310 | |
Jaegeuk Kim | 35782b2 | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 3311 | for (i = 0; i < NR_COUNT_TYPE; i++) |
| 3312 | atomic_set(&sbi->nr_pages[i], 0); |
| 3313 | |
Chao Yu | c29fd0c | 2018-06-04 23:20:36 +0800 | [diff] [blame] | 3314 | for (i = 0; i < META; i++) |
| 3315 | atomic_set(&sbi->wb_sync_req[i], 0); |
Jaegeuk Kim | 687de7f | 2017-03-28 18:07:38 -0700 | [diff] [blame] | 3316 | |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 3317 | INIT_LIST_HEAD(&sbi->s_list); |
| 3318 | mutex_init(&sbi->umount_mutex); |
Chao Yu | 107a805 | 2018-05-26 09:00:13 +0800 | [diff] [blame] | 3319 | init_rwsem(&sbi->io_order_lock); |
Chao Yu | aaec2b1 | 2016-09-20 11:04:18 +0800 | [diff] [blame] | 3320 | spin_lock_init(&sbi->cp_lock); |
Chao Yu | 1228b48 | 2017-09-29 13:59:39 +0800 | [diff] [blame] | 3321 | |
| 3322 | sbi->dirty_device = 0; |
| 3323 | spin_lock_init(&sbi->dev_lock); |
Chao Yu | d0d3f1b | 2018-02-11 22:53:20 +0800 | [diff] [blame] | 3324 | |
Chao Yu | 846ae67 | 2018-02-26 22:04:13 +0800 | [diff] [blame] | 3325 | init_rwsem(&sbi->sb_lock); |
Jaegeuk Kim | f5a53ed | 2019-10-18 10:06:40 -0700 | [diff] [blame] | 3326 | init_rwsem(&sbi->pin_sem); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3327 | } |
| 3328 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 3329 | static int init_percpu_info(struct f2fs_sb_info *sbi) |
| 3330 | { |
Jaegeuk Kim | 35782b2 | 2016-10-20 19:09:57 -0700 | [diff] [blame] | 3331 | int err; |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 3332 | |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 3333 | err = percpu_counter_init(&sbi->alloc_valid_block_count, 0, GFP_KERNEL); |
| 3334 | if (err) |
| 3335 | return err; |
| 3336 | |
Chao Yu | 4a70e25 | 2018-09-05 14:54:02 +0800 | [diff] [blame] | 3337 | err = percpu_counter_init(&sbi->total_valid_inode_count, 0, |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 3338 | GFP_KERNEL); |
Chao Yu | 4a70e25 | 2018-09-05 14:54:02 +0800 | [diff] [blame] | 3339 | if (err) |
| 3340 | percpu_counter_destroy(&sbi->alloc_valid_block_count); |
| 3341 | |
| 3342 | return err; |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3345 | #ifdef CONFIG_BLK_DEV_ZONED |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3346 | |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 3347 | struct f2fs_report_zones_args { |
| 3348 | struct f2fs_dev_info *dev; |
| 3349 | bool zone_cap_mismatch; |
| 3350 | }; |
| 3351 | |
| 3352 | static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx, |
| 3353 | void *data) |
| 3354 | { |
| 3355 | struct f2fs_report_zones_args *rz_args = data; |
| 3356 | |
| 3357 | if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) |
| 3358 | return 0; |
| 3359 | |
| 3360 | set_bit(idx, rz_args->dev->blkz_seq); |
| 3361 | rz_args->dev->zone_capacity_blocks[idx] = zone->capacity >> |
| 3362 | F2FS_LOG_SECTORS_PER_BLOCK; |
| 3363 | if (zone->len != zone->capacity && !rz_args->zone_cap_mismatch) |
| 3364 | rz_args->zone_cap_mismatch = true; |
| 3365 | |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3366 | return 0; |
| 3367 | } |
| 3368 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3369 | static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3370 | { |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3371 | struct block_device *bdev = FDEV(devi).bdev; |
Christoph Hellwig | a782483 | 2020-11-26 18:43:37 +0100 | [diff] [blame] | 3372 | sector_t nr_sectors = bdev_nr_sectors(bdev); |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 3373 | struct f2fs_report_zones_args rep_zone_arg; |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3374 | int ret; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3375 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3376 | if (!f2fs_sb_has_blkzoned(sbi)) |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3377 | return 0; |
| 3378 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3379 | if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 3380 | SECTOR_TO_BLOCK(bdev_zone_sectors(bdev))) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3381 | return -EINVAL; |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 3382 | sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_sectors(bdev)); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3383 | if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz != |
| 3384 | __ilog2_u32(sbi->blocks_per_blkz)) |
| 3385 | return -EINVAL; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3386 | sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3387 | FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >> |
| 3388 | sbi->log_blocks_per_blkz; |
Damien Le Moal | f99e864 | 2017-01-12 07:58:32 -0700 | [diff] [blame] | 3389 | if (nr_sectors & (bdev_zone_sectors(bdev) - 1)) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3390 | FDEV(devi).nr_blkz++; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3391 | |
Eric Biggers | 0b6d4ca | 2020-06-04 21:57:48 -0700 | [diff] [blame] | 3392 | FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, |
Damien Le Moal | 95175da | 2019-03-16 09:13:07 +0900 | [diff] [blame] | 3393 | BITS_TO_LONGS(FDEV(devi).nr_blkz) |
| 3394 | * sizeof(unsigned long), |
| 3395 | GFP_KERNEL); |
| 3396 | if (!FDEV(devi).blkz_seq) |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3397 | return -ENOMEM; |
| 3398 | |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 3399 | /* Get block zones type and zone-capacity */ |
| 3400 | FDEV(devi).zone_capacity_blocks = f2fs_kzalloc(sbi, |
| 3401 | FDEV(devi).nr_blkz * sizeof(block_t), |
| 3402 | GFP_KERNEL); |
| 3403 | if (!FDEV(devi).zone_capacity_blocks) |
| 3404 | return -ENOMEM; |
| 3405 | |
| 3406 | rep_zone_arg.dev = &FDEV(devi); |
| 3407 | rep_zone_arg.zone_cap_mismatch = false; |
| 3408 | |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3409 | ret = blkdev_report_zones(bdev, 0, BLK_ALL_ZONES, f2fs_report_zone_cb, |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 3410 | &rep_zone_arg); |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3411 | if (ret < 0) |
| 3412 | return ret; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3413 | |
Aravind Ramesh | de881df | 2020-07-16 18:26:56 +0530 | [diff] [blame] | 3414 | if (!rep_zone_arg.zone_cap_mismatch) { |
| 3415 | kfree(FDEV(devi).zone_capacity_blocks); |
| 3416 | FDEV(devi).zone_capacity_blocks = NULL; |
| 3417 | } |
| 3418 | |
Christoph Hellwig | d410035 | 2019-11-11 11:39:30 +0900 | [diff] [blame] | 3419 | return 0; |
Damien Le Moal | 178053e | 2016-10-28 17:45:05 +0900 | [diff] [blame] | 3420 | } |
| 3421 | #endif |
| 3422 | |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 3423 | /* |
| 3424 | * Read f2fs raw super block. |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3425 | * Because we have two copies of super block, so read both of them |
| 3426 | * to get the first valid one. If any one of them is broken, we pass |
| 3427 | * them recovery flag back to the caller. |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 3428 | */ |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3429 | static int read_raw_super_block(struct f2fs_sb_info *sbi, |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 3430 | struct f2fs_super_block **raw_super, |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3431 | int *valid_super_block, int *recovery) |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 3432 | { |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3433 | struct super_block *sb = sbi->sb; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3434 | int block; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3435 | struct buffer_head *bh; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3436 | struct f2fs_super_block *super; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3437 | int err = 0; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 3438 | |
Yunlei He | b39f0de | 2015-12-15 17:17:20 +0800 | [diff] [blame] | 3439 | super = kzalloc(sizeof(struct f2fs_super_block), GFP_KERNEL); |
| 3440 | if (!super) |
| 3441 | return -ENOMEM; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3442 | |
| 3443 | for (block = 0; block < 2; block++) { |
| 3444 | bh = sb_bread(sb, block); |
| 3445 | if (!bh) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3446 | f2fs_err(sbi, "Unable to read %dth superblock", |
| 3447 | block + 1); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3448 | err = -EIO; |
Chengguang Xu via Linux-f2fs-devel | ed352042 | 2019-09-27 09:35:48 +0800 | [diff] [blame] | 3449 | *recovery = 1; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3450 | continue; |
| 3451 | } |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 3452 | |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3453 | /* sanity checking of raw super */ |
Icenowy Zheng | 38fb6d0 | 2019-07-25 11:08:52 +0800 | [diff] [blame] | 3454 | err = sanity_check_raw_super(sbi, bh); |
| 3455 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3456 | f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock", |
| 3457 | block + 1); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3458 | brelse(bh); |
Chengguang Xu via Linux-f2fs-devel | ed352042 | 2019-09-27 09:35:48 +0800 | [diff] [blame] | 3459 | *recovery = 1; |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3460 | continue; |
| 3461 | } |
| 3462 | |
| 3463 | if (!*raw_super) { |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3464 | memcpy(super, bh->b_data + F2FS_SUPER_OFFSET, |
| 3465 | sizeof(*super)); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3466 | *valid_super_block = block; |
| 3467 | *raw_super = super; |
| 3468 | } |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3469 | brelse(bh); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3470 | } |
| 3471 | |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3472 | /* No valid superblock */ |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3473 | if (!*raw_super) |
Denis Efremov | 742532d | 2020-06-10 01:14:46 +0300 | [diff] [blame] | 3474 | kfree(super); |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3475 | else |
| 3476 | err = 0; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3477 | |
Shawn Lin | 2b39e90 | 2016-02-17 08:59:01 +0800 | [diff] [blame] | 3478 | return err; |
majianpeng | 14d7e9d | 2013-02-01 19:07:03 +0800 | [diff] [blame] | 3479 | } |
| 3480 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3481 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover) |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 3482 | { |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 3483 | struct buffer_head *bh; |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 3484 | __u32 crc = 0; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 3485 | int err; |
| 3486 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3487 | if ((recover && f2fs_readonly(sbi->sb)) || |
| 3488 | bdev_read_only(sbi->sb->s_bdev)) { |
| 3489 | set_sbi_flag(sbi, SBI_NEED_SB_WRITE); |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 3490 | return -EROFS; |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3491 | } |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 3492 | |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 3493 | /* we should update superblock crc here */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3494 | if (!recover && f2fs_sb_has_sb_chksum(sbi)) { |
Junling Zheng | d440c52 | 2018-09-28 20:25:56 +0800 | [diff] [blame] | 3495 | crc = f2fs_crc32(sbi, F2FS_RAW_SUPER(sbi), |
| 3496 | offsetof(struct f2fs_super_block, crc)); |
| 3497 | F2FS_RAW_SUPER(sbi)->crc = cpu_to_le32(crc); |
| 3498 | } |
| 3499 | |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3500 | /* write back-up superblock first */ |
Sheng Yong | 0964fc1 | 2018-01-29 19:13:15 +0800 | [diff] [blame] | 3501 | bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1); |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 3502 | if (!bh) |
| 3503 | return -EIO; |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3504 | err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 3505 | brelse(bh); |
Chao Yu | c5bda1c | 2015-06-08 13:28:03 +0800 | [diff] [blame] | 3506 | |
| 3507 | /* if we are in recovery path, skip writing valid superblock */ |
| 3508 | if (recover || err) |
Jaegeuk Kim | 5d909cd | 2015-12-07 10:16:58 -0800 | [diff] [blame] | 3509 | return err; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 3510 | |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3511 | /* write current valid superblock */ |
Sheng Yong | 0964fc1 | 2018-01-29 19:13:15 +0800 | [diff] [blame] | 3512 | bh = sb_bread(sbi->sb, sbi->valid_super_block); |
Jaegeuk Kim | fd69473 | 2016-03-20 15:33:20 -0700 | [diff] [blame] | 3513 | if (!bh) |
| 3514 | return -EIO; |
| 3515 | err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi)); |
| 3516 | brelse(bh); |
| 3517 | return err; |
Jaegeuk Kim | 26d815ad | 2015-04-20 18:49:51 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3520 | static int f2fs_scan_devices(struct f2fs_sb_info *sbi) |
| 3521 | { |
| 3522 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3523 | unsigned int max_devices = MAX_DEVICES; |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3524 | int i; |
| 3525 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3526 | /* Initialize single device information */ |
| 3527 | if (!RDEV(0).path[0]) { |
| 3528 | if (!bdev_is_zoned(sbi->sb->s_bdev)) |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3529 | return 0; |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3530 | max_devices = 1; |
| 3531 | } |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3532 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3533 | /* |
| 3534 | * Initialize multiple devices information, or single |
| 3535 | * zoned block device information. |
| 3536 | */ |
Kees Cook | 026f050 | 2018-06-12 14:28:23 -0700 | [diff] [blame] | 3537 | sbi->devs = f2fs_kzalloc(sbi, |
| 3538 | array_size(max_devices, |
| 3539 | sizeof(struct f2fs_dev_info)), |
| 3540 | GFP_KERNEL); |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3541 | if (!sbi->devs) |
| 3542 | return -ENOMEM; |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3543 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3544 | for (i = 0; i < max_devices; i++) { |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3545 | |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3546 | if (i > 0 && !RDEV(i).path[0]) |
| 3547 | break; |
| 3548 | |
| 3549 | if (max_devices == 1) { |
| 3550 | /* Single zoned block device mount */ |
| 3551 | FDEV(0).bdev = |
| 3552 | blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3553 | sbi->sb->s_mode, sbi->sb->s_type); |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3554 | } else { |
| 3555 | /* Multi-device mount */ |
| 3556 | memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN); |
| 3557 | FDEV(i).total_segments = |
| 3558 | le32_to_cpu(RDEV(i).total_segments); |
| 3559 | if (i == 0) { |
| 3560 | FDEV(i).start_blk = 0; |
| 3561 | FDEV(i).end_blk = FDEV(i).start_blk + |
| 3562 | (FDEV(i).total_segments << |
| 3563 | sbi->log_blocks_per_seg) - 1 + |
| 3564 | le32_to_cpu(raw_super->segment0_blkaddr); |
| 3565 | } else { |
| 3566 | FDEV(i).start_blk = FDEV(i - 1).end_blk + 1; |
| 3567 | FDEV(i).end_blk = FDEV(i).start_blk + |
| 3568 | (FDEV(i).total_segments << |
| 3569 | sbi->log_blocks_per_seg) - 1; |
| 3570 | } |
| 3571 | FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path, |
| 3572 | sbi->sb->s_mode, sbi->sb->s_type); |
| 3573 | } |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3574 | if (IS_ERR(FDEV(i).bdev)) |
| 3575 | return PTR_ERR(FDEV(i).bdev); |
| 3576 | |
| 3577 | /* to release errored devices */ |
| 3578 | sbi->s_ndevs = i + 1; |
| 3579 | |
| 3580 | #ifdef CONFIG_BLK_DEV_ZONED |
| 3581 | if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM && |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3582 | !f2fs_sb_has_blkzoned(sbi)) { |
Joe Perches | 833dcd3 | 2021-05-26 13:05:36 -0700 | [diff] [blame] | 3583 | f2fs_err(sbi, "Zoned block device feature not enabled"); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3584 | return -EINVAL; |
| 3585 | } |
| 3586 | if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) { |
| 3587 | if (init_blkz_info(sbi, i)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3588 | f2fs_err(sbi, "Failed to initialize F2FS blkzone information"); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3589 | return -EINVAL; |
| 3590 | } |
Masato Suzuki | 7bb3a37 | 2017-02-27 20:52:49 +0900 | [diff] [blame] | 3591 | if (max_devices == 1) |
| 3592 | break; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3593 | f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)", |
| 3594 | i, FDEV(i).path, |
| 3595 | FDEV(i).total_segments, |
| 3596 | FDEV(i).start_blk, FDEV(i).end_blk, |
| 3597 | bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ? |
| 3598 | "Host-aware" : "Host-managed"); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3599 | continue; |
| 3600 | } |
| 3601 | #endif |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3602 | f2fs_info(sbi, "Mount Device [%2d]: %20s, %8u, %8x - %8x", |
| 3603 | i, FDEV(i).path, |
| 3604 | FDEV(i).total_segments, |
| 3605 | FDEV(i).start_blk, FDEV(i).end_blk); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3606 | } |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3607 | f2fs_info(sbi, |
| 3608 | "IO Block Size: %8d KB", F2FS_IO_SIZE_KB(sbi)); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3609 | return 0; |
| 3610 | } |
| 3611 | |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 3612 | static int f2fs_setup_casefold(struct f2fs_sb_info *sbi) |
| 3613 | { |
| 3614 | #ifdef CONFIG_UNICODE |
Daniel Rosenberg | eca4873 | 2020-07-08 02:12:36 -0700 | [diff] [blame] | 3615 | if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) { |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 3616 | const struct f2fs_sb_encodings *encoding_info; |
| 3617 | struct unicode_map *encoding; |
| 3618 | __u16 encoding_flags; |
| 3619 | |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 3620 | if (f2fs_sb_read_encoding(sbi->raw_super, &encoding_info, |
| 3621 | &encoding_flags)) { |
| 3622 | f2fs_err(sbi, |
| 3623 | "Encoding requested by superblock is unknown"); |
| 3624 | return -EINVAL; |
| 3625 | } |
| 3626 | |
| 3627 | encoding = utf8_load(encoding_info->version); |
| 3628 | if (IS_ERR(encoding)) { |
| 3629 | f2fs_err(sbi, |
| 3630 | "can't mount with superblock charset: %s-%s " |
| 3631 | "not supported by the kernel. flags: 0x%x.", |
| 3632 | encoding_info->name, encoding_info->version, |
| 3633 | encoding_flags); |
| 3634 | return PTR_ERR(encoding); |
| 3635 | } |
| 3636 | f2fs_info(sbi, "Using encoding defined by superblock: " |
| 3637 | "%s-%s with flags 0x%hx", encoding_info->name, |
| 3638 | encoding_info->version?:"\b", encoding_flags); |
| 3639 | |
Daniel Rosenberg | eca4873 | 2020-07-08 02:12:36 -0700 | [diff] [blame] | 3640 | sbi->sb->s_encoding = encoding; |
| 3641 | sbi->sb->s_encoding_flags = encoding_flags; |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 3642 | } |
| 3643 | #else |
| 3644 | if (f2fs_sb_has_casefold(sbi)) { |
| 3645 | f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); |
| 3646 | return -EINVAL; |
| 3647 | } |
| 3648 | #endif |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
Jaegeuk Kim | 84b89e5 | 2018-02-22 14:09:30 -0800 | [diff] [blame] | 3652 | static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) |
| 3653 | { |
| 3654 | struct f2fs_sm_info *sm_i = SM_I(sbi); |
| 3655 | |
| 3656 | /* adjust parameters according to the volume size */ |
| 3657 | if (sm_i->main_segments <= SMALL_VOLUME_SEGMENTS) { |
Chao Yu | 63189b7 | 2018-03-08 14:22:56 +0800 | [diff] [blame] | 3658 | F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE; |
Jaegeuk Kim | 84b89e5 | 2018-02-22 14:09:30 -0800 | [diff] [blame] | 3659 | sm_i->dcc_info->discard_granularity = 1; |
| 3660 | sm_i->ipu_policy = 1 << F2FS_IPU_FORCE; |
| 3661 | } |
Chao Yu | 4cac90d | 2018-06-11 18:02:01 +0800 | [diff] [blame] | 3662 | |
| 3663 | sbi->readdir_ra = 1; |
Jaegeuk Kim | 84b89e5 | 2018-02-22 14:09:30 -0800 | [diff] [blame] | 3664 | } |
| 3665 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3666 | static int f2fs_fill_super(struct super_block *sb, void *data, int silent) |
| 3667 | { |
| 3668 | struct f2fs_sb_info *sbi; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3669 | struct f2fs_super_block *raw_super; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3670 | struct inode *root; |
Sheng Yong | 99e3e85 | 2016-05-11 17:08:14 +0800 | [diff] [blame] | 3671 | int err; |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 3672 | bool skip_recovery = false, need_fsck = false; |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 3673 | char *options = NULL; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3674 | int recovery, i, valid_super_block; |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 3675 | struct curseg_info *seg_i; |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 3676 | int retry_cnt = 1; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3677 | |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 3678 | try_onemore: |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3679 | err = -EINVAL; |
| 3680 | raw_super = NULL; |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3681 | valid_super_block = -1; |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 3682 | recovery = 0; |
| 3683 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3684 | /* allocate memory for f2fs-specific super block info */ |
| 3685 | sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); |
| 3686 | if (!sbi) |
| 3687 | return -ENOMEM; |
| 3688 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3689 | sbi->sb = sb; |
| 3690 | |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 3691 | /* Load the checksum driver */ |
| 3692 | sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); |
| 3693 | if (IS_ERR(sbi->s_chksum_driver)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3694 | f2fs_err(sbi, "Cannot load crc32 driver."); |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 3695 | err = PTR_ERR(sbi->s_chksum_driver); |
| 3696 | sbi->s_chksum_driver = NULL; |
| 3697 | goto free_sbi; |
| 3698 | } |
| 3699 | |
Namjae Jeon | ff9234a | 2013-01-12 14:41:13 +0900 | [diff] [blame] | 3700 | /* set a block size */ |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 3701 | if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3702 | f2fs_err(sbi, "unable to set blocksize"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3703 | goto free_sbi; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3704 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3705 | |
Jaegeuk Kim | df728b0 | 2016-03-23 17:05:27 -0700 | [diff] [blame] | 3706 | err = read_raw_super_block(sbi, &raw_super, &valid_super_block, |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3707 | &recovery); |
Gu Zheng | 9076a75 | 2013-10-14 18:47:11 +0800 | [diff] [blame] | 3708 | if (err) |
| 3709 | goto free_sbi; |
| 3710 | |
Gu Zheng | 5fb0837 | 2013-06-07 14:16:53 +0800 | [diff] [blame] | 3711 | sb->s_fs_info = sbi; |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 3712 | sbi->raw_super = raw_super; |
| 3713 | |
Chao Yu | 704956e | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 3714 | /* precompute checksum seed for metadata */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3715 | if (f2fs_sb_has_inode_chksum(sbi)) |
Chao Yu | 704956e | 2017-07-31 20:19:09 +0800 | [diff] [blame] | 3716 | sbi->s_chksum_seed = f2fs_chksum(sbi, ~0, raw_super->uuid, |
| 3717 | sizeof(raw_super->uuid)); |
| 3718 | |
Yunlei He | 498c5e9 | 2015-05-07 18:11:37 +0800 | [diff] [blame] | 3719 | default_options(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3720 | /* parse mount options */ |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 3721 | options = kstrdup((const char *)data, GFP_KERNEL); |
| 3722 | if (data && !options) { |
| 3723 | err = -ENOMEM; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3724 | goto free_sb_buf; |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 3725 | } |
| 3726 | |
Eric Biggers | ed318a6 | 2020-05-12 16:32:50 -0700 | [diff] [blame] | 3727 | err = parse_options(sb, options, false); |
Jaegeuk Kim | dabc4a5 | 2015-01-23 17:41:39 -0800 | [diff] [blame] | 3728 | if (err) |
| 3729 | goto free_options; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3730 | |
Chengguang Xu | 6d1451b | 2021-01-13 13:21:54 +0800 | [diff] [blame] | 3731 | sb->s_maxbytes = max_file_blocks(NULL) << |
Chao Yu | e0afc4d | 2015-12-31 14:35:37 +0800 | [diff] [blame] | 3732 | le32_to_cpu(raw_super->log_blocksize); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3733 | sb->s_max_links = F2FS_LINK_MAX; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3734 | |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 3735 | err = f2fs_setup_casefold(sbi); |
| 3736 | if (err) |
| 3737 | goto free_options; |
| 3738 | |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 3739 | #ifdef CONFIG_QUOTA |
| 3740 | sb->dq_op = &f2fs_quota_operations; |
Jaegeuk Kim | bc88ac9 | 2019-05-20 16:17:56 -0700 | [diff] [blame] | 3741 | sb->s_qcop = &f2fs_quotactl_ops; |
Chao Yu | 5c57132 | 2017-07-26 00:01:41 +0800 | [diff] [blame] | 3742 | sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ; |
Chao Yu | 292c196a | 2017-11-16 16:59:14 +0800 | [diff] [blame] | 3743 | |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3744 | if (f2fs_sb_has_quota_ino(sbi)) { |
Chao Yu | 292c196a | 2017-11-16 16:59:14 +0800 | [diff] [blame] | 3745 | for (i = 0; i < MAXQUOTAS; i++) { |
| 3746 | if (f2fs_qf_ino(sbi->sb, i)) |
| 3747 | sbi->nquota_files++; |
| 3748 | } |
| 3749 | } |
Chao Yu | 0abd675 | 2017-07-09 00:13:07 +0800 | [diff] [blame] | 3750 | #endif |
| 3751 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3752 | sb->s_op = &f2fs_sops; |
Chandan Rajendra | 643fa96 | 2018-12-12 15:20:12 +0530 | [diff] [blame] | 3753 | #ifdef CONFIG_FS_ENCRYPTION |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 3754 | sb->s_cop = &f2fs_cryptops; |
Eric Biggers | ffcc4182 | 2017-10-09 12:15:38 -0700 | [diff] [blame] | 3755 | #endif |
Eric Biggers | 95ae251 | 2019-07-22 09:26:24 -0700 | [diff] [blame] | 3756 | #ifdef CONFIG_FS_VERITY |
| 3757 | sb->s_vop = &f2fs_verityops; |
| 3758 | #endif |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3759 | sb->s_xattr = f2fs_xattr_handlers; |
| 3760 | sb->s_export_op = &f2fs_export_ops; |
| 3761 | sb->s_magic = F2FS_SUPER_MAGIC; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3762 | sb->s_time_gran = 1; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 3763 | sb->s_flags = (sb->s_flags & ~SB_POSIXACL) | |
| 3764 | (test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0); |
Christoph Hellwig | 8578709 | 2017-05-10 15:06:33 +0200 | [diff] [blame] | 3765 | memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid)); |
Yufen Yu | 578c647 | 2018-01-09 19:33:39 +0800 | [diff] [blame] | 3766 | sb->s_iflags |= SB_I_CGROUPWB; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3767 | |
| 3768 | /* init f2fs-specific super block info */ |
Chao Yu | e8240f6 | 2015-12-15 17:19:26 +0800 | [diff] [blame] | 3769 | sbi->valid_super_block = valid_super_block; |
Chao Yu | fb24fea | 2020-01-14 19:36:50 +0800 | [diff] [blame] | 3770 | init_rwsem(&sbi->gc_lock); |
Jaegeuk Kim | 853137c | 2018-08-09 17:53:34 -0700 | [diff] [blame] | 3771 | mutex_init(&sbi->writepages); |
Sahitya Tummala | 8769918 | 2020-11-23 10:58:32 +0530 | [diff] [blame] | 3772 | init_rwsem(&sbi->cp_global_sem); |
Chao Yu | b3582c6 | 2014-07-03 18:58:39 +0800 | [diff] [blame] | 3773 | init_rwsem(&sbi->node_write); |
Yunlei He | 59c9081 | 2017-03-13 20:22:18 +0800 | [diff] [blame] | 3774 | init_rwsem(&sbi->node_change); |
Jaegeuk Kim | 315df83 | 2015-08-11 12:45:39 -0700 | [diff] [blame] | 3775 | |
| 3776 | /* disallow all the data/node/meta page writes */ |
| 3777 | set_sbi_flag(sbi, SBI_POR_DOING); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3778 | spin_lock_init(&sbi->stat_lock); |
Jaegeuk Kim | 971767c | 2013-11-18 17:16:17 +0900 | [diff] [blame] | 3779 | |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 3780 | /* init iostat info */ |
| 3781 | spin_lock_init(&sbi->iostat_lock); |
| 3782 | sbi->iostat_enable = false; |
Daeho Jeong | 2bc4bea | 2020-03-30 03:30:59 +0000 | [diff] [blame] | 3783 | sbi->iostat_period_ms = DEFAULT_IOSTAT_PERIOD_MS; |
Chao Yu | b0af6d4 | 2017-08-02 23:21:48 +0800 | [diff] [blame] | 3784 | |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 3785 | for (i = 0; i < NR_PAGE_TYPE; i++) { |
Yi Zhuang | 5f029c0 | 2021-04-06 09:47:35 +0800 | [diff] [blame] | 3786 | int n = (i == META) ? 1 : NR_TEMP_TYPE; |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 3787 | int j; |
| 3788 | |
Kees Cook | c860659 | 2018-06-12 14:28:16 -0700 | [diff] [blame] | 3789 | sbi->write_io[i] = |
| 3790 | f2fs_kmalloc(sbi, |
| 3791 | array_size(n, |
| 3792 | sizeof(struct f2fs_bio_info)), |
| 3793 | GFP_KERNEL); |
Christophe JAILLET | b63def9 | 2017-06-11 09:21:11 +0200 | [diff] [blame] | 3794 | if (!sbi->write_io[i]) { |
| 3795 | err = -ENOMEM; |
Chao Yu | 0b2103e8 | 2018-09-05 14:54:01 +0800 | [diff] [blame] | 3796 | goto free_bio_info; |
Christophe JAILLET | b63def9 | 2017-06-11 09:21:11 +0200 | [diff] [blame] | 3797 | } |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 3798 | |
| 3799 | for (j = HOT; j < n; j++) { |
| 3800 | init_rwsem(&sbi->write_io[i][j].io_rwsem); |
| 3801 | sbi->write_io[i][j].sbi = sbi; |
| 3802 | sbi->write_io[i][j].bio = NULL; |
Chao Yu | fb830fc | 2017-05-19 23:37:01 +0800 | [diff] [blame] | 3803 | spin_lock_init(&sbi->write_io[i][j].io_lock); |
| 3804 | INIT_LIST_HEAD(&sbi->write_io[i][j].io_list); |
Chao Yu | 0b20fce | 2019-09-30 18:53:25 +0800 | [diff] [blame] | 3805 | INIT_LIST_HEAD(&sbi->write_io[i][j].bio_list); |
| 3806 | init_rwsem(&sbi->write_io[i][j].bio_list_lock); |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 3807 | } |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 3808 | } |
Jaegeuk Kim | 971767c | 2013-11-18 17:16:17 +0900 | [diff] [blame] | 3809 | |
Jaegeuk Kim | b873b79 | 2016-08-04 11:38:25 -0700 | [diff] [blame] | 3810 | init_rwsem(&sbi->cp_rwsem); |
Jaegeuk Kim | db6ec53 | 2019-05-29 10:58:45 -0700 | [diff] [blame] | 3811 | init_rwsem(&sbi->quota_sem); |
Changman Lee | fb51b5e | 2013-11-07 12:48:25 +0900 | [diff] [blame] | 3812 | init_waitqueue_head(&sbi->cp_wait); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3813 | init_sb_info(sbi); |
| 3814 | |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 3815 | err = init_percpu_info(sbi); |
| 3816 | if (err) |
Chao Yu | d7997e6 | 2018-01-17 16:31:35 +0800 | [diff] [blame] | 3817 | goto free_bio_info; |
Jaegeuk Kim | 523be8a | 2016-05-13 12:36:58 -0700 | [diff] [blame] | 3818 | |
Chao Yu | c72db71 | 2019-07-12 16:55:42 +0800 | [diff] [blame] | 3819 | if (F2FS_IO_ALIGNED(sbi)) { |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 3820 | sbi->write_io_dummy = |
Chao Yu | a3ebfe4 | 2017-02-27 18:43:13 +0800 | [diff] [blame] | 3821 | mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); |
Chao Yu | 1727f31 | 2017-06-12 09:44:27 +0800 | [diff] [blame] | 3822 | if (!sbi->write_io_dummy) { |
| 3823 | err = -ENOMEM; |
Chao Yu | d7997e6 | 2018-01-17 16:31:35 +0800 | [diff] [blame] | 3824 | goto free_percpu; |
Chao Yu | 1727f31 | 2017-06-12 09:44:27 +0800 | [diff] [blame] | 3825 | } |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 3826 | } |
| 3827 | |
Chao Yu | a999150 | 2020-02-25 18:17:10 +0800 | [diff] [blame] | 3828 | /* init per sbi slab cache */ |
| 3829 | err = f2fs_init_xattr_caches(sbi); |
| 3830 | if (err) |
| 3831 | goto free_io_dummy; |
Chao Yu | 3108303 | 2020-09-14 17:05:13 +0800 | [diff] [blame] | 3832 | err = f2fs_init_page_array_cache(sbi); |
| 3833 | if (err) |
| 3834 | goto free_xattr_cache; |
Chao Yu | a999150 | 2020-02-25 18:17:10 +0800 | [diff] [blame] | 3835 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3836 | /* get an inode for meta space */ |
| 3837 | sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi)); |
| 3838 | if (IS_ERR(sbi->meta_inode)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3839 | f2fs_err(sbi, "Failed to read F2FS meta data inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3840 | err = PTR_ERR(sbi->meta_inode); |
Chao Yu | 3108303 | 2020-09-14 17:05:13 +0800 | [diff] [blame] | 3841 | goto free_page_array_cache; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3842 | } |
| 3843 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3844 | err = f2fs_get_valid_checkpoint(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3845 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3846 | f2fs_err(sbi, "Failed to get valid F2FS checkpoint"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3847 | goto free_meta_inode; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3848 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3849 | |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 3850 | if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG)) |
| 3851 | set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR); |
Jaegeuk Kim | db610a6 | 2019-01-24 17:48:38 -0800 | [diff] [blame] | 3852 | if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_DISABLED_QUICK_FLAG)) { |
| 3853 | set_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); |
| 3854 | sbi->interval_time[DISABLE_TIME] = DEF_DISABLE_QUICK_INTERVAL; |
| 3855 | } |
Chao Yu | af033b2 | 2018-09-20 20:05:00 +0800 | [diff] [blame] | 3856 | |
Qiuyang Sun | 04f0b2e | 2019-06-05 11:33:25 +0800 | [diff] [blame] | 3857 | if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FSCK_FLAG)) |
| 3858 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
| 3859 | |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3860 | /* Initialize device list */ |
| 3861 | err = f2fs_scan_devices(sbi); |
| 3862 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3863 | f2fs_err(sbi, "Failed to find devices"); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 3864 | goto free_devices; |
| 3865 | } |
| 3866 | |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 3867 | err = f2fs_init_post_read_wq(sbi); |
| 3868 | if (err) { |
| 3869 | f2fs_err(sbi, "Failed to initialize post read workqueue"); |
| 3870 | goto free_devices; |
| 3871 | } |
| 3872 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3873 | sbi->total_valid_node_count = |
| 3874 | le32_to_cpu(sbi->ckpt->valid_node_count); |
Jaegeuk Kim | 513c5f3 | 2016-05-16 11:42:32 -0700 | [diff] [blame] | 3875 | percpu_counter_set(&sbi->total_valid_inode_count, |
| 3876 | le32_to_cpu(sbi->ckpt->valid_inode_count)); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3877 | sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count); |
| 3878 | sbi->total_valid_block_count = |
| 3879 | le64_to_cpu(sbi->ckpt->valid_block_count); |
| 3880 | sbi->last_valid_block_count = sbi->total_valid_block_count; |
Chao Yu | daeb433 | 2017-06-26 16:24:41 +0800 | [diff] [blame] | 3881 | sbi->reserved_blocks = 0; |
Yunlong Song | 80d4214 | 2017-10-27 20:45:05 +0800 | [diff] [blame] | 3882 | sbi->current_reserved_blocks = 0; |
Jaegeuk Kim | 7e65be4 | 2017-12-27 15:05:52 -0800 | [diff] [blame] | 3883 | limit_reserve_root(sbi); |
Jaegeuk Kim | 1ae18f7 | 2020-05-15 17:20:50 -0700 | [diff] [blame] | 3884 | adjust_unusable_cap_perc(sbi); |
Jaegeuk Kim | 41382ec | 2016-05-16 11:06:50 -0700 | [diff] [blame] | 3885 | |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 3886 | for (i = 0; i < NR_INODE_TYPE; i++) { |
| 3887 | INIT_LIST_HEAD(&sbi->inode_list[i]); |
| 3888 | spin_lock_init(&sbi->inode_lock[i]); |
| 3889 | } |
Chao Yu | 040d2bb | 2019-05-20 17:36:59 +0800 | [diff] [blame] | 3890 | mutex_init(&sbi->flush_lock); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3891 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3892 | f2fs_init_extent_cache_info(sbi); |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 3893 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3894 | f2fs_init_ino_entry_info(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3895 | |
Chao Yu | 50fa53e | 2018-08-02 23:03:19 +0800 | [diff] [blame] | 3896 | f2fs_init_fsync_node_info(sbi); |
| 3897 | |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 3898 | /* setup checkpoint request control and start checkpoint issue thread */ |
| 3899 | f2fs_init_ckpt_req_control(sbi); |
Chao Yu | 3f7070b | 2021-03-17 17:56:03 +0800 | [diff] [blame] | 3900 | if (!f2fs_readonly(sb) && !test_opt(sbi, DISABLE_CHECKPOINT) && |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 3901 | test_opt(sbi, MERGE_CHECKPOINT)) { |
| 3902 | err = f2fs_start_ckpt_thread(sbi); |
| 3903 | if (err) { |
| 3904 | f2fs_err(sbi, |
| 3905 | "Failed to start F2FS issue_checkpoint_thread (%d)", |
| 3906 | err); |
| 3907 | goto stop_ckpt_thread; |
| 3908 | } |
| 3909 | } |
| 3910 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3911 | /* setup f2fs internal modules */ |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3912 | err = f2fs_build_segment_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3913 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3914 | f2fs_err(sbi, "Failed to initialize F2FS segment manager (%d)", |
| 3915 | err); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3916 | goto free_sm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3917 | } |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3918 | err = f2fs_build_node_manager(sbi); |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3919 | if (err) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3920 | f2fs_err(sbi, "Failed to initialize F2FS node manager (%d)", |
| 3921 | err); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3922 | goto free_nm; |
Namjae Jeon | a07ef78 | 2012-12-30 14:52:05 +0900 | [diff] [blame] | 3923 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3924 | |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 3925 | /* For write statistics */ |
Chao Yu | 3a0a9cb | 2020-11-27 21:20:06 +0800 | [diff] [blame] | 3926 | sbi->sectors_written_start = f2fs_get_sectors_written(sbi); |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 3927 | |
| 3928 | /* Read accumulated write IO statistics if exists */ |
| 3929 | seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); |
| 3930 | if (__exist_node_summaries(sbi)) |
| 3931 | sbi->kbytes_written = |
Shuoran Liu | b2dde6f | 2016-03-29 18:00:15 +0800 | [diff] [blame] | 3932 | le64_to_cpu(seg_i->journal->info.kbytes_written); |
Shuoran Liu | 8f1dbbb | 2016-01-27 09:57:30 +0800 | [diff] [blame] | 3933 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3934 | f2fs_build_gc_manager(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3935 | |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 3936 | err = f2fs_build_stats(sbi); |
| 3937 | if (err) |
| 3938 | goto free_nm; |
| 3939 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3940 | /* get an inode for node space */ |
| 3941 | sbi->node_inode = f2fs_iget(sb, F2FS_NODE_INO(sbi)); |
| 3942 | if (IS_ERR(sbi->node_inode)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3943 | f2fs_err(sbi, "Failed to read node inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3944 | err = PTR_ERR(sbi->node_inode); |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 3945 | goto free_stats; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3946 | } |
| 3947 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3948 | /* read root inode and dentry */ |
| 3949 | root = f2fs_iget(sb, F2FS_ROOT_INO(sbi)); |
| 3950 | if (IS_ERR(root)) { |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3951 | f2fs_err(sbi, "Failed to read root inode"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3952 | err = PTR_ERR(root); |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 3953 | goto free_node_inode; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3954 | } |
Chao Yu | bcbfbd6 | 2018-06-29 00:19:25 +0800 | [diff] [blame] | 3955 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || |
| 3956 | !root->i_size || !root->i_nlink) { |
Chao Yu | 9d84795 | 2014-07-25 12:55:09 +0800 | [diff] [blame] | 3957 | iput(root); |
Chao Yu | 8f99a94 | 2013-11-28 15:43:43 +0800 | [diff] [blame] | 3958 | err = -EINVAL; |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 3959 | goto free_node_inode; |
Chao Yu | 8f99a94 | 2013-11-28 15:43:43 +0800 | [diff] [blame] | 3960 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3961 | |
| 3962 | sb->s_root = d_make_root(root); /* allocate root dentry */ |
| 3963 | if (!sb->s_root) { |
| 3964 | err = -ENOMEM; |
Chengguang Xu | 025cdb16 | 2019-01-23 15:49:44 +0800 | [diff] [blame] | 3965 | goto free_node_inode; |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 3966 | } |
| 3967 | |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 3968 | err = f2fs_register_sysfs(sbi); |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 3969 | if (err) |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 3970 | goto free_root_inode; |
Namjae Jeon | b59d0ba | 2013-08-04 23:09:40 +0900 | [diff] [blame] | 3971 | |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 3972 | #ifdef CONFIG_QUOTA |
Sheng Yong | 76cf05d | 2018-07-26 19:24:25 +0800 | [diff] [blame] | 3973 | /* Enable quota usage during mount */ |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 3974 | if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) { |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 3975 | err = f2fs_enable_quotas(sb); |
Jaegeuk Kim | 730746c | 2018-10-02 17:20:58 -0700 | [diff] [blame] | 3976 | if (err) |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 3977 | f2fs_err(sbi, "Cannot turn on quotas: error %d", err); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 3978 | } |
| 3979 | #endif |
Chao Yu | 7a88ddb | 2020-02-27 19:30:05 +0800 | [diff] [blame] | 3980 | /* if there are any orphan inodes, free them */ |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 3981 | err = f2fs_recover_orphan_inodes(sbi); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 3982 | if (err) |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 3983 | goto free_meta; |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 3984 | |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 3985 | if (unlikely(is_set_ckpt_flags(sbi, CP_DISABLED_FLAG))) |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 3986 | goto reset_checkpoint; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 3987 | |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 3988 | /* recover fsynced data */ |
Chao Yu | a9117ec | 2020-02-14 17:45:11 +0800 | [diff] [blame] | 3989 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD) && |
| 3990 | !test_opt(sbi, NORECOVERY)) { |
Jaegeuk Kim | 081d78c | 2015-01-23 19:16:59 -0800 | [diff] [blame] | 3991 | /* |
| 3992 | * mount should be failed, when device has readonly mode, and |
| 3993 | * previous checkpoint was not done by clean system shutdown. |
| 3994 | */ |
Chao Yu | b61af31 | 2019-04-22 20:22:37 +0800 | [diff] [blame] | 3995 | if (f2fs_hw_is_readonly(sbi)) { |
Chao Yu | 23738e7 | 2021-03-31 11:16:32 +0800 | [diff] [blame] | 3996 | if (!is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { |
| 3997 | err = f2fs_recover_fsync_data(sbi, true); |
| 3998 | if (err > 0) { |
| 3999 | err = -EROFS; |
| 4000 | f2fs_err(sbi, "Need to recover fsync data, but " |
| 4001 | "write access unavailable, please try " |
| 4002 | "mount w/ disable_roll_forward or norecovery"); |
| 4003 | } |
| 4004 | if (err < 0) |
| 4005 | goto free_meta; |
| 4006 | } |
| 4007 | f2fs_info(sbi, "write access unavailable, skipping recovery"); |
Chao Yu | b61af31 | 2019-04-22 20:22:37 +0800 | [diff] [blame] | 4008 | goto reset_checkpoint; |
Jaegeuk Kim | 081d78c | 2015-01-23 19:16:59 -0800 | [diff] [blame] | 4009 | } |
Chao Yu | 2adc350 | 2015-03-16 21:08:44 +0800 | [diff] [blame] | 4010 | |
| 4011 | if (need_fsck) |
| 4012 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
| 4013 | |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 4014 | if (skip_recovery) |
| 4015 | goto reset_checkpoint; |
Jaegeuk Kim | a468f0e | 2016-09-19 17:55:10 -0700 | [diff] [blame] | 4016 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4017 | err = f2fs_recover_fsync_data(sbi, false); |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 4018 | if (err < 0) { |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 4019 | if (err != -ENOMEM) |
| 4020 | skip_recovery = true; |
Chao Yu | 2adc350 | 2015-03-16 21:08:44 +0800 | [diff] [blame] | 4021 | need_fsck = true; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 4022 | f2fs_err(sbi, "Cannot recover all fsync data errno=%d", |
| 4023 | err); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4024 | goto free_meta; |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 4025 | } |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 4026 | } else { |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4027 | err = f2fs_recover_fsync_data(sbi, true); |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 4028 | |
| 4029 | if (!f2fs_readonly(sb) && err > 0) { |
| 4030 | err = -EINVAL; |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 4031 | f2fs_err(sbi, "Need to recover fsync data"); |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 4032 | goto free_meta; |
Jaegeuk Kim | 6781eab | 2016-03-23 16:12:58 -0700 | [diff] [blame] | 4033 | } |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4034 | } |
Shin'ichiro Kawasaki | d508c94 | 2019-12-09 19:44:45 +0900 | [diff] [blame] | 4035 | |
| 4036 | /* |
| 4037 | * If the f2fs is not readonly and fsync data recovery succeeds, |
| 4038 | * check zoned block devices' write pointer consistency. |
| 4039 | */ |
| 4040 | if (!err && !f2fs_readonly(sb) && f2fs_sb_has_blkzoned(sbi)) { |
| 4041 | err = f2fs_check_write_pointer(sbi); |
| 4042 | if (err) |
| 4043 | goto free_meta; |
| 4044 | } |
| 4045 | |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 4046 | reset_checkpoint: |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 4047 | f2fs_init_inmem_curseg(sbi); |
| 4048 | |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4049 | /* f2fs_recover_fsync_data() cleared this already */ |
Jaegeuk Kim | 315df83 | 2015-08-11 12:45:39 -0700 | [diff] [blame] | 4050 | clear_sbi_flag(sbi, SBI_POR_DOING); |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4051 | |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 4052 | if (test_opt(sbi, DISABLE_CHECKPOINT)) { |
| 4053 | err = f2fs_disable_checkpoint(sbi); |
| 4054 | if (err) |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 4055 | goto sync_free_meta; |
Daniel Rosenberg | 4354994 | 2018-08-20 19:21:43 -0700 | [diff] [blame] | 4056 | } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) { |
| 4057 | f2fs_enable_checkpoint(sbi); |
| 4058 | } |
| 4059 | |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4060 | /* |
| 4061 | * If filesystem is not mounted as read-only then |
| 4062 | * do start the gc_thread. |
| 4063 | */ |
Chao Yu | 5911d2d | 2021-03-27 17:57:06 +0800 | [diff] [blame] | 4064 | if ((F2FS_OPTION(sbi).bggc_mode != BGGC_MODE_OFF || |
| 4065 | test_opt(sbi, GC_MERGE)) && !f2fs_readonly(sb)) { |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4066 | /* After POR, we can run background GC thread.*/ |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4067 | err = f2fs_start_gc_thread(sbi); |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4068 | if (err) |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 4069 | goto sync_free_meta; |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4070 | } |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 4071 | kvfree(options); |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 4072 | |
| 4073 | /* recover broken superblock */ |
Jaegeuk Kim | f2353d7 | 2016-03-23 10:42:01 -0700 | [diff] [blame] | 4074 | if (recovery) { |
Chao Yu | 41214b3 | 2016-02-22 18:33:20 +0800 | [diff] [blame] | 4075 | err = f2fs_commit_super(sbi, true); |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 4076 | f2fs_info(sbi, "Try to recover %dth superblock, ret: %d", |
| 4077 | sbi->valid_super_block ? 1 : 2, err); |
hujianyang | da554e4 | 2015-05-21 14:42:53 +0800 | [diff] [blame] | 4078 | } |
| 4079 | |
Chao Yu | bae01ed | 2017-11-30 19:28:20 +0800 | [diff] [blame] | 4080 | f2fs_join_shrinker(sbi); |
| 4081 | |
Jaegeuk Kim | 84b89e5 | 2018-02-22 14:09:30 -0800 | [diff] [blame] | 4082 | f2fs_tuning_parameters(sbi); |
| 4083 | |
Joe Perches | dcbb4c1 | 2019-06-18 17:48:42 +0800 | [diff] [blame] | 4084 | f2fs_notice(sbi, "Mounted with checkpoint version = %llx", |
| 4085 | cur_cp_version(F2FS_CKPT(sbi))); |
Jaegeuk Kim | 6beceb5 | 2016-01-08 15:51:50 -0800 | [diff] [blame] | 4086 | f2fs_update_time(sbi, CP_TIME); |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 4087 | f2fs_update_time(sbi, REQ_TIME); |
Jaegeuk Kim | db610a6 | 2019-01-24 17:48:38 -0800 | [diff] [blame] | 4088 | clear_sbi_flag(sbi, SBI_CP_DISABLED_QUICK); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4089 | return 0; |
Jaegeuk Kim | 6437d1b | 2014-02-19 18:23:32 +0900 | [diff] [blame] | 4090 | |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 4091 | sync_free_meta: |
| 4092 | /* safe to flush all the data */ |
| 4093 | sync_filesystem(sbi->sb); |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 4094 | retry_cnt = 0; |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 4095 | |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4096 | free_meta: |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 4097 | #ifdef CONFIG_QUOTA |
Sheng Yong | 26b5a07 | 2018-10-12 18:49:26 +0800 | [diff] [blame] | 4098 | f2fs_truncate_quota_inode_pages(sb); |
Chao Yu | 7beb01f | 2018-10-24 18:34:26 +0800 | [diff] [blame] | 4099 | if (f2fs_sb_has_quota_ino(sbi) && !f2fs_readonly(sb)) |
Jaegeuk Kim | ea67673 | 2017-10-06 09:14:28 -0700 | [diff] [blame] | 4100 | f2fs_quota_off_umount(sbi->sb); |
| 4101 | #endif |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4102 | /* |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4103 | * Some dirty meta pages can be produced by f2fs_recover_orphan_inodes() |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4104 | * failed by EIO. Then, iput(node_inode) can trigger balance_fs_bg() |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4105 | * followed by f2fs_write_checkpoint() through f2fs_write_node_pages(), which |
| 4106 | * falls into an infinite loop in f2fs_sync_meta_pages(). |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4107 | */ |
| 4108 | truncate_inode_pages_final(META_MAPPING(sbi)); |
Jaegeuk Kim | 812a959 | 2019-01-22 14:04:33 -0800 | [diff] [blame] | 4109 | /* evict some inodes being cached by GC */ |
| 4110 | evict_inodes(sb); |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 4111 | f2fs_unregister_sysfs(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4112 | free_root_inode: |
| 4113 | dput(sb->s_root); |
| 4114 | sb->s_root = NULL; |
Chao Yu | bae01ed | 2017-11-30 19:28:20 +0800 | [diff] [blame] | 4115 | free_node_inode: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4116 | f2fs_release_ino_entry(sbi, true); |
Chao Yu | bae01ed | 2017-11-30 19:28:20 +0800 | [diff] [blame] | 4117 | truncate_inode_pages_final(NODE_MAPPING(sbi)); |
| 4118 | iput(sbi->node_inode); |
Jaegeuk Kim | 7c77bf7 | 2019-01-01 00:11:30 -0800 | [diff] [blame] | 4119 | sbi->node_inode = NULL; |
Sahitya Tummala | 60aa4d5 | 2018-12-26 11:20:29 +0530 | [diff] [blame] | 4120 | free_stats: |
| 4121 | f2fs_destroy_stats(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4122 | free_nm: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4123 | f2fs_destroy_node_manager(sbi); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4124 | free_sm: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4125 | f2fs_destroy_segment_manager(sbi); |
Chao Yu | 4c8ff70 | 2019-11-01 18:07:14 +0800 | [diff] [blame] | 4126 | f2fs_destroy_post_read_wq(sbi); |
Daeho Jeong | 261eeb9 | 2021-01-19 09:00:42 +0900 | [diff] [blame] | 4127 | stop_ckpt_thread: |
| 4128 | f2fs_stop_ckpt_thread(sbi); |
Jaegeuk Kim | 3c62be1 | 2016-10-06 19:02:05 -0700 | [diff] [blame] | 4129 | free_devices: |
| 4130 | destroy_device_list(sbi); |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 4131 | kvfree(sbi->ckpt); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4132 | free_meta_inode: |
| 4133 | make_bad_inode(sbi->meta_inode); |
| 4134 | iput(sbi->meta_inode); |
Jaegeuk Kim | 7c77bf7 | 2019-01-01 00:11:30 -0800 | [diff] [blame] | 4135 | sbi->meta_inode = NULL; |
Chao Yu | 3108303 | 2020-09-14 17:05:13 +0800 | [diff] [blame] | 4136 | free_page_array_cache: |
| 4137 | f2fs_destroy_page_array_cache(sbi); |
Chao Yu | a999150 | 2020-02-25 18:17:10 +0800 | [diff] [blame] | 4138 | free_xattr_cache: |
| 4139 | f2fs_destroy_xattr_caches(sbi); |
Jaegeuk Kim | 0a595eb | 2016-12-14 10:12:56 -0800 | [diff] [blame] | 4140 | free_io_dummy: |
| 4141 | mempool_destroy(sbi->write_io_dummy); |
Chao Yu | d7997e6 | 2018-01-17 16:31:35 +0800 | [diff] [blame] | 4142 | free_percpu: |
| 4143 | destroy_percpu_info(sbi); |
| 4144 | free_bio_info: |
Jaegeuk Kim | a912b54 | 2017-05-10 11:18:25 -0700 | [diff] [blame] | 4145 | for (i = 0; i < NR_PAGE_TYPE; i++) |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 4146 | kvfree(sbi->write_io[i]); |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 4147 | |
| 4148 | #ifdef CONFIG_UNICODE |
Daniel Rosenberg | eca4873 | 2020-07-08 02:12:36 -0700 | [diff] [blame] | 4149 | utf8_unload(sb->s_encoding); |
Hyeongseok Kim | 89ff600 | 2020-11-12 18:14:54 +0900 | [diff] [blame] | 4150 | sb->s_encoding = NULL; |
Daniel Rosenberg | 5aba543 | 2019-07-23 16:05:28 -0700 | [diff] [blame] | 4151 | #endif |
Chao Yu | d7997e6 | 2018-01-17 16:31:35 +0800 | [diff] [blame] | 4152 | free_options: |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4153 | #ifdef CONFIG_QUOTA |
| 4154 | for (i = 0; i < MAXQUOTAS; i++) |
Wang Xiaojun | ba87a45 | 2020-06-17 20:30:12 +0800 | [diff] [blame] | 4155 | kfree(F2FS_OPTION(sbi).s_qf_names[i]); |
Chao Yu | 4b2414d | 2017-08-08 10:54:31 +0800 | [diff] [blame] | 4156 | #endif |
Eric Biggers | ac4acb1 | 2020-09-16 21:11:35 -0700 | [diff] [blame] | 4157 | fscrypt_free_dummy_policy(&F2FS_OPTION(sbi).dummy_enc_policy); |
Jaegeuk Kim | 5222595 | 2018-12-13 18:38:33 -0800 | [diff] [blame] | 4158 | kvfree(options); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4159 | free_sb_buf: |
Denis Efremov | 742532d | 2020-06-10 01:14:46 +0300 | [diff] [blame] | 4160 | kfree(raw_super); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4161 | free_sbi: |
Keith Mok | 43b6573 | 2016-03-02 12:04:24 -0800 | [diff] [blame] | 4162 | if (sbi->s_chksum_driver) |
| 4163 | crypto_free_shash(sbi->s_chksum_driver); |
Denis Efremov | 742532d | 2020-06-10 01:14:46 +0300 | [diff] [blame] | 4164 | kfree(sbi); |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 4165 | |
| 4166 | /* give only one another chance */ |
Chao Yu | aa2c8c4 | 2019-02-19 16:23:53 +0800 | [diff] [blame] | 4167 | if (retry_cnt > 0 && skip_recovery) { |
| 4168 | retry_cnt--; |
Jaegeuk Kim | ed2e621 | 2014-08-08 15:37:41 -0700 | [diff] [blame] | 4169 | shrink_dcache_sb(sb); |
| 4170 | goto try_onemore; |
| 4171 | } |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4172 | return err; |
| 4173 | } |
| 4174 | |
| 4175 | static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags, |
| 4176 | const char *dev_name, void *data) |
| 4177 | { |
| 4178 | return mount_bdev(fs_type, flags, dev_name, data, f2fs_fill_super); |
| 4179 | } |
| 4180 | |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 4181 | static void kill_f2fs_super(struct super_block *sb) |
| 4182 | { |
Chao Yu | cce1325 | 2017-06-29 23:17:45 +0800 | [diff] [blame] | 4183 | if (sb->s_root) { |
Jaegeuk Kim | 1cb50f8 | 2018-07-06 16:47:34 -0700 | [diff] [blame] | 4184 | struct f2fs_sb_info *sbi = F2FS_SB(sb); |
| 4185 | |
| 4186 | set_sbi_flag(sbi, SBI_IS_CLOSE); |
| 4187 | f2fs_stop_gc_thread(sbi); |
| 4188 | f2fs_stop_discard_thread(sbi); |
| 4189 | |
| 4190 | if (is_sbi_flag_set(sbi, SBI_IS_DIRTY) || |
| 4191 | !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { |
| 4192 | struct cp_control cpc = { |
| 4193 | .reason = CP_UMOUNT, |
| 4194 | }; |
| 4195 | f2fs_write_checkpoint(sbi, &cpc); |
| 4196 | } |
Chao Yu | 1378752 | 2018-08-22 17:11:05 +0800 | [diff] [blame] | 4197 | |
| 4198 | if (is_sbi_flag_set(sbi, SBI_IS_RECOVERED) && f2fs_readonly(sb)) |
| 4199 | sb->s_flags &= ~SB_RDONLY; |
Chao Yu | cce1325 | 2017-06-29 23:17:45 +0800 | [diff] [blame] | 4200 | } |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 4201 | kill_block_super(sb); |
| 4202 | } |
| 4203 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4204 | static struct file_system_type f2fs_fs_type = { |
| 4205 | .owner = THIS_MODULE, |
| 4206 | .name = "f2fs", |
| 4207 | .mount = f2fs_mount, |
Jaegeuk Kim | 30a5537 | 2015-01-14 16:34:24 -0800 | [diff] [blame] | 4208 | .kill_sb = kill_f2fs_super, |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4209 | .fs_flags = FS_REQUIRES_DEV, |
| 4210 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 4211 | MODULE_ALIAS_FS("f2fs"); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4212 | |
Namjae Jeon | 6e6093a | 2013-01-17 00:08:30 +0900 | [diff] [blame] | 4213 | static int __init init_inodecache(void) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4214 | { |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 4215 | f2fs_inode_cachep = kmem_cache_create("f2fs_inode_cache", |
| 4216 | sizeof(struct f2fs_inode_info), 0, |
| 4217 | SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT, NULL); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 4218 | if (!f2fs_inode_cachep) |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4219 | return -ENOMEM; |
| 4220 | return 0; |
| 4221 | } |
| 4222 | |
| 4223 | static void destroy_inodecache(void) |
| 4224 | { |
| 4225 | /* |
| 4226 | * Make sure all delayed rcu free inodes are flushed before we |
| 4227 | * destroy cache. |
| 4228 | */ |
| 4229 | rcu_barrier(); |
| 4230 | kmem_cache_destroy(f2fs_inode_cachep); |
| 4231 | } |
| 4232 | |
| 4233 | static int __init init_f2fs_fs(void) |
| 4234 | { |
| 4235 | int err; |
| 4236 | |
Anatoly Pugachev | 4071e67 | 2018-05-28 02:06:37 +0300 | [diff] [blame] | 4237 | if (PAGE_SIZE != F2FS_BLKSIZE) { |
| 4238 | printk("F2FS not supported on PAGE_SIZE(%lu) != %d\n", |
| 4239 | PAGE_SIZE, F2FS_BLKSIZE); |
| 4240 | return -EINVAL; |
| 4241 | } |
| 4242 | |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4243 | err = init_inodecache(); |
| 4244 | if (err) |
| 4245 | goto fail; |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4246 | err = f2fs_create_node_manager_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4247 | if (err) |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4248 | goto free_inodecache; |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4249 | err = f2fs_create_segment_manager_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4250 | if (err) |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4251 | goto free_node_manager_caches; |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4252 | err = f2fs_create_checkpoint_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4253 | if (err) |
Chao Yu | 0629207 | 2014-12-29 15:56:18 +0800 | [diff] [blame] | 4254 | goto free_segment_manager_caches; |
Chao Yu | cad83c9 | 2021-05-07 18:10:38 +0800 | [diff] [blame] | 4255 | err = f2fs_create_recovery_cache(); |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 4256 | if (err) |
| 4257 | goto free_checkpoint_caches; |
Chao Yu | cad83c9 | 2021-05-07 18:10:38 +0800 | [diff] [blame] | 4258 | err = f2fs_create_extent_cache(); |
| 4259 | if (err) |
| 4260 | goto free_recovery_cache; |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 4261 | err = f2fs_create_garbage_collection_cache(); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 4262 | if (err) |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 4263 | goto free_extent_cache; |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 4264 | err = f2fs_init_sysfs(); |
| 4265 | if (err) |
| 4266 | goto free_garbage_collection_cache; |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 4267 | err = register_shrinker(&f2fs_shrinker_info); |
Jaegeuk Kim | cfc4d97 | 2015-05-15 15:37:24 -0700 | [diff] [blame] | 4268 | if (err) |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 4269 | goto free_sysfs; |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 4270 | err = register_filesystem(&f2fs_fs_type); |
| 4271 | if (err) |
| 4272 | goto free_shrinker; |
Greg Kroah-Hartman | 21acc07 | 2019-01-04 14:26:18 +0100 | [diff] [blame] | 4273 | f2fs_create_root_stats(); |
Eric Biggers | 6dbb179 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 4274 | err = f2fs_init_post_read_processing(); |
| 4275 | if (err) |
| 4276 | goto free_root_stats; |
Chao Yu | 0b20fce | 2019-09-30 18:53:25 +0800 | [diff] [blame] | 4277 | err = f2fs_init_bio_entry_cache(); |
| 4278 | if (err) |
| 4279 | goto free_post_read; |
Chao Yu | f543805 | 2019-12-04 09:52:58 +0800 | [diff] [blame] | 4280 | err = f2fs_init_bioset(); |
| 4281 | if (err) |
| 4282 | goto free_bio_enrty_cache; |
Chao Yu | 5e6bbde | 2020-04-08 19:56:05 +0800 | [diff] [blame] | 4283 | err = f2fs_init_compress_mempool(); |
| 4284 | if (err) |
| 4285 | goto free_bioset; |
Chao Yu | c68d6c8 | 2020-09-14 17:05:14 +0800 | [diff] [blame] | 4286 | err = f2fs_init_compress_cache(); |
| 4287 | if (err) |
| 4288 | goto free_compress_mempool; |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4289 | return 0; |
Chao Yu | c68d6c8 | 2020-09-14 17:05:14 +0800 | [diff] [blame] | 4290 | free_compress_mempool: |
| 4291 | f2fs_destroy_compress_mempool(); |
Chao Yu | 5e6bbde | 2020-04-08 19:56:05 +0800 | [diff] [blame] | 4292 | free_bioset: |
| 4293 | f2fs_destroy_bioset(); |
Chao Yu | f543805 | 2019-12-04 09:52:58 +0800 | [diff] [blame] | 4294 | free_bio_enrty_cache: |
| 4295 | f2fs_destroy_bio_entry_cache(); |
Chao Yu | 0b20fce | 2019-09-30 18:53:25 +0800 | [diff] [blame] | 4296 | free_post_read: |
| 4297 | f2fs_destroy_post_read_processing(); |
Eric Biggers | 6dbb179 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 4298 | free_root_stats: |
| 4299 | f2fs_destroy_root_stats(); |
Chao Yu | 787c7b8c | 2015-10-29 09:13:04 +0800 | [diff] [blame] | 4300 | unregister_filesystem(&f2fs_fs_type); |
Jaegeuk Kim | 2658e50 | 2015-06-19 12:01:21 -0700 | [diff] [blame] | 4301 | free_shrinker: |
| 4302 | unregister_shrinker(&f2fs_shrinker_info); |
Chao Yu | a398101 | 2017-06-14 17:39:46 +0800 | [diff] [blame] | 4303 | free_sysfs: |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 4304 | f2fs_exit_sysfs(); |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 4305 | free_garbage_collection_cache: |
| 4306 | f2fs_destroy_garbage_collection_cache(); |
Chao Yu | 1dcc336 | 2015-02-05 17:57:31 +0800 | [diff] [blame] | 4307 | free_extent_cache: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4308 | f2fs_destroy_extent_cache(); |
Chao Yu | cad83c9 | 2021-05-07 18:10:38 +0800 | [diff] [blame] | 4309 | free_recovery_cache: |
| 4310 | f2fs_destroy_recovery_cache(); |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4311 | free_checkpoint_caches: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4312 | f2fs_destroy_checkpoint_caches(); |
Jaegeuk Kim | 7fd9e54 | 2013-11-15 13:55:58 +0900 | [diff] [blame] | 4313 | free_segment_manager_caches: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4314 | f2fs_destroy_segment_manager_caches(); |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4315 | free_node_manager_caches: |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4316 | f2fs_destroy_node_manager_caches(); |
Zhao Hongjiang | 9890ff3 | 2013-08-20 16:49:51 +0800 | [diff] [blame] | 4317 | free_inodecache: |
| 4318 | destroy_inodecache(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4319 | fail: |
| 4320 | return err; |
| 4321 | } |
| 4322 | |
| 4323 | static void __exit exit_f2fs_fs(void) |
| 4324 | { |
Chao Yu | c68d6c8 | 2020-09-14 17:05:14 +0800 | [diff] [blame] | 4325 | f2fs_destroy_compress_cache(); |
Chao Yu | 5e6bbde | 2020-04-08 19:56:05 +0800 | [diff] [blame] | 4326 | f2fs_destroy_compress_mempool(); |
Chao Yu | f543805 | 2019-12-04 09:52:58 +0800 | [diff] [blame] | 4327 | f2fs_destroy_bioset(); |
Chao Yu | 0b20fce | 2019-09-30 18:53:25 +0800 | [diff] [blame] | 4328 | f2fs_destroy_bio_entry_cache(); |
Eric Biggers | 6dbb179 | 2018-04-18 11:09:48 -0700 | [diff] [blame] | 4329 | f2fs_destroy_post_read_processing(); |
Namjae Jeon | 4589d25 | 2013-01-15 19:58:47 +0900 | [diff] [blame] | 4330 | f2fs_destroy_root_stats(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4331 | unregister_filesystem(&f2fs_fs_type); |
Tiezhu Yang | b8bef79 | 2016-05-18 08:02:25 +0800 | [diff] [blame] | 4332 | unregister_shrinker(&f2fs_shrinker_info); |
Jaegeuk Kim | dc6b205 | 2017-07-26 11:24:13 -0700 | [diff] [blame] | 4333 | f2fs_exit_sysfs(); |
Chao Yu | 093749e | 2020-08-04 21:14:49 +0800 | [diff] [blame] | 4334 | f2fs_destroy_garbage_collection_cache(); |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4335 | f2fs_destroy_extent_cache(); |
Chao Yu | cad83c9 | 2021-05-07 18:10:38 +0800 | [diff] [blame] | 4336 | f2fs_destroy_recovery_cache(); |
Chao Yu | 4d57b86 | 2018-05-30 00:20:41 +0800 | [diff] [blame] | 4337 | f2fs_destroy_checkpoint_caches(); |
| 4338 | f2fs_destroy_segment_manager_caches(); |
| 4339 | f2fs_destroy_node_manager_caches(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4340 | destroy_inodecache(); |
Jaegeuk Kim | aff063e | 2012-11-02 17:07:47 +0900 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | module_init(init_f2fs_fs) |
| 4344 | module_exit(exit_f2fs_fs) |
| 4345 | |
| 4346 | MODULE_AUTHOR("Samsung Electronics's Praesto Team"); |
| 4347 | MODULE_DESCRIPTION("Flash Friendly File System"); |
| 4348 | MODULE_LICENSE("GPL"); |
Chao Yu | 0dd5717 | 2021-05-18 09:57:54 +0800 | [diff] [blame] | 4349 | MODULE_SOFTDEP("pre: crc32"); |
Jaegeuk Kim | b4b9d34 | 2016-11-04 14:59:15 -0700 | [diff] [blame] | 4350 | |