[PATCH 1/2] erofs-utils: mkfs: enable block map chunk format

Gao Xiang xiang at kernel.org
Wed Nov 17 12:57:56 AEDT 2021


From: Gao Xiang <hsiangkao at linux.alibaba.com>

Use 4-byte block map format by default unless a blob device is
given or chunk index format is forcely specified.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 include/erofs/config.h |  8 +++++++-
 lib/blobchunk.c        | 12 +++++++-----
 lib/inode.c            |  5 ++++-
 man/mkfs.erofs.1       |  6 ++++++
 mkfs/main.c            | 20 ++++++++++++++++++++
 5 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/include/erofs/config.h b/include/erofs/config.h
index 8d459c692dac..2040dc6ff154 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -27,6 +27,11 @@ enum {
 	FORCE_INODE_EXTENDED,
 };
 
+enum {
+	FORCE_INODE_BLOCK_MAP = 1,
+	FORCE_INODE_CHUNK_INDEXES,
+};
+
 enum {
 	TIMESTAMP_NONE,
 	TIMESTAMP_FIXED,
@@ -55,7 +60,8 @@ struct erofs_configure {
 	char *c_compress_hints_file;
 	char *c_compr_alg_master;
 	int c_compr_level_master;
-	int c_force_inodeversion;
+	char c_force_inodeversion;
+	char c_force_chunkformat;
 	/* < 0, xattr disabled and INT_MAX, always use inline xattrs */
 	int c_inline_xattr_tolerance;
 
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index a10ca8cc8750..5cbb8315b277 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -110,16 +110,18 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 	bool first_extent = true;
 	erofs_blk_t base_blkaddr = 0;
 
+	if (multidev) {
+		idx.device_id = 1;
+		inode->u.chunkformat |= EROFS_CHUNK_FORMAT_INDEXES;
+	} else {
+		base_blkaddr = remapped_base;
+	}
+
 	if (inode->u.chunkformat & EROFS_CHUNK_FORMAT_INDEXES)
 		unit = sizeof(struct erofs_inode_chunk_index);
 	else
 		unit = EROFS_BLOCK_MAP_ENTRY_SIZE;
 
-	if (multidev)
-		idx.device_id = 1;
-	else
-		base_blkaddr = remapped_base;
-
 	for (dst = src = 0; dst < inode->extent_isize;
 	     src += sizeof(void *), dst += unit) {
 		struct erofs_blobchunk *chunk;
diff --git a/lib/inode.c b/lib/inode.c
index 855a0383f31e..5cbfc780e45f 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -390,7 +390,10 @@ int erofs_write_file(struct erofs_inode *inode)
 
 	if (cfg.c_chunkbits) {
 		inode->u.chunkbits = cfg.c_chunkbits;
-		inode->u.chunkformat = EROFS_CHUNK_FORMAT_INDEXES;
+		/* chunk indexes when explicitly specified */
+		inode->u.chunkformat = 0;
+		if (cfg.c_force_chunkformat == FORCE_INODE_CHUNK_INDEXES)
+			inode->u.chunkformat = EROFS_CHUNK_FORMAT_INDEXES;
 		return erofs_blob_write_chunked_file(inode);
 	}
 
diff --git a/man/mkfs.erofs.1 b/man/mkfs.erofs.1
index 71a26d88121a..f2e7d690c215 100644
--- a/man/mkfs.erofs.1
+++ b/man/mkfs.erofs.1
@@ -51,6 +51,12 @@ Forcely generate compact inodes (32-byte inodes) to output.
 .TP
 .BI force-inode-extended
 Forcely generate extended inodes (64-byte inodes) to output.
+.TP
+.BI force-inode-blockmap
+Forcely generate inode chunk format in 4-byte block address array.
+.TP
+.BI force-chunk-indexes
+Forcely generate inode chunk format in 8-byte chunk indexes (with device id).
 .RE
 .TP
 .BI "\-T " #
diff --git a/mkfs/main.c b/mkfs/main.c
index 29042c801794..58a64411b868 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -174,6 +174,18 @@ static int parse_extended_opts(const char *opts)
 				return -EINVAL;
 			cfg.c_noinline_data = true;
 		}
+
+		if (MATCH_EXTENTED_OPT("force-inode-blockmap", token, keylen)) {
+			if (vallen)
+				return -EINVAL;
+			cfg.c_force_chunkformat = FORCE_INODE_BLOCK_MAP;
+		}
+
+		if (MATCH_EXTENTED_OPT("force-chunk-indexes", token, keylen)) {
+			if (vallen)
+				return -EINVAL;
+			cfg.c_force_chunkformat = FORCE_INODE_CHUNK_INDEXES;
+		}
 	}
 	return 0;
 }
@@ -369,6 +381,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		erofs_err("--blobdev must be used together with --chunksize");
 		return -EINVAL;
 	}
+
+	/* TODO: can be implemented with (deviceslot) mapped_blkaddr */
+	if (cfg.c_blobdev_path &&
+	    cfg.c_force_chunkformat == FORCE_INODE_BLOCK_MAP) {
+		erofs_err("--blobdev cannot work with block map currently");
+		return -EINVAL;
+	}
+
 	cfg.c_img_path = strdup(argv[optind++]);
 	if (!cfg.c_img_path)
 		return -ENOMEM;
-- 
2.20.1



More information about the Linux-erofs mailing list