2019-07-31 23:57:31 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
2018-07-26 20:21:45 +08:00
|
|
|
* Copyright (C) 2017-2018 HUAWEI, Inc.
|
2020-07-13 21:09:44 +08:00
|
|
|
* https://www.huawei.com/
|
2021-08-20 18:00:19 +08:00
|
|
|
* Copyright (C) 2021, Alibaba Cloud
|
2018-07-26 20:21:45 +08:00
|
|
|
*/
|
2019-07-31 23:57:36 +08:00
|
|
|
#ifndef __EROFS_INTERNAL_H
|
|
|
|
#define __EROFS_INTERNAL_H
|
2018-07-26 20:21:45 +08:00
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/dcache.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/bio.h>
|
|
|
|
#include <linux/buffer_head.h>
|
2019-08-23 05:36:59 +08:00
|
|
|
#include <linux/magic.h>
|
2018-07-26 20:21:45 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2021-08-13 13:29:31 +08:00
|
|
|
#include <linux/iomap.h>
|
2018-07-26 20:21:45 +08:00
|
|
|
#include "erofs_fs.h"
|
|
|
|
|
|
|
|
/* redefine pr_fmt "erofs: " */
|
|
|
|
#undef pr_fmt
|
|
|
|
#define pr_fmt(fmt) "erofs: " fmt
|
|
|
|
|
2019-09-04 10:09:09 +08:00
|
|
|
__printf(3, 4) void _erofs_err(struct super_block *sb,
|
|
|
|
const char *function, const char *fmt, ...);
|
|
|
|
#define erofs_err(sb, fmt, ...) \
|
|
|
|
_erofs_err(sb, __func__, fmt "\n", ##__VA_ARGS__)
|
|
|
|
__printf(3, 4) void _erofs_info(struct super_block *sb,
|
|
|
|
const char *function, const char *fmt, ...);
|
|
|
|
#define erofs_info(sb, fmt, ...) \
|
|
|
|
_erofs_info(sb, __func__, fmt "\n", ##__VA_ARGS__)
|
2018-07-26 20:21:45 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_DEBUG
|
2019-09-04 10:09:09 +08:00
|
|
|
#define erofs_dbg(x, ...) pr_debug(x "\n", ##__VA_ARGS__)
|
2018-07-26 20:21:45 +08:00
|
|
|
#define DBG_BUGON BUG_ON
|
|
|
|
#else
|
2019-09-04 10:09:09 +08:00
|
|
|
#define erofs_dbg(x, ...) ((void)0)
|
2018-11-23 01:15:59 +08:00
|
|
|
#define DBG_BUGON(x) ((void)(x))
|
2019-07-31 23:57:36 +08:00
|
|
|
#endif /* !CONFIG_EROFS_FS_DEBUG */
|
2018-07-26 20:21:45 +08:00
|
|
|
|
|
|
|
/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */
|
|
|
|
#define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1
|
|
|
|
|
|
|
|
typedef u64 erofs_nid_t;
|
2019-07-31 23:57:36 +08:00
|
|
|
typedef u64 erofs_off_t;
|
|
|
|
/* data type for filesystem-wide blocks number */
|
|
|
|
typedef u32 erofs_blk_t;
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_device_info {
|
|
|
|
char *path;
|
2022-04-25 20:21:38 +08:00
|
|
|
struct erofs_fscache *fscache;
|
2021-10-14 16:10:10 +08:00
|
|
|
struct block_device *bdev;
|
|
|
|
struct dax_device *dax_dev;
|
2021-11-29 18:21:59 +08:00
|
|
|
u64 dax_part_off;
|
2021-10-14 16:10:10 +08:00
|
|
|
|
|
|
|
u32 blocks;
|
|
|
|
u32 mapped_blkaddr;
|
|
|
|
};
|
|
|
|
|
2021-12-06 22:35:52 +08:00
|
|
|
enum {
|
|
|
|
EROFS_SYNC_DECOMPRESS_AUTO,
|
|
|
|
EROFS_SYNC_DECOMPRESS_FORCE_ON,
|
|
|
|
EROFS_SYNC_DECOMPRESS_FORCE_OFF
|
|
|
|
};
|
|
|
|
|
2021-10-07 15:02:23 +08:00
|
|
|
struct erofs_mount_opts {
|
2020-05-29 18:48:36 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
/* current strategy of how to use managed cache */
|
|
|
|
unsigned char cache_strategy;
|
2021-12-06 22:35:52 +08:00
|
|
|
/* strategy of sync decompression (0 - auto, 1 - force on, 2 - force off) */
|
|
|
|
unsigned int sync_decompress;
|
2020-05-29 18:48:36 +08:00
|
|
|
|
|
|
|
/* threshold for decompression synchronously */
|
|
|
|
unsigned int max_sync_decompress_pages;
|
|
|
|
#endif
|
|
|
|
unsigned int mount_opt;
|
|
|
|
};
|
|
|
|
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_dev_context {
|
|
|
|
struct idr tree;
|
|
|
|
struct rw_semaphore rwsem;
|
|
|
|
|
|
|
|
unsigned int extra_devices;
|
|
|
|
};
|
|
|
|
|
2021-10-07 15:02:23 +08:00
|
|
|
struct erofs_fs_context {
|
|
|
|
struct erofs_mount_opts opt;
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_dev_context *devs;
|
2022-10-21 10:31:53 +08:00
|
|
|
char *fsid;
|
|
|
|
char *domain_id;
|
2021-10-07 15:02:23 +08:00
|
|
|
};
|
|
|
|
|
2021-03-29 09:23:06 +08:00
|
|
|
/* all filesystem-wide lz4 configurations */
|
|
|
|
struct erofs_sb_lz4_info {
|
|
|
|
/* # of pages needed for EROFS lz4 rolling decompression */
|
|
|
|
u16 max_distance_pages;
|
2021-04-07 12:39:23 +08:00
|
|
|
/* maximum possible blocks for pclusters in the filesystem */
|
|
|
|
u16 max_pclusterblks;
|
2021-03-29 09:23:06 +08:00
|
|
|
};
|
|
|
|
|
2022-09-18 12:34:53 +08:00
|
|
|
struct erofs_domain {
|
|
|
|
refcount_t ref;
|
|
|
|
struct list_head list;
|
|
|
|
struct fscache_volume *volume;
|
|
|
|
char *domain_id;
|
|
|
|
};
|
|
|
|
|
2022-04-25 20:21:34 +08:00
|
|
|
struct erofs_fscache {
|
|
|
|
struct fscache_cookie *cookie;
|
2022-04-25 20:21:35 +08:00
|
|
|
struct inode *inode;
|
2022-09-18 19:01:50 +08:00
|
|
|
struct inode *anon_inode;
|
|
|
|
struct erofs_domain *domain;
|
|
|
|
char *name;
|
2022-04-25 20:21:34 +08:00
|
|
|
};
|
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
struct erofs_sb_info {
|
2021-10-07 15:02:23 +08:00
|
|
|
struct erofs_mount_opts opt; /* options */
|
2019-07-31 23:57:39 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2018-07-26 20:22:03 +08:00
|
|
|
/* list for all registered superblocks, mainly for shrinker */
|
|
|
|
struct list_head list;
|
2018-07-26 20:22:04 +08:00
|
|
|
struct mutex umount_mutex;
|
2018-07-26 20:22:03 +08:00
|
|
|
|
2020-02-20 10:46:42 +08:00
|
|
|
/* managed XArray arranged in physical block number */
|
|
|
|
struct xarray managed_pslots;
|
2018-07-26 20:22:07 +08:00
|
|
|
|
2019-07-31 23:57:39 +08:00
|
|
|
unsigned int shrinker_run_no;
|
2021-03-29 18:00:12 +08:00
|
|
|
u16 available_compr_algs;
|
2019-07-31 23:57:39 +08:00
|
|
|
|
2019-07-31 23:57:49 +08:00
|
|
|
/* pseudo inode to manage cached pages */
|
|
|
|
struct inode *managed_cache;
|
2021-03-29 09:23:06 +08:00
|
|
|
|
|
|
|
struct erofs_sb_lz4_info lz4;
|
2022-09-23 10:11:22 +08:00
|
|
|
struct inode *packed_inode;
|
2019-07-31 23:57:39 +08:00
|
|
|
#endif /* CONFIG_EROFS_FS_ZIP */
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_dev_context *devs;
|
2021-08-05 08:36:00 +08:00
|
|
|
struct dax_device *dax_dev;
|
2021-11-29 18:21:59 +08:00
|
|
|
u64 dax_part_off;
|
2021-10-14 16:10:10 +08:00
|
|
|
u64 total_blocks;
|
|
|
|
u32 primarydevice_blocks;
|
|
|
|
|
2019-07-31 23:57:39 +08:00
|
|
|
u32 meta_blkaddr;
|
|
|
|
#ifdef CONFIG_EROFS_FS_XATTR
|
|
|
|
u32 xattr_blkaddr;
|
2018-07-26 20:21:58 +08:00
|
|
|
#endif
|
2021-10-14 16:10:10 +08:00
|
|
|
u16 device_id_mask; /* valid bits of device id to be used */
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2019-07-31 23:57:39 +08:00
|
|
|
/* inode slot unit size in bit shift */
|
|
|
|
unsigned char islotbits;
|
|
|
|
|
2021-03-29 18:00:12 +08:00
|
|
|
u32 sb_size; /* total superblock size */
|
2018-07-26 20:21:45 +08:00
|
|
|
u32 build_time_nsec;
|
|
|
|
u64 build_time;
|
|
|
|
|
|
|
|
/* what we really care is nid, rather than ino.. */
|
|
|
|
erofs_nid_t root_nid;
|
|
|
|
/* used for statfs, f_files - f_favail */
|
|
|
|
u64 inos;
|
|
|
|
|
|
|
|
u8 uuid[16]; /* 128-bit uuid for volume */
|
|
|
|
u8 volume_name[16]; /* volume name */
|
2019-11-04 10:49:37 +08:00
|
|
|
u32 feature_compat;
|
2019-09-04 10:08:53 +08:00
|
|
|
u32 feature_incompat;
|
2021-12-01 22:54:36 +08:00
|
|
|
|
|
|
|
/* sysfs support */
|
|
|
|
struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
|
|
|
|
struct completion s_kobj_unregister;
|
2022-04-25 20:21:33 +08:00
|
|
|
|
|
|
|
/* fscache support */
|
|
|
|
struct fscache_volume *volume;
|
2022-04-25 20:21:37 +08:00
|
|
|
struct erofs_fscache *s_fscache;
|
2022-09-18 12:34:53 +08:00
|
|
|
struct erofs_domain *domain;
|
2022-10-21 10:31:53 +08:00
|
|
|
char *fsid;
|
|
|
|
char *domain_id;
|
2018-07-26 20:21:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
|
|
|
|
#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
|
|
|
|
|
2018-07-26 20:21:52 +08:00
|
|
|
/* Mount flags set via mount options or defaults */
|
|
|
|
#define EROFS_MOUNT_XATTR_USER 0x00000010
|
|
|
|
#define EROFS_MOUNT_POSIX_ACL 0x00000020
|
2021-08-05 08:36:00 +08:00
|
|
|
#define EROFS_MOUNT_DAX_ALWAYS 0x00000040
|
|
|
|
#define EROFS_MOUNT_DAX_NEVER 0x00000080
|
2018-07-26 20:21:52 +08:00
|
|
|
|
2021-10-07 15:02:23 +08:00
|
|
|
#define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)
|
|
|
|
#define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
|
|
|
|
#define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option)
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2022-04-25 20:21:32 +08:00
|
|
|
static inline bool erofs_is_fscache_mode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !sb->s_bdev;
|
|
|
|
}
|
|
|
|
|
2019-07-31 23:57:49 +08:00
|
|
|
enum {
|
|
|
|
EROFS_ZIP_CACHE_DISABLED,
|
|
|
|
EROFS_ZIP_CACHE_READAHEAD,
|
|
|
|
EROFS_ZIP_CACHE_READAROUND
|
|
|
|
};
|
|
|
|
|
2019-07-31 23:57:36 +08:00
|
|
|
#define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
|
|
|
|
|
2018-07-26 20:22:05 +08:00
|
|
|
/* basic unit of the workstation of a super_block */
|
|
|
|
struct erofs_workgroup {
|
|
|
|
/* the workgroup index in the workstation */
|
|
|
|
pgoff_t index;
|
|
|
|
|
|
|
|
/* overall workgroup reference count */
|
|
|
|
atomic_t refcount;
|
|
|
|
};
|
|
|
|
|
2018-11-23 01:16:02 +08:00
|
|
|
static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
|
|
|
|
int val)
|
2018-07-26 20:22:05 +08:00
|
|
|
{
|
|
|
|
preempt_disable();
|
2018-11-23 01:16:02 +08:00
|
|
|
if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
|
2018-07-26 20:22:05 +08:00
|
|
|
preempt_enable();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-23 01:16:02 +08:00
|
|
|
static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
|
|
|
|
int orig_val)
|
2018-07-26 20:22:05 +08:00
|
|
|
{
|
2018-11-23 01:16:03 +08:00
|
|
|
/*
|
|
|
|
* other observers should notice all modifications
|
|
|
|
* in the freezing period.
|
|
|
|
*/
|
|
|
|
smp_mb();
|
2018-11-23 01:16:02 +08:00
|
|
|
atomic_set(&grp->refcount, orig_val);
|
2018-07-26 20:22:05 +08:00
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2018-11-23 01:16:01 +08:00
|
|
|
static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
|
|
|
|
{
|
|
|
|
return atomic_cond_read_relaxed(&grp->refcount,
|
|
|
|
VAL != EROFS_LOCKED_MAGIC);
|
|
|
|
}
|
2018-07-26 20:22:05 +08:00
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
/* we strictly follow PAGE_SIZE and no buffer head yet */
|
|
|
|
#define LOG_BLOCK_SIZE PAGE_SHIFT
|
|
|
|
|
|
|
|
#undef LOG_SECTORS_PER_BLOCK
|
|
|
|
#define LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)
|
|
|
|
|
|
|
|
#undef SECTORS_PER_BLOCK
|
|
|
|
#define SECTORS_PER_BLOCK (1 << SECTORS_PER_BLOCK)
|
|
|
|
|
|
|
|
#define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE)
|
|
|
|
|
|
|
|
#if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
|
|
|
|
#error erofs cannot be used in this platform
|
|
|
|
#endif
|
|
|
|
|
2022-01-02 12:00:13 +08:00
|
|
|
enum erofs_kmap_type {
|
|
|
|
EROFS_NO_KMAP, /* don't map the buffer */
|
|
|
|
EROFS_KMAP, /* use kmap() to map the buffer */
|
|
|
|
EROFS_KMAP_ATOMIC, /* use kmap_atomic() to map the buffer */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct erofs_buf {
|
|
|
|
struct page *page;
|
|
|
|
void *base;
|
|
|
|
enum erofs_kmap_type kmap_type;
|
|
|
|
};
|
|
|
|
#define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })
|
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
#define ROOT_NID(sb) ((sb)->root_nid)
|
|
|
|
|
|
|
|
#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)
|
|
|
|
#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
|
|
|
|
#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)
|
|
|
|
|
|
|
|
static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
|
|
|
|
{
|
|
|
|
return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
|
|
|
|
}
|
|
|
|
|
2021-03-29 09:23:05 +08:00
|
|
|
#define EROFS_FEATURE_FUNCS(name, compat, feature) \
|
|
|
|
static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
|
|
|
|
{ \
|
|
|
|
return sbi->feature_##compat & EROFS_FEATURE_##feature; \
|
|
|
|
}
|
|
|
|
|
2021-11-13 00:09:33 +08:00
|
|
|
EROFS_FEATURE_FUNCS(zero_padding, incompat, INCOMPAT_ZERO_PADDING)
|
2021-03-29 18:00:12 +08:00
|
|
|
EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
|
2021-04-07 12:39:22 +08:00
|
|
|
EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
|
2021-12-01 22:54:36 +08:00
|
|
|
EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE)
|
2021-10-14 16:10:10 +08:00
|
|
|
EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE)
|
2021-12-01 22:54:36 +08:00
|
|
|
EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2)
|
2021-12-28 13:46:04 +08:00
|
|
|
EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING)
|
2022-09-23 10:11:22 +08:00
|
|
|
EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS)
|
2022-09-23 09:49:15 +08:00
|
|
|
EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE)
|
2021-03-29 09:23:05 +08:00
|
|
|
EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
|
|
|
|
|
2019-02-18 15:19:04 +08:00
|
|
|
/* atomic flag definitions */
|
2019-09-04 10:08:56 +08:00
|
|
|
#define EROFS_I_EA_INITED_BIT 0
|
|
|
|
#define EROFS_I_Z_INITED_BIT 1
|
2019-02-18 15:19:04 +08:00
|
|
|
|
|
|
|
/* bitlock definitions (arranged in reverse order) */
|
2019-09-04 10:08:56 +08:00
|
|
|
#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
|
|
|
|
#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2019-09-04 10:08:56 +08:00
|
|
|
struct erofs_inode {
|
2018-07-26 20:21:45 +08:00
|
|
|
erofs_nid_t nid;
|
2019-02-18 15:19:04 +08:00
|
|
|
|
|
|
|
/* atomic flags (including bitlocks) */
|
|
|
|
unsigned long flags;
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2019-09-04 10:08:54 +08:00
|
|
|
unsigned char datalayout;
|
2018-07-26 20:21:45 +08:00
|
|
|
unsigned char inode_isize;
|
|
|
|
unsigned short xattr_isize;
|
|
|
|
|
2019-07-15 20:21:27 +08:00
|
|
|
unsigned int xattr_shared_count;
|
|
|
|
unsigned int *xattr_shared_xattrs;
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2019-06-24 15:22:52 +08:00
|
|
|
union {
|
|
|
|
erofs_blk_t raw_blkaddr;
|
2021-08-20 18:00:19 +08:00
|
|
|
struct {
|
|
|
|
unsigned short chunkformat;
|
|
|
|
unsigned char chunkbits;
|
|
|
|
};
|
2019-06-24 15:22:52 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
|
|
|
struct {
|
|
|
|
unsigned short z_advise;
|
|
|
|
unsigned char z_algorithmtype[2];
|
|
|
|
unsigned char z_logical_clusterbits;
|
2021-12-28 13:46:04 +08:00
|
|
|
unsigned long z_tailextent_headlcn;
|
2022-09-23 10:11:22 +08:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
erofs_off_t z_idataoff;
|
|
|
|
unsigned short z_idata_size;
|
|
|
|
};
|
|
|
|
erofs_off_t z_fragmentoff;
|
|
|
|
};
|
2019-06-24 15:22:52 +08:00
|
|
|
};
|
2019-07-31 23:57:36 +08:00
|
|
|
#endif /* CONFIG_EROFS_FS_ZIP */
|
2019-06-24 15:22:52 +08:00
|
|
|
};
|
2018-07-26 20:21:45 +08:00
|
|
|
/* the corresponding vfs inode */
|
|
|
|
struct inode vfs_inode;
|
|
|
|
};
|
|
|
|
|
2019-09-04 10:08:56 +08:00
|
|
|
#define EROFS_I(ptr) \
|
|
|
|
container_of(ptr, struct erofs_inode, vfs_inode)
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2019-09-04 10:09:05 +08:00
|
|
|
static inline unsigned long erofs_inode_datablocks(struct inode *inode)
|
2018-07-26 20:21:45 +08:00
|
|
|
{
|
|
|
|
/* since i_size cannot be changed */
|
|
|
|
return DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
|
|
|
|
}
|
|
|
|
|
2019-09-04 10:08:54 +08:00
|
|
|
static inline unsigned int erofs_bitrange(unsigned int value, unsigned int bit,
|
|
|
|
unsigned int bits)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (value >> bit) & ((1 << bits) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline unsigned int erofs_inode_version(unsigned int value)
|
2018-07-26 20:21:45 +08:00
|
|
|
{
|
2019-09-04 10:08:54 +08:00
|
|
|
return erofs_bitrange(value, EROFS_I_VERSION_BIT,
|
|
|
|
EROFS_I_VERSION_BITS);
|
2018-07-26 20:21:45 +08:00
|
|
|
}
|
|
|
|
|
2019-09-04 10:08:54 +08:00
|
|
|
static inline unsigned int erofs_inode_datalayout(unsigned int value)
|
2018-07-26 20:21:45 +08:00
|
|
|
{
|
2019-09-04 10:08:54 +08:00
|
|
|
return erofs_bitrange(value, EROFS_I_DATALAYOUT_BIT,
|
|
|
|
EROFS_I_DATALAYOUT_BITS);
|
2018-07-26 20:21:45 +08:00
|
|
|
}
|
|
|
|
|
2021-10-09 04:08:39 +08:00
|
|
|
/*
|
|
|
|
* Different from grab_cache_page_nowait(), reclaiming is never triggered
|
|
|
|
* when allocating new pages.
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
struct page *erofs_grab_cache_page_nowait(struct address_space *mapping,
|
|
|
|
pgoff_t index)
|
|
|
|
{
|
|
|
|
return pagecache_get_page(mapping, index,
|
|
|
|
FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
|
|
|
|
readahead_gfp_mask(mapping) & ~__GFP_RECLAIM);
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
extern const struct super_operations erofs_sops;
|
2022-09-18 12:34:54 +08:00
|
|
|
extern struct file_system_type erofs_fs_type;
|
2018-07-26 20:21:45 +08:00
|
|
|
|
|
|
|
extern const struct address_space_operations erofs_raw_access_aops;
|
2019-11-08 11:37:33 +08:00
|
|
|
extern const struct address_space_operations z_erofs_aops;
|
2018-07-26 20:21:45 +08:00
|
|
|
|
|
|
|
enum {
|
2021-10-09 04:08:37 +08:00
|
|
|
BH_Encoded = BH_PrivateStart,
|
2019-06-24 15:22:58 +08:00
|
|
|
BH_FullMapped,
|
2022-09-23 10:11:22 +08:00
|
|
|
BH_Fragment,
|
2022-09-23 09:49:15 +08:00
|
|
|
BH_Partialref,
|
2018-07-26 20:21:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Has a disk mapping */
|
|
|
|
#define EROFS_MAP_MAPPED (1 << BH_Mapped)
|
|
|
|
/* Located in metadata (could be copied from bd_inode) */
|
|
|
|
#define EROFS_MAP_META (1 << BH_Meta)
|
2021-10-09 04:08:37 +08:00
|
|
|
/* The extent is encoded */
|
|
|
|
#define EROFS_MAP_ENCODED (1 << BH_Encoded)
|
2019-06-24 15:22:58 +08:00
|
|
|
/* The length of extent is full */
|
|
|
|
#define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped)
|
2022-09-23 10:11:22 +08:00
|
|
|
/* Located in the special packed inode */
|
|
|
|
#define EROFS_MAP_FRAGMENT (1 << BH_Fragment)
|
2022-09-23 09:49:15 +08:00
|
|
|
/* The extent refers to partial decompressed data */
|
|
|
|
#define EROFS_MAP_PARTIAL_REF (1 << BH_Partialref)
|
2018-07-26 20:21:45 +08:00
|
|
|
|
|
|
|
struct erofs_map_blocks {
|
2022-01-02 12:00:17 +08:00
|
|
|
struct erofs_buf buf;
|
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
erofs_off_t m_pa, m_la;
|
|
|
|
u64 m_plen, m_llen;
|
|
|
|
|
2021-10-14 16:10:10 +08:00
|
|
|
unsigned short m_deviceid;
|
2021-10-09 04:08:37 +08:00
|
|
|
char m_algorithmformat;
|
2018-07-26 20:21:45 +08:00
|
|
|
unsigned int m_flags;
|
|
|
|
};
|
|
|
|
|
2021-03-25 15:10:08 +08:00
|
|
|
/* Flags used by erofs_map_blocks_flatmode() */
|
2018-07-26 20:21:45 +08:00
|
|
|
#define EROFS_GET_BLOCKS_RAW 0x0001
|
2021-08-18 23:22:31 +08:00
|
|
|
/*
|
|
|
|
* Used to get the exact decompressed length, e.g. fiemap (consider lookback
|
|
|
|
* approach instead if possible since it's more metadata lightweight.)
|
|
|
|
*/
|
|
|
|
#define EROFS_GET_BLOCKS_FIEMAP 0x0002
|
2021-10-11 05:31:45 +08:00
|
|
|
/* Used to map the whole extent if non-negligible data is requested for LZMA */
|
|
|
|
#define EROFS_GET_BLOCKS_READMORE 0x0004
|
2022-09-23 10:11:22 +08:00
|
|
|
/* Used to map tail extent for tailpacking inline or fragment pcluster */
|
2021-12-28 13:46:04 +08:00
|
|
|
#define EROFS_GET_BLOCKS_FINDTAIL 0x0008
|
2018-07-26 20:21:45 +08:00
|
|
|
|
2021-10-09 04:08:37 +08:00
|
|
|
enum {
|
|
|
|
Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
|
2022-09-23 10:11:21 +08:00
|
|
|
Z_EROFS_COMPRESSION_INTERLACED,
|
2021-10-09 04:08:37 +08:00
|
|
|
Z_EROFS_COMPRESSION_RUNTIME_MAX
|
|
|
|
};
|
|
|
|
|
2019-06-24 15:22:52 +08:00
|
|
|
/* zmap.c */
|
2021-08-13 13:29:31 +08:00
|
|
|
extern const struct iomap_ops z_erofs_iomap_report_ops;
|
|
|
|
|
2019-01-15 09:42:21 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2019-06-24 15:22:52 +08:00
|
|
|
int z_erofs_fill_inode(struct inode *inode);
|
2019-01-15 09:42:21 +08:00
|
|
|
int z_erofs_map_blocks_iter(struct inode *inode,
|
|
|
|
struct erofs_map_blocks *map,
|
|
|
|
int flags);
|
|
|
|
#else
|
2019-08-14 18:37:05 +08:00
|
|
|
static inline int z_erofs_fill_inode(struct inode *inode) { return -EOPNOTSUPP; }
|
2019-01-15 09:42:21 +08:00
|
|
|
static inline int z_erofs_map_blocks_iter(struct inode *inode,
|
|
|
|
struct erofs_map_blocks *map,
|
|
|
|
int flags)
|
|
|
|
{
|
2019-08-14 18:37:05 +08:00
|
|
|
return -EOPNOTSUPP;
|
2019-01-15 09:42:21 +08:00
|
|
|
}
|
2019-07-31 23:57:36 +08:00
|
|
|
#endif /* !CONFIG_EROFS_FS_ZIP */
|
2019-01-15 09:42:21 +08:00
|
|
|
|
2021-10-14 16:10:10 +08:00
|
|
|
struct erofs_map_dev {
|
2022-04-25 20:21:38 +08:00
|
|
|
struct erofs_fscache *m_fscache;
|
2021-10-14 16:10:10 +08:00
|
|
|
struct block_device *m_bdev;
|
|
|
|
struct dax_device *m_daxdev;
|
2021-11-29 18:22:00 +08:00
|
|
|
u64 m_dax_part_off;
|
2021-10-14 16:10:10 +08:00
|
|
|
|
|
|
|
erofs_off_t m_pa;
|
|
|
|
unsigned int m_deviceid;
|
|
|
|
};
|
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
/* data.c */
|
2021-08-05 08:35:59 +08:00
|
|
|
extern const struct file_operations erofs_file_fops;
|
2022-01-02 12:00:17 +08:00
|
|
|
void erofs_unmap_metabuf(struct erofs_buf *buf);
|
2022-01-02 12:00:14 +08:00
|
|
|
void erofs_put_metabuf(struct erofs_buf *buf);
|
2022-03-16 09:22:45 +08:00
|
|
|
void *erofs_bread(struct erofs_buf *buf, struct inode *inode,
|
|
|
|
erofs_blk_t blkaddr, enum erofs_kmap_type type);
|
2022-01-02 12:00:14 +08:00
|
|
|
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
|
|
|
|
erofs_blk_t blkaddr, enum erofs_kmap_type type);
|
2021-10-14 16:10:10 +08:00
|
|
|
int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev);
|
2021-08-13 13:29:31 +08:00
|
|
|
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
|
|
|
u64 start, u64 len);
|
2022-04-25 20:21:31 +08:00
|
|
|
int erofs_map_blocks(struct inode *inode,
|
|
|
|
struct erofs_map_blocks *map, int flags);
|
2018-08-21 22:49:30 +08:00
|
|
|
|
2018-07-26 20:21:45 +08:00
|
|
|
/* inode.c */
|
2018-10-09 22:07:13 +08:00
|
|
|
static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
|
|
|
|
{
|
|
|
|
#if BITS_PER_LONG == 32
|
|
|
|
return (nid >> 32) ^ (nid & 0xffffffff);
|
|
|
|
#else
|
|
|
|
return nid;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-14 19:40:24 +08:00
|
|
|
extern const struct inode_operations erofs_generic_iops;
|
|
|
|
extern const struct inode_operations erofs_symlink_iops;
|
|
|
|
extern const struct inode_operations erofs_fast_symlink_iops;
|
2018-07-26 20:21:52 +08:00
|
|
|
|
2022-09-27 14:36:07 +08:00
|
|
|
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid);
|
2021-01-21 21:19:43 +08:00
|
|
|
int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,
|
|
|
|
struct kstat *stat, u32 request_mask,
|
|
|
|
unsigned int query_flags);
|
2019-01-16 16:59:56 +08:00
|
|
|
|
2019-01-14 19:40:24 +08:00
|
|
|
/* namei.c */
|
|
|
|
extern const struct inode_operations erofs_dir_iops;
|
|
|
|
|
2022-04-25 12:07:12 +08:00
|
|
|
int erofs_namei(struct inode *dir, const struct qstr *name,
|
2019-01-14 19:40:24 +08:00
|
|
|
erofs_nid_t *nid, unsigned int *d_type);
|
|
|
|
|
|
|
|
/* dir.c */
|
|
|
|
extern const struct file_operations erofs_dir_fops;
|
|
|
|
|
erofs: support decompress big pcluster for lz4 backend
Prior to big pcluster, there was only one compressed page so it'd
easy to map this. However, when big pcluster is enabled, more work
needs to be done to handle multiple compressed pages. In detail,
- (maptype 0) if there is only one compressed page + no need
to copy inplace I/O, just map it directly what we did before;
- (maptype 1) if there are more compressed pages + no need to
copy inplace I/O, vmap such compressed pages instead;
- (maptype 2) if inplace I/O needs to be copied, use per-CPU
buffers for decompression then.
Another thing is how to detect inplace decompression is feasable or
not (it's still quite easy for non big pclusters), apart from the
inplace margin calculation, inplace I/O page reusing order is also
needed to be considered for each compressed page. Currently, if the
compressed page is the xth page, it shouldn't be reused as [0 ...
nrpages_out - nrpages_in + x], otherwise a full copy will be triggered.
Although there are some extra optimization ideas for this, I'd like
to make big pcluster work correctly first and obviously it can be
further optimized later since it has nothing with the on-disk format
at all.
Link: https://lore.kernel.org/r/20210407043927.10623-10-xiang@kernel.org
Acked-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
2021-04-07 12:39:26 +08:00
|
|
|
static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count)
|
|
|
|
{
|
|
|
|
int retried = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
void *p = vm_map_ram(pages, count, -1);
|
|
|
|
|
|
|
|
/* retry two more times (totally 3 times) */
|
|
|
|
if (p || ++retried >= 3)
|
|
|
|
return p;
|
|
|
|
vm_unmap_aliases();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-04-10 03:06:30 +08:00
|
|
|
/* pcpubuf.c */
|
|
|
|
void *erofs_get_pcpubuf(unsigned int requiredpages);
|
|
|
|
void erofs_put_pcpubuf(void *ptr);
|
|
|
|
int erofs_pcpubuf_growsize(unsigned int nrpages);
|
|
|
|
void erofs_pcpubuf_init(void);
|
|
|
|
void erofs_pcpubuf_exit(void);
|
|
|
|
|
2021-12-01 22:54:36 +08:00
|
|
|
/* sysfs.c */
|
|
|
|
int erofs_register_sysfs(struct super_block *sb);
|
|
|
|
void erofs_unregister_sysfs(struct super_block *sb);
|
|
|
|
int __init erofs_init_sysfs(void);
|
|
|
|
void erofs_exit_sysfs(void);
|
|
|
|
|
2019-07-31 23:57:36 +08:00
|
|
|
/* utils.c / zdata.c */
|
2021-10-22 17:01:20 +08:00
|
|
|
struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp);
|
|
|
|
static inline void erofs_pagepool_add(struct page **pagepool,
|
|
|
|
struct page *page)
|
|
|
|
{
|
|
|
|
set_page_private(page, (unsigned long)*pagepool);
|
|
|
|
*pagepool = page;
|
|
|
|
}
|
|
|
|
void erofs_release_pages(struct page **pagepool);
|
2019-06-24 15:22:53 +08:00
|
|
|
|
2019-07-31 23:57:39 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP
|
2019-07-31 23:57:36 +08:00
|
|
|
int erofs_workgroup_put(struct erofs_workgroup *grp);
|
|
|
|
struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
|
2020-01-02 20:01:16 +08:00
|
|
|
pgoff_t index);
|
2020-02-20 10:46:42 +08:00
|
|
|
struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
|
|
|
|
struct erofs_workgroup *grp);
|
2019-07-31 23:57:36 +08:00
|
|
|
void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
|
2019-07-31 23:57:39 +08:00
|
|
|
void erofs_shrinker_register(struct super_block *sb);
|
|
|
|
void erofs_shrinker_unregister(struct super_block *sb);
|
|
|
|
int __init erofs_init_shrinker(void);
|
|
|
|
void erofs_exit_shrinker(void);
|
|
|
|
int __init z_erofs_init_zip_subsystem(void);
|
|
|
|
void z_erofs_exit_zip_subsystem(void);
|
2019-07-31 23:57:36 +08:00
|
|
|
int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
|
|
|
|
struct erofs_workgroup *egrp);
|
2021-08-10 15:24:16 +08:00
|
|
|
int erofs_try_to_free_cached_page(struct page *page);
|
2021-03-29 09:23:06 +08:00
|
|
|
int z_erofs_load_lz4_config(struct super_block *sb,
|
2021-03-29 09:23:07 +08:00
|
|
|
struct erofs_super_block *dsb,
|
|
|
|
struct z_erofs_lz4_cfgs *lz4, int len);
|
2019-07-31 23:57:39 +08:00
|
|
|
#else
|
|
|
|
static inline void erofs_shrinker_register(struct super_block *sb) {}
|
|
|
|
static inline void erofs_shrinker_unregister(struct super_block *sb) {}
|
|
|
|
static inline int erofs_init_shrinker(void) { return 0; }
|
|
|
|
static inline void erofs_exit_shrinker(void) {}
|
|
|
|
static inline int z_erofs_init_zip_subsystem(void) { return 0; }
|
|
|
|
static inline void z_erofs_exit_zip_subsystem(void) {}
|
2021-03-29 09:23:06 +08:00
|
|
|
static inline int z_erofs_load_lz4_config(struct super_block *sb,
|
2021-03-29 09:23:07 +08:00
|
|
|
struct erofs_super_block *dsb,
|
|
|
|
struct z_erofs_lz4_cfgs *lz4, int len)
|
2021-03-29 09:23:06 +08:00
|
|
|
{
|
2021-03-29 18:00:12 +08:00
|
|
|
if (lz4 || dsb->u1.lz4_max_distance) {
|
2021-03-29 09:23:06 +08:00
|
|
|
erofs_err(sb, "lz4 algorithm isn't enabled");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-31 23:57:39 +08:00
|
|
|
#endif /* !CONFIG_EROFS_FS_ZIP */
|
2019-01-16 16:59:56 +08:00
|
|
|
|
2021-10-11 05:31:45 +08:00
|
|
|
#ifdef CONFIG_EROFS_FS_ZIP_LZMA
|
|
|
|
int z_erofs_lzma_init(void);
|
|
|
|
void z_erofs_lzma_exit(void);
|
|
|
|
int z_erofs_load_lzma_config(struct super_block *sb,
|
|
|
|
struct erofs_super_block *dsb,
|
|
|
|
struct z_erofs_lzma_cfgs *lzma, int size);
|
|
|
|
#else
|
|
|
|
static inline int z_erofs_lzma_init(void) { return 0; }
|
|
|
|
static inline int z_erofs_lzma_exit(void) { return 0; }
|
|
|
|
static inline int z_erofs_load_lzma_config(struct super_block *sb,
|
|
|
|
struct erofs_super_block *dsb,
|
|
|
|
struct z_erofs_lzma_cfgs *lzma, int size) {
|
|
|
|
if (lzma) {
|
|
|
|
erofs_err(sb, "lzma algorithm isn't enabled");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_EROFS_FS_ZIP */
|
|
|
|
|
2022-04-25 20:21:33 +08:00
|
|
|
/* fscache.c */
|
|
|
|
#ifdef CONFIG_EROFS_FS_ONDEMAND
|
|
|
|
int erofs_fscache_register_fs(struct super_block *sb);
|
|
|
|
void erofs_fscache_unregister_fs(struct super_block *sb);
|
2022-04-25 20:21:34 +08:00
|
|
|
|
2022-09-18 12:34:52 +08:00
|
|
|
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
|
|
|
|
char *name, bool need_inode);
|
|
|
|
void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache);
|
2022-04-25 20:21:40 +08:00
|
|
|
|
|
|
|
extern const struct address_space_operations erofs_fscache_access_aops;
|
2022-04-25 20:21:33 +08:00
|
|
|
#else
|
|
|
|
static inline int erofs_fscache_register_fs(struct super_block *sb)
|
|
|
|
{
|
2022-09-18 12:34:52 +08:00
|
|
|
return -EOPNOTSUPP;
|
2022-04-25 20:21:33 +08:00
|
|
|
}
|
|
|
|
static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}
|
2022-04-25 20:21:34 +08:00
|
|
|
|
2022-09-18 12:34:52 +08:00
|
|
|
static inline
|
|
|
|
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
|
|
|
|
char *name, bool need_inode)
|
2022-04-25 20:21:34 +08:00
|
|
|
{
|
2022-09-18 12:34:52 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2022-04-25 20:21:34 +08:00
|
|
|
}
|
|
|
|
|
2022-09-18 12:34:52 +08:00
|
|
|
static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache)
|
2022-04-25 20:21:34 +08:00
|
|
|
{
|
|
|
|
}
|
2022-04-25 20:21:33 +08:00
|
|
|
#endif
|
|
|
|
|
2019-08-14 18:37:03 +08:00
|
|
|
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
|
|
|
|
|
2019-07-31 23:57:36 +08:00
|
|
|
#endif /* __EROFS_INTERNAL_H */
|