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: [PATCH] erofs: support uncompressed pcluster with more than 1 block
Date: Fri, 2 Sep 2022 14:31:34 +0800 [thread overview]
Message-ID: <20220902063134.7639-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>
---
fs/erofs/decompressor.c | 56 +++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 2d55569f96ac..fe6abb79e560 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -320,41 +320,55 @@ 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;
+ const unsigned int lefthalf = min_t(unsigned int,
+ rq->outputsize - righthalf,
+ PAGE_SIZE - righthalf);
unsigned char *src, *dst;
+ unsigned int i;
- 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 {
+ 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);
+ } while (++i < nrpages_in);
+
return 0;
}
--
2.17.1
reply other threads:[~2022-09-02 6:32 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=20220902063134.7639-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®