Commit | Line | Data |
---|---|---|
29b24f6c | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
27481233 | 2 | /* |
27481233 | 3 | * Copyright (C) 2019 HUAWEI, Inc. |
592e7cd0 | 4 | * https://www.huawei.com/ |
27481233 GX |
5 | */ |
6 | #ifndef __EROFS_FS_COMPRESS_H | |
7 | #define __EROFS_FS_COMPRESS_H | |
8 | ||
7fc45dbc GX |
9 | #include "internal.h" |
10 | ||
7fc45dbc | 11 | struct z_erofs_decompress_req { |
0ffd71bc | 12 | struct super_block *sb; |
7fc45dbc GX |
13 | struct page **in, **out; |
14 | ||
15 | unsigned short pageofs_out; | |
16 | unsigned int inputsize, outputsize; | |
17 | ||
18 | /* indicate the algorithm will be used for decompression */ | |
19 | unsigned int alg; | |
20 | bool inplace_io, partial_decoding; | |
21 | }; | |
22 | ||
622ceadd GX |
23 | struct z_erofs_decompressor { |
24 | int (*decompress)(struct z_erofs_decompress_req *rq, | |
eaa9172a | 25 | struct page **pagepool); |
622ceadd GX |
26 | char *name; |
27 | }; | |
28 | ||
6aaa7b06 GX |
29 | /* some special page->private (unsigned long, see below) */ |
30 | #define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2) | |
1825c8d7 | 31 | #define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2) |
6aaa7b06 | 32 | |
27481233 | 33 | /* |
6aaa7b06 GX |
34 | * For all pages in a pcluster, page->private should be one of |
35 | * Type Last 2bits page->private | |
36 | * short-lived page 00 Z_EROFS_SHORTLIVED_PAGE | |
1825c8d7 | 37 | * preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE |
6aaa7b06 GX |
38 | * cached/managed page 00 pointer to z_erofs_pcluster |
39 | * online page (file-backed, 01/10/11 sub-index << 2 | count | |
40 | * some pages can be used for inplace I/O) | |
41 | * | |
42 | * page->mapping should be one of | |
43 | * Type page->mapping | |
44 | * short-lived page NULL | |
1825c8d7 | 45 | * preallocated page NULL |
6aaa7b06 GX |
46 | * cached/managed page non-NULL or NULL (invalidated/truncated page) |
47 | * online page non-NULL | |
48 | * | |
49 | * For all managed pages, PG_private should be set with 1 extra refcount, | |
50 | * which is used for page reclaim / migration. | |
27481233 | 51 | */ |
27481233 | 52 | |
6aaa7b06 GX |
53 | /* |
54 | * short-lived pages are pages directly from buddy system with specific | |
55 | * page->private (no need to set PagePrivate since these are non-LRU / | |
56 | * non-movable pages and bypass reclaim / migration code). | |
57 | */ | |
58 | static inline bool z_erofs_is_shortlived_page(struct page *page) | |
27481233 | 59 | { |
6aaa7b06 GX |
60 | if (page->private != Z_EROFS_SHORTLIVED_PAGE) |
61 | return false; | |
62 | ||
63 | DBG_BUGON(page->mapping); | |
64 | return true; | |
27481233 GX |
65 | } |
66 | ||
eaa9172a | 67 | static inline bool z_erofs_put_shortlivedpage(struct page **pagepool, |
6aaa7b06 | 68 | struct page *page) |
27481233 | 69 | { |
6aaa7b06 | 70 | if (!z_erofs_is_shortlived_page(page)) |
27481233 GX |
71 | return false; |
72 | ||
6aaa7b06 GX |
73 | /* short-lived pages should not be used by others at the same time */ |
74 | if (page_ref_count(page) > 1) { | |
27481233 | 75 | put_page(page); |
6aaa7b06 GX |
76 | } else { |
77 | /* follow the pcluster rule above. */ | |
eaa9172a | 78 | erofs_pagepool_add(pagepool, page); |
6aaa7b06 | 79 | } |
27481233 GX |
80 | return true; |
81 | } | |
82 | ||
622ceadd GX |
83 | #define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping) |
84 | static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi, | |
85 | struct page *page) | |
86 | { | |
87 | return page->mapping == MNGD_MAPPING(sbi); | |
88 | } | |
89 | ||
7fc45dbc | 90 | int z_erofs_decompress(struct z_erofs_decompress_req *rq, |
eaa9172a | 91 | struct page **pagepool); |
7fc45dbc | 92 | |
622ceadd GX |
93 | /* prototypes for specific algorithms */ |
94 | int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq, | |
eaa9172a | 95 | struct page **pagepool); |
27481233 | 96 | #endif |