linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH 8/8] erofs-utils: mkfs: support compact indexes for bigpcluster
Date: Sun, 11 Apr 2021 11:48:44 +0800	[thread overview]
Message-ID: <20210411034844.12673-9-xiang@kernel.org> (raw)
In-Reply-To: <20210411034844.12673-1-xiang@kernel.org>

This adds support to generate big pcluster compact indexes.

Different from non big pcluster, blkaddr recorded in each pack is
the 1st pcluster blkaddr with a valid CBLKCNT since we don't know
compressed block count of each pcluster when reading HEAD lcluster.

For more details, also see related kernel commits.

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

diff --git a/lib/compress.c b/lib/compress.c
index c8b627db5bec..654286d3f33e 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -267,9 +267,10 @@ static void *write_compacted_indexes(u8 *out,
 				     erofs_blk_t *blkaddr_ret,
 				     unsigned int destsize,
 				     unsigned int logical_clusterbits,
-				     bool final)
+				     bool final, bool *dummy_head)
 {
-	unsigned int vcnt, encodebits, pos, i;
+	unsigned int vcnt, encodebits, pos, i, cblks;
+	bool update_blkaddr;
 	erofs_blk_t blkaddr;
 
 	if (destsize == 4) {
@@ -281,6 +282,7 @@ static void *write_compacted_indexes(u8 *out,
 	}
 	encodebits = (vcnt * destsize * 8 - 32) / vcnt;
 	blkaddr = *blkaddr_ret;
+	update_blkaddr = erofs_sb_has_big_pcluster();
 
 	pos = 0;
 	for (i = 0; i < vcnt; ++i) {
@@ -288,13 +290,26 @@ static void *write_compacted_indexes(u8 *out,
 		u8 ch, rem;
 
 		if (cv[i].clustertype == Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD) {
-			if (i + 1 == vcnt)
+			if (cv[i].u.delta[0] & Z_EROFS_VLE_DI_D0_CBLKCNT) {
+				cblks = cv[i].u.delta[0] & ~Z_EROFS_VLE_DI_D0_CBLKCNT;
+				offset = cv[i].u.delta[0];
+				blkaddr += cblks;
+				*dummy_head = false;
+			} else if (i + 1 == vcnt) {
 				offset = cv[i].u.delta[1];
-			else
+			} else {
 				offset = cv[i].u.delta[0];
+			}
 		} else {
 			offset = cv[i].clusterofs;
-			++blkaddr;
+			if (*dummy_head) {
+				++blkaddr;
+				if (update_blkaddr)
+					*blkaddr_ret = blkaddr;
+			}
+			*dummy_head = true;
+			update_blkaddr = false;
+
 			if (cv[i].u.blkaddr != blkaddr) {
 				if (i + 1 != vcnt)
 					DBG_BUGON(!final);
@@ -330,6 +345,7 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 	/* # of 8-byte units so that it can be aligned with 32 bytes */
 	unsigned int compacted_4b_initial, compacted_4b_end;
 	unsigned int compacted_2b;
+	bool dummy_head;
 
 	if (logical_clusterbits < LOG_BLOCK_SIZE || LOG_BLOCK_SIZE < 12)
 		return -EINVAL;
@@ -359,11 +375,19 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 	out += sizeof(mapheader);
 	in += Z_EROFS_LEGACY_MAP_HEADER_SIZE;
 
+	dummy_head = false;
+	/* prior to bigpcluster, blkaddr was bumped up once coming into HEAD */
+	if (!erofs_sb_has_big_pcluster()) {
+		--blkaddr;
+		dummy_head = true;
+	}
+
 	/* generate compacted_4b_initial */
 	while (compacted_4b_initial) {
 		in = parse_legacy_indexes(cv, 2, in);
 		out = write_compacted_indexes(out, cv, &blkaddr,
-					      4, logical_clusterbits, false);
+					      4, logical_clusterbits, false,
+					      &dummy_head);
 		compacted_4b_initial -= 2;
 	}
 	DBG_BUGON(compacted_4b_initial);
@@ -372,7 +396,8 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 	while (compacted_2b) {
 		in = parse_legacy_indexes(cv, 16, in);
 		out = write_compacted_indexes(out, cv, &blkaddr,
-					      2, logical_clusterbits, false);
+					      2, logical_clusterbits, false,
+					      &dummy_head);
 		compacted_2b -= 16;
 	}
 	DBG_BUGON(compacted_2b);
@@ -381,7 +406,8 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 	while (compacted_4b_end > 1) {
 		in = parse_legacy_indexes(cv, 2, in);
 		out = write_compacted_indexes(out, cv, &blkaddr,
-					      4, logical_clusterbits, false);
+					      4, logical_clusterbits, false,
+					      &dummy_head);
 		compacted_4b_end -= 2;
 	}
 
@@ -390,7 +416,8 @@ int z_erofs_convert_to_compacted_format(struct erofs_inode *inode,
 		memset(cv, 0, sizeof(cv));
 		in = parse_legacy_indexes(cv, 1, in);
 		out = write_compacted_indexes(out, cv, &blkaddr,
-					      4, logical_clusterbits, true);
+					      4, logical_clusterbits, true,
+					      &dummy_head);
 	}
 	inode->extent_isize = out - (u8 *)inode->compressmeta;
 	inode->datalayout = EROFS_INODE_FLAT_COMPRESSION;
@@ -485,12 +512,11 @@ int erofs_write_compressed_file(struct erofs_inode *inode)
 	inode->u.i_blocks = compressed_blocks;
 
 	legacymetasize = ctx.metacur - compressmeta;
-	/* XXX: temporarily use legacy index instead for mbpcluster */
-	if (cfg.c_legacy_compress || cfg.c_physical_clusterblks > 1) {
+	if (cfg.c_legacy_compress) {
 		inode->extent_isize = legacymetasize;
 		inode->datalayout = EROFS_INODE_FLAT_COMPRESSION_LEGACY;
 	} else {
-		ret = z_erofs_convert_to_compacted_format(inode, blkaddr - 1,
+		ret = z_erofs_convert_to_compacted_format(inode, blkaddr,
 							  legacymetasize, 12);
 		DBG_BUGON(ret);
 	}
@@ -591,6 +617,8 @@ int z_erofs_compress_init(struct erofs_buffer_head *sb_bh)
 		}
 		erofs_sb_set_big_pcluster();
 		mapheader.h_advise |= Z_EROFS_ADVISE_BIG_PCLUSTER_1;
+		if (!cfg.c_legacy_compress)
+			mapheader.h_advise |= Z_EROFS_ADVISE_BIG_PCLUSTER_2;
 	}
 	mapheader.h_algorithmtype = algorithmtype[1] << 4 |
 					  algorithmtype[0];
-- 
2.20.1


  parent reply	other threads:[~2021-04-11  3:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-11  3:48 [PATCH 0/8] erofs-utils: support big pcluster compression Gao Xiang
2021-04-11  3:48 ` [PATCH 1/8] erofs-utils: support adjust lz4 history window size Gao Xiang
2021-04-11  3:48 ` [PATCH 2/8] erofs-utils: introduce ondisk compression cfgs Gao Xiang
2021-04-11  3:48 ` [PATCH 3/8] erofs-utils: add -C# for the maximum size of pclusters Gao Xiang
2021-04-11  3:48 ` [PATCH 4/8] erofs-utils: add big physical cluster definition Gao Xiang
2021-04-11  3:48 ` [PATCH 5/8] erofs-utils: fuse: support multiple block compression Gao Xiang
2021-04-11  3:48 ` [PATCH 6/8] erofs-utils: mkfs: " Gao Xiang
2021-04-11  3:48 ` [PATCH 7/8] erofs-utils: fuse: support compact indexes for bigpcluster Gao Xiang
2021-04-11  3:48 ` Gao Xiang [this message]
2021-04-15  3:27 ` [PATCH v1.1 1/8] erofs-utils: support adjust lz4 history window size Gao Xiang

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=20210411034844.12673-9-xiang@kernel.org \
    --to=xiang@kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --subject='Re: [PATCH 8/8] erofs-utils: mkfs: support compact indexes for bigpcluster' \
    /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

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).