[PATCH 1/2] erofs-utils: record pclustersize in bytes instead of blocks
Gao Xiang
hsiangkao at linux.alibaba.com
Tue Apr 30 16:37:29 AEST 2024
So that we don't need to handle blocksizes everywhere.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs/config.h | 4 +++-
lib/compress.c | 30 ++++++++++++++++--------------
lib/compress_hints.c | 11 ++++++-----
lib/config.c | 2 --
mkfs/main.c | 16 +++++++++-------
5 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 16910ea..3ce8c59 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -79,7 +79,9 @@ struct erofs_configure {
u64 c_mkfs_segment_size;
u32 c_mt_workers;
#endif
- u32 c_pclusterblks_max, c_pclusterblks_def, c_pclusterblks_packed;
+ u32 c_mkfs_pclustersize_max;
+ u32 c_mkfs_pclustersize_def;
+ u32 c_mkfs_pclustersize_packed;
u32 c_max_decompressed_extent_bytes;
u64 c_unix_timestamp;
u32 c_uid, c_gid;
diff --git a/lib/compress.c b/lib/compress.c
index f918322..20d1568 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -416,22 +416,23 @@ static int write_uncompressed_extent(struct z_erofs_compress_sctx *ctx,
static unsigned int z_erofs_get_max_pclustersize(struct erofs_inode *inode)
{
- unsigned int pclusterblks;
+ unsigned int pclustersize;
if (erofs_is_packed_inode(inode))
- pclusterblks = cfg.c_pclusterblks_packed;
+ pclustersize = cfg.c_mkfs_pclustersize_packed;
#ifndef NDEBUG
else if (cfg.c_random_pclusterblks)
- pclusterblks = 1 + rand() % cfg.c_pclusterblks_max;
+ pclustersize = ((1 + rand()) << inode->sbi->blkszbits) %
+ cfg.c_mkfs_pclustersize_max;
#endif
else if (cfg.c_compress_hints_file) {
z_erofs_apply_compress_hints(inode);
DBG_BUGON(!inode->z_physical_clusterblks);
- pclusterblks = inode->z_physical_clusterblks;
+ pclustersize = inode->z_physical_clusterblks << inode->sbi->blkszbits;
} else {
- pclusterblks = cfg.c_pclusterblks_def;
+ pclustersize = cfg.c_mkfs_pclustersize_def;
}
- return pclusterblks * erofs_blksiz(inode->sbi);
+ return pclustersize;
}
static int z_erofs_fill_inline_data(struct erofs_inode *inode, void *data,
@@ -1591,7 +1592,8 @@ static int z_erofs_build_compr_cfgs(struct erofs_sb_info *sbi,
.lz4 = {
.max_distance =
cpu_to_le16(sbi->lz4_max_distance),
- .max_pclusterblks = cfg.c_pclusterblks_max,
+ .max_pclusterblks =
+ cfg.c_mkfs_pclustersize_max >> sbi->blkszbits,
}
};
@@ -1696,17 +1698,17 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *s
* if big pcluster is enabled, an extra CBLKCNT lcluster index needs
* to be loaded in order to get those compressed block counts.
*/
- if (cfg.c_pclusterblks_max > 1) {
- if (cfg.c_pclusterblks_max >
- Z_EROFS_PCLUSTER_MAX_SIZE / erofs_blksiz(sbi)) {
- erofs_err("unsupported clusterblks %u (too large)",
- cfg.c_pclusterblks_max);
+ if (cfg.c_mkfs_pclustersize_max > erofs_blksiz(sbi)) {
+ if (cfg.c_mkfs_pclustersize_max > Z_EROFS_PCLUSTER_MAX_SIZE) {
+ erofs_err("unsupported pclustersize %u (too large)",
+ cfg.c_mkfs_pclustersize_max);
return -EINVAL;
}
erofs_sb_set_big_pcluster(sbi);
}
- if (cfg.c_pclusterblks_packed > cfg.c_pclusterblks_max) {
- erofs_err("invalid physical cluster size for the packed file");
+ if (cfg.c_mkfs_pclustersize_packed > cfg.c_mkfs_pclustersize_max) {
+ erofs_err("invalid pclustersize for the packed file %u",
+ cfg.c_mkfs_pclustersize_packed);
return -EINVAL;
}
diff --git a/lib/compress_hints.c b/lib/compress_hints.c
index 8b78f80..e79bd48 100644
--- a/lib/compress_hints.c
+++ b/lib/compress_hints.c
@@ -55,7 +55,7 @@ bool z_erofs_apply_compress_hints(struct erofs_inode *inode)
return true;
s = erofs_fspath(inode->i_srcpath);
- pclusterblks = cfg.c_pclusterblks_def;
+ pclusterblks = cfg.c_mkfs_pclustersize_def >> inode->sbi->blkszbits;
algorithmtype = 0;
list_for_each_entry(r, &compress_hints_head, list) {
@@ -136,7 +136,7 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi)
if (pclustersize % erofs_blksiz(sbi)) {
erofs_warn("invalid physical clustersize %u, "
"use default pclusterblks %u",
- pclustersize, cfg.c_pclusterblks_def);
+ pclustersize, cfg.c_mkfs_pclustersize_def);
continue;
}
erofs_insert_compress_hints(pattern,
@@ -146,9 +146,10 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi)
max_pclustersize = pclustersize;
}
- if (cfg.c_pclusterblks_max * erofs_blksiz(sbi) < max_pclustersize) {
- cfg.c_pclusterblks_max = max_pclustersize / erofs_blksiz(sbi);
- erofs_warn("update max pclusterblks to %u", cfg.c_pclusterblks_max);
+ if (cfg.c_mkfs_pclustersize_max < max_pclustersize) {
+ cfg.c_mkfs_pclustersize_max = max_pclustersize;
+ erofs_warn("update max pclustersize to %u",
+ cfg.c_mkfs_pclustersize_max);
}
out:
fclose(f);
diff --git a/lib/config.c b/lib/config.c
index 98adaef..26f1c35 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -35,8 +35,6 @@ void erofs_init_configure(void)
cfg.c_unix_timestamp = -1;
cfg.c_uid = -1;
cfg.c_gid = -1;
- cfg.c_pclusterblks_max = 1;
- cfg.c_pclusterblks_def = 1;
cfg.c_max_decompressed_extent_bytes = -1;
erofs_stdout_tty = isatty(STDOUT_FILENO);
}
diff --git a/mkfs/main.c b/mkfs/main.c
index 9ad213b..3d19f60 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -820,8 +820,8 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
pclustersize_max);
return -EINVAL;
}
- cfg.c_pclusterblks_max = pclustersize_max >> sbi.blkszbits;
- cfg.c_pclusterblks_def = cfg.c_pclusterblks_max;
+ cfg.c_mkfs_pclustersize_max = pclustersize_max;
+ cfg.c_mkfs_pclustersize_def = cfg.c_mkfs_pclustersize_max;
}
if (cfg.c_chunkbits && cfg.c_chunkbits < sbi.blkszbits) {
erofs_err("chunksize %u must be larger than block size",
@@ -830,13 +830,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
}
if (pclustersize_packed) {
- if (pclustersize_max < erofs_blksiz(&sbi) ||
- pclustersize_max % erofs_blksiz(&sbi)) {
+ if (pclustersize_packed < erofs_blksiz(&sbi) ||
+ pclustersize_packed % erofs_blksiz(&sbi)) {
erofs_err("invalid pcluster size for the packed file %u",
pclustersize_packed);
return -EINVAL;
}
- cfg.c_pclusterblks_packed = pclustersize_packed >> sbi.blkszbits;
+ cfg.c_mkfs_pclustersize_packed = pclustersize_packed;
}
return 0;
}
@@ -948,6 +948,8 @@ static void erofs_mkfs_default_options(void)
cfg.c_legacy_compress = false;
cfg.c_inline_data = true;
cfg.c_xattr_name_filter = true;
+ cfg.c_mkfs_pclustersize_max = erofs_blksiz(&sbi);
+ cfg.c_mkfs_pclustersize_def = cfg.c_mkfs_pclustersize_max;
#ifdef EROFS_MT_ENABLED
cfg.c_mt_workers = erofs_get_available_processors();
cfg.c_mkfs_segment_size = 16ULL * 1024 * 1024;
@@ -1153,8 +1155,8 @@ int main(int argc, char **argv)
#endif
erofs_show_config();
if (cfg.c_fragments || cfg.c_extra_ea_name_prefixes) {
- if (!cfg.c_pclusterblks_packed)
- cfg.c_pclusterblks_packed = cfg.c_pclusterblks_def;
+ if (!cfg.c_mkfs_pclustersize_packed)
+ cfg.c_mkfs_pclustersize_packed = cfg.c_mkfs_pclustersize_def;
packedfile = erofs_packedfile_init();
if (IS_ERR(packedfile)) {
--
2.39.3
More information about the Linux-erofs
mailing list