| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2017-2018 HUAWEI, Inc. |
| 4 |
* https://www.huawei.com/ |
| 5 |
* Copyright (C) 2021, Alibaba Cloud |
| 6 |
*/ |
| 7 |
#ifndef __EROFS_INTERNAL_H |
| 8 |
#define __EROFS_INTERNAL_H |
| 9 |
|
| 10 |
#include <linux/fs.h> |
| 11 |
#include <linux/dax.h> |
| 12 |
#include <linux/dcache.h> |
| 13 |
#include <linux/mm.h> |
| 14 |
#include <linux/module.h> |
| 15 |
#include <linux/pagemap.h> |
| 16 |
#include <linux/bio.h> |
| 17 |
#include <linux/magic.h> |
| 18 |
#include <linux/slab.h> |
| 19 |
#include <linux/vmalloc.h> |
| 20 |
#include <linux/iomap.h> |
| 21 |
#include "erofs_fs.h" |
| 22 |
|
| 23 |
__printf(2, 3) void _erofs_printk(struct super_block *sb, const char *fmt, ...); |
| 24 |
#define erofs_err(sb, fmt, ...) \ |
| 25 |
_erofs_printk(sb, KERN_ERR fmt "\n", ##__VA_ARGS__) |
| 26 |
#define erofs_info(sb, fmt, ...) \ |
| 27 |
_erofs_printk(sb, KERN_INFO fmt "\n", ##__VA_ARGS__) |
| 28 |
|
| 29 |
#ifdef CONFIG_EROFS_FS_DEBUG |
| 30 |
#define DBG_BUGON BUG_ON |
| 31 |
#else |
| 32 |
#define DBG_BUGON(x) ((void)(x)) |
| 33 |
#endif /* !CONFIG_EROFS_FS_DEBUG */ |
| 34 |
|
| 35 |
/* EROFS_SUPER_MAGIC_V1 to represent the whole file system */ |
| 36 |
#define EROFS_SUPER_MAGIC EROFS_SUPER_MAGIC_V1 |
| 37 |
|
| 38 |
typedef u64 erofs_nid_t; |
| 39 |
typedef u64 erofs_off_t; |
| 40 |
typedef u64 erofs_blk_t; |
| 41 |
|
| 42 |
struct erofs_device_info { |
| 43 |
char *path; |
| 44 |
struct erofs_fscache *fscache; |
| 45 |
struct file *file; |
| 46 |
struct dax_device *dax_dev; |
| 47 |
u64 fsoff, dax_part_off; |
| 48 |
|
| 49 |
erofs_blk_t blocks; |
| 50 |
erofs_blk_t uniaddr; |
| 51 |
}; |
| 52 |
|
| 53 |
enum { |
| 54 |
EROFS_SYNC_DECOMPRESS_AUTO, |
| 55 |
EROFS_SYNC_DECOMPRESS_FORCE_ON, |
| 56 |
EROFS_SYNC_DECOMPRESS_FORCE_OFF |
| 57 |
}; |
| 58 |
|
| 59 |
struct erofs_mount_opts { |
| 60 |
/* current strategy of how to use managed cache */ |
| 61 |
unsigned char cache_strategy; |
| 62 |
unsigned int mount_opt; |
| 63 |
}; |
| 64 |
|
| 65 |
struct erofs_dev_context { |
| 66 |
struct idr tree; |
| 67 |
struct rw_semaphore rwsem; |
| 68 |
|
| 69 |
unsigned int extra_devices; |
| 70 |
bool flatdev; |
| 71 |
}; |
| 72 |
|
| 73 |
/* all filesystem-wide lz4 configurations */ |
| 74 |
struct erofs_sb_lz4_info { |
| 75 |
/* # of pages needed for EROFS lz4 rolling decompression */ |
| 76 |
u16 max_distance_pages; |
| 77 |
/* maximum possible blocks for pclusters in the filesystem */ |
| 78 |
u16 max_pclusterblks; |
| 79 |
}; |
| 80 |
|
| 81 |
struct erofs_domain { |
| 82 |
refcount_t ref; |
| 83 |
struct list_head list; |
| 84 |
struct fscache_volume *volume; |
| 85 |
char *domain_id; |
| 86 |
}; |
| 87 |
|
| 88 |
struct erofs_fscache { |
| 89 |
struct fscache_cookie *cookie; |
| 90 |
struct inode *inode; /* anonymous inode for the blob */ |
| 91 |
|
| 92 |
/* used for share domain mode */ |
| 93 |
struct erofs_domain *domain; |
| 94 |
struct list_head node; |
| 95 |
refcount_t ref; |
| 96 |
char *name; |
| 97 |
}; |
| 98 |
|
| 99 |
struct erofs_xattr_prefix_item { |
| 100 |
struct erofs_xattr_long_prefix *prefix; |
| 101 |
u8 infix_len; |
| 102 |
}; |
| 103 |
|
| 104 |
struct erofs_sb_info { |
| 105 |
struct erofs_device_info dif0; |
| 106 |
struct erofs_mount_opts opt; /* options */ |
| 107 |
#ifdef CONFIG_EROFS_FS_ZIP |
| 108 |
/* list for all registered superblocks, mainly for shrinker */ |
| 109 |
struct list_head list; |
| 110 |
struct mutex umount_mutex; |
| 111 |
|
| 112 |
/* managed XArray arranged in physical block number */ |
| 113 |
struct xarray managed_pslots; |
| 114 |
|
| 115 |
unsigned int sync_decompress; /* strategy for sync decompression */ |
| 116 |
unsigned int shrinker_run_no; |
| 117 |
|
| 118 |
/* pseudo inode to manage cached pages */ |
| 119 |
struct inode *managed_cache; |
| 120 |
|
| 121 |
struct erofs_sb_lz4_info lz4; |
| 122 |
#endif /* CONFIG_EROFS_FS_ZIP */ |
| 123 |
struct inode *packed_inode; |
| 124 |
struct inode *metabox_inode; |
| 125 |
struct erofs_dev_context *devs; |
| 126 |
u64 total_blocks; |
| 127 |
|
| 128 |
u32 meta_blkaddr; |
| 129 |
#ifdef CONFIG_EROFS_FS_XATTR |
| 130 |
u32 xattr_blkaddr; |
| 131 |
u32 xattr_prefix_start; |
| 132 |
u8 xattr_prefix_count; |
| 133 |
u8 ishare_xattr_prefix_id; |
| 134 |
struct erofs_xattr_prefix_item *xattr_prefixes; |
| 135 |
unsigned int xattr_filter_reserved; |
| 136 |
#endif |
| 137 |
u16 device_id_mask; /* valid bits of device id to be used */ |
| 138 |
|
| 139 |
unsigned char islotbits; /* inode slot unit size in bit shift */ |
| 140 |
unsigned char blkszbits; /* filesystem block size in bit shift */ |
| 141 |
|
| 142 |
u32 sb_size; /* total superblock size */ |
| 143 |
u32 fixed_nsec; |
| 144 |
s64 epoch; |
| 145 |
|
| 146 |
/* what we really care is nid, rather than ino.. */ |
| 147 |
erofs_nid_t root_nid; |
| 148 |
erofs_nid_t packed_nid; |
| 149 |
erofs_nid_t metabox_nid; |
| 150 |
/* used for statfs, f_files - f_favail */ |
| 151 |
u64 inos; |
| 152 |
|
| 153 |
char *volume_name; |
| 154 |
u32 feature_compat; |
| 155 |
u32 feature_incompat; |
| 156 |
u16 available_compr_algs; |
| 157 |
|
| 158 |
/* sysfs support */ |
| 159 |
struct kobject s_kobj; /* /sys/fs/erofs/<devname> */ |
| 160 |
struct completion s_kobj_unregister; |
| 161 |
erofs_off_t dir_ra_bytes; |
| 162 |
|
| 163 |
/* fscache support */ |
| 164 |
struct fscache_volume *volume; |
| 165 |
struct erofs_domain *domain; |
| 166 |
char *fsid; |
| 167 |
char *domain_id; |
| 168 |
}; |
| 169 |
|
| 170 |
#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) |
| 171 |
#define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info) |
| 172 |
|
| 173 |
/* Mount flags set via mount options or defaults */ |
| 174 |
#define EROFS_MOUNT_XATTR_USER 0x00000010 |
| 175 |
#define EROFS_MOUNT_POSIX_ACL 0x00000020 |
| 176 |
#define EROFS_MOUNT_DAX_ALWAYS 0x00000040 |
| 177 |
#define EROFS_MOUNT_DAX_NEVER 0x00000080 |
| 178 |
#define EROFS_MOUNT_DIRECT_IO 0x00000100 |
| 179 |
#define EROFS_MOUNT_INODE_SHARE 0x00000200 |
| 180 |
|
| 181 |
#define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option) |
| 182 |
#define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option) |
| 183 |
#define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option) |
| 184 |
|
| 185 |
static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi) |
| 186 |
{ |
| 187 |
return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file; |
| 188 |
} |
| 189 |
|
| 190 |
extern struct file_system_type erofs_anon_fs_type; |
| 191 |
|
| 192 |
static inline bool erofs_is_fscache_mode(struct super_block *sb) |
| 193 |
{ |
| 194 |
return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && |
| 195 |
!erofs_is_fileio_mode(EROFS_SB(sb)) && !sb->s_bdev; |
| 196 |
} |
| 197 |
|
| 198 |
enum { |
| 199 |
EROFS_ZIP_CACHE_DISABLED, |
| 200 |
EROFS_ZIP_CACHE_READAHEAD, |
| 201 |
EROFS_ZIP_CACHE_READAROUND |
| 202 |
}; |
| 203 |
|
| 204 |
struct erofs_buf { |
| 205 |
struct address_space *mapping; |
| 206 |
struct file *file; |
| 207 |
u64 off; |
| 208 |
struct page *page; |
| 209 |
void *base; |
| 210 |
}; |
| 211 |
#define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL }) |
| 212 |
|
| 213 |
#define erofs_blknr(sb, pos) ((erofs_blk_t)((pos) >> (sb)->s_blocksize_bits)) |
| 214 |
#define erofs_blkoff(sb, pos) ((pos) & ((sb)->s_blocksize - 1)) |
| 215 |
#define erofs_pos(sb, blk) ((erofs_off_t)(blk) << (sb)->s_blocksize_bits) |
| 216 |
#define erofs_iblks(i) (round_up((i)->i_size, i_blocksize(i)) >> (i)->i_blkbits) |
| 217 |
|
| 218 |
#define EROFS_FEATURE_FUNCS(name, compat, feature) \ |
| 219 |
static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \ |
| 220 |
{ \ |
| 221 |
return sbi->feature_##compat & EROFS_FEATURE_##feature; \ |
| 222 |
} |
| 223 |
|
| 224 |
EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING) |
| 225 |
EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS) |
| 226 |
EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER) |
| 227 |
EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE) |
| 228 |
EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE) |
| 229 |
EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2) |
| 230 |
EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) |
| 231 |
EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) |
| 232 |
EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) |
| 233 |
EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) |
| 234 |
EROFS_FEATURE_FUNCS(48bit, incompat, INCOMPAT_48BIT) |
| 235 |
EROFS_FEATURE_FUNCS(metabox, incompat, INCOMPAT_METABOX) |
| 236 |
EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) |
| 237 |
EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER) |
| 238 |
EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX) |
| 239 |
EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX) |
| 240 |
EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS) |
| 241 |
|
| 242 |
static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid) |
| 243 |
{ |
| 244 |
if (!erofs_sb_has_metabox(sbi)) |
| 245 |
return nid; |
| 246 |
|
| 247 |
/* |
| 248 |
* When metadata compression is enabled, avoid generating excessively |
| 249 |
* large inode numbers for metadata-compressed inodes. Shift NIDs in |
| 250 |
* the 31-62 bit range left by one and move the metabox flag to bit 31. |
| 251 |
* |
| 252 |
* Note: on-disk NIDs remain unchanged as they are primarily used for |
| 253 |
* compatibility with non-LFS 32-bit applications. |
| 254 |
*/ |
| 255 |
return ((nid << 1) & GENMASK_ULL(63, 32)) | (nid & GENMASK(30, 0)) | |
| 256 |
((nid >> EROFS_DIRENT_NID_METABOX_BIT) << 31); |
| 257 |
} |
| 258 |
|
| 259 |
/* atomic flag definitions */ |
| 260 |
#define EROFS_I_EA_INITED_BIT 0 |
| 261 |
#define EROFS_I_Z_INITED_BIT 1 |
| 262 |
|
| 263 |
/* bitlock definitions (arranged in reverse order) */ |
| 264 |
#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1) |
| 265 |
#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2) |
| 266 |
|
| 267 |
/* default readahead size of directories */ |
| 268 |
#define EROFS_DIR_RA_BYTES 16384 |
| 269 |
|
| 270 |
struct erofs_inode_fingerprint { |
| 271 |
u8 *opaque; |
| 272 |
int size; |
| 273 |
}; |
| 274 |
|
| 275 |
struct erofs_inode { |
| 276 |
erofs_nid_t nid; |
| 277 |
|
| 278 |
/* atomic flags (including bitlocks) */ |
| 279 |
unsigned long flags; |
| 280 |
|
| 281 |
unsigned char datalayout; |
| 282 |
unsigned char inode_isize; |
| 283 |
bool dot_omitted; |
| 284 |
unsigned int xattr_isize; |
| 285 |
|
| 286 |
unsigned int xattr_name_filter; |
| 287 |
unsigned int xattr_shared_count; |
| 288 |
unsigned int *xattr_shared_xattrs; |
| 289 |
|
| 290 |
union { |
| 291 |
erofs_blk_t startblk; |
| 292 |
struct { |
| 293 |
unsigned short chunkformat; |
| 294 |
unsigned char chunkbits; |
| 295 |
}; |
| 296 |
#ifdef CONFIG_EROFS_FS_ZIP |
| 297 |
struct { |
| 298 |
unsigned short z_advise; |
| 299 |
unsigned char z_algorithmtype[2]; |
| 300 |
unsigned char z_lclusterbits; |
| 301 |
union { |
| 302 |
u64 z_tailextent_headlcn; |
| 303 |
u64 z_extents; |
| 304 |
}; |
| 305 |
erofs_off_t z_fragmentoff; |
| 306 |
unsigned short z_idata_size; |
| 307 |
}; |
| 308 |
#endif /* CONFIG_EROFS_FS_ZIP */ |
| 309 |
}; |
| 310 |
#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE |
| 311 |
struct list_head ishare_list; |
| 312 |
union { |
| 313 |
/* for each anon shared inode */ |
| 314 |
struct { |
| 315 |
struct erofs_inode_fingerprint fingerprint; |
| 316 |
spinlock_t ishare_lock; |
| 317 |
}; |
| 318 |
/* for each real inode */ |
| 319 |
struct inode *sharedinode; |
| 320 |
}; |
| 321 |
#endif |
| 322 |
/* the corresponding vfs inode */ |
| 323 |
struct inode vfs_inode; |
| 324 |
}; |
| 325 |
|
| 326 |
#define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode) |
| 327 |
|
| 328 |
static inline bool erofs_inode_in_metabox(struct inode *inode) |
| 329 |
{ |
| 330 |
return EROFS_I(inode)->nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT); |
| 331 |
} |
| 332 |
|
| 333 |
static inline erofs_off_t erofs_iloc(struct inode *inode) |
| 334 |
{ |
| 335 |
struct erofs_sb_info *sbi = EROFS_I_SB(inode); |
| 336 |
erofs_nid_t nid_lo = EROFS_I(inode)->nid & EROFS_DIRENT_NID_MASK; |
| 337 |
|
| 338 |
if (erofs_inode_in_metabox(inode)) |
| 339 |
return nid_lo << sbi->islotbits; |
| 340 |
return erofs_pos(inode->i_sb, sbi->meta_blkaddr) + |
| 341 |
(nid_lo << sbi->islotbits); |
| 342 |
} |
| 343 |
|
| 344 |
static inline unsigned int erofs_inode_version(unsigned int ifmt) |
| 345 |
{ |
| 346 |
return (ifmt >> EROFS_I_VERSION_BIT) & EROFS_I_VERSION_MASK; |
| 347 |
} |
| 348 |
|
| 349 |
static inline unsigned int erofs_inode_datalayout(unsigned int ifmt) |
| 350 |
{ |
| 351 |
return (ifmt >> EROFS_I_DATALAYOUT_BIT) & EROFS_I_DATALAYOUT_MASK; |
| 352 |
} |
| 353 |
|
| 354 |
/* reclaiming is never triggered when allocating new folios. */ |
| 355 |
static inline struct folio *erofs_grab_folio_nowait(struct address_space *as, |
| 356 |
pgoff_t index) |
| 357 |
{ |
| 358 |
return __filemap_get_folio(as, index, |
| 359 |
FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT, |
| 360 |
readahead_gfp_mask(as) & ~__GFP_RECLAIM); |
| 361 |
} |
| 362 |
|
| 363 |
/* Has a disk mapping */ |
| 364 |
#define EROFS_MAP_MAPPED 0x0001 |
| 365 |
/* Located in metadata (could be copied from bd_inode) */ |
| 366 |
#define EROFS_MAP_META 0x0002 |
| 367 |
/* The extent is encoded */ |
| 368 |
#define EROFS_MAP_ENCODED 0x0004 |
| 369 |
/* The length of extent is full */ |
| 370 |
#define EROFS_MAP_FULL_MAPPED 0x0008 |
| 371 |
/* Located in the special packed inode */ |
| 372 |
#define __EROFS_MAP_FRAGMENT 0x0010 |
| 373 |
/* The extent refers to partial decompressed data */ |
| 374 |
#define EROFS_MAP_PARTIAL_REF 0x0020 |
| 375 |
|
| 376 |
#define EROFS_MAP_FRAGMENT (EROFS_MAP_MAPPED | __EROFS_MAP_FRAGMENT) |
| 377 |
|
| 378 |
struct erofs_map_blocks { |
| 379 |
struct erofs_buf buf; |
| 380 |
|
| 381 |
erofs_off_t m_pa, m_la; |
| 382 |
u64 m_plen, m_llen; |
| 383 |
|
| 384 |
unsigned short m_deviceid; |
| 385 |
char m_algorithmformat; |
| 386 |
unsigned int m_flags; |
| 387 |
}; |
| 388 |
|
| 389 |
/* |
| 390 |
* Used to get the exact decompressed length, e.g. fiemap (consider lookback |
| 391 |
* approach instead if possible since it's more metadata lightweight.) |
| 392 |
*/ |
| 393 |
#define EROFS_GET_BLOCKS_FIEMAP 0x0001 |
| 394 |
/* Used to map the whole extent if non-negligible data is requested for LZMA */ |
| 395 |
#define EROFS_GET_BLOCKS_READMORE 0x0002 |
| 396 |
/* Used to map tail extent for tailpacking inline or fragment pcluster */ |
| 397 |
#define EROFS_GET_BLOCKS_FINDTAIL 0x0004 |
| 398 |
|
| 399 |
enum { |
| 400 |
Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX, |
| 401 |
Z_EROFS_COMPRESSION_INTERLACED, |
| 402 |
Z_EROFS_COMPRESSION_RUNTIME_MAX |
| 403 |
}; |
| 404 |
|
| 405 |
struct erofs_map_dev { |
| 406 |
struct super_block *m_sb; |
| 407 |
struct erofs_device_info *m_dif; |
| 408 |
struct block_device *m_bdev; |
| 409 |
|
| 410 |
erofs_off_t m_pa; |
| 411 |
unsigned int m_deviceid; |
| 412 |
}; |
| 413 |
|
| 414 |
extern const struct super_operations erofs_sops; |
| 415 |
|
| 416 |
extern const struct address_space_operations erofs_aops; |
| 417 |
extern const struct address_space_operations erofs_fileio_aops; |
| 418 |
extern const struct address_space_operations z_erofs_aops; |
| 419 |
extern const struct address_space_operations erofs_fscache_access_aops; |
| 420 |
|
| 421 |
extern const struct inode_operations erofs_generic_iops; |
| 422 |
extern const struct inode_operations erofs_symlink_iops; |
| 423 |
extern const struct inode_operations erofs_fast_symlink_iops; |
| 424 |
extern const struct inode_operations erofs_dir_iops; |
| 425 |
|
| 426 |
extern const struct file_operations erofs_file_fops; |
| 427 |
extern const struct file_operations erofs_dir_fops; |
| 428 |
extern const struct file_operations erofs_ishare_fops; |
| 429 |
|
| 430 |
extern const struct iomap_ops z_erofs_iomap_report_ops; |
| 431 |
|
| 432 |
/* flags for erofs_fscache_register_cookie() */ |
| 433 |
#define EROFS_REG_COOKIE_SHARE 0x0001 |
| 434 |
#define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002 |
| 435 |
|
| 436 |
void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, |
| 437 |
erofs_off_t *offset, int *lengthp); |
| 438 |
void erofs_unmap_metabuf(struct erofs_buf *buf); |
| 439 |
void erofs_put_metabuf(struct erofs_buf *buf); |
| 440 |
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap); |
| 441 |
int erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb, |
| 442 |
bool in_metabox); |
| 443 |
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, |
| 444 |
erofs_off_t offset, bool in_metabox); |
| 445 |
int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *dev); |
| 446 |
int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
| 447 |
u64 start, u64 len); |
| 448 |
int erofs_map_blocks(struct inode *inode, struct erofs_map_blocks *map); |
| 449 |
void erofs_onlinefolio_init(struct folio *folio); |
| 450 |
void erofs_onlinefolio_split(struct folio *folio); |
| 451 |
void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty); |
| 452 |
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid); |
| 453 |
int erofs_getattr(struct mnt_idmap *idmap, const struct path *path, |
| 454 |
struct kstat *stat, u32 request_mask, |
| 455 |
unsigned int query_flags); |
| 456 |
int erofs_namei(struct inode *dir, const struct qstr *name, |
| 457 |
erofs_nid_t *nid, unsigned int *d_type); |
| 458 |
|
| 459 |
static inline void *erofs_vm_map_ram(struct page **pages, unsigned int count) |
| 460 |
{ |
| 461 |
int retried = 0; |
| 462 |
|
| 463 |
while (1) { |
| 464 |
void *p = vm_map_ram(pages, count, -1); |
| 465 |
|
| 466 |
/* retry two more times (totally 3 times) */ |
| 467 |
if (p || ++retried >= 3) |
| 468 |
return p; |
| 469 |
vm_unmap_aliases(); |
| 470 |
} |
| 471 |
return NULL; |
| 472 |
} |
| 473 |
|
| 474 |
static inline const struct address_space_operations * |
| 475 |
erofs_get_aops(struct inode *realinode, bool no_fscache) |
| 476 |
{ |
| 477 |
if (erofs_inode_is_data_compressed(EROFS_I(realinode)->datalayout)) { |
| 478 |
if (!IS_ENABLED(CONFIG_EROFS_FS_ZIP)) |
| 479 |
return ERR_PTR(-EOPNOTSUPP); |
| 480 |
DO_ONCE_LITE_IF(realinode->i_blkbits != PAGE_SHIFT, |
| 481 |
erofs_info, realinode->i_sb, |
| 482 |
"EXPERIMENTAL EROFS subpage compressed block support in use. Use at your own risk!"); |
| 483 |
return &z_erofs_aops; |
| 484 |
} |
| 485 |
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !no_fscache && |
| 486 |
erofs_is_fscache_mode(realinode->i_sb)) |
| 487 |
return &erofs_fscache_access_aops; |
| 488 |
if (IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && |
| 489 |
erofs_is_fileio_mode(EROFS_SB(realinode->i_sb))) |
| 490 |
return &erofs_fileio_aops; |
| 491 |
return &erofs_aops; |
| 492 |
} |
| 493 |
|
| 494 |
int erofs_register_sysfs(struct super_block *sb); |
| 495 |
void erofs_unregister_sysfs(struct super_block *sb); |
| 496 |
int __init erofs_init_sysfs(void); |
| 497 |
void erofs_exit_sysfs(void); |
| 498 |
|
| 499 |
struct page *__erofs_allocpage(struct page **pagepool, gfp_t gfp, bool tryrsv); |
| 500 |
static inline struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp) |
| 501 |
{ |
| 502 |
return __erofs_allocpage(pagepool, gfp, false); |
| 503 |
} |
| 504 |
static inline void erofs_pagepool_add(struct page **pagepool, struct page *page) |
| 505 |
{ |
| 506 |
set_page_private(page, (unsigned long)*pagepool); |
| 507 |
*pagepool = page; |
| 508 |
} |
| 509 |
void erofs_release_pages(struct page **pagepool); |
| 510 |
|
| 511 |
#ifdef CONFIG_EROFS_FS_ZIP |
| 512 |
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping) |
| 513 |
|
| 514 |
extern atomic_long_t erofs_global_shrink_cnt; |
| 515 |
void erofs_shrinker_register(struct super_block *sb); |
| 516 |
void erofs_shrinker_unregister(struct super_block *sb); |
| 517 |
int __init erofs_init_shrinker(void); |
| 518 |
void erofs_exit_shrinker(void); |
| 519 |
int __init z_erofs_init_subsystem(void); |
| 520 |
void z_erofs_exit_subsystem(void); |
| 521 |
int z_erofs_init_super(struct super_block *sb); |
| 522 |
unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi, |
| 523 |
unsigned long nr_shrink); |
| 524 |
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, |
| 525 |
int flags); |
| 526 |
void *z_erofs_get_gbuf(unsigned int requiredpages); |
| 527 |
void z_erofs_put_gbuf(void *ptr); |
| 528 |
int z_erofs_gbuf_growsize(unsigned int nrpages); |
| 529 |
int __init z_erofs_gbuf_init(void); |
| 530 |
void z_erofs_gbuf_exit(void); |
| 531 |
#else |
| 532 |
static inline void erofs_shrinker_register(struct super_block *sb) {} |
| 533 |
static inline void erofs_shrinker_unregister(struct super_block *sb) {} |
| 534 |
static inline int erofs_init_shrinker(void) { return 0; } |
| 535 |
static inline void erofs_exit_shrinker(void) {} |
| 536 |
static inline int z_erofs_init_subsystem(void) { return 0; } |
| 537 |
static inline void z_erofs_exit_subsystem(void) {} |
| 538 |
static inline int z_erofs_init_super(struct super_block *sb) { return 0; } |
| 539 |
#endif /* !CONFIG_EROFS_FS_ZIP */ |
| 540 |
int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb); |
| 541 |
|
| 542 |
#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE |
| 543 |
struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev); |
| 544 |
void erofs_fileio_submit_bio(struct bio *bio); |
| 545 |
#else |
| 546 |
static inline struct bio *erofs_fileio_bio_alloc(struct erofs_map_dev *mdev) { return NULL; } |
| 547 |
static inline void erofs_fileio_submit_bio(struct bio *bio) {} |
| 548 |
#endif |
| 549 |
|
| 550 |
#ifdef CONFIG_EROFS_FS_ONDEMAND |
| 551 |
int erofs_fscache_register_fs(struct super_block *sb); |
| 552 |
void erofs_fscache_unregister_fs(struct super_block *sb); |
| 553 |
|
| 554 |
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, |
| 555 |
char *name, unsigned int flags); |
| 556 |
void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); |
| 557 |
struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev); |
| 558 |
void erofs_fscache_submit_bio(struct bio *bio); |
| 559 |
#else |
| 560 |
static inline int erofs_fscache_register_fs(struct super_block *sb) |
| 561 |
{ |
| 562 |
return -EOPNOTSUPP; |
| 563 |
} |
| 564 |
static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} |
| 565 |
|
| 566 |
static inline |
| 567 |
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, |
| 568 |
char *name, unsigned int flags) |
| 569 |
{ |
| 570 |
return ERR_PTR(-EOPNOTSUPP); |
| 571 |
} |
| 572 |
|
| 573 |
static inline void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache) |
| 574 |
{ |
| 575 |
} |
| 576 |
static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { return NULL; } |
| 577 |
static inline void erofs_fscache_submit_bio(struct bio *bio) {} |
| 578 |
#endif |
| 579 |
|
| 580 |
#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE |
| 581 |
int __init erofs_init_ishare(void); |
| 582 |
void erofs_exit_ishare(void); |
| 583 |
bool erofs_ishare_fill_inode(struct inode *inode); |
| 584 |
void erofs_ishare_free_inode(struct inode *inode); |
| 585 |
struct inode *erofs_real_inode(struct inode *inode, bool *need_iput); |
| 586 |
#else |
| 587 |
static inline int erofs_init_ishare(void) { return 0; } |
| 588 |
static inline void erofs_exit_ishare(void) {} |
| 589 |
static inline bool erofs_ishare_fill_inode(struct inode *inode) { return false; } |
| 590 |
static inline void erofs_ishare_free_inode(struct inode *inode) {} |
| 591 |
static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_iput) |
| 592 |
{ |
| 593 |
*need_iput = false; |
| 594 |
return inode; |
| 595 |
} |
| 596 |
#endif |
| 597 |
|
| 598 |
long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
| 599 |
long erofs_compat_ioctl(struct file *filp, unsigned int cmd, |
| 600 |
unsigned long arg); |
| 601 |
|
| 602 |
#endif /* __EROFS_INTERNAL_H */ |