erofs-utils: lib: migrate `c_compr_opts`
PATCH 1/2 erofs-utils: lib: migrate `c_compr_opts`
It's also used to prepare for extra compression option support.
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/config.h | 7 --- include/erofs/importer.h | 1 + include/erofs/internal.h | 6 ++ lib/compress.c | 53 +++++++++-------- lib/compress_hints.c | 2 +- lib/compressor.c | 29 ++++------ lib/compressor.h | 2 +- lib/config.c | 4 -- lib/inode.c | 4 +- lib/remotes/s3.c | 2 +- lib/tar.c | 2 +- mkfs/main.c | 120 +++++++++++++++++++-------------------- 12 files changed, 113 insertions(+), 119 deletions(-)
include/erofs/config.h +0 -7
@@ -29,12 +29,6 @@ enum {#define EROFS_MAX_COMPR_CFGS 64 -struct erofs_compr_opts { -char *alg; -int level; -u32 dict_size; -}; -struct erofs_configure {const char *c_version;int c_dbg_lvl;
@@ -54,7 +48,6 @@ struct erofs_configure {char *c_src_path;char *c_blobdev_path;char *c_compress_hints_file; -struct erofs_compr_opts c_compr_opts[EROFS_MAX_COMPR_CFGS ];char c_force_chunkformat;u8 c_mkfs_metabox_algid;u32 c_max_decompressed_extent_bytes;
include/erofs/importer.h +1 -0
@@ -30,6 +30,7 @@ enum { };struct erofs_importer_params { +struct z_erofs_paramset *z_paramsets;char *source;u32 mt_async_queue_limit;u32 fixed_uid;
include/erofs/internal.h +6 -0
@@ -434,6 +434,12 @@ struct erofs_map_dev {unsigned int m_deviceid; }; +struct z_erofs_paramset { +char *alg; +int clevel; +u32 dict_size; +}; +int liberofs_global_init (void );void liberofs_global_exit (void );
lib/compress.c +30 -23
115 lines not on this page · raw message
lib/compress_hints.c +1 -1
@@ -129,7 +129,7 @@ int erofs_load_compress_hints(struct erofs_importer *im, }else { ccfg =atoi (alg);if (ccfg >=EROFS_MAX_COMPR_CFGS || - !cfg.c_compr_opts[ccfg].alg) { + !params->z_paramsets[ccfg].alg) {erofs_err ("invalid compressing configuration \"%s\" at line %u" , alg, line); ret = -EINVAL ;
lib/compressor.c +12 -17
@@ -97,8 +97,8 @@ int erofs_compress(const struct erofs_compress *c, }int erofs_compressor_init (struct erofs_sb_info *sbi,struct erofs_compress *c, -char *alg_name,int compression_level, -u32 dict_size,u32 pclustersize_max) +const struct z_erofs_paramset *zset, +u32 pclustersize_max) {int ret, i;
@@ -109,43 +109,38 @@ int erofs_compressor_init(struct erofs_sb_info *sbi, struct erofs_compress *c, c->compression_level =-1 ; c->dict_size =0 ; -if (!alg_name) { - c->alg =NULL ; -return 0 ; - } - ret = -EINVAL ;for (i =0 ; i <ARRAY_SIZE (erofs_algs); ++i) { -if (alg_name &&strcmp (alg_name, erofs_algs[i].name)) +if (strcmp (zset->alg, erofs_algs[i].name))continue ;if (!erofs_algs[i].c)continue ;if (erofs_algs[i].c->setlevel) { - ret = erofs_algs[i].c->setlevel (c, compression_level); + ret = erofs_algs[i].c->setlevel (c, zset->clevel);if (ret) {erofs_err ("failed to set compression level %d for %s" , - compression_level, alg_name); + zset->clevel, zset->alg);return ret; } - }else if (compression_level >=0 ) { + }else if (zset->clevel >=0 ) {erofs_err ("compression level %d is not supported for %s" , - compression_level, alg_name); + zset->clevel, zset->alg);return -EINVAL ; }if (erofs_algs[i].c->setdictsize) { - ret = erofs_algs[i].c->setdictsize (c, dict_size, + ret = erofs_algs[i].c->setdictsize (c, zset->dict_size, pclustersize_max);if (ret) {erofs_err ("failed to set dict size %u for %s" , - dict_size, alg_name); + zset->dict_size, zset->alg);return ret; } - }else if (dict_size) { + }else if (zset->dict_size) {erofs_err ("dict size is not supported for %s" , - alg_name); + zset->alg);return -EINVAL ; }
@@ -158,7 +153,7 @@ int erofs_compressor_init(struct erofs_sb_info *sbi, struct erofs_compress *c,return 0 ; } } -erofs_err ("Cannot find a valid compressor %s" , alg_name); +erofs_err ("Cannot find a valid compressor %s" , zset->alg);return ret; }
lib/compressor.h +1 -1
@@ -69,7 +69,7 @@ int erofs_compress(const struct erofs_compress *c, void *dst, unsigned int dstcapacity);int erofs_compressor_init (struct erofs_sb_info *sbi,struct erofs_compress *c, -char *alg_name,int compression_level,u32 dict_size, +const struct z_erofs_paramset *zset,u32 pclustersize_max);int erofs_compressor_exit (struct erofs_compress *c);void erofs_compressor_reset (struct erofs_compress *c);
lib/config.c +0 -4
@@ -46,8 +46,6 @@ void erofs_show_config(void)void erofs_exit_configure (void ) { -int i; -#ifdef HAVE_LIBSELINUX if (cfg.sehnd)selabel_close (cfg.sehnd);
@@ -56,8 +54,6 @@ void erofs_exit_configure(void)free (cfg.c_img_path);if (cfg.c_src_path)free (cfg.c_src_path); -for (i =0 ; i <EROFS_MAX_COMPR_CFGS && cfg.c_compr_opts[i].alg; i++) -free (cfg.c_compr_opts[i].alg); }struct erofs_configure *erofs_get_configure ()
lib/inode.c +2 -2
@@ -2023,7 +2023,7 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,return ret; } -if (cfg.c_compr_opts[0 ].alg && +if (inode->sbi->available_compr_algs &&erofs_file_is_compressible (im, inode)) { ctx.ictx =erofs_prepare_compressed_file (im, inode);if (IS_ERR (ctx.ictx))
@@ -2352,7 +2352,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,return ERR_PTR (ret); } -if (cfg.c_compr_opts[0 ].alg && +if (sbi->available_compr_algs &&erofs_file_is_compressible (im, inode)) { ictx =erofs_prepare_compressed_file (im, inode);if (IS_ERR (ictx))
lib/remotes/s3.c +1 -1
@@ -1028,7 +1028,7 @@ static int s3erofs_remote_getobject(struct erofs_importer *im,return -EIO ; resp.pos =0 ; -if (!cfg.c_compr_opts[0 ].alg && im->params->no_datainline) { +if (!sbi->available_compr_algs && im->params->no_datainline) { inode->datalayout =EROFS_INODE_FLAT_PLAIN ; inode->idata_size =0 ; ret = erofs_allocate_inode_bh_data(inode,
lib/tar.c +1 -1
@@ -1105,7 +1105,7 @@ new_inode: inode->i_size)) ret = -EIO ; }else if (tar->try_no_reorder && - !cfg.c_compr_opts[0 ].alg && + !sbi->available_compr_algs && params->no_datainline) { ret =tarerofs_write_uncompressed_file (inode, tar); }else {
mkfs/main.c +58 -62
180 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH 2/2 erofs-utils: mkfs: support lc,lp,pb properties for LZMA
Add support for specifying LZMA compression parameters lc (literal context bits), lp (literal position bits), and pb (position bits) via mkfs.erofs command-line options.
Note that these are all advanced parameters: Default values are used if not specified. Users are advised to keep defaults unless they understand their impact.
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/internal.h | 1 + lib/compress.c | 15 +++++-- lib/compressor.c | 70 ++++++++++++++++++++---------- lib/compressor.h | 4 +- lib/compressor_liblzma.c | 93 ++++++++++++++++++++++++++++++---------- mkfs/main.c | 20 ++++++++- 6 files changed, 150 insertions(+), 53 deletions(-)
include/erofs/internal.h +1 -0
@@ -438,6 +438,7 @@ struct z_erofs_paramset {char *alg;int clevel;u32 dict_size; +char *extraopts; };int liberofs_global_init (void );
lib/compress.c +11 -4
@@ -1457,10 +1457,11 @@ void *z_erofs_mt_wq_tls_free(struct erofs_workqueue *wq, void *priv)struct erofs_compress_wq_tls *tls = priv;int i; -for (i =0 ; i <EROFS_MAX_COMPR_CFGS ; i++) -if (tls->ccfg[i].enable) -erofs_compressor_exit (&tls->ccfg[i].handle); - +for (i =0 ; i <EROFS_MAX_COMPR_CFGS ; i++) { +if (!tls->ccfg[i].enable) +continue ; +erofs_compressor_exit (&tls->ccfg[i].handle); + }free (tls->ccfg);free (tls->destbuf);free (tls->queue);
@@ -2163,6 +2164,11 @@ int z_erofs_compress_init(struct erofs_importer *im) ccfg->zset.alg =strdup (zset->alg);if (!ccfg->zset.alg)return -ENOMEM ; +if (zset->extraopts) { + ccfg->zset.extraopts =strdup (zset->extraopts); +if (!ccfg->zset.extraopts) +return -ENOMEM ; + } ret =erofs_compressor_init (sbi, c, &ccfg->zset, pclustersize_max);
@@ -2264,6 +2270,7 @@ int z_erofs_compress_exit(struct erofs_sb_info *sbi)if (ret)return ret;free (sbi->zmgr->ccfg[i].zset.alg); +free (sbi->zmgr->ccfg[i].zset.extraopts); }free (sbi->zmgr);return 0 ;
lib/compressor.c +47 -23
102 lines not on this page · raw message
lib/compressor.h +3 -1
@@ -17,12 +17,14 @@ struct erofs_compressor {u32 default_dictsize;u32 max_dictsize; -int (*init)(struct erofs_compress *c); +int (*preinit)(struct erofs_compress *c);int (*exit)(struct erofs_compress *c);void (*reset)(struct erofs_compress *c);int (*setlevel)(struct erofs_compress *c,int compression_level);int (*setdictsize)(struct erofs_compress *c,u32 dict_size,u32 pclustersize_max); +int (*setextraopts)(struct erofs_compress *c,const char *extraopts); +int (*init)(struct erofs_compress *c); int (*compress_destsize)(const struct erofs_compress *c, const void *src, unsigned int *srcsize,
lib/compressor_liblzma.c +70 -23
137 lines not on this page · raw message
mkfs/main.c +18 -2
@@ -166,6 +166,12 @@ static void usage(int argc, char **argv)printf ("%s [,dictsize=<dictsize>]\t(default=<auto>, max=%u)\n" , spaces, s->c->max_dictsize); } +if (!strcmp (s->name,"lzma" )) { +printf ("\n%s LZMA advanced options (do not specify if unsure):\n" , spaces); +printf ("%s [,lc=<n>] n = number of literal context bits\n" , spaces); +printf ("%s [,lp=<n>] n = number of literal position bits\n" , spaces); +printf ("%s [,pb=<n>] n = number of position bits\n" , spaces); + } }printf ( " -C# specify the size of compress physical cluster in bytes\n"
@@ -845,7 +851,9 @@ unsigned int erofs_mkfs_total_ccfgs;static int mkfs_parse_one_compress_alg (char *alg) {struct z_erofs_paramset *zset = mkfscfg.zcfgs + mkfscfg.total_zcfgs; +char extraopts[48 ];char *p, *q, *opt, *endptr; +int i, j;if (zset >= erofs_mkfs_zparams +ARRAY_SIZE (erofs_mkfs_zparams)) {erofs_err ("too many algorithm types" );
@@ -854,6 +862,7 @@ static int mkfs_parse_one_compress_alg(char *alg) zset->clevel =-1 ; zset->dict_size =0 ; + i =0 ; p =strchr (alg,',' );if (!p) { zset->alg = alg;
@@ -891,13 +900,20 @@ static int mkfs_parse_one_compress_alg(char *alg)return -EINVAL ; } }else { -erofs_err ("invalid compression option %s" , opt); -return -EINVAL ; +if (i) + j =snprintf (extraopts + i,sizeof (extraopts) - i,",%s" , opt); +else + j =snprintf (extraopts,sizeof (extraopts),"%s" , opt); +if (j <0 ) +return -ERANGE ; + i += j; } opt = q ? q +1 :NULL ; } } } +if (i) + zset->extraopts =strdup (extraopts);return mkfscfg.total_zcfgs++; }
Signature · 1 line
2.43.5