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. |
Alexander A. Klimov | 592e7cd | 2020-07-13 15:09:44 +0200 | [diff] [blame] | 4 | * https://www.huawei.com/ |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 5 | * Copyright (C) 2021, Alibaba Cloud |
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> |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 12 | #include <linux/crc32c.h> |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 13 | #include <linux/fs_context.h> |
| 14 | #include <linux/fs_parser.h> |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 15 | #include <linux/dax.h> |
Gao Xiang | 6af7b48 | 2019-01-14 19:40:25 +0800 | [diff] [blame] | 16 | #include "xattr.h" |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 17 | |
Chao Yu | 13f06f4 | 2018-07-26 20:21:55 +0800 | [diff] [blame] | 18 | #define CREATE_TRACE_POINTS |
| 19 | #include <trace/events/erofs.h> |
| 20 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 21 | static struct kmem_cache *erofs_inode_cachep __read_mostly; |
| 22 | |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 23 | void _erofs_err(struct super_block *sb, const char *function, |
| 24 | const char *fmt, ...) |
| 25 | { |
| 26 | struct va_format vaf; |
| 27 | va_list args; |
| 28 | |
| 29 | va_start(args, fmt); |
| 30 | |
| 31 | vaf.fmt = fmt; |
| 32 | vaf.va = &args; |
| 33 | |
| 34 | pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf); |
| 35 | va_end(args); |
| 36 | } |
| 37 | |
| 38 | void _erofs_info(struct super_block *sb, const char *function, |
| 39 | const char *fmt, ...) |
| 40 | { |
| 41 | struct va_format vaf; |
| 42 | va_list args; |
| 43 | |
| 44 | va_start(args, fmt); |
| 45 | |
| 46 | vaf.fmt = fmt; |
| 47 | vaf.va = &args; |
| 48 | |
| 49 | pr_info("(device %s): %pV", sb->s_id, &vaf); |
| 50 | va_end(args); |
| 51 | } |
| 52 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 53 | static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata) |
| 54 | { |
| 55 | struct erofs_super_block *dsb; |
| 56 | u32 expected_crc, crc; |
| 57 | |
| 58 | dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET, |
| 59 | EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL); |
| 60 | if (!dsb) |
| 61 | return -ENOMEM; |
| 62 | |
| 63 | expected_crc = le32_to_cpu(dsb->checksum); |
| 64 | dsb->checksum = 0; |
| 65 | /* to allow for x86 boot sectors and other oddities. */ |
| 66 | crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET); |
| 67 | kfree(dsb); |
| 68 | |
| 69 | if (crc != expected_crc) { |
| 70 | erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected", |
| 71 | crc, expected_crc); |
| 72 | return -EBADMSG; |
| 73 | } |
| 74 | return 0; |
| 75 | } |
| 76 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 77 | static void erofs_inode_init_once(void *ptr) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 78 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 79 | struct erofs_inode *vi = ptr; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 80 | |
| 81 | inode_init_once(&vi->vfs_inode); |
| 82 | } |
| 83 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 84 | static struct inode *erofs_alloc_inode(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 85 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 86 | struct erofs_inode *vi = |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 87 | kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL); |
| 88 | |
Vatsala Narang | e2ff9f1 | 2019-03-21 05:36:13 +0530 | [diff] [blame] | 89 | if (!vi) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 90 | return NULL; |
| 91 | |
| 92 | /* zero out everything except vfs_inode */ |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 93 | memset(vi, 0, offsetof(struct erofs_inode, vfs_inode)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 94 | return &vi->vfs_inode; |
| 95 | } |
| 96 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 97 | static void erofs_free_inode(struct inode *inode) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 98 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 99 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 100 | |
Gao Xiang | a2c75c8 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 101 | /* be careful of RCU symlink path */ |
| 102 | if (inode->i_op == &erofs_fast_symlink_iops) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 103 | kfree(inode->i_link); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 104 | kfree(vi->xattr_shared_xattrs); |
| 105 | |
| 106 | kmem_cache_free(erofs_inode_cachep, vi); |
| 107 | } |
| 108 | |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 109 | static bool check_layout_compatibility(struct super_block *sb, |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 110 | struct erofs_super_block *dsb) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 111 | { |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 112 | const unsigned int feature = le32_to_cpu(dsb->feature_incompat); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 113 | |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 114 | EROFS_SB(sb)->feature_incompat = feature; |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 115 | |
| 116 | /* check if current kernel meets all mandatory requirements */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 117 | if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 118 | erofs_err(sb, |
| 119 | "unidentified incompatible feature %x, please upgrade kernel version", |
| 120 | feature & ~EROFS_ALL_FEATURE_INCOMPAT); |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 121 | return false; |
| 122 | } |
| 123 | return true; |
| 124 | } |
| 125 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 126 | #ifdef CONFIG_EROFS_FS_ZIP |
| 127 | /* read variable-sized metadata, offset will be aligned by 4-byte */ |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 128 | static void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 129 | erofs_off_t *offset, int *lengthp) |
| 130 | { |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 131 | u8 *buffer, *ptr; |
| 132 | int len, i, cnt; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 133 | |
| 134 | *offset = round_up(*offset, 4); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 135 | ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), EROFS_KMAP); |
| 136 | if (IS_ERR(ptr)) |
| 137 | return ptr; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 138 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 139 | len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]); |
| 140 | if (!len) |
| 141 | len = U16_MAX + 1; |
| 142 | buffer = kmalloc(len, GFP_KERNEL); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 143 | if (!buffer) |
| 144 | return ERR_PTR(-ENOMEM); |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 145 | *offset += sizeof(__le16); |
| 146 | *lengthp = len; |
| 147 | |
| 148 | for (i = 0; i < len; i += cnt) { |
| 149 | cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 150 | ptr = erofs_read_metabuf(buf, sb, erofs_blknr(*offset), |
| 151 | EROFS_KMAP); |
| 152 | if (IS_ERR(ptr)) { |
| 153 | kfree(buffer); |
| 154 | return ptr; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 155 | } |
| 156 | memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt); |
| 157 | *offset += cnt; |
| 158 | } |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 159 | return buffer; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int erofs_load_compr_cfgs(struct super_block *sb, |
| 163 | struct erofs_super_block *dsb) |
| 164 | { |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 165 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 166 | struct erofs_buf buf = __EROFS_BUF_INITIALIZER; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 167 | unsigned int algs, alg; |
| 168 | erofs_off_t offset; |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 169 | int size, ret = 0; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 170 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 171 | sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs); |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 172 | if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) { |
| 173 | erofs_err(sb, "try to load compressed fs with unsupported algorithms %x", |
| 174 | sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | offset = EROFS_SUPER_OFFSET + sbi->sb_size; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 179 | alg = 0; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 180 | for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) { |
| 181 | void *data; |
| 182 | |
| 183 | if (!(algs & 1)) |
| 184 | continue; |
| 185 | |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 186 | data = erofs_read_metadata(sb, &buf, &offset, &size); |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 187 | if (IS_ERR(data)) { |
| 188 | ret = PTR_ERR(data); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 189 | break; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | switch (alg) { |
| 193 | case Z_EROFS_COMPRESSION_LZ4: |
| 194 | ret = z_erofs_load_lz4_config(sb, dsb, data, size); |
| 195 | break; |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 196 | case Z_EROFS_COMPRESSION_LZMA: |
| 197 | ret = z_erofs_load_lzma_config(sb, dsb, data, size); |
| 198 | break; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 199 | default: |
| 200 | DBG_BUGON(1); |
| 201 | ret = -EFAULT; |
| 202 | } |
| 203 | kfree(data); |
| 204 | if (ret) |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 205 | break; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 206 | } |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 207 | erofs_put_metabuf(&buf); |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 208 | return ret; |
| 209 | } |
| 210 | #else |
| 211 | static int erofs_load_compr_cfgs(struct super_block *sb, |
| 212 | struct erofs_super_block *dsb) |
| 213 | { |
| 214 | if (dsb->u1.available_compr_algs) { |
| 215 | erofs_err(sb, "try to load compressed fs when compression is disabled"); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | return 0; |
| 219 | } |
| 220 | #endif |
| 221 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 222 | static int erofs_init_devices(struct super_block *sb, |
| 223 | struct erofs_super_block *dsb) |
| 224 | { |
| 225 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 226 | unsigned int ondisk_extradevs; |
| 227 | erofs_off_t pos; |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 228 | struct erofs_buf buf = __EROFS_BUF_INITIALIZER; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 229 | struct erofs_device_info *dif; |
| 230 | struct erofs_deviceslot *dis; |
| 231 | void *ptr; |
| 232 | int id, err = 0; |
| 233 | |
| 234 | sbi->total_blocks = sbi->primarydevice_blocks; |
| 235 | if (!erofs_sb_has_device_table(sbi)) |
| 236 | ondisk_extradevs = 0; |
| 237 | else |
| 238 | ondisk_extradevs = le16_to_cpu(dsb->extra_devices); |
| 239 | |
| 240 | if (ondisk_extradevs != sbi->devs->extra_devices) { |
| 241 | erofs_err(sb, "extra devices don't match (ondisk %u, given %u)", |
| 242 | ondisk_extradevs, sbi->devs->extra_devices); |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | if (!ondisk_extradevs) |
| 246 | return 0; |
| 247 | |
| 248 | sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1; |
| 249 | pos = le16_to_cpu(dsb->devt_slotoff) * EROFS_DEVT_SLOT_SIZE; |
| 250 | down_read(&sbi->devs->rwsem); |
| 251 | idr_for_each_entry(&sbi->devs->tree, dif, id) { |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 252 | struct block_device *bdev; |
| 253 | |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 254 | ptr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), |
| 255 | EROFS_KMAP); |
| 256 | if (IS_ERR(ptr)) { |
| 257 | err = PTR_ERR(ptr); |
| 258 | break; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 259 | } |
| 260 | dis = ptr + erofs_blkoff(pos); |
| 261 | |
| 262 | bdev = blkdev_get_by_path(dif->path, |
| 263 | FMODE_READ | FMODE_EXCL, |
| 264 | sb->s_type); |
| 265 | if (IS_ERR(bdev)) { |
| 266 | err = PTR_ERR(bdev); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 267 | break; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 268 | } |
| 269 | dif->bdev = bdev; |
Christoph Hellwig | cd913c7 | 2021-11-29 11:21:59 +0100 | [diff] [blame] | 270 | dif->dax_dev = fs_dax_get_by_bdev(bdev, &dif->dax_part_off); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 271 | dif->blocks = le32_to_cpu(dis->blocks); |
| 272 | dif->mapped_blkaddr = le32_to_cpu(dis->mapped_blkaddr); |
| 273 | sbi->total_blocks += dif->blocks; |
| 274 | pos += EROFS_DEVT_SLOT_SIZE; |
| 275 | } |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 276 | up_read(&sbi->devs->rwsem); |
Gao Xiang | 2b5379f | 2022-01-02 16:13:17 +0800 | [diff] [blame] | 277 | erofs_put_metabuf(&buf); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 278 | return err; |
| 279 | } |
| 280 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 281 | static int erofs_read_superblock(struct super_block *sb) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 282 | { |
| 283 | struct erofs_sb_info *sbi; |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 284 | struct page *page; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 285 | struct erofs_super_block *dsb; |
Thomas Weißschuh | 7dd68b1 | 2018-09-10 21:41:14 +0200 | [diff] [blame] | 286 | unsigned int blkszbits; |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 287 | void *data; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 288 | int ret; |
| 289 | |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 290 | page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL); |
Wei Yongjun | 517d6b9 | 2019-09-18 08:30:33 +0000 | [diff] [blame] | 291 | if (IS_ERR(page)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 292 | erofs_err(sb, "cannot read erofs superblock"); |
Wei Yongjun | 517d6b9 | 2019-09-18 08:30:33 +0000 | [diff] [blame] | 293 | return PTR_ERR(page); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | sbi = EROFS_SB(sb); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 297 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 298 | data = kmap(page); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 299 | dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 300 | |
| 301 | ret = -EINVAL; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 302 | if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 303 | erofs_err(sb, "cannot find valid erofs superblock"); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 304 | goto out; |
| 305 | } |
| 306 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 307 | sbi->feature_compat = le32_to_cpu(dsb->feature_compat); |
Gao Xiang | de06a6a | 2021-03-29 09:23:05 +0800 | [diff] [blame] | 308 | if (erofs_sb_has_sb_chksum(sbi)) { |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 309 | ret = erofs_superblock_csum_verify(sb, data); |
| 310 | if (ret) |
| 311 | goto out; |
| 312 | } |
| 313 | |
Wei Yongjun | 0508c1a | 2021-05-19 14:16:57 +0000 | [diff] [blame] | 314 | ret = -EINVAL; |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 315 | blkszbits = dsb->blkszbits; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 316 | /* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */ |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 317 | if (blkszbits != LOG_BLOCK_SIZE) { |
Gao Xiang | bde5452 | 2021-01-20 09:30:16 +0800 | [diff] [blame] | 318 | erofs_err(sb, "blkszbits %u isn't supported on this platform", |
| 319 | blkszbits); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 320 | goto out; |
| 321 | } |
| 322 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 323 | if (!check_layout_compatibility(sb, dsb)) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 324 | goto out; |
| 325 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 326 | sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE; |
| 327 | if (sbi->sb_size > EROFS_BLKSIZ) { |
| 328 | erofs_err(sb, "invalid sb_extslots %u (more than a fs block)", |
| 329 | sbi->sb_size); |
| 330 | goto out; |
| 331 | } |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 332 | sbi->primarydevice_blocks = le32_to_cpu(dsb->blocks); |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 333 | sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 334 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 335 | sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 336 | #endif |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 337 | sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact)); |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 338 | sbi->root_nid = le16_to_cpu(dsb->root_nid); |
| 339 | sbi->inos = le64_to_cpu(dsb->inos); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 340 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 341 | sbi->build_time = le64_to_cpu(dsb->build_time); |
| 342 | sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 343 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 344 | memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 345 | |
Gao Xiang | 0259f20 | 2019-09-04 10:09:00 +0800 | [diff] [blame] | 346 | ret = strscpy(sbi->volume_name, dsb->volume_name, |
| 347 | sizeof(dsb->volume_name)); |
Gao Xiang | a64d949 | 2019-08-18 18:28:24 +0800 | [diff] [blame] | 348 | if (ret < 0) { /* -E2BIG */ |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 349 | erofs_err(sb, "bad volume name without NIL terminator"); |
Gao Xiang | a64d949 | 2019-08-18 18:28:24 +0800 | [diff] [blame] | 350 | ret = -EFSCORRUPTED; |
| 351 | goto out; |
| 352 | } |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 353 | |
| 354 | /* parse on-disk compression configurations */ |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 355 | if (erofs_sb_has_compr_cfgs(sbi)) |
| 356 | ret = erofs_load_compr_cfgs(sb, dsb); |
| 357 | else |
| 358 | ret = z_erofs_load_lz4_config(sb, dsb, NULL, 0); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 359 | if (ret < 0) |
| 360 | goto out; |
| 361 | |
| 362 | /* handle multiple devices */ |
| 363 | ret = erofs_init_devices(sb, dsb); |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 364 | |
| 365 | if (erofs_sb_has_ztailpacking(sbi)) |
| 366 | erofs_info(sb, "EXPERIMENTAL compressed inline data feature in use. Use at your own risk!"); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 367 | out: |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 368 | kunmap(page); |
Gao Xiang | fe7c242 | 2019-09-04 10:09:10 +0800 | [diff] [blame] | 369 | put_page(page); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 370 | return ret; |
| 371 | } |
| 372 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 373 | /* set up default EROFS parameters */ |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 374 | static void erofs_default_options(struct erofs_fs_context *ctx) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 375 | { |
| 376 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 377 | ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND; |
| 378 | ctx->opt.max_sync_decompress_pages = 3; |
Huang Jianan | 40452ff | 2021-12-06 22:35:52 +0800 | [diff] [blame] | 379 | ctx->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO; |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 380 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 381 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 382 | set_opt(&ctx->opt, XATTR_USER); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 383 | #endif |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 384 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 385 | set_opt(&ctx->opt, POSIX_ACL); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 386 | #endif |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | enum { |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 390 | Opt_user_xattr, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 391 | Opt_acl, |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 392 | Opt_cache_strategy, |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 393 | Opt_dax, |
| 394 | Opt_dax_enum, |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 395 | Opt_device, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 396 | Opt_err |
| 397 | }; |
| 398 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 399 | static const struct constant_table erofs_param_cache_strategy[] = { |
| 400 | {"disabled", EROFS_ZIP_CACHE_DISABLED}, |
| 401 | {"readahead", EROFS_ZIP_CACHE_READAHEAD}, |
| 402 | {"readaround", EROFS_ZIP_CACHE_READAROUND}, |
| 403 | {} |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 404 | }; |
| 405 | |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 406 | static const struct constant_table erofs_dax_param_enums[] = { |
| 407 | {"always", EROFS_MOUNT_DAX_ALWAYS}, |
| 408 | {"never", EROFS_MOUNT_DAX_NEVER}, |
| 409 | {} |
| 410 | }; |
| 411 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 412 | static const struct fs_parameter_spec erofs_fs_parameters[] = { |
| 413 | fsparam_flag_no("user_xattr", Opt_user_xattr), |
| 414 | fsparam_flag_no("acl", Opt_acl), |
| 415 | fsparam_enum("cache_strategy", Opt_cache_strategy, |
| 416 | erofs_param_cache_strategy), |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 417 | fsparam_flag("dax", Opt_dax), |
| 418 | fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums), |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 419 | fsparam_string("device", Opt_device), |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 420 | {} |
| 421 | }; |
| 422 | |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 423 | static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode) |
| 424 | { |
| 425 | #ifdef CONFIG_FS_DAX |
| 426 | struct erofs_fs_context *ctx = fc->fs_private; |
| 427 | |
| 428 | switch (mode) { |
| 429 | case EROFS_MOUNT_DAX_ALWAYS: |
| 430 | warnfc(fc, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk"); |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 431 | set_opt(&ctx->opt, DAX_ALWAYS); |
| 432 | clear_opt(&ctx->opt, DAX_NEVER); |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 433 | return true; |
| 434 | case EROFS_MOUNT_DAX_NEVER: |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 435 | set_opt(&ctx->opt, DAX_NEVER); |
| 436 | clear_opt(&ctx->opt, DAX_ALWAYS); |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 437 | return true; |
| 438 | default: |
| 439 | DBG_BUGON(1); |
| 440 | return false; |
| 441 | } |
| 442 | #else |
| 443 | errorfc(fc, "dax options not supported"); |
| 444 | return false; |
| 445 | #endif |
| 446 | } |
| 447 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 448 | static int erofs_fc_parse_param(struct fs_context *fc, |
| 449 | struct fs_parameter *param) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 450 | { |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 451 | struct erofs_fs_context *ctx = fc->fs_private; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 452 | struct fs_parse_result result; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 453 | struct erofs_device_info *dif; |
| 454 | int opt, ret; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 455 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 456 | opt = fs_parse(fc, erofs_fs_parameters, param, &result); |
| 457 | if (opt < 0) |
| 458 | return opt; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 459 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 460 | switch (opt) { |
| 461 | case Opt_user_xattr: |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 462 | #ifdef CONFIG_EROFS_FS_XATTR |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 463 | if (result.boolean) |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 464 | set_opt(&ctx->opt, XATTR_USER); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 465 | else |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 466 | clear_opt(&ctx->opt, XATTR_USER); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 467 | #else |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 468 | errorfc(fc, "{,no}user_xattr options not supported"); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 469 | #endif |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 470 | break; |
| 471 | case Opt_acl: |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 472 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 473 | if (result.boolean) |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 474 | set_opt(&ctx->opt, POSIX_ACL); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 475 | else |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 476 | clear_opt(&ctx->opt, POSIX_ACL); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 477 | #else |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 478 | errorfc(fc, "{,no}acl options not supported"); |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 479 | #endif |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 480 | break; |
| 481 | case Opt_cache_strategy: |
| 482 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 483 | ctx->opt.cache_strategy = result.uint_32; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 484 | #else |
| 485 | errorfc(fc, "compression not supported, cache_strategy ignored"); |
| 486 | #endif |
| 487 | break; |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 488 | case Opt_dax: |
| 489 | if (!erofs_fc_set_dax_mode(fc, EROFS_MOUNT_DAX_ALWAYS)) |
| 490 | return -EINVAL; |
| 491 | break; |
| 492 | case Opt_dax_enum: |
| 493 | if (!erofs_fc_set_dax_mode(fc, result.uint_32)) |
| 494 | return -EINVAL; |
| 495 | break; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 496 | case Opt_device: |
| 497 | dif = kzalloc(sizeof(*dif), GFP_KERNEL); |
| 498 | if (!dif) |
| 499 | return -ENOMEM; |
| 500 | dif->path = kstrdup(param->string, GFP_KERNEL); |
| 501 | if (!dif->path) { |
| 502 | kfree(dif); |
| 503 | return -ENOMEM; |
| 504 | } |
| 505 | down_write(&ctx->devs->rwsem); |
| 506 | ret = idr_alloc(&ctx->devs->tree, dif, 0, 0, GFP_KERNEL); |
| 507 | up_write(&ctx->devs->rwsem); |
| 508 | if (ret < 0) { |
| 509 | kfree(dif->path); |
| 510 | kfree(dif); |
| 511 | return ret; |
| 512 | } |
| 513 | ++ctx->devs->extra_devices; |
| 514 | break; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 515 | default: |
| 516 | return -ENOPARAM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 517 | } |
| 518 | return 0; |
| 519 | } |
| 520 | |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 521 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 522 | static const struct address_space_operations managed_cache_aops; |
| 523 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 524 | 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] | 525 | { |
| 526 | int ret = 1; /* 0 - busy */ |
| 527 | struct address_space *const mapping = page->mapping; |
| 528 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 529 | DBG_BUGON(!PageLocked(page)); |
| 530 | DBG_BUGON(mapping->a_ops != &managed_cache_aops); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 531 | |
| 532 | if (PagePrivate(page)) |
Yue Hu | d252ff3 | 2021-08-10 15:24:16 +0800 | [diff] [blame] | 533 | ret = erofs_try_to_free_cached_page(page); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 534 | |
| 535 | return ret; |
| 536 | } |
| 537 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 538 | static void erofs_managed_cache_invalidatepage(struct page *page, |
| 539 | unsigned int offset, |
| 540 | unsigned int length) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 541 | { |
| 542 | const unsigned int stop = length + offset; |
| 543 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 544 | DBG_BUGON(!PageLocked(page)); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 545 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 546 | /* Check for potential overflow in debug mode */ |
| 547 | DBG_BUGON(stop > PAGE_SIZE || stop < length); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 548 | |
| 549 | if (offset == 0 && stop == PAGE_SIZE) |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 550 | while (!erofs_managed_cache_releasepage(page, GFP_NOFS)) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 551 | cond_resched(); |
| 552 | } |
| 553 | |
| 554 | static const struct address_space_operations managed_cache_aops = { |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 555 | .releasepage = erofs_managed_cache_releasepage, |
| 556 | .invalidatepage = erofs_managed_cache_invalidatepage, |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 557 | }; |
| 558 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 559 | static int erofs_init_managed_cache(struct super_block *sb) |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 560 | { |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 561 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 562 | struct inode *const inode = new_inode(sb); |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 563 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 564 | if (!inode) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 565 | return -ENOMEM; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 566 | |
| 567 | set_nlink(inode, 1); |
| 568 | inode->i_size = OFFSET_MAX; |
| 569 | |
| 570 | inode->i_mapping->a_ops = &managed_cache_aops; |
| 571 | mapping_set_gfp_mask(inode->i_mapping, |
Gao Xiang | 8494c29 | 2019-07-31 23:57:42 +0800 | [diff] [blame] | 572 | GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 573 | sbi->managed_cache = inode; |
| 574 | return 0; |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 575 | } |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 576 | #else |
| 577 | static int erofs_init_managed_cache(struct super_block *sb) { return 0; } |
Gao Xiang | 105d4ad | 2018-07-26 20:22:07 +0800 | [diff] [blame] | 578 | #endif |
| 579 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 580 | static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 581 | { |
| 582 | struct inode *inode; |
| 583 | struct erofs_sb_info *sbi; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 584 | struct erofs_fs_context *ctx = fc->fs_private; |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 585 | int err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 586 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 587 | sb->s_magic = EROFS_SUPER_MAGIC; |
| 588 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 589 | if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 590 | erofs_err(sb, "failed to set erofs blksize"); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 591 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 592 | } |
| 593 | |
Shobhit Kukreti | a9f69bd | 2019-06-26 22:31:18 -0700 | [diff] [blame] | 594 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 595 | if (!sbi) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 596 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 597 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 598 | sb->s_fs_info = sbi; |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 599 | sbi->opt = ctx->opt; |
Christoph Hellwig | cd913c7 | 2021-11-29 11:21:59 +0100 | [diff] [blame] | 600 | sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev, &sbi->dax_part_off); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 601 | sbi->devs = ctx->devs; |
| 602 | ctx->devs = NULL; |
| 603 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 604 | err = erofs_read_superblock(sb); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 605 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 606 | return err; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 607 | |
Christoph Hellwig | 7b0800d | 2021-11-29 11:21:42 +0100 | [diff] [blame] | 608 | if (test_opt(&sbi->opt, DAX_ALWAYS)) { |
| 609 | BUILD_BUG_ON(EROFS_BLKSIZ != PAGE_SIZE); |
| 610 | |
| 611 | if (!sbi->dax_dev) { |
| 612 | errorfc(fc, "DAX unsupported by block device. Turning off DAX."); |
| 613 | clear_opt(&sbi->opt, DAX_ALWAYS); |
| 614 | } |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 615 | } |
Gao Xiang | 5f0abea | 2018-09-06 17:01:47 +0800 | [diff] [blame] | 616 | sb->s_flags |= SB_RDONLY | SB_NOATIME; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 617 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 618 | sb->s_time_gran = 1; |
| 619 | |
| 620 | sb->s_op = &erofs_sops; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 621 | sb->s_xattr = erofs_xattr_handlers; |
Chengguang Xu | e7cda1e | 2020-05-26 17:03:43 +0800 | [diff] [blame] | 622 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 623 | if (test_opt(&sbi->opt, POSIX_ACL)) |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 624 | sb->s_flags |= SB_POSIXACL; |
| 625 | else |
| 626 | sb->s_flags &= ~SB_POSIXACL; |
| 627 | |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 628 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 64094a0 | 2020-02-20 10:46:42 +0800 | [diff] [blame] | 629 | xa_init(&sbi->managed_pslots); |
Gao Xiang | e7e9a30 | 2018-07-26 20:22:05 +0800 | [diff] [blame] | 630 | #endif |
| 631 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 632 | /* get the root inode */ |
| 633 | inode = erofs_iget(sb, ROOT_NID(sbi), true); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 634 | if (IS_ERR(inode)) |
| 635 | return PTR_ERR(inode); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 636 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 637 | if (!S_ISDIR(inode->i_mode)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 638 | erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)", |
| 639 | ROOT_NID(sbi), inode->i_mode); |
Chengguang Xu | 94832d9 | 2019-01-23 14:12:25 +0800 | [diff] [blame] | 640 | iput(inode); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 641 | return -EINVAL; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | sb->s_root = d_make_root(inode); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 645 | if (!sb->s_root) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 646 | return -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 647 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 648 | erofs_shrinker_register(sb); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 649 | /* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */ |
| 650 | err = erofs_init_managed_cache(sb); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 651 | if (err) |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 652 | return err; |
Gao Xiang | 2497ee4 | 2018-07-26 20:22:03 +0800 | [diff] [blame] | 653 | |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 654 | err = erofs_register_sysfs(sb); |
| 655 | if (err) |
| 656 | return err; |
| 657 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 658 | erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi)); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 659 | return 0; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 660 | } |
| 661 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 662 | static int erofs_fc_get_tree(struct fs_context *fc) |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 663 | { |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 664 | return get_tree_bdev(fc, erofs_fc_fill_super); |
| 665 | } |
| 666 | |
| 667 | static int erofs_fc_reconfigure(struct fs_context *fc) |
| 668 | { |
| 669 | struct super_block *sb = fc->root->d_sb; |
| 670 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 671 | struct erofs_fs_context *ctx = fc->fs_private; |
| 672 | |
| 673 | DBG_BUGON(!sb_rdonly(sb)); |
| 674 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 675 | if (test_opt(&ctx->opt, POSIX_ACL)) |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 676 | fc->sb_flags |= SB_POSIXACL; |
| 677 | else |
| 678 | fc->sb_flags &= ~SB_POSIXACL; |
| 679 | |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 680 | sbi->opt = ctx->opt; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 681 | |
| 682 | fc->sb_flags |= SB_RDONLY; |
| 683 | return 0; |
| 684 | } |
| 685 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 686 | static int erofs_release_device_info(int id, void *ptr, void *data) |
| 687 | { |
| 688 | struct erofs_device_info *dif = ptr; |
| 689 | |
| 690 | fs_put_dax(dif->dax_dev); |
| 691 | if (dif->bdev) |
| 692 | blkdev_put(dif->bdev, FMODE_READ | FMODE_EXCL); |
| 693 | kfree(dif->path); |
| 694 | kfree(dif); |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static void erofs_free_dev_context(struct erofs_dev_context *devs) |
| 699 | { |
| 700 | if (!devs) |
| 701 | return; |
| 702 | idr_for_each(&devs->tree, &erofs_release_device_info, NULL); |
| 703 | idr_destroy(&devs->tree); |
| 704 | kfree(devs); |
| 705 | } |
| 706 | |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 707 | static void erofs_fc_free(struct fs_context *fc) |
| 708 | { |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 709 | struct erofs_fs_context *ctx = fc->fs_private; |
| 710 | |
| 711 | erofs_free_dev_context(ctx->devs); |
| 712 | kfree(ctx); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static const struct fs_context_operations erofs_context_ops = { |
| 716 | .parse_param = erofs_fc_parse_param, |
| 717 | .get_tree = erofs_fc_get_tree, |
| 718 | .reconfigure = erofs_fc_reconfigure, |
| 719 | .free = erofs_fc_free, |
| 720 | }; |
| 721 | |
| 722 | static int erofs_init_fs_context(struct fs_context *fc) |
| 723 | { |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 724 | struct erofs_fs_context *ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 725 | |
| 726 | if (!ctx) |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 727 | return -ENOMEM; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 728 | ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); |
| 729 | if (!ctx->devs) { |
| 730 | kfree(ctx); |
| 731 | return -ENOMEM; |
| 732 | } |
| 733 | fc->fs_private = ctx; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 734 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 735 | idr_init(&ctx->devs->tree); |
| 736 | init_rwsem(&ctx->devs->rwsem); |
| 737 | erofs_default_options(ctx); |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 738 | fc->ops = &erofs_context_ops; |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 739 | return 0; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 740 | } |
| 741 | |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 742 | /* |
| 743 | * could be triggered after deactivate_locked_super() |
| 744 | * is called, thus including umount and failed to initialize. |
| 745 | */ |
| 746 | static void erofs_kill_sb(struct super_block *sb) |
| 747 | { |
| 748 | struct erofs_sb_info *sbi; |
| 749 | |
| 750 | WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 751 | |
| 752 | kill_block_super(sb); |
| 753 | |
| 754 | sbi = EROFS_SB(sb); |
| 755 | if (!sbi) |
| 756 | return; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 757 | |
| 758 | erofs_free_dev_context(sbi->devs); |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 759 | fs_put_dax(sbi->dax_dev); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 760 | kfree(sbi); |
| 761 | sb->s_fs_info = NULL; |
| 762 | } |
| 763 | |
| 764 | /* called when ->s_root is non-NULL */ |
| 765 | static void erofs_put_super(struct super_block *sb) |
| 766 | { |
| 767 | struct erofs_sb_info *const sbi = EROFS_SB(sb); |
| 768 | |
| 769 | DBG_BUGON(!sbi); |
| 770 | |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 771 | erofs_unregister_sysfs(sb); |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 772 | erofs_shrinker_unregister(sb); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 773 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 774 | iput(sbi->managed_cache); |
| 775 | sbi->managed_cache = NULL; |
| 776 | #endif |
| 777 | } |
| 778 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 779 | static struct file_system_type erofs_fs_type = { |
| 780 | .owner = THIS_MODULE, |
| 781 | .name = "erofs", |
Chao Yu | f57a3fe | 2020-05-29 18:48:36 +0800 | [diff] [blame] | 782 | .init_fs_context = erofs_init_fs_context, |
Gao Xiang | 8f7acda | 2019-07-31 23:57:41 +0800 | [diff] [blame] | 783 | .kill_sb = erofs_kill_sb, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 784 | .fs_flags = FS_REQUIRES_DEV, |
| 785 | }; |
| 786 | MODULE_ALIAS_FS("erofs"); |
| 787 | |
| 788 | static int __init erofs_module_init(void) |
| 789 | { |
| 790 | int err; |
| 791 | |
| 792 | erofs_check_ondisk_layout_definitions(); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 793 | |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 794 | erofs_inode_cachep = kmem_cache_create("erofs_inode", |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 795 | sizeof(struct erofs_inode), 0, |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 796 | SLAB_RECLAIM_ACCOUNT, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 797 | erofs_inode_init_once); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 798 | if (!erofs_inode_cachep) { |
| 799 | err = -ENOMEM; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 800 | goto icache_err; |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 801 | } |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 802 | |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 803 | err = erofs_init_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 804 | if (err) |
| 805 | goto shrinker_err; |
| 806 | |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 807 | err = z_erofs_lzma_init(); |
| 808 | if (err) |
| 809 | goto lzma_err; |
| 810 | |
Gao Xiang | 5248873 | 2021-04-10 03:06:30 +0800 | [diff] [blame] | 811 | erofs_pcpubuf_init(); |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 812 | err = z_erofs_init_zip_subsystem(); |
| 813 | if (err) |
| 814 | goto zip_err; |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 815 | |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 816 | err = erofs_init_sysfs(); |
| 817 | if (err) |
| 818 | goto sysfs_err; |
| 819 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 820 | err = register_filesystem(&erofs_fs_type); |
| 821 | if (err) |
| 822 | goto fs_err; |
| 823 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 824 | return 0; |
| 825 | |
| 826 | fs_err: |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 827 | erofs_exit_sysfs(); |
| 828 | sysfs_err: |
Gao Xiang | 3883a79 | 2018-07-26 20:22:06 +0800 | [diff] [blame] | 829 | z_erofs_exit_zip_subsystem(); |
| 830 | zip_err: |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 831 | z_erofs_lzma_exit(); |
| 832 | lzma_err: |
Gao Xiang | 22fe04a | 2019-07-31 23:57:39 +0800 | [diff] [blame] | 833 | erofs_exit_shrinker(); |
Gao Xiang | a158131 | 2018-07-26 20:22:04 +0800 | [diff] [blame] | 834 | shrinker_err: |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 835 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 836 | icache_err: |
| 837 | return err; |
| 838 | } |
| 839 | |
| 840 | static void __exit erofs_module_exit(void) |
| 841 | { |
| 842 | unregister_filesystem(&erofs_fs_type); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 843 | |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 844 | /* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 845 | rcu_barrier(); |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 846 | |
Huang Jianan | 168e9a7 | 2021-12-01 22:54:36 +0800 | [diff] [blame] | 847 | erofs_exit_sysfs(); |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 848 | z_erofs_exit_zip_subsystem(); |
| 849 | z_erofs_lzma_exit(); |
| 850 | erofs_exit_shrinker(); |
Gao Xiang | 1c2dfbf | 2019-09-04 10:08:55 +0800 | [diff] [blame] | 851 | kmem_cache_destroy(erofs_inode_cachep); |
Gao Xiang | 5248873 | 2021-04-10 03:06:30 +0800 | [diff] [blame] | 852 | erofs_pcpubuf_exit(); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /* get filesystem statistics */ |
| 856 | static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 857 | { |
| 858 | struct super_block *sb = dentry->d_sb; |
| 859 | struct erofs_sb_info *sbi = EROFS_SB(sb); |
| 860 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
| 861 | |
| 862 | buf->f_type = sb->s_magic; |
| 863 | buf->f_bsize = EROFS_BLKSIZ; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 864 | buf->f_blocks = sbi->total_blocks; |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 865 | buf->f_bfree = buf->f_bavail = 0; |
| 866 | |
| 867 | buf->f_files = ULLONG_MAX; |
| 868 | buf->f_ffree = ULLONG_MAX - sbi->inos; |
| 869 | |
| 870 | buf->f_namelen = EROFS_NAME_LEN; |
| 871 | |
Al Viro | 6d1349c | 2020-09-18 16:45:50 -0400 | [diff] [blame] | 872 | buf->f_fsid = u64_to_fsid(id); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int erofs_show_options(struct seq_file *seq, struct dentry *root) |
| 877 | { |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 878 | struct erofs_sb_info *sbi = EROFS_SB(root->d_sb); |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 879 | struct erofs_mount_opts *opt = &sbi->opt; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 880 | |
| 881 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 882 | if (test_opt(opt, XATTR_USER)) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 883 | seq_puts(seq, ",user_xattr"); |
| 884 | else |
| 885 | seq_puts(seq, ",nouser_xattr"); |
| 886 | #endif |
| 887 | #ifdef CONFIG_EROFS_FS_POSIX_ACL |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 888 | if (test_opt(opt, POSIX_ACL)) |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 889 | seq_puts(seq, ",acl"); |
| 890 | else |
| 891 | seq_puts(seq, ",noacl"); |
| 892 | #endif |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 893 | #ifdef CONFIG_EROFS_FS_ZIP |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 894 | if (opt->cache_strategy == EROFS_ZIP_CACHE_DISABLED) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 895 | seq_puts(seq, ",cache_strategy=disabled"); |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 896 | else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAHEAD) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 897 | seq_puts(seq, ",cache_strategy=readahead"); |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 898 | else if (opt->cache_strategy == EROFS_ZIP_CACHE_READAROUND) |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 899 | seq_puts(seq, ",cache_strategy=readaround"); |
Gao Xiang | 4279f3f | 2019-07-31 23:57:49 +0800 | [diff] [blame] | 900 | #endif |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 901 | if (test_opt(opt, DAX_ALWAYS)) |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 902 | seq_puts(seq, ",dax=always"); |
Gao Xiang | e624246 | 2021-10-07 15:02:23 +0800 | [diff] [blame] | 903 | if (test_opt(opt, DAX_NEVER)) |
Gao Xiang | 06252e9 | 2021-08-05 08:36:00 +0800 | [diff] [blame] | 904 | seq_puts(seq, ",dax=never"); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 905 | return 0; |
| 906 | } |
| 907 | |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 908 | const struct super_operations erofs_sops = { |
| 909 | .put_super = erofs_put_super, |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 910 | .alloc_inode = erofs_alloc_inode, |
| 911 | .free_inode = erofs_free_inode, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 912 | .statfs = erofs_statfs, |
| 913 | .show_options = erofs_show_options, |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 914 | }; |
| 915 | |
| 916 | module_init(erofs_module_init); |
| 917 | module_exit(erofs_module_exit); |
| 918 | |
| 919 | MODULE_DESCRIPTION("Enhanced ROM File System"); |
Gao Xiang | bc33d9f | 2019-07-31 23:57:51 +0800 | [diff] [blame] | 920 | MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc."); |
Gao Xiang | ba2b77a | 2018-07-26 20:21:46 +0800 | [diff] [blame] | 921 | MODULE_LICENSE("GPL"); |