Commit 1ca01520 authored by Gao Xiang's avatar Gao Xiang

erofs: refine z_erofs_transform_plain() for sub-page block support

Sub-page block support is still unusable even with previous commits if
interlaced PLAIN pclusters exist.  Such pclusters can be found if the
fragment feature is enabled.

This commit tries to handle "the head part" of interlaced PLAIN
pclusters first: it was once explained in commit fdffc091 ("erofs:
support interlaced uncompressed data for compressed files").

It uses a unique way for both shifted and interlaced PLAIN pclusters.
As an added bonus, PLAIN pclusters larger than the block size is also
supported now for the upcoming large lclusters.
Reviewed-by: default avatarYue Hu <huyue2@coolpad.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20231206091057.87027-5-hsiangkao@linux.alibaba.com
parent e5aba911
...@@ -320,43 +320,58 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, ...@@ -320,43 +320,58 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq, static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
struct page **pagepool) struct page **pagepool)
{ {
const unsigned int inpages = PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT; const unsigned int nrpages_in =
const unsigned int outpages = PAGE_ALIGN(rq->pageofs_in + rq->inputsize) >> PAGE_SHIFT;
const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
const unsigned int righthalf = min_t(unsigned int, rq->outputsize, const unsigned int bs = rq->sb->s_blocksize;
PAGE_SIZE - rq->pageofs_out); unsigned int cur = 0, ni = 0, no, pi, po, insz, cnt;
const unsigned int lefthalf = rq->outputsize - righthalf; u8 *kin;
const unsigned int interlaced_offset =
rq->alg == Z_EROFS_COMPRESSION_SHIFTED ? 0 : rq->pageofs_out; DBG_BUGON(rq->outputsize > rq->inputsize);
u8 *src; if (rq->alg == Z_EROFS_COMPRESSION_INTERLACED) {
cur = bs - (rq->pageofs_out & (bs - 1));
if (outpages > 2 && rq->alg == Z_EROFS_COMPRESSION_SHIFTED) { pi = (rq->pageofs_in + rq->inputsize - cur) & ~PAGE_MASK;
DBG_BUGON(1); cur = min(cur, rq->outputsize);
return -EFSCORRUPTED; if (cur && rq->out[0]) {
} kin = kmap_local_page(rq->in[nrpages_in - 1]);
if (rq->out[0] == rq->in[nrpages_in - 1]) {
if (rq->out[0] == *rq->in) { memmove(kin + rq->pageofs_out, kin + pi, cur);
DBG_BUGON(rq->pageofs_out); flush_dcache_page(rq->out[0]);
return 0; } else {
memcpy_to_page(rq->out[0], rq->pageofs_out,
kin + pi, cur);
}
kunmap_local(kin);
}
rq->outputsize -= cur;
} }
src = kmap_local_page(rq->in[inpages - 1]) + rq->pageofs_in; for (; rq->outputsize; rq->pageofs_in = 0, cur += PAGE_SIZE, ni++) {
if (rq->out[0]) insz = min(PAGE_SIZE - rq->pageofs_in, rq->outputsize);
memcpy_to_page(rq->out[0], rq->pageofs_out, rq->outputsize -= insz;
src + interlaced_offset, righthalf); if (!rq->in[ni])
continue;
if (outpages > inpages) { kin = kmap_local_page(rq->in[ni]);
DBG_BUGON(!rq->out[outpages - 1]); pi = 0;
if (rq->out[outpages - 1] != rq->in[inpages - 1]) { do {
memcpy_to_page(rq->out[outpages - 1], 0, src + no = (rq->pageofs_out + cur + pi) >> PAGE_SHIFT;
(interlaced_offset ? 0 : righthalf), po = (rq->pageofs_out + cur + pi) & ~PAGE_MASK;
lefthalf); DBG_BUGON(no >= nrpages_out);
} else if (!interlaced_offset) { cnt = min(insz - pi, PAGE_SIZE - po);
memmove(src, src + righthalf, lefthalf); if (rq->out[no] == rq->in[ni]) {
flush_dcache_page(rq->in[inpages - 1]); memmove(kin + po,
} kin + rq->pageofs_in + pi, cnt);
flush_dcache_page(rq->out[no]);
} else if (rq->out[no]) {
memcpy_to_page(rq->out[no], po,
kin + rq->pageofs_in + pi, cnt);
}
pi += cnt;
} while (pi < insz);
kunmap_local(kin);
} }
kunmap_local(src); DBG_BUGON(ni > nrpages_in);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment