From: Yue Hu <zbestahu@gmail.com>
To: xiang@kernel.org, chao@kernel.org
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org,
zhangwen@coolpad.com, Yue Hu <huyue2@coolpad.com>
Subject: [RFC PATCH v2] erofs: support uncompressed pcluster with more than 1 block
Date: Fri, 2 Sep 2022 21:50:36 +0800 [thread overview]
Message-ID: <20220902135036.11595-1-zbestahu@gmail.com> (raw)
From: Yue Hu <huyue2@coolpad.com>
The length of uncompressed pcluster may exceed one block in some new
scenarios such as non 4K-sized lcluster (which will be supported later).
So, let's support the decompression for this firstly.
Signed-off-by: Yue Hu <huyue2@coolpad.com>
---
v2: fix tail data length.
fs/erofs/decompressor.c | 64 ++++++++++++++++++++++++++---------------
1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 2d55569f96ac..77d2b6cb6eda 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -320,41 +320,59 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
struct page **pagepool)
{
+ const unsigned int nrpages_in = rq->inputsize >> PAGE_SHIFT;
const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
- const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
- PAGE_SIZE - rq->pageofs_out);
- const unsigned int lefthalf = rq->outputsize - righthalf;
+ unsigned int righthalf, lefthalf, i;
unsigned char *src, *dst;
- if (nrpages_out > 2) {
+ if (nrpages_in == 1 && nrpages_out > 2) {
DBG_BUGON(1);
return -EIO;
}
- if (rq->out[0] == *rq->in) {
- DBG_BUGON(nrpages_out != 1);
- return 0;
- }
+ i = 0;
+ do {
+ unsigned int outputsize = rq->outputsize;
+
+ righthalf = min_t(unsigned int, outputsize,
+ PAGE_SIZE - rq->pageofs_out);
+ lefthalf = min_t(unsigned int, outputsize - righthalf,
+ PAGE_SIZE - righthalf);
+
+ src = kmap_atomic(rq->in[i]) + rq->pageofs_in;
+ if (rq->out[i]) {
+ if (rq->out[i] == rq->in[i]) {
+ DBG_BUGON(nrpages_in == 1 && nrpages_out != 1);
+ } else {
+ dst = kmap_atomic(rq->out[i]);
+ memcpy(dst + rq->pageofs_out, src, righthalf);
+ kunmap_atomic(dst);
+ }
+ }
- src = kmap_atomic(*rq->in) + rq->pageofs_in;
- if (rq->out[0]) {
- dst = kmap_atomic(rq->out[0]);
- memcpy(dst + rq->pageofs_out, src, righthalf);
- kunmap_atomic(dst);
- }
+ if (i + 1 == nrpages_out) {
+ kunmap_atomic(src);
+ break;
+ }
- if (nrpages_out == 2) {
- DBG_BUGON(!rq->out[1]);
- if (rq->out[1] == *rq->in) {
- memmove(src, src + righthalf, lefthalf);
+ if (rq->out[i + 1]) {
+ if (rq->out[i + 1] == rq->in[i]) {
+ memmove(src, src + righthalf, lefthalf);
+ } else {
+ dst = kmap_atomic(rq->out[i + 1]);
+ memcpy(dst, src + righthalf, lefthalf);
+ kunmap_atomic(dst);
+ }
} else {
- dst = kmap_atomic(rq->out[1]);
- memcpy(dst, src + righthalf, lefthalf);
- kunmap_atomic(dst);
+ DBG_BUGON(nrpages_in == 1 && nrpages_out == 2);
}
- }
- kunmap_atomic(src);
+ kunmap_atomic(src);
+
+ if (outputsize > PAGE_SIZE)
+ outputsize -= PAGE_SIZE;
+ } while (++i < nrpages_in);
+
return 0;
}
--
2.17.1
reply other threads:[~2022-09-02 14:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220902135036.11595-1-zbestahu@gmail.com \
--to=zbestahu@gmail.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
--cc=zhangwen@coolpad.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®