blob: f92e3e32b9f484dcf70b0c7705bc7aad561622f2 [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;
Gao Xiang4fea63f2021-04-07 12:39:23 +080066 /* maximum possible blocks for pclusters in the filesystem */
67 u16 max_pclusterblks;
Huang Jianan5d505382021-03-29 09:23:06 +080068};
69
Gao Xiangbfb86742018-07-26 20:21:45 +080070struct erofs_sb_info {
Gao Xiang22fe04a2019-07-31 23:57:39 +080071#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang2497ee42018-07-26 20:22:03 +080072 /* list for all registered superblocks, mainly for shrinker */
73 struct list_head list;
Gao Xianga1581312018-07-26 20:22:04 +080074 struct mutex umount_mutex;
Gao Xiang2497ee42018-07-26 20:22:03 +080075
Gao Xiang64094a02020-02-20 10:46:42 +080076 /* managed XArray arranged in physical block number */
77 struct xarray managed_pslots;
Gao Xiang22fe04a2019-07-31 23:57:39 +080078
Gao Xiang22fe04a2019-07-31 23:57:39 +080079 unsigned int shrinker_run_no;
Gao Xiang14373712021-03-29 18:00:12 +080080 u16 available_compr_algs;
Gao Xiang22fe04a2019-07-31 23:57:39 +080081
Gao Xiang4279f3f2019-07-31 23:57:49 +080082 /* pseudo inode to manage cached pages */
83 struct inode *managed_cache;
Huang Jianan5d505382021-03-29 09:23:06 +080084
85 struct erofs_sb_lz4_info lz4;
Gao Xiang22fe04a2019-07-31 23:57:39 +080086#endif /* CONFIG_EROFS_FS_ZIP */
Gao Xiangbfb86742018-07-26 20:21:45 +080087 u32 blocks;
88 u32 meta_blkaddr;
Gao Xiangb17500a2018-07-26 20:21:52 +080089#ifdef CONFIG_EROFS_FS_XATTR
90 u32 xattr_blkaddr;
91#endif
Gao Xiangbfb86742018-07-26 20:21:45 +080092
93 /* inode slot unit size in bit shift */
94 unsigned char islotbits;
95
Gao Xiang14373712021-03-29 18:00:12 +080096 u32 sb_size; /* total superblock size */
Gao Xiangbfb86742018-07-26 20:21:45 +080097 u32 build_time_nsec;
98 u64 build_time;
99
100 /* what we really care is nid, rather than ino.. */
101 erofs_nid_t root_nid;
102 /* used for statfs, f_files - f_favail */
103 u64 inos;
104
105 u8 uuid[16]; /* 128-bit uuid for volume */
106 u8 volume_name[16]; /* volume name */
Pratik Shindeb858a482019-11-04 10:49:37 +0800107 u32 feature_compat;
Gao Xiang426a9302019-09-04 10:08:53 +0800108 u32 feature_incompat;
Gao Xiang5efe5132019-06-13 16:35:41 +0800109
Chao Yuf57a3fe2020-05-29 18:48:36 +0800110 struct erofs_fs_context ctx; /* options */
Gao Xiangbfb86742018-07-26 20:21:45 +0800111};
112
113#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
114#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
115
Gao Xiangb17500a2018-07-26 20:21:52 +0800116/* Mount flags set via mount options or defaults */
117#define EROFS_MOUNT_XATTR_USER 0x00000010
118#define EROFS_MOUNT_POSIX_ACL 0x00000020
119
Chao Yuf57a3fe2020-05-29 18:48:36 +0800120#define clear_opt(ctx, option) ((ctx)->mount_opt &= ~EROFS_MOUNT_##option)
121#define set_opt(ctx, option) ((ctx)->mount_opt |= EROFS_MOUNT_##option)
122#define test_opt(ctx, option) ((ctx)->mount_opt & EROFS_MOUNT_##option)
Gao Xiangbfb86742018-07-26 20:21:45 +0800123
Gao Xiang4279f3f2019-07-31 23:57:49 +0800124enum {
125 EROFS_ZIP_CACHE_DISABLED,
126 EROFS_ZIP_CACHE_READAHEAD,
127 EROFS_ZIP_CACHE_READAROUND
128};
129
Chao Yuf57a3fe2020-05-29 18:48:36 +0800130#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang14f362b2019-07-31 23:57:36 +0800131#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
132
Gao Xiange7e9a302018-07-26 20:22:05 +0800133/* basic unit of the workstation of a super_block */
134struct erofs_workgroup {
135 /* the workgroup index in the workstation */
136 pgoff_t index;
137
138 /* overall workgroup reference count */
139 atomic_t refcount;
140};
141
Gao Xiang73f5c662018-11-23 01:16:02 +0800142#if defined(CONFIG_SMP)
143static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
144 int val)
Gao Xiange7e9a302018-07-26 20:22:05 +0800145{
Gao Xiange7e9a302018-07-26 20:22:05 +0800146 preempt_disable();
Gao Xiang73f5c662018-11-23 01:16:02 +0800147 if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
Gao Xiange7e9a302018-07-26 20:22:05 +0800148 preempt_enable();
149 return false;
150 }
Gao Xiange7e9a302018-07-26 20:22:05 +0800151 return true;
152}
153
Gao Xiang73f5c662018-11-23 01:16:02 +0800154static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
155 int orig_val)
Gao Xiange7e9a302018-07-26 20:22:05 +0800156{
Gao Xiang948bbdb2018-11-23 01:16:03 +0800157 /*
158 * other observers should notice all modifications
159 * in the freezing period.
160 */
161 smp_mb();
Gao Xiang73f5c662018-11-23 01:16:02 +0800162 atomic_set(&grp->refcount, orig_val);
Gao Xiange7e9a302018-07-26 20:22:05 +0800163 preempt_enable();
164}
165
Gao Xiangdf134b82018-11-23 01:16:01 +0800166static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
167{
168 return atomic_cond_read_relaxed(&grp->refcount,
169 VAL != EROFS_LOCKED_MAGIC);
170}
171#else
Gao Xiang73f5c662018-11-23 01:16:02 +0800172static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
173 int val)
174{
175 preempt_disable();
176 /* no need to spin on UP platforms, let's just disable preemption. */
177 if (val != atomic_read(&grp->refcount)) {
178 preempt_enable();
179 return false;
180 }
181 return true;
182}
183
184static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
185 int orig_val)
186{
187 preempt_enable();
188}
189
Gao Xiangdf134b82018-11-23 01:16:01 +0800190static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
191{
192 int v = atomic_read(&grp->refcount);
193
194 /* workgroup is never freezed on uniprocessor systems */
195 DBG_BUGON(v == EROFS_LOCKED_MAGIC);
196 return v;
197}
Gao Xiang14f362b2019-07-31 23:57:36 +0800198#endif /* !CONFIG_SMP */
Gao Xiang14f362b2019-07-31 23:57:36 +0800199#endif /* !CONFIG_EROFS_FS_ZIP */
Gao Xiange7e9a302018-07-26 20:22:05 +0800200
Gao Xiangbfb86742018-07-26 20:21:45 +0800201/* we strictly follow PAGE_SIZE and no buffer head yet */
202#define LOG_BLOCK_SIZE PAGE_SHIFT
203
204#undef LOG_SECTORS_PER_BLOCK
205#define LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)
206
207#undef SECTORS_PER_BLOCK
208#define SECTORS_PER_BLOCK (1 << SECTORS_PER_BLOCK)
209
210#define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE)
211
212#if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
213#error erofs cannot be used in this platform
214#endif
215
216#define ROOT_NID(sb) ((sb)->root_nid)
217
Gao Xiangbfb86742018-07-26 20:21:45 +0800218#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)
219#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
220#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)
221
222static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
223{
224 return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
225}
226
Gao Xiangde06a6a2021-03-29 09:23:05 +0800227#define EROFS_FEATURE_FUNCS(name, compat, feature) \
228static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
229{ \
230 return sbi->feature_##compat & EROFS_FEATURE_##feature; \
231}
232
233EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
Gao Xiang14373712021-03-29 18:00:12 +0800234EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
Gao Xiang5404c33012021-04-07 12:39:22 +0800235EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
Gao Xiangde06a6a2021-03-29 09:23:05 +0800236EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
237
Gao Xiang62dc4592019-02-18 15:19:04 +0800238/* atomic flag definitions */
Gao Xianga5876e22019-09-04 10:08:56 +0800239#define EROFS_I_EA_INITED_BIT 0
240#define EROFS_I_Z_INITED_BIT 1
Gao Xiang62dc4592019-02-18 15:19:04 +0800241
242/* bitlock definitions (arranged in reverse order) */
Gao Xianga5876e22019-09-04 10:08:56 +0800243#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
244#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
Gao Xiangbfb86742018-07-26 20:21:45 +0800245
Gao Xianga5876e22019-09-04 10:08:56 +0800246struct erofs_inode {
Gao Xiangbfb86742018-07-26 20:21:45 +0800247 erofs_nid_t nid;
Gao Xiang62dc4592019-02-18 15:19:04 +0800248
249 /* atomic flags (including bitlocks) */
250 unsigned long flags;
Gao Xiangbfb86742018-07-26 20:21:45 +0800251
Gao Xiang8a765682019-09-04 10:08:54 +0800252 unsigned char datalayout;
Gao Xiangbfb86742018-07-26 20:21:45 +0800253 unsigned char inode_isize;
254 unsigned short xattr_isize;
255
Pratik Shindee82a9a12019-07-15 17:51:27 +0530256 unsigned int xattr_shared_count;
257 unsigned int *xattr_shared_xattrs;
Gao Xiangbfb86742018-07-26 20:21:45 +0800258
Gao Xiang152a3332019-06-24 15:22:52 +0800259 union {
260 erofs_blk_t raw_blkaddr;
261#ifdef CONFIG_EROFS_FS_ZIP
262 struct {
263 unsigned short z_advise;
264 unsigned char z_algorithmtype[2];
265 unsigned char z_logical_clusterbits;
Gao Xiang152a3332019-06-24 15:22:52 +0800266 };
Gao Xiang14f362b2019-07-31 23:57:36 +0800267#endif /* CONFIG_EROFS_FS_ZIP */
Gao Xiang152a3332019-06-24 15:22:52 +0800268 };
Gao Xiangbfb86742018-07-26 20:21:45 +0800269 /* the corresponding vfs inode */
270 struct inode vfs_inode;
271};
272
Gao Xianga5876e22019-09-04 10:08:56 +0800273#define EROFS_I(ptr) \
274 container_of(ptr, struct erofs_inode, vfs_inode)
Gao Xiangbfb86742018-07-26 20:21:45 +0800275
Gao Xiang99634bf2019-09-04 10:09:05 +0800276static inline unsigned long erofs_inode_datablocks(struct inode *inode)
Gao Xiangbfb86742018-07-26 20:21:45 +0800277{
278 /* since i_size cannot be changed */
279 return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
280}
281
Gao Xiang8a765682019-09-04 10:08:54 +0800282static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
283 unsigned int bits)
Gao Xiangbfb86742018-07-26 20:21:45 +0800284{
Gao Xiang8a765682019-09-04 10:08:54 +0800285
286 return (value >> bit) & ((1 << bits) - 1);
Gao Xiangbfb86742018-07-26 20:21:45 +0800287}
288
Gao Xiang8a765682019-09-04 10:08:54 +0800289
290static inline unsigned int erofs_inode_version(unsigned int value)
Gao Xiangbfb86742018-07-26 20:21:45 +0800291{
Gao Xiang8a765682019-09-04 10:08:54 +0800292 return erofs_bitrange(value, EROFS_I_VERSION_BIT,
293 EROFS_I_VERSION_BITS);
294}
295
296static inline unsigned int erofs_inode_datalayout(unsigned int value)
297{
298 return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
299 EROFS_I_DATALAYOUT_BITS);
Gao Xiangbfb86742018-07-26 20:21:45 +0800300}
301
302extern const struct super_operations erofs_sops;
Gao Xiangbfb86742018-07-26 20:21:45 +0800303
304extern const struct address_space_operations erofs_raw_access_aops;
Gao Xiang0c638f72019-11-08 11:37:33 +0800305extern const struct address_space_operations z_erofs_aops;
Gao Xiangbfb86742018-07-26 20:21:45 +0800306
307/*
Yue Hu81378242021-03-25 15:10:08 +0800308 * Logical to physical block mapping
Gao Xiangbfb86742018-07-26 20:21:45 +0800309 *
310 * Different with other file systems, it is used for 2 access modes:
311 *
312 * 1) RAW access mode:
313 *
314 * Users pass a valid (m_lblk, m_lofs -- usually 0) pair,
315 * and get the valid m_pblk, m_pofs and the longest m_len(in bytes).
316 *
317 * Note that m_lblk in the RAW access mode refers to the number of
318 * the compressed ondisk block rather than the uncompressed
319 * in-memory block for the compressed file.
320 *
321 * m_pofs equals to m_lofs except for the inline data page.
322 *
323 * 2) Normal access mode:
324 *
325 * If the inode is not compressed, it has no difference with
326 * the RAW access mode. However, if the inode is compressed,
327 * users should pass a valid (m_lblk, m_lofs) pair, and get
328 * the needed m_pblk, m_pofs, m_len to get the compressed data
329 * and the updated m_lblk, m_lofs which indicates the start
330 * of the corresponding uncompressed data in the file.
331 */
332enum {
333 BH_Zipped = BH_PrivateStart,
Gao Xiangb6a76182019-06-24 15:22:58 +0800334 BH_FullMapped,
Gao Xiangbfb86742018-07-26 20:21:45 +0800335};
336
337/* Has a disk mapping */
338#define EROFS_MAP_MAPPED (1 << BH_Mapped)
339/* Located in metadata (could be copied from bd_inode) */
340#define EROFS_MAP_META (1 << BH_Meta)
341/* The extent has been compressed */
342#define EROFS_MAP_ZIPPED (1 << BH_Zipped)
Gao Xiangb6a76182019-06-24 15:22:58 +0800343/* The length of extent is full */
344#define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped)
Gao Xiangbfb86742018-07-26 20:21:45 +0800345
346struct erofs_map_blocks {
347 erofs_off_t m_pa, m_la;
348 u64 m_plen, m_llen;
349
350 unsigned int m_flags;
Chao Yu3b423412019-01-15 09:42:21 +0800351
352 struct page *mpage;
Gao Xiangbfb86742018-07-26 20:21:45 +0800353};
354
Yue Hu81378242021-03-25 15:10:08 +0800355/* Flags used by erofs_map_blocks_flatmode() */
Gao Xiangbfb86742018-07-26 20:21:45 +0800356#define EROFS_GET_BLOCKS_RAW 0x0001
357
Gao Xiang152a3332019-06-24 15:22:52 +0800358/* zmap.c */
Chao Yu3b423412019-01-15 09:42:21 +0800359#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang152a3332019-06-24 15:22:52 +0800360int z_erofs_fill_inode(struct inode *inode);
Chao Yu3b423412019-01-15 09:42:21 +0800361int z_erofs_map_blocks_iter(struct inode *inode,
362 struct erofs_map_blocks *map,
363 int flags);
364#else
Gao Xiangff784a72019-08-14 18:37:05 +0800365static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
Chao Yu3b423412019-01-15 09:42:21 +0800366static inline int z_erofs_map_blocks_iter(struct inode *inode,
367 struct erofs_map_blocks *map,
368 int flags)
369{
Gao Xiangff784a72019-08-14 18:37:05 +0800370 return -EOPNOTSUPP;
Chao Yu3b423412019-01-15 09:42:21 +0800371}
Gao Xiang14f362b2019-07-31 23:57:36 +0800372#endif /* !CONFIG_EROFS_FS_ZIP */
Chao Yu3b423412019-01-15 09:42:21 +0800373
Gao Xiangbfb86742018-07-26 20:21:45 +0800374/* data.c */
Gao Xiange655b5b2019-09-04 10:09:03 +0800375struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr);
Gao Xiang6e789012018-08-21 22:49:30 +0800376
Gao Xiangbfb86742018-07-26 20:21:45 +0800377/* inode.c */
Gao Xiang2abd7812018-10-09 22:07:13 +0800378static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
379{
380#if BITS_PER_LONG == 32
381 return (nid >> 32) ^ (nid & 0xffffffff);
382#else
383 return nid;
384#endif
385}
386
Gao Xiang60939822019-01-14 19:40:24 +0800387extern const struct inode_operations erofs_generic_iops;
388extern const struct inode_operations erofs_symlink_iops;
389extern const struct inode_operations erofs_fast_symlink_iops;
Gao Xiangb17500a2018-07-26 20:21:52 +0800390
Gao Xiang2e1d6632019-01-16 16:59:56 +0800391struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
Christian Brauner549c7292021-01-21 14:19:43 +0100392int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,
393 struct kstat *stat, u32 request_mask,
394 unsigned int query_flags);
Gao Xiang2e1d6632019-01-16 16:59:56 +0800395
Gao Xiang60939822019-01-14 19:40:24 +0800396/* namei.c */
397extern const struct inode_operations erofs_dir_iops;
398
399int erofs_namei(struct inode *dir, struct qstr *name,
400 erofs_nid_t *nid, unsigned int *d_type);
401
402/* dir.c */
403extern const struct file_operations erofs_dir_fops;
404
Gao Xiang598162d2021-04-07 12:39:26 +0800405static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
406{
407 int retried = 0;
408
409 while (1) {
410 void *p = vm_map_ram(pages, count, -1);
411
412 /* retry two more times (totally 3 times) */
413 if (p || ++retried >= 3)
414 return p;
415 vm_unmap_aliases();
416 }
417 return NULL;
418}
419
Gao Xiang52488732021-04-10 03:06:30 +0800420/* pcpubuf.c */
421void *erofs_get_pcpubuf(unsigned int requiredpages);
422void erofs_put_pcpubuf(void *ptr);
423int erofs_pcpubuf_growsize(unsigned int nrpages);
424void erofs_pcpubuf_init(void);
425void erofs_pcpubuf_exit(void);
426
Gao Xiang14f362b2019-07-31 23:57:36 +0800427/* utils.c / zdata.c */
Gao Xiang5ddcee12019-11-21 21:59:54 +0800428struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
Gao Xiangfa61a332019-06-24 15:22:53 +0800429
Gao Xiang22fe04a2019-07-31 23:57:39 +0800430#ifdef CONFIG_EROFS_FS_ZIP
Gao Xiang14f362b2019-07-31 23:57:36 +0800431int erofs_workgroup_put(struct erofs_workgroup *grp);
432struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
Vladimir Zapolskiy997626d2020-01-02 14:01:16 +0200433 pgoff_t index);
Gao Xiang64094a02020-02-20 10:46:42 +0800434struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
435 struct erofs_workgroup *grp);
Gao Xiang14f362b2019-07-31 23:57:36 +0800436void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
Gao Xiang22fe04a2019-07-31 23:57:39 +0800437void erofs_shrinker_register(struct super_block *sb);
438void erofs_shrinker_unregister(struct super_block *sb);
439int __init erofs_init_shrinker(void);
440void erofs_exit_shrinker(void);
441int __init z_erofs_init_zip_subsystem(void);
442void z_erofs_exit_zip_subsystem(void);
Gao Xiang14f362b2019-07-31 23:57:36 +0800443int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
444 struct erofs_workgroup *egrp);
445int erofs_try_to_free_cached_page(struct address_space *mapping,
446 struct page *page);
Huang Jianan5d505382021-03-29 09:23:06 +0800447int z_erofs_load_lz4_config(struct super_block *sb,
Gao Xiang46249cd2021-03-29 09:23:07 +0800448 struct erofs_super_block *dsb,
449 struct z_erofs_lz4_cfgs *lz4, int len);
Gao Xiang22fe04a2019-07-31 23:57:39 +0800450#else
451static inline void erofs_shrinker_register(struct super_block *sb) {}
452static inline void erofs_shrinker_unregister(struct super_block *sb) {}
453static inline int erofs_init_shrinker(void) { return 0; }
454static inline void erofs_exit_shrinker(void) {}
455static inline int z_erofs_init_zip_subsystem(void) { return 0; }
456static inline void z_erofs_exit_zip_subsystem(void) {}
Huang Jianan5d505382021-03-29 09:23:06 +0800457static inline int z_erofs_load_lz4_config(struct super_block *sb,
Gao Xiang46249cd2021-03-29 09:23:07 +0800458 struct erofs_super_block *dsb,
459 struct z_erofs_lz4_cfgs *lz4, int len)
Huang Jianan5d505382021-03-29 09:23:06 +0800460{
Gao Xiang14373712021-03-29 18:00:12 +0800461 if (lz4 || dsb->u1.lz4_max_distance) {
Huang Jianan5d505382021-03-29 09:23:06 +0800462 erofs_err(sb, "lz4 algorithm isn't enabled");
463 return -EINVAL;
464 }
465 return 0;
466}
Gao Xiang22fe04a2019-07-31 23:57:39 +0800467#endif /* !CONFIG_EROFS_FS_ZIP */
Gao Xiang2e1d6632019-01-16 16:59:56 +0800468
Gao Xianga6b9b1d2019-08-14 18:37:03 +0800469#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
470
Gao Xiang14f362b2019-07-31 23:57:36 +0800471#endif /* __EROFS_INTERNAL_H */
Gao Xiangbfb86742018-07-26 20:21:45 +0800472