All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org, Li Guifu <bluce.liguifu@huawei.com>
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH 4/4] erofs-utils: sync up z_erofs_get_extent_compressedlen()
Date: Mon, 10 May 2021 15:23:03 +0800	[thread overview]
Message-ID: <20210510072303.4628-5-xiang@kernel.org> (raw)
In-Reply-To: <20210510072303.4628-1-xiang@kernel.org>

Sync up with in-kernel z_erofs_get_extent_compressedlen(), mainly
fix 1 lcluster-sized pcluster for big pcluster.

Signed-off-by: Gao Xiang <xiang@kernel.org>
---
 lib/zmap.c | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/lib/zmap.c b/lib/zmap.c
index 0c5c4f52bbd0..1084faa6e489 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -386,16 +386,13 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
 
 	DBG_BUGON(m->type != Z_EROFS_VLE_CLUSTER_TYPE_PLAIN &&
 		  m->type != Z_EROFS_VLE_CLUSTER_TYPE_HEAD);
-	if (!((map->m_flags & EROFS_MAP_ZIPPED) &&
-	      (vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1))) {
+	if (!(map->m_flags & EROFS_MAP_ZIPPED) ||
+	    !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) {
 		map->m_plen = 1 << lclusterbits;
 		return 0;
 	}
 
 	lcn = m->lcn + 1;
-	if (lcn == initial_lcn && !m->compressedlcs)
-		m->compressedlcs = 2;
-
 	if (m->compressedlcs)
 		goto out;
 
@@ -403,21 +400,46 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
 	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:
-		DBG_BUGON(m->delta[0] != 1);
-		if (m->compressedlcs) {
+		if (m->delta[0] != 1)
+			goto err_bonus_cblkcnt;
+		if (m->compressedlcs)
 			break;
-		}
+		/* fallthrough */
 	default:
 		erofs_err("cannot found CBLKCNT @ lcn %lu of nid %llu",
-			  lcn, (unsigned long long)vi->nid);
+			  lcn, vi->nid | 0ULL);
 		DBG_BUGON(1);
 		return -EFSCORRUPTED;
 	}
 out:
 	map->m_plen = m->compressedlcs << lclusterbits;
 	return 0;
+err_bonus_cblkcnt:
+	erofs_err("bogus CBLKCNT @ lcn %lu of nid %llu",
+		  lcn, vi->nid | 0ULL);
+	DBG_BUGON(1);
+	return -EFSCORRUPTED;
 }
 
 int z_erofs_map_blocks_iter(struct erofs_inode *vi,
-- 
2.20.1


      parent reply	other threads:[~2021-05-10  7:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10  7:22 [PATCH 0/4] erofs-utils: prepare for per-(sub)file compression strategies Gao Xiang
2021-05-10  7:23 ` [PATCH 1/4] erofs-utils: compress trailing data for big pcluster properly Gao Xiang
2021-05-10  7:23 ` [PATCH 2/4] erofs-utils: reserve physical_clusterbits[] Gao Xiang
2021-05-10  7:23 ` [PATCH 3/4] erofs-utils: prepare for per-(sub)file compress strategies Gao Xiang
2021-05-10  7:23 ` Gao Xiang [this message]

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=20210510072303.4628-5-xiang@kernel.org \
    --to=xiang@kernel.org \
    --cc=bluce.liguifu@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.