blob: 3efa686c764417eb0b4cf8b46f600555b641cbf9 [file] [log] [blame]
Gao Xiang29b24f62019-07-31 23:57:31 +08001// SPDX-License-Identifier: GPL-2.0-only
Gao Xiang7fc45db2019-06-24 15:22:55 +08002/*
Gao Xiang7fc45db2019-06-24 15:22:55 +08003 * Copyright (C) 2019 HUAWEI, Inc.
Alexander A. Klimov592e7cd2020-07-13 15:09:44 +02004 * https://www.huawei.com/
Gao Xiang7fc45db2019-06-24 15:22:55 +08005 */
6#include "compress.h"
Gao Xiang46c2d142019-07-31 23:57:44 +08007#include <linux/module.h>
Gao Xiang7fc45db2019-06-24 15:22:55 +08008#include <linux/lz4.h>
9
10#ifndef LZ4_DISTANCE_MAX /* history window size */
11#define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
12#endif
13
Gao Xiangaf89bce2019-07-03 14:52:09 +080014#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1)
Gao Xiang0ffd71b2019-06-24 15:22:56 +080015#ifndef LZ4_DECOMPRESS_INPLACE_MARGIN
16#define LZ4_DECOMPRESS_INPLACE_MARGIN(srcsize) (((srcsize) >> 8) + 32)
17#endif
Gao Xiang7fc45db2019-06-24 15:22:55 +080018
Gao Xiangd67aee72021-12-28 13:46:00 +080019struct z_erofs_lz4_decompress_ctx {
20 struct z_erofs_decompress_req *rq;
21 /* # of encoded, decoded pages */
22 unsigned int inpages, outpages;
23 /* decoded block total length (used for in-place decompression) */
24 unsigned int oend;
25};
26
Huang Jianan5d505382021-03-29 09:23:06 +080027int z_erofs_load_lz4_config(struct super_block *sb,
Gao Xiang46249cd2021-03-29 09:23:07 +080028 struct erofs_super_block *dsb,
29 struct z_erofs_lz4_cfgs *lz4, int size)
Huang Jianan5d505382021-03-29 09:23:06 +080030{
Gao Xiang4fea63f2021-04-07 12:39:23 +080031 struct erofs_sb_info *sbi = EROFS_SB(sb);
Gao Xiang46249cd2021-03-29 09:23:07 +080032 u16 distance;
33
34 if (lz4) {
35 if (size < sizeof(struct z_erofs_lz4_cfgs)) {
36 erofs_err(sb, "invalid lz4 cfgs, size=%u", size);
37 return -EINVAL;
38 }
39 distance = le16_to_cpu(lz4->max_distance);
Gao Xiang4fea63f2021-04-07 12:39:23 +080040
41 sbi->lz4.max_pclusterblks = le16_to_cpu(lz4->max_pclusterblks);
42 if (!sbi->lz4.max_pclusterblks) {
43 sbi->lz4.max_pclusterblks = 1; /* reserved case */
44 } else if (sbi->lz4.max_pclusterblks >
45 Z_EROFS_PCLUSTER_MAX_SIZE / EROFS_BLKSIZ) {
46 erofs_err(sb, "too large lz4 pclusterblks %u",
47 sbi->lz4.max_pclusterblks);
48 return -EINVAL;
49 } else if (sbi->lz4.max_pclusterblks >= 2) {
50 erofs_info(sb, "EXPERIMENTAL big pcluster feature in use. Use at your own risk!");
51 }
Gao Xiang46249cd2021-03-29 09:23:07 +080052 } else {
Gao Xiang14373712021-03-29 18:00:12 +080053 distance = le16_to_cpu(dsb->u1.lz4_max_distance);
Gao Xiang4fea63f2021-04-07 12:39:23 +080054 sbi->lz4.max_pclusterblks = 1;
Gao Xiang46249cd2021-03-29 09:23:07 +080055 }
Huang Jianan5d505382021-03-29 09:23:06 +080056
Gao Xiang4fea63f2021-04-07 12:39:23 +080057 sbi->lz4.max_distance_pages = distance ?
Huang Jianan5d505382021-03-29 09:23:06 +080058 DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
59 LZ4_MAX_DISTANCE_PAGES;
Gao Xiang4fea63f2021-04-07 12:39:23 +080060 return erofs_pcpubuf_growsize(sbi->lz4.max_pclusterblks);
Huang Jianan5d505382021-03-29 09:23:06 +080061}
62
Gao Xiang966edfb2021-10-11 05:31:44 +080063/*
64 * Fill all gaps with bounce pages if it's a sparse page list. Also check if
65 * all physical pages are consecutive, which can be seen for moderate CR.
66 */
Gao Xiangd67aee72021-12-28 13:46:00 +080067static int z_erofs_lz4_prepare_dstpages(struct z_erofs_lz4_decompress_ctx *ctx,
Gao Xiangeaa91722021-10-22 17:01:20 +080068 struct page **pagepool)
Gao Xiang7fc45db2019-06-24 15:22:55 +080069{
Gao Xiangd67aee72021-12-28 13:46:00 +080070 struct z_erofs_decompress_req *rq = ctx->rq;
Gao Xiang7fc45db2019-06-24 15:22:55 +080071 struct page *availables[LZ4_MAX_DISTANCE_PAGES] = { NULL };
Gao Xiangaf89bce2019-07-03 14:52:09 +080072 unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES,
73 BITS_PER_LONG)] = { 0 };
Huang Jianan5d505382021-03-29 09:23:06 +080074 unsigned int lz4_max_distance_pages =
75 EROFS_SB(rq->sb)->lz4.max_distance_pages;
Gao Xiang7fc45db2019-06-24 15:22:55 +080076 void *kaddr = NULL;
Gao Xiangaf89bce2019-07-03 14:52:09 +080077 unsigned int i, j, top;
Gao Xiang7fc45db2019-06-24 15:22:55 +080078
Gao Xiangaf89bce2019-07-03 14:52:09 +080079 top = 0;
Gao Xiangd67aee72021-12-28 13:46:00 +080080 for (i = j = 0; i < ctx->outpages; ++i, ++j) {
Gao Xiang7fc45db2019-06-24 15:22:55 +080081 struct page *const page = rq->out[i];
Gao Xiangaf89bce2019-07-03 14:52:09 +080082 struct page *victim;
Gao Xiang7fc45db2019-06-24 15:22:55 +080083
Huang Jianan5d505382021-03-29 09:23:06 +080084 if (j >= lz4_max_distance_pages)
Gao Xiangaf89bce2019-07-03 14:52:09 +080085 j = 0;
86
87 /* 'valid' bounced can only be tested after a complete round */
88 if (test_bit(j, bounced)) {
Huang Jianan5d505382021-03-29 09:23:06 +080089 DBG_BUGON(i < lz4_max_distance_pages);
90 DBG_BUGON(top >= lz4_max_distance_pages);
91 availables[top++] = rq->out[i - lz4_max_distance_pages];
Gao Xiangaf89bce2019-07-03 14:52:09 +080092 }
Gao Xiang7fc45db2019-06-24 15:22:55 +080093
94 if (page) {
Gao Xiangaf89bce2019-07-03 14:52:09 +080095 __clear_bit(j, bounced);
Gao Xiang7fc45db2019-06-24 15:22:55 +080096 if (kaddr) {
97 if (kaddr + PAGE_SIZE == page_address(page))
98 kaddr += PAGE_SIZE;
99 else
100 kaddr = NULL;
101 } else if (!i) {
102 kaddr = page_address(page);
103 }
104 continue;
105 }
106 kaddr = NULL;
Gao Xiangaf89bce2019-07-03 14:52:09 +0800107 __set_bit(j, bounced);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800108
Gao Xiangaf89bce2019-07-03 14:52:09 +0800109 if (top) {
110 victim = availables[--top];
111 get_page(victim);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800112 } else {
Huang Jiananb4892fa2021-03-16 11:15:14 +0800113 victim = erofs_allocpage(pagepool,
114 GFP_KERNEL | __GFP_NOFAIL);
Gao Xiang6aaa7b02020-12-08 17:58:32 +0800115 set_page_private(victim, Z_EROFS_SHORTLIVED_PAGE);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800116 }
Gao Xiangaf89bce2019-07-03 14:52:09 +0800117 rq->out[i] = victim;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800118 }
119 return kaddr ? 1 : 0;
120}
121
Gao Xiangd67aee72021-12-28 13:46:00 +0800122static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx,
Gao Xiang598162d2021-04-07 12:39:26 +0800123 void *inpage, unsigned int *inputmargin, int *maptype,
Gao Xiangab749ba2021-12-28 13:46:02 +0800124 bool may_inplace)
Gao Xiang7fc45db2019-06-24 15:22:55 +0800125{
Gao Xiangd67aee72021-12-28 13:46:00 +0800126 struct z_erofs_decompress_req *rq = ctx->rq;
127 unsigned int omargin, total, i, j;
Gao Xiang598162d2021-04-07 12:39:26 +0800128 struct page **in;
129 void *src, *tmp;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800130
Gao Xiang598162d2021-04-07 12:39:26 +0800131 if (rq->inplace_io) {
Gao Xiangd67aee72021-12-28 13:46:00 +0800132 omargin = PAGE_ALIGN(ctx->oend) - ctx->oend;
Gao Xiangab749ba2021-12-28 13:46:02 +0800133 if (rq->partial_decoding || !may_inplace ||
Gao Xiangd67aee72021-12-28 13:46:00 +0800134 omargin < LZ4_DECOMPRESS_INPLACE_MARGIN(rq->inputsize))
Gao Xiang598162d2021-04-07 12:39:26 +0800135 goto docopy;
136
Gao Xiangd67aee72021-12-28 13:46:00 +0800137 for (i = 0; i < ctx->inpages; ++i) {
Gao Xiang598162d2021-04-07 12:39:26 +0800138 DBG_BUGON(rq->in[i] == NULL);
Gao Xiangd67aee72021-12-28 13:46:00 +0800139 for (j = 0; j < ctx->outpages - ctx->inpages + i; ++j)
Gao Xiang598162d2021-04-07 12:39:26 +0800140 if (rq->out[j] == rq->in[i])
141 goto docopy;
142 }
Gao Xiang7fc45db2019-06-24 15:22:55 +0800143 }
Gao Xiang598162d2021-04-07 12:39:26 +0800144
Gao Xiangd67aee72021-12-28 13:46:00 +0800145 if (ctx->inpages <= 1) {
Gao Xiang598162d2021-04-07 12:39:26 +0800146 *maptype = 0;
147 return inpage;
148 }
149 kunmap_atomic(inpage);
150 might_sleep();
Gao Xiangd67aee72021-12-28 13:46:00 +0800151 src = erofs_vm_map_ram(rq->in, ctx->inpages);
Gao Xiang598162d2021-04-07 12:39:26 +0800152 if (!src)
153 return ERR_PTR(-ENOMEM);
154 *maptype = 1;
155 return src;
156
157docopy:
158 /* Or copy compressed data which can be overlapped to per-CPU buffer */
159 in = rq->in;
Gao Xiangd67aee72021-12-28 13:46:00 +0800160 src = erofs_get_pcpubuf(ctx->inpages);
Gao Xiang598162d2021-04-07 12:39:26 +0800161 if (!src) {
162 DBG_BUGON(1);
163 kunmap_atomic(inpage);
164 return ERR_PTR(-EFAULT);
165 }
166
167 tmp = src;
168 total = rq->inputsize;
169 while (total) {
170 unsigned int page_copycnt =
171 min_t(unsigned int, total, PAGE_SIZE - *inputmargin);
172
173 if (!inpage)
174 inpage = kmap_atomic(*in);
175 memcpy(tmp, inpage + *inputmargin, page_copycnt);
176 kunmap_atomic(inpage);
177 inpage = NULL;
178 tmp += page_copycnt;
179 total -= page_copycnt;
180 ++in;
181 *inputmargin = 0;
182 }
183 *maptype = 2;
184 return src;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800185}
186
Gao Xiang10e5f6e2021-12-28 13:46:01 +0800187/*
188 * Get the exact inputsize with zero_padding feature.
189 * - For LZ4, it should work if zero_padding feature is on (5.3+);
190 * - For MicroLZMA, it'd be enabled all the time.
191 */
192int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
193 unsigned int padbufsize)
194{
195 const char *padend;
196
197 padend = memchr_inv(padbuf, 0, padbufsize);
198 if (!padend)
199 return -EFSCORRUPTED;
200 rq->inputsize -= padend - padbuf;
201 rq->pageofs_in += padend - padbuf;
202 return 0;
203}
204
Gao Xiangd67aee72021-12-28 13:46:00 +0800205static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *ctx,
Gao Xiang966edfb2021-10-11 05:31:44 +0800206 u8 *out)
Gao Xiang7fc45db2019-06-24 15:22:55 +0800207{
Gao Xiangd67aee72021-12-28 13:46:00 +0800208 struct z_erofs_decompress_req *rq = ctx->rq;
Gao Xiangab749ba2021-12-28 13:46:02 +0800209 bool support_0padding = false, may_inplace = false;
Gao Xiang598162d2021-04-07 12:39:26 +0800210 unsigned int inputmargin;
211 u8 *headpage, *src;
Gao Xiang598162d2021-04-07 12:39:26 +0800212 int ret, maptype;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800213
Gao Xiang598162d2021-04-07 12:39:26 +0800214 DBG_BUGON(*rq->in == NULL);
215 headpage = kmap_atomic(*rq->in);
Gao Xiang0ffd71b2019-06-24 15:22:56 +0800216
Gao Xiang10e5f6e2021-12-28 13:46:01 +0800217 /* LZ4 decompression inplace is only safe if zero_padding is enabled */
Huang Jianan7e508f22021-11-13 00:09:33 +0800218 if (erofs_sb_has_zero_padding(EROFS_SB(rq->sb))) {
Gao Xiang0ffd71b2019-06-24 15:22:56 +0800219 support_0padding = true;
Gao Xiang10e5f6e2021-12-28 13:46:01 +0800220 ret = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in,
221 min_t(unsigned int, rq->inputsize,
222 EROFS_BLKSIZ - rq->pageofs_in));
223 if (ret) {
Gao Xiang598162d2021-04-07 12:39:26 +0800224 kunmap_atomic(headpage);
Gao Xiang10e5f6e2021-12-28 13:46:01 +0800225 return ret;
Gao Xiang0ffd71b2019-06-24 15:22:56 +0800226 }
Gao Xiangab749ba2021-12-28 13:46:02 +0800227 may_inplace = !((rq->pageofs_in + rq->inputsize) &
228 (EROFS_BLKSIZ - 1));
Gao Xiang0ffd71b2019-06-24 15:22:56 +0800229 }
Gao Xiang7fc45db2019-06-24 15:22:55 +0800230
Gao Xiang10e5f6e2021-12-28 13:46:01 +0800231 inputmargin = rq->pageofs_in;
Gao Xiangd67aee72021-12-28 13:46:00 +0800232 src = z_erofs_lz4_handle_overlap(ctx, headpage, &inputmargin,
Gao Xiangab749ba2021-12-28 13:46:02 +0800233 &maptype, may_inplace);
Gao Xiang598162d2021-04-07 12:39:26 +0800234 if (IS_ERR(src))
235 return PTR_ERR(src);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800236
Gao Xiangaf1038a2020-02-26 16:10:07 +0800237 /* legacy format could compress extra data in a pcluster. */
238 if (rq->partial_decoding || !support_0padding)
239 ret = LZ4_decompress_safe_partial(src + inputmargin, out,
Gao Xiang598162d2021-04-07 12:39:26 +0800240 rq->inputsize, rq->outputsize, rq->outputsize);
Gao Xiangaf1038a2020-02-26 16:10:07 +0800241 else
242 ret = LZ4_decompress_safe(src + inputmargin, out,
Gao Xiang598162d2021-04-07 12:39:26 +0800243 rq->inputsize, rq->outputsize);
Gao Xiangaf1038a2020-02-26 16:10:07 +0800244
Gao Xiangaa99a762020-02-26 16:10:08 +0800245 if (ret != rq->outputsize) {
246 erofs_err(rq->sb, "failed to decompress %d in[%u, %u] out[%u]",
Gao Xiang598162d2021-04-07 12:39:26 +0800247 ret, rq->inputsize, inputmargin, rq->outputsize);
Gao Xiangaa99a762020-02-26 16:10:08 +0800248
Gao Xiang7fc45db2019-06-24 15:22:55 +0800249 print_hex_dump(KERN_DEBUG, "[ in]: ", DUMP_PREFIX_OFFSET,
Gao Xiang598162d2021-04-07 12:39:26 +0800250 16, 1, src + inputmargin, rq->inputsize, true);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800251 print_hex_dump(KERN_DEBUG, "[out]: ", DUMP_PREFIX_OFFSET,
252 16, 1, out, rq->outputsize, true);
Gao Xiangaa99a762020-02-26 16:10:08 +0800253
254 if (ret >= 0)
255 memset(out + ret, 0, rq->outputsize - ret);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800256 ret = -EIO;
Yue Hu5b6e7e12021-10-14 14:57:44 +0800257 } else {
258 ret = 0;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800259 }
260
Gao Xiang598162d2021-04-07 12:39:26 +0800261 if (maptype == 0) {
Gao Xiangd67aee72021-12-28 13:46:00 +0800262 kunmap_atomic(headpage);
Gao Xiang598162d2021-04-07 12:39:26 +0800263 } else if (maptype == 1) {
Gao Xiangd67aee72021-12-28 13:46:00 +0800264 vm_unmap_ram(src, ctx->inpages);
Gao Xiang598162d2021-04-07 12:39:26 +0800265 } else if (maptype == 2) {
266 erofs_put_pcpubuf(src);
267 } else {
268 DBG_BUGON(1);
269 return -EFAULT;
270 }
Gao Xiang7fc45db2019-06-24 15:22:55 +0800271 return ret;
272}
273
Gao Xiang966edfb2021-10-11 05:31:44 +0800274static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
Gao Xiangeaa91722021-10-22 17:01:20 +0800275 struct page **pagepool)
Gao Xiang7fc45db2019-06-24 15:22:55 +0800276{
Gao Xiangd67aee72021-12-28 13:46:00 +0800277 struct z_erofs_lz4_decompress_ctx ctx;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800278 unsigned int dst_maptype;
279 void *dst;
Gao Xiang598162d2021-04-07 12:39:26 +0800280 int ret;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800281
Gao Xiangd67aee72021-12-28 13:46:00 +0800282 ctx.rq = rq;
283 ctx.oend = rq->pageofs_out + rq->outputsize;
284 ctx.outpages = PAGE_ALIGN(ctx.oend) >> PAGE_SHIFT;
285 ctx.inpages = PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT;
286
Yue Hu5b6e7e12021-10-14 14:57:44 +0800287 /* one optimized fast path only for non bigpcluster cases yet */
Gao Xiangd67aee72021-12-28 13:46:00 +0800288 if (ctx.inpages == 1 && ctx.outpages == 1 && !rq->inplace_io) {
Yue Hu5b6e7e12021-10-14 14:57:44 +0800289 DBG_BUGON(!*rq->out);
290 dst = kmap_atomic(*rq->out);
291 dst_maptype = 0;
292 goto dstmap_out;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800293 }
294
Gao Xiang598162d2021-04-07 12:39:26 +0800295 /* general decoding path which can be used for all cases */
Gao Xiangd67aee72021-12-28 13:46:00 +0800296 ret = z_erofs_lz4_prepare_dstpages(&ctx, pagepool);
297 if (ret < 0) {
Gao Xiang7fc45db2019-06-24 15:22:55 +0800298 return ret;
Gao Xiangd67aee72021-12-28 13:46:00 +0800299 } else if (ret > 0) {
Gao Xiang7fc45db2019-06-24 15:22:55 +0800300 dst = page_address(*rq->out);
301 dst_maptype = 1;
Gao Xiangd67aee72021-12-28 13:46:00 +0800302 } else {
303 dst = erofs_vm_map_ram(rq->out, ctx.outpages);
304 if (!dst)
305 return -ENOMEM;
306 dst_maptype = 2;
Gao Xiang7fc45db2019-06-24 15:22:55 +0800307 }
308
Gao Xiang7fc45db2019-06-24 15:22:55 +0800309dstmap_out:
Gao Xiangd67aee72021-12-28 13:46:00 +0800310 ret = z_erofs_lz4_decompress_mem(&ctx, dst + rq->pageofs_out);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800311 if (!dst_maptype)
312 kunmap_atomic(dst);
313 else if (dst_maptype == 2)
Gao Xiangd67aee72021-12-28 13:46:00 +0800314 vm_unmap_ram(dst, ctx.outpages);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800315 return ret;
316}
317
Gao Xiang966edfb2021-10-11 05:31:44 +0800318static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
Gao Xiangeaa91722021-10-22 17:01:20 +0800319 struct page **pagepool)
Gao Xiang7fc45db2019-06-24 15:22:55 +0800320{
321 const unsigned int nrpages_out =
322 PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
Gao Xiangab749ba2021-12-28 13:46:02 +0800323 const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
324 PAGE_SIZE - rq->pageofs_out);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800325 unsigned char *src, *dst;
326
327 if (nrpages_out > 2) {
328 DBG_BUGON(1);
329 return -EIO;
330 }
331
332 if (rq->out[0] == *rq->in) {
333 DBG_BUGON(nrpages_out != 1);
334 return 0;
335 }
336
Gao Xiangab749ba2021-12-28 13:46:02 +0800337 src = kmap_atomic(*rq->in) + rq->pageofs_in;
Gao Xiang4d202432020-01-07 10:25:46 +0800338 if (rq->out[0]) {
Gao Xiang7fc45db2019-06-24 15:22:55 +0800339 dst = kmap_atomic(rq->out[0]);
340 memcpy(dst + rq->pageofs_out, src, righthalf);
Gao Xiang4d202432020-01-07 10:25:46 +0800341 kunmap_atomic(dst);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800342 }
343
Gao Xiang4d202432020-01-07 10:25:46 +0800344 if (nrpages_out == 2) {
Gao Xiang7fc45db2019-06-24 15:22:55 +0800345 DBG_BUGON(!rq->out[1]);
Gao Xiang4d202432020-01-07 10:25:46 +0800346 if (rq->out[1] == *rq->in) {
347 memmove(src, src + righthalf, rq->pageofs_out);
348 } else {
349 dst = kmap_atomic(rq->out[1]);
350 memcpy(dst, src + righthalf, rq->pageofs_out);
351 kunmap_atomic(dst);
352 }
Gao Xiang7fc45db2019-06-24 15:22:55 +0800353 }
Gao Xiang7fc45db2019-06-24 15:22:55 +0800354 kunmap_atomic(src);
355 return 0;
356}
357
Gao Xiang966edfb2021-10-11 05:31:44 +0800358static struct z_erofs_decompressor decompressors[] = {
359 [Z_EROFS_COMPRESSION_SHIFTED] = {
360 .decompress = z_erofs_shifted_transform,
361 .name = "shifted"
362 },
363 [Z_EROFS_COMPRESSION_LZ4] = {
364 .decompress = z_erofs_lz4_decompress,
365 .name = "lz4"
366 },
Gao Xiang622cead2021-10-11 05:31:45 +0800367#ifdef CONFIG_EROFS_FS_ZIP_LZMA
368 [Z_EROFS_COMPRESSION_LZMA] = {
369 .decompress = z_erofs_lzma_decompress,
370 .name = "lzma"
371 },
372#endif
Gao Xiang966edfb2021-10-11 05:31:44 +0800373};
374
Gao Xiang7fc45db2019-06-24 15:22:55 +0800375int z_erofs_decompress(struct z_erofs_decompress_req *rq,
Gao Xiangeaa91722021-10-22 17:01:20 +0800376 struct page **pagepool)
Gao Xiang7fc45db2019-06-24 15:22:55 +0800377{
Gao Xiang966edfb2021-10-11 05:31:44 +0800378 return decompressors[rq->alg].decompress(rq, pagepool);
Gao Xiang7fc45db2019-06-24 15:22:55 +0800379}