erofs-utils: compress trailing data for big pcluster properly
Compress in smaller pcluster size if the trailing data isn't enough for
maximum pcluster size instead of leaving trailing data uncompressed.
Fixes: b71dc92df6f1 ("erofs-utils: mkfs: support multiple block compression")
Link: https://lore.kernel.org/r/20210510072303.4628-2-xiang@kernel.org
Signed-off-by: Gao Xiang <xiang@kernel.org>
diff --git a/lib/compress.c b/lib/compress.c
index deef6a2..e146416 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -166,9 +166,12 @@
bool raw;
if (len <= pclustersize) {
- if (final)
- goto nocompression;
- break;
+ if (final) {
+ if (len <= EROFS_BLKSIZ)
+ goto nocompression;
+ } else {
+ break;
+ }
}
count = len;
@@ -195,6 +198,8 @@
EROFS_BLKSIZ - tailused : 0;
ctx->compressedblks = DIV_ROUND_UP(ret, EROFS_BLKSIZ);
+ DBG_BUGON(ctx->compressedblks * EROFS_BLKSIZ >= count);
+
/* zero out garbage trailing data for non-0padding */
if (!erofs_sb_has_lz4_0padding())
memset(dst + ret, 0,
diff --git a/lib/compressor.c b/lib/compressor.c
index b2434e0..8836e0c 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -28,6 +28,7 @@
void *dst,
unsigned int dstsize)
{
+ unsigned uncompressed_size;
int ret;
DBG_BUGON(!c->alg);
@@ -40,7 +41,9 @@
return ret;
/* check if there is enough gains to compress */
- if (*srcsize <= dstsize * c->compress_threshold / 100)
+ uncompressed_size = *srcsize;
+ if (roundup(ret, EROFS_BLKSIZ) >= uncompressed_size *
+ c->compress_threshold / 100)
return -EAGAIN;
return ret;
}