Gao Xiang | 29b24f6 | 2019-07-31 23:57:31 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 2 | /* |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 3 | * Copyright (C) 2017-2018 HUAWEI, Inc. |
| 4 | * http://www.huawei.com/ |
| 5 | * Created by Gao Xiang <gaoxiang25@huawei.com> |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/buffer_head.h> |
| 9 | #include <linux/statfs.h> |
| 10 | #include <linux/parser.h> |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 11 | #include <linux/seq_file.h> |
Gao Xiang | 6af7b48 | 2019-01-14 19:40:25 +0800 | [diff] [blame] | 12 | #include "xattr.h" |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 13 | |
Chao Yu | 13f06f4 | 2018-07-26 20:21:55 +0800 | [diff] [blame] | 14 | #define CREATE_TRACE_POINTS |
| 15 | #include <trace/events/erofs.h> |
| 16 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 17 | static struct kmem_cache *erofs_inode_cachep __read_mostly; |
| 18 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 19 | static void erofs_inode_init_once(void *ptr) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 20 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 21 | struct erofs_inode *vi = ptr; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 22 | |
| 23 | inode_init_once(&vi->vfs_inode); |
| 24 | } |
| 25 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 26 | static struct inode *erofs_alloc_inode(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 27 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 28 | struct erofs_inode *vi = |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 29 | kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL); |
| 30 | |
Vatsala Narang | e2ff9f1 | 2019-03-21 05:36:13 +0530 | [diff] [blame] | 31 | if (!vi) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 32 | return NULL; |
| 33 | |
| 34 | /* zero out everything except vfs_inode */ |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 35 | memset(vi, 0, offsetof(struct erofs_inode, vfs_inode)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 36 | return &vi->vfs_inode; |
| 37 | } |
| 38 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 39 | static void erofs_free_inode(struct inode *inode) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 40 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 41 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 42 | |
Gao Xiang | a2c75c8 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 43 | /* be careful of RCU symlink path */ |
| 44 | if (inode->i_op == &erofs_fast_symlink_iops) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 45 | kfree(inode->i_link); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 46 | kfree(vi->xattr_shared_xattrs); |
| 47 | |
| 48 | kmem_cache_free(erofs_inode_cachep, vi); |
| 49 | } |
| 50 | |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 51 | static bool check_layout_compatibility(struct super_block *sb, |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 52 | struct erofs_super_block *dsb) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 53 | { |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 54 | const unsigned int feature = le32_to_cpu(dsb->feature_incompat); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 55 | |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 56 | EROFS_SB(sb)->feature_incompat = feature; |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 57 | |
| 58 | /* check if current kernel meets all mandatory requirements */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 59 | if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) { |
| 60 | errln("unidentified incompatible feature %x, please upgrade kernel version", |
| 61 | feature & ~EROFS_ALL_FEATURE_INCOMPAT); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 62 | return false; |
| 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 67 | static int erofs_read_superblock(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 68 | { |
| 69 | struct erofs_sb_info *sbi; |
| 70 | struct buffer_head *bh; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 71 | struct erofs_super_block *dsb; |
Thomas Weißschuh | 7dd68b1 | 2018-09-10 21:41:14 +0200 | [diff] [blame] | 72 | unsigned int blkszbits; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 73 | int ret; |
| 74 | |
| 75 | bh = sb_bread(sb, 0); |
| 76 | |
Vatsala Narang | e2ff9f1 | 2019-03-21 05:36:13 +0530 | [diff] [blame] | 77 | if (!bh) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 78 | errln("cannot read erofs superblock"); |
| 79 | return -EIO; |
| 80 | } |
| 81 | |
| 82 | sbi = EROFS_SB(sb); |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 83 | dsb = (struct erofs_super_block *)(bh->b_data + EROFS_SUPER_OFFSET); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 84 | |
| 85 | ret = -EINVAL; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 86 | if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 87 | errln("cannot find valid erofs superblock"); |
| 88 | goto out; |
| 89 | } |
| 90 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 91 | blkszbits = dsb->blkszbits; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 92 | /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 93 | if (blkszbits != LOG_BLOCK_SIZE) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 94 | errln("blksize %u isn't supported on this platform", |
Julian Merida | 447a362 | 2019-03-18 20:58:41 -0300 | [diff] [blame] | 95 | 1 << blkszbits); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 96 | goto out; |
| 97 | } |
| 98 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 99 | if (!check_layout_compatibility(sb, dsb)) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 100 | goto out; |
| 101 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 102 | sbi->blocks = le32_to_cpu(dsb->blocks); |
| 103 | sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 104 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 105 | sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 106 | #endif |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 107 | sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 108 | sbi->root_nid = le16_to_cpu(dsb->root_nid); |
| 109 | sbi->inos = le64_to_cpu(dsb->inos); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 110 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 111 | sbi->build_time = le64_to_cpu(dsb->build_time); |
| 112 | sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 113 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 114 | memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 115 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 116 | ret = strscpy(sbi->volume_name, dsb->volume_name, |
| 117 | sizeof(dsb->volume_name)); |
Gao Xiang | a64d949 | 2019-08-18 18:28:24 +0800 | [diff] [blame] | 118 | if (ret < 0) { /* -E2BIG */ |
| 119 | errln("bad volume name without NIL terminator"); |
| 120 | ret = -EFSCORRUPTED; |
| 121 | goto out; |
| 122 | } |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 123 | ret = 0; |
| 124 | out: |
| 125 | brelse(bh); |
| 126 | return ret; |
| 127 | } |
| 128 | |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 129 | #ifdef CONFIG_EROFS_FAULT_INJECTION |
Gao Xiang | 14a56ec | 2019-03-25 11:40:09 +0800 | [diff] [blame] | 130 | const char *erofs_fault_name[FAULT_MAX] = { |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 131 | [FAULT_KMALLOC] = "kmalloc", |
Gao Xiang | 14a56ec | 2019-03-25 11:40:09 +0800 | [diff] [blame] | 132 | [FAULT_READ_IO] = "read IO error", |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 133 | }; |
| 134 | |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 135 | static void __erofs_build_fault_attr(struct erofs_sb_info *sbi, |
| 136 | unsigned int rate) |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 137 | { |
| 138 | struct erofs_fault_info *ffi = &sbi->fault_info; |
| 139 | |
| 140 | if (rate) { |
| 141 | atomic_set(&ffi->inject_ops, 0); |
| 142 | ffi->inject_rate = rate; |
| 143 | ffi->inject_type = (1 << FAULT_MAX) - 1; |
| 144 | } else { |
| 145 | memset(ffi, 0, sizeof(struct erofs_fault_info)); |
| 146 | } |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 147 | |
| 148 | set_opt(sbi, FAULT_INJECTION); |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static int erofs_build_fault_attr(struct erofs_sb_info *sbi, |
| 152 | substring_t *args) |
| 153 | { |
| 154 | int rate = 0; |
| 155 | |
| 156 | if (args->from && match_int(args, &rate)) |
| 157 | return -EINVAL; |
| 158 | |
| 159 | __erofs_build_fault_attr(sbi, rate); |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 160 | return 0; |
| 161 | } |
Chengguang Xu | 2ab3dd8 | 2018-09-19 22:53:45 +0800 | [diff] [blame] | 162 | |
| 163 | static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi) |
| 164 | { |
| 165 | return sbi->fault_info.inject_rate; |
| 166 | } |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 167 | #else |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 168 | static void __erofs_build_fault_attr(struct erofs_sb_info *sbi, |
| 169 | unsigned int rate) |
| 170 | { |
| 171 | } |
| 172 | |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 173 | static int erofs_build_fault_attr(struct erofs_sb_info *sbi, |
| 174 | substring_t *args) |
| 175 | { |
| 176 | infoln("fault_injection options not supported"); |
| 177 | return 0; |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 178 | } |
Chengguang Xu | 2ab3dd8 | 2018-09-19 22:53:45 +0800 | [diff] [blame] | 179 | |
| 180 | static unsigned int erofs_get_fault_rate(struct erofs_sb_info *sbi) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 184 | #endif |
| 185 | |
Gao Xiang | 5fb76bb | 2018-09-20 00:06:56 +0800 | [diff] [blame] | 186 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 187 | static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, |
| 188 | substring_t *args) |
| 189 | { |
| 190 | const char *cs = match_strdup(args); |
| 191 | int err = 0; |
| 192 | |
| 193 | if (!cs) { |
| 194 | errln("Not enough memory to store cache strategy"); |
| 195 | return -ENOMEM; |
| 196 | } |
| 197 | |
| 198 | if (!strcmp(cs, "disabled")) { |
| 199 | sbi->cache_strategy = EROFS_ZIP_CACHE_DISABLED; |
| 200 | } else if (!strcmp(cs, "readahead")) { |
| 201 | sbi->cache_strategy = EROFS_ZIP_CACHE_READAHEAD; |
| 202 | } else if (!strcmp(cs, "readaround")) { |
| 203 | sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND; |
| 204 | } else { |
| 205 | errln("Unrecognized cache strategy \"%s\"", cs); |
| 206 | err = -EINVAL; |
| 207 | } |
| 208 | kfree(cs); |
| 209 | return err; |
| 210 | } |
| 211 | #else |
| 212 | static int erofs_build_cache_strategy(struct erofs_sb_info *sbi, |
| 213 | substring_t *args) |
| 214 | { |
| 215 | infoln("EROFS compression is disabled, so cache strategy is ignored"); |
| 216 | return 0; |
| 217 | } |
Gao Xiang | 5fb76bb | 2018-09-20 00:06:56 +0800 | [diff] [blame] | 218 | #endif |
| 219 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 220 | /* set up default EROFS parameters */ |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 221 | static void erofs_default_options(struct erofs_sb_info *sbi) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 222 | { |
| 223 | #ifdef CONFIG_EROFS_FS_ZIP |
| 224 | sbi->cache_strategy = EROFS_ZIP_CACHE_READAROUND; |
| 225 | sbi->max_sync_decompress_pages = 3; |
| 226 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 227 | #ifdef CONFIG_EROFS_FS_XATTR |
| 228 | set_opt(sbi, XATTR_USER); |
| 229 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 230 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
| 231 | set_opt(sbi, POSIX_ACL); |
| 232 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | enum { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 236 | Opt_user_xattr, |
| 237 | Opt_nouser_xattr, |
| 238 | Opt_acl, |
| 239 | Opt_noacl, |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 240 | Opt_fault_injection, |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 241 | Opt_cache_strategy, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 242 | Opt_err |
| 243 | }; |
| 244 | |
| 245 | static match_table_t erofs_tokens = { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 246 | {Opt_user_xattr, "user_xattr"}, |
| 247 | {Opt_nouser_xattr, "nouser_xattr"}, |
| 248 | {Opt_acl, "acl"}, |
| 249 | {Opt_noacl, "noacl"}, |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 250 | {Opt_fault_injection, "fault_injection=%u"}, |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 251 | {Opt_cache_strategy, "cache_strategy=%s"}, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 252 | {Opt_err, NULL} |
| 253 | }; |
| 254 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 255 | static int erofs_parse_options(struct super_block *sb, char *options) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 256 | { |
| 257 | substring_t args[MAX_OPT_ARGS]; |
| 258 | char *p; |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 259 | int err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 260 | |
| 261 | if (!options) |
| 262 | return 0; |
| 263 | |
Bhanusree Pola | 561fb35 | 2019-03-22 10:38:16 +0800 | [diff] [blame] | 264 | while ((p = strsep(&options, ","))) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 265 | int token; |
| 266 | |
| 267 | if (!*p) |
| 268 | continue; |
| 269 | |
| 270 | args[0].to = args[0].from = NULL; |
| 271 | token = match_token(p, erofs_tokens, args); |
| 272 | |
| 273 | switch (token) { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 274 | #ifdef CONFIG_EROFS_FS_XATTR |
| 275 | case Opt_user_xattr: |
| 276 | set_opt(EROFS_SB(sb), XATTR_USER); |
| 277 | break; |
| 278 | case Opt_nouser_xattr: |
| 279 | clear_opt(EROFS_SB(sb), XATTR_USER); |
| 280 | break; |
| 281 | #else |
| 282 | case Opt_user_xattr: |
| 283 | infoln("user_xattr options not supported"); |
| 284 | break; |
| 285 | case Opt_nouser_xattr: |
| 286 | infoln("nouser_xattr options not supported"); |
| 287 | break; |
| 288 | #endif |
| 289 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
| 290 | case Opt_acl: |
| 291 | set_opt(EROFS_SB(sb), POSIX_ACL); |
| 292 | break; |
| 293 | case Opt_noacl: |
| 294 | clear_opt(EROFS_SB(sb), POSIX_ACL); |
| 295 | break; |
| 296 | #else |
| 297 | case Opt_acl: |
| 298 | infoln("acl options not supported"); |
| 299 | break; |
| 300 | case Opt_noacl: |
| 301 | infoln("noacl options not supported"); |
| 302 | break; |
| 303 | #endif |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 304 | case Opt_fault_injection: |
Chengguang Xu | 01e4ae4 | 2018-09-19 22:53:44 +0800 | [diff] [blame] | 305 | err = erofs_build_fault_attr(EROFS_SB(sb), args); |
| 306 | if (err) |
| 307 | return err; |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 308 | break; |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 309 | case Opt_cache_strategy: |
| 310 | err = erofs_build_cache_strategy(EROFS_SB(sb), args); |
| 311 | if (err) |
| 312 | return err; |
| 313 | break; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 314 | default: |
Gao Xiang | bc33d9f | 2019-07-31 23:57:51 +0800 | [diff] [blame] | 315 | errln("Unrecognized mount option \"%s\" or missing value", p); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 316 | return -EINVAL; |
| 317 | } |
| 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 322 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 323 | static const struct address_space_operations managed_cache_aops; |
| 324 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 325 | static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 326 | { |
| 327 | int ret = 1; /* 0 - busy */ |
| 328 | struct address_space *const mapping = page->mapping; |
| 329 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 330 | DBG_BUGON(!PageLocked(page)); |
| 331 | DBG_BUGON(mapping->a_ops != &managed_cache_aops); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 332 | |
| 333 | if (PagePrivate(page)) |
Gao Xiang | 47e541a | 2018-07-29 13:34:58 +0800 | [diff] [blame] | 334 | ret = erofs_try_to_free_cached_page(mapping, page); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 335 | |
| 336 | return ret; |
| 337 | } |
| 338 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 339 | static void erofs_managed_cache_invalidatepage(struct page *page, |
| 340 | unsigned int offset, |
| 341 | unsigned int length) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 342 | { |
| 343 | const unsigned int stop = length + offset; |
| 344 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 345 | DBG_BUGON(!PageLocked(page)); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 346 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 347 | /* Check for potential overflow in debug mode */ |
| 348 | DBG_BUGON(stop > PAGE_SIZE || stop < length); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 349 | |
| 350 | if (offset == 0 && stop == PAGE_SIZE) |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 351 | while (!erofs_managed_cache_releasepage(page, GFP_NOFS)) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 352 | cond_resched(); |
| 353 | } |
| 354 | |
| 355 | static const struct address_space_operations managed_cache_aops = { |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 356 | .releasepage = erofs_managed_cache_releasepage, |
| 357 | .invalidatepage = erofs_managed_cache_invalidatepage, |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 358 | }; |
| 359 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 360 | static int erofs_init_managed_cache(struct super_block *sb) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 361 | { |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 362 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 363 | struct inode *const inode = new_inode(sb); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 364 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 365 | if (!inode) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 366 | return -ENOMEM; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 367 | |
| 368 | set_nlink(inode, 1); |
| 369 | inode->i_size = OFFSET_MAX; |
| 370 | |
| 371 | inode->i_mapping->a_ops = &managed_cache_aops; |
| 372 | mapping_set_gfp_mask(inode->i_mapping, |
Gao Xiang | 8494c29 | 2019-07-31 23:57:42 +0800 | [diff] [blame] | 373 | GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 374 | sbi->managed_cache = inode; |
| 375 | return 0; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 376 | } |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 377 | #else |
| 378 | static int erofs_init_managed_cache(struct super_block *sb) { return 0; } |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 379 | #endif |
| 380 | |
Gao Xiang | 9e794de | 2019-07-31 23:57:40 +0800 | [diff] [blame] | 381 | static int erofs_fill_super(struct super_block *sb, void *data, int silent) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 382 | { |
| 383 | struct inode *inode; |
| 384 | struct erofs_sb_info *sbi; |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 385 | int err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 386 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 387 | sb->s_magic = EROFS_SUPER_MAGIC; |
| 388 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 389 | if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 390 | errln("failed to set erofs blksize"); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 391 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 392 | } |
| 393 | |
Shobhit Kukreti | a9f69bd | 2019-06-26 22:31:18 -0700 | [diff] [blame] | 394 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 395 | if (!sbi) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 396 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 397 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 398 | sb->s_fs_info = sbi; |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 399 | err = erofs_read_superblock(sb); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 400 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 401 | return err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 402 | |
Gao Xiang | 5f0abea | 2018-09-06 17:01:47 +0800 | [diff] [blame] | 403 | sb->s_flags |= SB_RDONLY | SB_NOATIME; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 404 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 405 | sb->s_time_gran = 1; |
| 406 | |
| 407 | sb->s_op = &erofs_sops; |
| 408 | |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 409 | #ifdef CONFIG_EROFS_FS_XATTR |
| 410 | sb->s_xattr = erofs_xattr_handlers; |
| 411 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 412 | /* set erofs default mount options */ |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 413 | erofs_default_options(sbi); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 414 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 415 | err = erofs_parse_options(sb, data); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 416 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 417 | return err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 418 | |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 419 | if (test_opt(sbi, POSIX_ACL)) |
| 420 | sb->s_flags |= SB_POSIXACL; |
| 421 | else |
| 422 | sb->s_flags &= ~SB_POSIXACL; |
| 423 | |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 424 | #ifdef CONFIG_EROFS_FS_ZIP |
| 425 | INIT_RADIX_TREE(&sbi->workstn_tree, GFP_ATOMIC); |
| 426 | #endif |
| 427 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 428 | /* get the root inode */ |
| 429 | inode = erofs_iget(sb, ROOT_NID(sbi), true); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 430 | if (IS_ERR(inode)) |
| 431 | return PTR_ERR(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 432 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 433 | if (!S_ISDIR(inode->i_mode)) { |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 434 | errln("rootino(nid %llu) is not a directory(i_mode %o)", |
Julian Merida | 447a362 | 2019-03-18 20:58:41 -0300 | [diff] [blame] | 435 | ROOT_NID(sbi), inode->i_mode); |
Chengguang Xu | 94832d9 | 2019-01-23 14:12:25 +0800 | [diff] [blame] | 436 | iput(inode); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 437 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | sb->s_root = d_make_root(inode); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 441 | if (!sb->s_root) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 442 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 443 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 444 | erofs_shrinker_register(sb); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 445 | /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ |
| 446 | err = erofs_init_managed_cache(sb); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 447 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 448 | return err; |
Gao Xiang | 2497ee4 | 2018-07-26 20:22:03 +0800 | [diff] [blame] | 449 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 450 | if (!silent) |
Gao Xiang | 688a5f2 | 2019-09-04 10:09:01 +0800 | [diff] [blame] | 451 | infoln("mounted on %s with opts: %s, root inode @ nid %llu.", |
| 452 | sb->s_id, (char *)data, ROOT_NID(sbi)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 453 | return 0; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 454 | } |
| 455 | |
Gao Xiang | 9e794de | 2019-07-31 23:57:40 +0800 | [diff] [blame] | 456 | static struct dentry *erofs_mount(struct file_system_type *fs_type, int flags, |
| 457 | const char *dev_name, void *data) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 458 | { |
Gao Xiang | 9e794de | 2019-07-31 23:57:40 +0800 | [diff] [blame] | 459 | return mount_bdev(fs_type, flags, dev_name, data, erofs_fill_super); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 460 | } |
| 461 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 462 | /* |
| 463 | * could be triggered after deactivate_locked_super() |
| 464 | * is called, thus including umount and failed to initialize. |
| 465 | */ |
| 466 | static void erofs_kill_sb(struct super_block *sb) |
| 467 | { |
| 468 | struct erofs_sb_info *sbi; |
| 469 | |
| 470 | WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC); |
| 471 | infoln("unmounting for %s", sb->s_id); |
| 472 | |
| 473 | kill_block_super(sb); |
| 474 | |
| 475 | sbi = EROFS_SB(sb); |
| 476 | if (!sbi) |
| 477 | return; |
| 478 | kfree(sbi); |
| 479 | sb->s_fs_info = NULL; |
| 480 | } |
| 481 | |
| 482 | /* called when ->s_root is non-NULL */ |
| 483 | static void erofs_put_super(struct super_block *sb) |
| 484 | { |
| 485 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 486 | |
| 487 | DBG_BUGON(!sbi); |
| 488 | |
| 489 | erofs_shrinker_unregister(sb); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 490 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 491 | iput(sbi->managed_cache); |
| 492 | sbi->managed_cache = NULL; |
| 493 | #endif |
| 494 | } |
| 495 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 496 | static struct file_system_type erofs_fs_type = { |
| 497 | .owner = THIS_MODULE, |
| 498 | .name = "erofs", |
| 499 | .mount = erofs_mount, |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 500 | .kill_sb = erofs_kill_sb, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 501 | .fs_flags = FS_REQUIRES_DEV, |
| 502 | }; |
| 503 | MODULE_ALIAS_FS("erofs"); |
| 504 | |
| 505 | static int __init erofs_module_init(void) |
| 506 | { |
| 507 | int err; |
| 508 | |
| 509 | erofs_check_ondisk_layout_definitions(); |
| 510 | infoln("initializing erofs " EROFS_VERSION); |
| 511 | |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 512 | erofs_inode_cachep = kmem_cache_create("erofs_inode", |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 513 | sizeof(struct erofs_inode), 0, |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 514 | SLAB_RECLAIM_ACCOUNT, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 515 | erofs_inode_init_once); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 516 | if (!erofs_inode_cachep) { |
| 517 | err = -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 518 | goto icache_err; |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 519 | } |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 520 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 521 | err = erofs_init_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 522 | if (err) |
| 523 | goto shrinker_err; |
| 524 | |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 525 | err = z_erofs_init_zip_subsystem(); |
| 526 | if (err) |
| 527 | goto zip_err; |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 528 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 529 | err = register_filesystem(&erofs_fs_type); |
| 530 | if (err) |
| 531 | goto fs_err; |
| 532 | |
| 533 | infoln("successfully to initialize erofs"); |
| 534 | return 0; |
| 535 | |
| 536 | fs_err: |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 537 | z_erofs_exit_zip_subsystem(); |
| 538 | zip_err: |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 539 | erofs_exit_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 540 | shrinker_err: |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 541 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 542 | icache_err: |
| 543 | return err; |
| 544 | } |
| 545 | |
| 546 | static void __exit erofs_module_exit(void) |
| 547 | { |
| 548 | unregister_filesystem(&erofs_fs_type); |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 549 | z_erofs_exit_zip_subsystem(); |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 550 | erofs_exit_shrinker(); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 551 | |
| 552 | /* Ensure all RCU free inodes are safe before cache is destroyed. */ |
| 553 | rcu_barrier(); |
| 554 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 555 | infoln("successfully finalize erofs"); |
| 556 | } |
| 557 | |
| 558 | /* get filesystem statistics */ |
| 559 | static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 560 | { |
| 561 | struct super_block *sb = dentry->d_sb; |
| 562 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 563 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 564 | |
| 565 | buf->f_type = sb->s_magic; |
| 566 | buf->f_bsize = EROFS_BLKSIZ; |
| 567 | buf->f_blocks = sbi->blocks; |
| 568 | buf->f_bfree = buf->f_bavail = 0; |
| 569 | |
| 570 | buf->f_files = ULLONG_MAX; |
| 571 | buf->f_ffree = ULLONG_MAX - sbi->inos; |
| 572 | |
| 573 | buf->f_namelen = EROFS_NAME_LEN; |
| 574 | |
| 575 | buf->f_fsid.val[0] = (u32)id; |
| 576 | buf->f_fsid.val[1] = (u32)(id >> 32); |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int erofs_show_options(struct seq_file *seq, struct dentry *root) |
| 581 | { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 582 | struct erofs_sb_info *sbi __maybe_unused = EROFS_SB(root->d_sb); |
| 583 | |
| 584 | #ifdef CONFIG_EROFS_FS_XATTR |
| 585 | if (test_opt(sbi, XATTR_USER)) |
| 586 | seq_puts(seq, ",user_xattr"); |
| 587 | else |
| 588 | seq_puts(seq, ",nouser_xattr"); |
| 589 | #endif |
| 590 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
| 591 | if (test_opt(sbi, POSIX_ACL)) |
| 592 | seq_puts(seq, ",acl"); |
| 593 | else |
| 594 | seq_puts(seq, ",noacl"); |
| 595 | #endif |
Chao Yu | 9c07b3b | 2018-07-26 20:21:54 +0800 | [diff] [blame] | 596 | if (test_opt(sbi, FAULT_INJECTION)) |
| 597 | seq_printf(seq, ",fault_injection=%u", |
Julian Merida | 447a362 | 2019-03-18 20:58:41 -0300 | [diff] [blame] | 598 | erofs_get_fault_rate(sbi)); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 599 | #ifdef CONFIG_EROFS_FS_ZIP |
| 600 | if (sbi->cache_strategy == EROFS_ZIP_CACHE_DISABLED) { |
| 601 | seq_puts(seq, ",cache_strategy=disabled"); |
| 602 | } else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAHEAD) { |
| 603 | seq_puts(seq, ",cache_strategy=readahead"); |
| 604 | } else if (sbi->cache_strategy == EROFS_ZIP_CACHE_READAROUND) { |
| 605 | seq_puts(seq, ",cache_strategy=readaround"); |
| 606 | } else { |
| 607 | seq_puts(seq, ",cache_strategy=(unknown)"); |
| 608 | DBG_BUGON(1); |
| 609 | } |
| 610 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | static int erofs_remount(struct super_block *sb, int *flags, char *data) |
| 615 | { |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 616 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 617 | unsigned int org_mnt_opt = sbi->mount_opt; |
| 618 | unsigned int org_inject_rate = erofs_get_fault_rate(sbi); |
| 619 | int err; |
| 620 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 621 | DBG_BUGON(!sb_rdonly(sb)); |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 622 | err = erofs_parse_options(sb, data); |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 623 | if (err) |
| 624 | goto out; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 625 | |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 626 | if (test_opt(sbi, POSIX_ACL)) |
| 627 | sb->s_flags |= SB_POSIXACL; |
| 628 | else |
| 629 | sb->s_flags &= ~SB_POSIXACL; |
| 630 | |
Gao Xiang | 5f0abea | 2018-09-06 17:01:47 +0800 | [diff] [blame] | 631 | *flags |= SB_RDONLY; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 632 | return 0; |
Chengguang Xu | d41076e | 2018-09-19 22:53:46 +0800 | [diff] [blame] | 633 | out: |
| 634 | __erofs_build_fault_attr(sbi, org_inject_rate); |
| 635 | sbi->mount_opt = org_mnt_opt; |
| 636 | |
| 637 | return err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | const struct super_operations erofs_sops = { |
| 641 | .put_super = erofs_put_super, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame^] | 642 | .alloc_inode = erofs_alloc_inode, |
| 643 | .free_inode = erofs_free_inode, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 644 | .statfs = erofs_statfs, |
| 645 | .show_options = erofs_show_options, |
| 646 | .remount_fs = erofs_remount, |
| 647 | }; |
| 648 | |
| 649 | module_init(erofs_module_init); |
| 650 | module_exit(erofs_module_exit); |
| 651 | |
| 652 | MODULE_DESCRIPTION("Enhanced ROM File System"); |
Gao Xiang | bc33d9f | 2019-07-31 23:57:51 +0800 | [diff] [blame] | 653 | MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc."); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 654 | MODULE_LICENSE("GPL"); |
| 655 | |