blob: c130e3848322c94b0ca3a31cdbfcb9c1aa21504d [file] [log] [blame]
Gao Xiang29b24f62019-07-31 23:57:31 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
Gao Xiangbfb86742018-07-26 20:21:45 +08003 * Copyright (C) 2017-2018 HUAWEI, Inc.
Alexander A. Klimov592e7cd2020-07-13 15:09:44 +02004 * https://www.huawei.com/
Gao Xiangbfb86742018-07-26 20:21:45 +08005 * Created by Gao Xiang <gaoxiang25@huawei.com>
Gao Xiangbfb86742018-07-26 20:21:45 +08006 */
Gao Xiang14f362b2019-07-31 23:57:36 +08007#ifndef __EROFS_INTERNAL_H
8#define __EROFS_INTERNAL_H
Gao Xiangbfb86742018-07-26 20:21:45 +08009
10#include <linux/fs.h>
11#include <linux/dcache.h>
12#include <linux/mm.h>
13#include <linux/pagemap.h>
14#include <linux/bio.h>
15#include <linux/buffer_head.h>
Gao Xiang47e49372019-08-23 05:36:59 +080016#include <linux/magic.h>
Gao Xiangbfb86742018-07-26 20:21:45 +080017#include <linux/slab.h>
18#include <linux/vmalloc.h>
19#include "erofs_fs.h"
20
21/* redefine pr_fmt "erofs: " */
22#undef pr_fmt
23#define pr_fmt(fmt) "erofs: " fmt
24
Gao Xiang4f761fa2019-09-04 10:09:09 +080025__printf(3, 4) void _erofs_err(struct super_block *sb,
26 const char *function, const char *fmt, ...);
27#define erofs_err(sb, fmt, ...) \
28 _erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
29__printf(3, 4) void _erofs_info(struct super_block *sb,
30 const char *function, const char *fmt, ...);
31#define erofs_info(sb, fmt, ...) \
32 _erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
Gao Xiangbfb86742018-07-26 20:21:45 +080033#ifdef CONFIG_EROFS_FS_DEBUG
Gao Xiang4f761fa2019-09-04 10:09:09 +080034#define erofs_dbg(x, ...) pr_debug(x "\n", ##__VA_ARGS__)
Gao Xiangbfb86742018-07-26 20:21:45 +080035#define DBG_BUGON BUG_ON
36#else
Gao Xiang4f761fa2019-09-04 10:09:09 +080037#define erofs_dbg(x, ...) ((void)0)
Gao Xiangeef16872018-11-23 01:15:59 +080038#define DBG_BUGON(x) ((void)(x))
Gao Xiang14f362b2019-07-31 23:57:36 +080039#endif /* !CONFIG_EROFS_FS_DEBUG */
Gao Xiangbfb86742018-07-26 20:21:45 +080040
41/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
42#define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1
43
44typedef u64 erofs_nid_t;
Gao Xiang14f362b2019-07-31 23:57:36 +080045typedef u64 erofs_off_t;
46/* data type for filesystem-wide blocks number */
47typedef u32 erofs_blk_t;
Gao Xiangbfb86742018-07-26 20:21:45 +080048
Chao Yuf57a3fe2020-05-29 18:48:36 +080049struct erofs_fs_context {
50#ifdef CONFIG_EROFS_FS_ZIP
51 /* current strategy of how to use managed cache */
52 unsigned char cache_strategy;
Huang Jianan30048cd2021-03-17 11:54:48 +080053 /* strategy of sync decompression (false - auto, true - force on) */
54 bool readahead_sync_decompress;
Chao Yuf57a3fe2020-05-29 18:48:36 +080055
56 /* threshold for decompression synchronously */
57 unsigned int max_sync_decompress_pages;
58#endif
59 unsigned int mount_opt;
60};
61
Huang Jianan5d505382021-03-29 09:23:06 +080062/* all filesystem-wide lz4 configurations */
63struct erofs_sb_lz4_info {
64 /* # of pages needed for EROFS lz4 rolling decompression */
65 u16 max_distance_pages;
66};
67
Gao Xiangbfb86742018-07-26 20:21:45 +080068struct erofs_sb_info {
Gao Xiang22fe04a2019-07-31 23:57:39 +080069#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang2497ee42018-07-26 20:22:03 +080070 /* list for all registered superblocks, mainly for shrinker */
71 struct list_head list;
Gao Xianga1581312018-07-26 20:22:04 +080072 struct mutex umount_mutex;
Gao Xiang2497ee42018-07-26 20:22:03 +080073
Gao Xiang64094a02020-02-20 10:46:42 +080074 /* managed XArray arranged in physical block number */
75 struct xarray managed_pslots;
Gao Xiang22fe04a2019-07-31 23:57:39 +080076
Gao Xiang22fe04a2019-07-31 23:57:39 +080077 unsigned int shrinker_run_no;
Gao Xiang14373712021-03-29 18:00:12 +080078 u16 available_compr_algs;
Gao Xiang22fe04a2019-07-31 23:57:39 +080079
Gao Xiang4279f3f2019-07-31 23:57:49 +080080 /* pseudo inode to manage cached pages */
81 struct inode *managed_cache;
Huang Jianan5d505382021-03-29 09:23:06 +080082
83 struct erofs_sb_lz4_info lz4;
Gao Xiang22fe04a2019-07-31 23:57:39 +080084#endif /* CONFIG_EROFS_FS_ZIP */
Gao Xiangbfb86742018-07-26 20:21:45 +080085 u32 blocks;
86 u32 meta_blkaddr;
Gao Xiangb17500a2018-07-26 20:21:52 +080087#ifdef CONFIG_EROFS_FS_XATTR
88 u32 xattr_blkaddr;
89#endif
Gao Xiangbfb86742018-07-26 20:21:45 +080090
91 /* inode slot unit size in bit shift */
92 unsigned char islotbits;
93
Gao Xiang14373712021-03-29 18:00:12 +080094 u32 sb_size; /* total superblock size */
Gao Xiangbfb86742018-07-26 20:21:45 +080095 u32 build_time_nsec;
96 u64 build_time;
97
98 /* what we really care is nid, rather than ino.. */
99 erofs_nid_t root_nid;
100 /* used for statfs, f_files - f_favail */
101 u64 inos;
102
103 u8 uuid[16]; /* 128-bit uuid for volume */
104 u8 volume_name[16]; /* volume name */
Pratik Shindeb858a482019-11-04 10:49:37 +0800105 u32 feature_compat;
Gao Xiang426a9302019-09-04 10:08:53 +0800106 u32 feature_incompat;
Gao Xiang5efe5132019-06-13 16:35:41 +0800107
Chao Yuf57a3fe2020-05-29 18:48:36 +0800108 struct erofs_fs_context ctx; /* options */
Gao Xiangbfb86742018-07-26 20:21:45 +0800109};
110
111#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
112#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
113
Gao Xiangb17500a2018-07-26 20:21:52 +0800114/* Mount flags set via mount options or defaults */
115#define EROFS_MOUNT_XATTR_USER 0x00000010
116#define EROFS_MOUNT_POSIX_ACL 0x00000020
117
Chao Yuf57a3fe2020-05-29 18:48:36 +0800118#define clear_opt(ctx, option) ((ctx)->mount_opt &= ~EROFS_MOUNT_##option)
119#define set_opt(ctx, option) ((ctx)->mount_opt |= EROFS_MOUNT_##option)
120#define test_opt(ctx, option) ((ctx)->mount_opt & EROFS_MOUNT_##option)
Gao Xiangbfb86742018-07-26 20:21:45 +0800121
Gao Xiang4279f3f2019-07-31 23:57:49 +0800122enum {
123 EROFS_ZIP_CACHE_DISABLED,
124 EROFS_ZIP_CACHE_READAHEAD,
125 EROFS_ZIP_CACHE_READAROUND
126};
127
Chao Yuf57a3fe2020-05-29 18:48:36 +0800128#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang14f362b2019-07-31 23:57:36 +0800129#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
130
Gao Xiange7e9a302018-07-26 20:22:05 +0800131/* basic unit of the workstation of a super_block */
132struct erofs_workgroup {
133 /* the workgroup index in the workstation */
134 pgoff_t index;
135
136 /* overall workgroup reference count */
137 atomic_t refcount;
138};
139
Gao Xiang73f5c662018-11-23 01:16:02 +0800140#if defined(CONFIG_SMP)
141static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
142 int val)
Gao Xiange7e9a302018-07-26 20:22:05 +0800143{
Gao Xiange7e9a302018-07-26 20:22:05 +0800144 preempt_disable();
Gao Xiang73f5c662018-11-23 01:16:02 +0800145 if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
Gao Xiange7e9a302018-07-26 20:22:05 +0800146 preempt_enable();
147 return false;
148 }
Gao Xiange7e9a302018-07-26 20:22:05 +0800149 return true;
150}
151
Gao Xiang73f5c662018-11-23 01:16:02 +0800152static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
153 int orig_val)
Gao Xiange7e9a302018-07-26 20:22:05 +0800154{
Gao Xiang948bbdb2018-11-23 01:16:03 +0800155 /*
156 * other observers should notice all modifications
157 * in the freezing period.
158 */
159 smp_mb();
Gao Xiang73f5c662018-11-23 01:16:02 +0800160 atomic_set(&grp->refcount, orig_val);
Gao Xiange7e9a302018-07-26 20:22:05 +0800161 preempt_enable();
162}
163
Gao Xiangdf134b82018-11-23 01:16:01 +0800164static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
165{
166 return atomic_cond_read_relaxed(&grp->refcount,
167 VAL != EROFS_LOCKED_MAGIC);
168}
169#else
Gao Xiang73f5c662018-11-23 01:16:02 +0800170static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
171 int val)
172{
173 preempt_disable();
174 /* no need to spin on UP platforms, let's just disable preemption. */
175 if (val != atomic_read(&grp->refcount)) {
176 preempt_enable();
177 return false;
178 }
179 return true;
180}
181
182static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
183 int orig_val)
184{
185 preempt_enable();
186}
187
Gao Xiangdf134b82018-11-23 01:16:01 +0800188static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
189{
190 int v = atomic_read(&grp->refcount);
191
192 /* workgroup is never freezed on uniprocessor systems */
193 DBG_BUGON(v == EROFS_LOCKED_MAGIC);
194 return v;
195}
Gao Xiang14f362b2019-07-31 23:57:36 +0800196#endif /* !CONFIG_SMP */
Gao Xiang14f362b2019-07-31 23:57:36 +0800197#endif /* !CONFIG_EROFS_FS_ZIP */
Gao Xiange7e9a302018-07-26 20:22:05 +0800198
Gao Xiangbfb86742018-07-26 20:21:45 +0800199/* we strictly follow PAGE_SIZE and no buffer head yet */
200#define LOG_BLOCK_SIZE PAGE_SHIFT
201
202#undef LOG_SECTORS_PER_BLOCK
203#define LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)
204
205#undef SECTORS_PER_BLOCK
206#define SECTORS_PER_BLOCK (1 << SECTORS_PER_BLOCK)
207
208#define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE)
209
210#if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
211#error erofs cannot be used in this platform
212#endif
213
214#define ROOT_NID(sb) ((sb)->root_nid)
215
Gao Xiangbfb86742018-07-26 20:21:45 +0800216#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)
217#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
218#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)
219
220static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
221{
222 return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
223}
224
Gao Xiangde06a6a2021-03-29 09:23:05 +0800225#define EROFS_FEATURE_FUNCS(name, compat, feature) \
226static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
227{ \
228 return sbi->feature_##compat & EROFS_FEATURE_##feature; \
229}
230
231EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
Gao Xiang14373712021-03-29 18:00:12 +0800232EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
Gao Xiang5404c33012021-04-07 12:39:22 +0800233EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
Gao Xiangde06a6a2021-03-29 09:23:05 +0800234EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
235
Gao Xiang62dc4592019-02-18 15:19:04 +0800236/* atomic flag definitions */
Gao Xianga5876e22019-09-04 10:08:56 +0800237#define EROFS_I_EA_INITED_BIT 0
238#define EROFS_I_Z_INITED_BIT 1
Gao Xiang62dc4592019-02-18 15:19:04 +0800239
240/* bitlock definitions (arranged in reverse order) */
Gao Xianga5876e22019-09-04 10:08:56 +0800241#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
242#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
Gao Xiangbfb86742018-07-26 20:21:45 +0800243
Gao Xianga5876e22019-09-04 10:08:56 +0800244struct erofs_inode {
Gao Xiangbfb86742018-07-26 20:21:45 +0800245 erofs_nid_t nid;
Gao Xiang62dc4592019-02-18 15:19:04 +0800246
247 /* atomic flags (including bitlocks) */
248 unsigned long flags;
Gao Xiangbfb86742018-07-26 20:21:45 +0800249
Gao Xiang8a765682019-09-04 10:08:54 +0800250 unsigned char datalayout;
Gao Xiangbfb86742018-07-26 20:21:45 +0800251 unsigned char inode_isize;
252 unsigned short xattr_isize;
253
Pratik Shindee82a9a12019-07-15 17:51:27 +0530254 unsigned int xattr_shared_count;
255 unsigned int *xattr_shared_xattrs;
Gao Xiangbfb86742018-07-26 20:21:45 +0800256
Gao Xiang152a3332019-06-24 15:22:52 +0800257 union {
258 erofs_blk_t raw_blkaddr;
259#ifdef CONFIG_EROFS_FS_ZIP
260 struct {
261 unsigned short z_advise;
262 unsigned char z_algorithmtype[2];
263 unsigned char z_logical_clusterbits;
Gao Xiang152a3332019-06-24 15:22:52 +0800264 };
Gao Xiang14f362b2019-07-31 23:57:36 +0800265#endif /* CONFIG_EROFS_FS_ZIP */
Gao Xiang152a3332019-06-24 15:22:52 +0800266 };
Gao Xiangbfb86742018-07-26 20:21:45 +0800267 /* the corresponding vfs inode */
268 struct inode vfs_inode;
269};
270
Gao Xianga5876e22019-09-04 10:08:56 +0800271#define EROFS_I(ptr) \
272 container_of(ptr, struct erofs_inode, vfs_inode)
Gao Xiangbfb86742018-07-26 20:21:45 +0800273
Gao Xiang99634bf2019-09-04 10:09:05 +0800274static inline unsigned long erofs_inode_datablocks(struct inode *inode)
Gao Xiangbfb86742018-07-26 20:21:45 +0800275{
276 /* since i_size cannot be changed */
277 return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
278}
279
Gao Xiang8a765682019-09-04 10:08:54 +0800280static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
281 unsigned int bits)
Gao Xiangbfb86742018-07-26 20:21:45 +0800282{
Gao Xiang8a765682019-09-04 10:08:54 +0800283
284 return (value >> bit) & ((1 << bits) - 1);
Gao Xiangbfb86742018-07-26 20:21:45 +0800285}
286
Gao Xiang8a765682019-09-04 10:08:54 +0800287
288static inline unsigned int erofs_inode_version(unsigned int value)
Gao Xiangbfb86742018-07-26 20:21:45 +0800289{
Gao Xiang8a765682019-09-04 10:08:54 +0800290 return erofs_bitrange(value, EROFS_I_VERSION_BIT,
291 EROFS_I_VERSION_BITS);
292}
293
294static inline unsigned int erofs_inode_datalayout(unsigned int value)
295{
296 return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
297 EROFS_I_DATALAYOUT_BITS);
Gao Xiangbfb86742018-07-26 20:21:45 +0800298}
299
300extern const struct super_operations erofs_sops;
Gao Xiangbfb86742018-07-26 20:21:45 +0800301
302extern const struct address_space_operations erofs_raw_access_aops;
Gao Xiang0c638f72019-11-08 11:37:33 +0800303extern const struct address_space_operations z_erofs_aops;
Gao Xiangbfb86742018-07-26 20:21:45 +0800304
305/*
Yue Hu81378242021-03-25 15:10:08 +0800306 * Logical to physical block mapping
Gao Xiangbfb86742018-07-26 20:21:45 +0800307 *
308 * Different with other file systems, it is used for 2 access modes:
309 *
310 * 1) RAW access mode:
311 *
312 * Users pass a valid (m_lblk, m_lofs -- usually 0) pair,
313 * and get the valid m_pblk, m_pofs and the longest m_len(in bytes).
314 *
315 * Note that m_lblk in the RAW access mode refers to the number of
316 * the compressed ondisk block rather than the uncompressed
317 * in-memory block for the compressed file.
318 *
319 * m_pofs equals to m_lofs except for the inline data page.
320 *
321 * 2) Normal access mode:
322 *
323 * If the inode is not compressed, it has no difference with
324 * the RAW access mode. However, if the inode is compressed,
325 * users should pass a valid (m_lblk, m_lofs) pair, and get
326 * the needed m_pblk, m_pofs, m_len to get the compressed data
327 * and the updated m_lblk, m_lofs which indicates the start
328 * of the corresponding uncompressed data in the file.
329 */
330enum {
331 BH_Zipped = BH_PrivateStart,
Gao Xiangb6a76182019-06-24 15:22:58 +0800332 BH_FullMapped,
Gao Xiangbfb86742018-07-26 20:21:45 +0800333};
334
335/* Has a disk mapping */
336#define EROFS_MAP_MAPPED (1 << BH_Mapped)
337/* Located in metadata (could be copied from bd_inode) */
338#define EROFS_MAP_META (1 << BH_Meta)
339/* The extent has been compressed */
340#define EROFS_MAP_ZIPPED (1 << BH_Zipped)
Gao Xiangb6a76182019-06-24 15:22:58 +0800341/* The length of extent is full */
342#define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped)
Gao Xiangbfb86742018-07-26 20:21:45 +0800343
344struct erofs_map_blocks {
345 erofs_off_t m_pa, m_la;
346 u64 m_plen, m_llen;
347
348 unsigned int m_flags;
Chao Yu3b423412019-01-15 09:42:21 +0800349
350 struct page *mpage;
Gao Xiangbfb86742018-07-26 20:21:45 +0800351};
352
Yue Hu81378242021-03-25 15:10:08 +0800353/* Flags used by erofs_map_blocks_flatmode() */
Gao Xiangbfb86742018-07-26 20:21:45 +0800354#define EROFS_GET_BLOCKS_RAW 0x0001
355
Gao Xiang152a3332019-06-24 15:22:52 +0800356/* zmap.c */
Chao Yu3b423412019-01-15 09:42:21 +0800357#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang152a3332019-06-24 15:22:52 +0800358int z_erofs_fill_inode(struct inode *inode);
Chao Yu3b423412019-01-15 09:42:21 +0800359int z_erofs_map_blocks_iter(struct inode *inode,
360 struct erofs_map_blocks *map,
361 int flags);
362#else
Gao Xiangff784a72019-08-14 18:37:05 +0800363static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
Chao Yu3b423412019-01-15 09:42:21 +0800364static inline int z_erofs_map_blocks_iter(struct inode *inode,
365 struct erofs_map_blocks *map,
366 int flags)
367{
Gao Xiangff784a72019-08-14 18:37:05 +0800368 return -EOPNOTSUPP;
Chao Yu3b423412019-01-15 09:42:21 +0800369}
Gao Xiang14f362b2019-07-31 23:57:36 +0800370#endif /* !CONFIG_EROFS_FS_ZIP */
Chao Yu3b423412019-01-15 09:42:21 +0800371
Gao Xiangbfb86742018-07-26 20:21:45 +0800372/* data.c */
Gao Xiange655b5b2019-09-04 10:09:03 +0800373struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
Gao Xiang6e789012018-08-21 22:49:30 +0800374
Gao Xiangbfb86742018-07-26 20:21:45 +0800375/* inode.c */
Gao Xiang2abd7812018-10-09 22:07:13 +0800376static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
377{
378#if BITS_PER_LONG == 32
379 return (nid >> 32) ^ (nid & 0xffffffff);
380#else
381 return nid;
382#endif
383}
384
Gao Xiang60939822019-01-14 19:40:24 +0800385extern const struct inode_operations erofs_generic_iops;
386extern const struct inode_operations erofs_symlink_iops;
387extern const struct inode_operations erofs_fast_symlink_iops;
Gao Xiangb17500a2018-07-26 20:21:52 +0800388
Gao Xiang2e1d6632019-01-16 16:59:56 +0800389struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
Christian Brauner549c7292021-01-21 14:19:43 +0100390int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,
391 struct kstat *stat, u32 request_mask,
392 unsigned int query_flags);
Gao Xiang2e1d6632019-01-16 16:59:56 +0800393
Gao Xiang60939822019-01-14 19:40:24 +0800394/* namei.c */
395extern const struct inode_operations erofs_dir_iops;
396
397int erofs_namei(struct inode *dir, struct qstr *name,
398 erofs_nid_t *nid, unsigned int *d_type);
399
400/* dir.c */
401extern const struct file_operations erofs_dir_fops;
402
Gao Xiang52488732021-04-10 03:06:30 +0800403/* pcpubuf.c */
404void *erofs_get_pcpubuf(unsigned int requiredpages);
405void erofs_put_pcpubuf(void *ptr);
406int erofs_pcpubuf_growsize(unsigned int nrpages);
407void erofs_pcpubuf_init(void);
408void erofs_pcpubuf_exit(void);
409
Gao Xiang14f362b2019-07-31 23:57:36 +0800410/* utils.c / zdata.c */
Gao Xiang5ddcee12019-11-21 21:59:54 +0800411struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
Gao Xiangfa61a332019-06-24 15:22:53 +0800412
Gao Xiang22fe04a2019-07-31 23:57:39 +0800413#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang14f362b2019-07-31 23:57:36 +0800414int erofs_workgroup_put(struct erofs_workgroup *grp);
415struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
Vladimir Zapolskiy997626d2020-01-02 14:01:16 +0200416 pgoff_t index);
Gao Xiang64094a02020-02-20 10:46:42 +0800417struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
418 struct erofs_workgroup *grp);
Gao Xiang14f362b2019-07-31 23:57:36 +0800419void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
Gao Xiang22fe04a2019-07-31 23:57:39 +0800420void erofs_shrinker_register(struct super_block *sb);
421void erofs_shrinker_unregister(struct super_block *sb);
422int __init erofs_init_shrinker(void);
423void erofs_exit_shrinker(void);
424int __init z_erofs_init_zip_subsystem(void);
425void z_erofs_exit_zip_subsystem(void);
Gao Xiang14f362b2019-07-31 23:57:36 +0800426int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
427 struct erofs_workgroup *egrp);
428int erofs_try_to_free_cached_page(struct address_space *mapping,
429 struct page *page);
Huang Jianan5d505382021-03-29 09:23:06 +0800430int z_erofs_load_lz4_config(struct super_block *sb,
Gao Xiang46249cd2021-03-29 09:23:07 +0800431 struct erofs_super_block *dsb,
432 struct z_erofs_lz4_cfgs *lz4, int len);
Gao Xiang22fe04a2019-07-31 23:57:39 +0800433#else
434static inline void erofs_shrinker_register(struct super_block *sb) {}
435static inline void erofs_shrinker_unregister(struct super_block *sb) {}
436static inline int erofs_init_shrinker(void) { return 0; }
437static inline void erofs_exit_shrinker(void) {}
438static inline int z_erofs_init_zip_subsystem(void) { return 0; }
439static inline void z_erofs_exit_zip_subsystem(void) {}
Huang Jianan5d505382021-03-29 09:23:06 +0800440static inline int z_erofs_load_lz4_config(struct super_block *sb,
Gao Xiang46249cd2021-03-29 09:23:07 +0800441 struct erofs_super_block *dsb,
442 struct z_erofs_lz4_cfgs *lz4, int len)
Huang Jianan5d505382021-03-29 09:23:06 +0800443{
Gao Xiang14373712021-03-29 18:00:12 +0800444 if (lz4 || dsb->u1.lz4_max_distance) {
Huang Jianan5d505382021-03-29 09:23:06 +0800445 erofs_err(sb, "lz4 algorithm isn't enabled");
446 return -EINVAL;
447 }
448 return 0;
449}
Gao Xiang22fe04a2019-07-31 23:57:39 +0800450#endif /* !CONFIG_EROFS_FS_ZIP */
Gao Xiang2e1d6632019-01-16 16:59:56 +0800451
Gao Xianga6b9b1d2019-08-14 18:37:03 +0800452#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
453
Gao Xiang14f362b2019-07-31 23:57:36 +0800454#endif /* __EROFS_INTERNAL_H */
Gao Xiangbfb86742018-07-26 20:21:45 +0800455