linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs: fix 1 lcluster-sized pcluster for big pcluster
@ 2021-05-10  6:47 Gao Xiang
  2021-05-13  6:54 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Gao Xiang @ 2021-05-10  6:47 UTC (permalink / raw)
  To: linux-erofs, Chao Yu; +Cc: LKML, Gao Xiang

If the 1st NONHEAD lcluster of a pcluster isn't CBLKCNT lcluster type
rather than a HEAD or PLAIN type instead, which means its pclustersize
_must_ be 1 lcluster (since its uncompressed size < 2 lclusters),
as illustrated below:

       HEAD     HEAD / PLAIN    lcluster type
   ____________ ____________
  |_:__________|_________:__|   file data (uncompressed)
   .                .
  .____________.
  |____________|                pcluster data (compressed)

Such on-disk case was explained before [1] but missed to be handled
properly in the runtime implementation.

It can be observed if manually generating 1 lcluster-sized pcluster
with 2 lclusters (thus CBLKCNT doesn't exist.) Let's fix it now.

[1] https://lore.kernel.org/r/20210407043927.10623-1-xiang@kernel.org
Fixes: cec6e93beadf ("erofs: support parsing big pcluster compress indexes")
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
 fs/erofs/zmap.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index e62d813756f2..efaf32596b97 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -450,14 +450,31 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
 	lcn = m->lcn + 1;
 	if (m->compressedlcs)
 		goto out;
-	if (lcn == initial_lcn)
-		goto err_bonus_cblkcnt;
 
 	err = z_erofs_load_cluster_from_disk(m, lcn);
 	if (err)
 		return err;
 
+	/*
+	 * If the 1st NONHEAD lcluster has already been handled initially w/o
+	 * valid compressedlcs, which means at least it mustn't be CBLKCNT, or
+	 * an internal implemenatation error is detected.
+	 *
+	 * The following code can also handle it properly anyway, but let's
+	 * BUG_ON in the debugging mode only for developers to notice that.
+	 */
+	DBG_BUGON(lcn == initial_lcn &&
+		  m->type == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD);
+
 	switch (m->type) {
+	case Z_EROFS_VLE_CLUSTER_TYPE_PLAIN:
+	case Z_EROFS_VLE_CLUSTER_TYPE_HEAD:
+		/*
+		 * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type
+		 * rather than CBLKCNT, it's a 1 lcluster-sized pcluster.
+		 */
+		m->compressedlcs = 1;
+		break;
 	case Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD:
 		if (m->delta[0] != 1)
 			goto err_bonus_cblkcnt;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] erofs: fix 1 lcluster-sized pcluster for big pcluster
  2021-05-10  6:47 [PATCH] erofs: fix 1 lcluster-sized pcluster for big pcluster Gao Xiang
@ 2021-05-13  6:54 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2021-05-13  6:54 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs; +Cc: LKML

On 2021/5/10 14:47, Gao Xiang wrote:
> If the 1st NONHEAD lcluster of a pcluster isn't CBLKCNT lcluster type
> rather than a HEAD or PLAIN type instead, which means its pclustersize
> _must_ be 1 lcluster (since its uncompressed size < 2 lclusters),
> as illustrated below:
> 
>         HEAD     HEAD / PLAIN    lcluster type
>     ____________ ____________
>    |_:__________|_________:__|   file data (uncompressed)
>     .                .
>    .____________.
>    |____________|                pcluster data (compressed)
> 
> Such on-disk case was explained before [1] but missed to be handled
> properly in the runtime implementation.
> 
> It can be observed if manually generating 1 lcluster-sized pcluster
> with 2 lclusters (thus CBLKCNT doesn't exist.) Let's fix it now.
> 
> [1] https://lore.kernel.org/r/20210407043927.10623-1-xiang@kernel.org
> Fixes: cec6e93beadf ("erofs: support parsing big pcluster compress indexes")
> Signed-off-by: Gao Xiang <xiang@kernel.org>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-13  6:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10  6:47 [PATCH] erofs: fix 1 lcluster-sized pcluster for big pcluster Gao Xiang
2021-05-13  6:54 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).