erofs-utils: rename `cfg` to `g_cfg`
Subsystems (2)
PATCH 1/2 erofs-utils: rename `cfg` to `g_cfg`
Rename the global variable cfg to g_cfg in preparation for the per-superblock configuration.
--- dump/main.c | 8 +- fsck/main.c | 12 +-- fuse/main.c | 10 +- include/erofs/config.h | 2 +- include/erofs/print.h | 8 +- lib/blobchunk.c | 2 +- lib/block_list.c | 8 +- lib/compress.c | 82 +++++++------- lib/compress_hints.c | 16 +-- lib/compressor_liblzma.c | 2 +- lib/compressor_libzstd.c | 2 +- lib/config.c | 54 +++++----- lib/inode.c | 62 +++++------ lib/io.c | 12 +-- lib/xattr.c | 20 ++-- mkfs/main.c | 228 +++++++++++++++++++-------------------- 16 files changed, 264 insertions(+), 264 deletions(-)
dump/main.c +4 -4
@@ -131,7 +131,7 @@ static void usage(int argc, char **argv)static void erofsdump_print_version (void ) { -printf ("dump.erofs (erofs-utils) %s\n" , cfg.c_version); +printf ("dump.erofs (erofs-utils) %s\n" , g_cfg.c_version); }static int erofsdump_parse_options_cfg (int argc,char **argv)
@@ -196,8 +196,8 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)return -EINVAL ; } - cfg.c_img_path =strdup (argv[optind++]); -if (!cfg.c_img_path) + g_cfg.c_img_path =strdup (argv[optind++]); +if (!g_cfg.c_img_path)return -ENOMEM ;if (optind < argc) {
@@ -684,7 +684,7 @@ int main(int argc, char **argv) goto exit; } - err =erofs_dev_open (&g_sbi, cfg.c_img_path,O_RDONLY |O_TRUNC ); + err =erofs_dev_open (&g_sbi, g_cfg.c_img_path,O_RDONLY |O_TRUNC );if (err) {erofs_err ("failed to open image file" ); goto exit;
fsck/main.c +6 -6
@@ -124,7 +124,7 @@ static void usage(int argc, char **argv)static void erofsfsck_print_version (void ) {printf ("fsck.erofs (erofs-utils) %s\navailable decompressors: " , - cfg.c_version); + g_cfg.c_version);print_available_decompressors (stdout,", " ); }
@@ -146,7 +146,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)erofs_err ("invalid debug level %d" , ret);return -EINVAL ; } - cfg.c_dbg_lvl = ret; + g_cfg.c_dbg_lvl = ret;break ;case 'p' : fsckcfg.print_comp_ratio = true;
@@ -267,8 +267,8 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)return -EINVAL ; } - cfg.c_img_path =strdup (argv[optind++]); -if (!cfg.c_img_path) + g_cfg.c_img_path =strdup (argv[optind++]); +if (!g_cfg.c_img_path)return -ENOMEM ;if (optind < argc) {
@@ -1074,10 +1074,10 @@ int main(int argc, char *argv[]) }#ifdef FUZZING - cfg.c_dbg_lvl =-1 ; + g_cfg.c_dbg_lvl =-1 ;#endif - err =erofs_dev_open (&g_sbi, cfg.c_img_path,O_RDONLY ); + err =erofs_dev_open (&g_sbi, g_cfg.c_img_path,O_RDONLY );if (err) {erofs_err ("failed to open image file" ); goto exit;
fuse/main.c +5 -5
@@ -643,8 +643,8 @@ int main(int argc, char *argv[])#endif erofs_init_configure (); - fusecfg.debug_lvl = cfg.c_dbg_lvl; -printf ("erofsfuse %s\n" , cfg.c_version); + fusecfg.debug_lvl = g_cfg.c_dbg_lvl; +printf ("erofsfuse %s\n" , g_cfg.c_version);#if defined(HAVE_EXECINFO_H ) && defined(HAVE_BACKTRACE )if (signal (SIGSEGV , signal_handle_sigsegv) ==SIG_ERR ) {
@@ -670,10 +670,10 @@ int main(int argc, char *argv[])if (fusecfg.show_help || fusecfg.show_version || !opts.mountpoint)usage (); - cfg.c_dbg_lvl = fusecfg.debug_lvl; + g_cfg.c_dbg_lvl = fusecfg.debug_lvl; -if (fusecfg.odebug && cfg.c_dbg_lvl <EROFS_DBG ) - cfg.c_dbg_lvl =EROFS_DBG ; +if (fusecfg.odebug && g_cfg.c_dbg_lvl <EROFS_DBG ) + g_cfg.c_dbg_lvl =EROFS_DBG ; g_sbi.bdev.offset = fusecfg.offset; ret =erofs_dev_open (&g_sbi, fusecfg.disk,O_RDONLY );
include/erofs/config.h +1 -1
@@ -96,7 +96,7 @@ struct erofs_configure {#endif }; -extern struct erofs_configure cfg; +extern struct erofs_configure g_cfg;void erofs_init_configure (void );void erofs_show_config (void );
include/erofs/print.h +4 -4
@@ -44,7 +44,7 @@ enum {void erofs_msg (int dbglv,const char *fmt, ...);#define erofs_dbg (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= EROFS_DBG) { \ + if (g_cfg.c_dbg_lvl >= EROFS_DBG) { \ erofs_msg(EROFS_DBG, \ "<D> " PR_FMT_FUNC_LINE(fmt), \ ##__VA_ARGS__); \
@@ -52,7 +52,7 @@ void erofs_msg(int dbglv, const char *fmt, ...); } while (0)#define erofs_info (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= EROFS_INFO) { \ + if (g_cfg.c_dbg_lvl >= EROFS_INFO) { \ erofs_msg(EROFS_INFO, \ "<I> " PR_FMT_FUNC_LINE(fmt), \ ##__VA_ARGS__); \
@@ -61,7 +61,7 @@ void erofs_msg(int dbglv, const char *fmt, ...); } while (0)#define erofs_warn (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= EROFS_WARN) { \ + if (g_cfg.c_dbg_lvl >= EROFS_WARN) { \ erofs_msg(EROFS_WARN, \ "<W> " PR_FMT_FUNC_LINE(fmt), \ ##__VA_ARGS__); \
@@ -70,7 +70,7 @@ void erofs_msg(int dbglv, const char *fmt, ...); } while (0)#define erofs_err (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= EROFS_ERR) { \ + if (g_cfg.c_dbg_lvl >= EROFS_ERR) { \ erofs_msg(EROFS_ERR, \ "<E> " PR_FMT_FUNC_LINE(fmt), \ ##__VA_ARGS__); \
lib/blobchunk.c +1 -1
@@ -261,7 +261,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, erofs_off_t startoff) {struct erofs_sb_info *sbi = inode->sbi; -unsigned int chunkbits = cfg.c_chunkbits; +unsigned int chunkbits = g_cfg.c_chunkbits;unsigned int count, unit;struct erofs_blobchunk *chunk, *lastch;struct erofs_inode_chunk_index *idx;
lib/block_list.c +4 -4
@@ -49,7 +49,7 @@ static void blocklist_write(const char *path, erofs_blk_t blk_start,const char *fspath =erofs_fspath (path);if (first_extent) { -fprintf (block_list_fp,"/%s" , cfg.mount_point); +fprintf (block_list_fp,"/%s" , g_cfg.mount_point);if (fspath[0 ] !='/' )fprintf (block_list_fp,"/" );
@@ -72,7 +72,7 @@ void erofs_droid_blocklist_write_extent(struct erofs_inode *inode, erofs_blk_t nblocks, bool first_extent, bool last_extent) { - if (!block_list_fp || !cfg.mount_point) + if (!block_list_fp || !g_cfg.mount_point) return;if (!nblocks) {
@@ -88,7 +88,7 @@ void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,void erofs_droid_blocklist_write (struct erofs_inode *inode,erofs_blk_t blk_start,erofs_blk_t nblocks) { -if (!block_list_fp || !cfg.mount_point || !nblocks) +if (!block_list_fp || !g_cfg.mount_point || !nblocks)return ; blocklist_write(inode->i_srcpath, blk_start, nblocks,
@@ -98,7 +98,7 @@ void erofs_droid_blocklist_write(struct erofs_inode *inode,void erofs_droid_blocklist_write_tail_end (struct erofs_inode *inode,erofs_blk_t blkaddr) { -if (!block_list_fp || !cfg.mount_point) +if (!block_list_fp || !g_cfg.mount_point)return ;/* XXX: a bit hacky.. may need a better approach */
lib/compress.c +41 -41
224 lines not on this page · raw message
lib/compress_hints.c +8 -8
@@ -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_mkfs_pclustersize_def >> inode->sbi->blkszbits; + pclusterblks = g_cfg.c_mkfs_pclustersize_def >> inode->sbi->blkszbits; algorithmtype =0 ;list_for_each_entry (r, &compress_hints_head, list) {
@@ -93,10 +93,10 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi)unsigned int line, max_pclustersize =0 ;int ret =0 ; -if (!cfg.c_compress_hints_file) +if (!g_cfg.c_compress_hints_file)return 0 ; - f =fopen (cfg.c_compress_hints_file,"r" ); + f =fopen (g_cfg.c_compress_hints_file,"r" );if (!f)return -errno;
@@ -125,7 +125,7 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi) }else { ccfg =atoi (alg);if (ccfg >=EROFS_MAX_COMPR_CFGS || - !cfg.c_compr_opts[ccfg].alg) { + !g_cfg.c_compr_opts[ccfg].alg) {erofs_err ("invalid compressing configuration \"%s\" at line %u" , alg, line); ret = -EINVAL ;
@@ -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_mkfs_pclustersize_def); + pclustersize, g_cfg.c_mkfs_pclustersize_def);continue ; } erofs_insert_compress_hints(pattern,
@@ -146,10 +146,10 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi) max_pclustersize = pclustersize; } -if (cfg.c_mkfs_pclustersize_max < max_pclustersize) { - cfg.c_mkfs_pclustersize_max = max_pclustersize; +if (g_cfg.c_mkfs_pclustersize_max < max_pclustersize) { + g_cfg.c_mkfs_pclustersize_max = max_pclustersize;erofs_warn ("update max pclustersize to %u" , - cfg.c_mkfs_pclustersize_max); + g_cfg.c_mkfs_pclustersize_max); } out:fclose (f);
lib/compressor_liblzma.c +1 -1
@@ -75,7 +75,7 @@ static int erofs_compressor_liblzma_setdictsize(struct erofs_compress *c, dict_size = erofs_compressor_lzma.default_dictsize; }else { dict_size =min_t (u32,Z_EROFS_LZMA_MAX_DICT_SIZE , - cfg.c_mkfs_pclustersize_max <<3 ); + g_cfg.c_mkfs_pclustersize_max <<3 );if (dict_size <32768 ) dict_size =32768 ; }
lib/compressor_libzstd.c +1 -1
@@ -86,7 +86,7 @@ static int erofs_compressor_libzstd_setdictsize(struct erofs_compress *c, dict_size = erofs_compressor_libzstd.default_dictsize; }else { dict_size =min_t (u32,Z_EROFS_ZSTD_MAX_DICT_SIZE , - cfg.c_mkfs_pclustersize_max <<3 ); + g_cfg.c_mkfs_pclustersize_max <<3 ); dict_size =1 <<ilog2 (dict_size); } }
lib/config.c +27 -27
98 lines not on this page · raw message
lib/inode.c +31 -31
185 lines not on this page · raw message
lib/io.c +6 -6
@@ -28,7 +28,7 @@int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf) { -if (__erofs_unlikely (cfg.c_dry_run)) { +if (__erofs_unlikely (g_cfg.c_dry_run)) { buf->st_size =0 ; buf->st_mode =S_IFREG |0777 ;return 0 ;
@@ -44,7 +44,7 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf, {ssize_t ret, written =0 ; -if (__erofs_unlikely (cfg.c_dry_run)) +if (__erofs_unlikely (g_cfg.c_dry_run))return 0 ;if (vf->ops)
@@ -78,7 +78,7 @@ int erofs_io_fsync(struct erofs_vfile *vf) {int ret; -if (__erofs_unlikely (cfg.c_dry_run)) +if (__erofs_unlikely (g_cfg.c_dry_run))return 0 ;if (vf->ops)
@@ -98,7 +98,7 @@ ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset,static const char zero[EROFS_MAX_BLOCK_SIZE ] = {0 };ssize_t ret; -if (__erofs_unlikely (cfg.c_dry_run)) +if (__erofs_unlikely (g_cfg.c_dry_run))return 0 ;if (vf->ops)
@@ -124,7 +124,7 @@ int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length)int ret;struct stat st; -if (__erofs_unlikely (cfg.c_dry_run)) +if (__erofs_unlikely (g_cfg.c_dry_run))return 0 ;if (vf->ops)
@@ -145,7 +145,7 @@ ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 pos, size_t len) {ssize_t ret, read =0 ; -if (__erofs_unlikely (cfg.c_dry_run)) +if (__erofs_unlikely (g_cfg.c_dry_run))return 0 ;if (vf->ops)
lib/xattr.c +10 -10
@@ -297,22 +297,22 @@ static struct xattr_item *erofs_get_selabel_xattr(const char *srcpath, mode_t mode) {#ifdef HAVE_LIBSELINUX -if (cfg.sehnd) { +if (g_cfg.sehnd) {char *secontext;int ret;unsigned int len[2 ];char *kvbuf, *fspath;struct xattr_item *item; -if (cfg.mount_point) - ret =asprintf (&fspath,"/%s/%s" , cfg.mount_point, +if (g_cfg.mount_point) + ret =asprintf (&fspath,"/%s/%s" , g_cfg.mount_point,erofs_fspath (srcpath));else ret =asprintf (&fspath,"/%s" ,erofs_fspath (srcpath));if (ret <=0 )return ERR_PTR (-ENOMEM ); - ret =selabel_lookup (cfg.sehnd, &secontext, fspath, mode); + ret =selabel_lookup (g_cfg.sehnd, &secontext, fspath, mode);free (fspath);if (ret) {
@@ -369,7 +369,7 @@ static int erofs_xattr_add(struct list_head *ixattrs, struct xattr_item *item)if (ixattrs)return inode_xattr_add (ixattrs, item); -if (item->count == cfg.c_inline_xattr_tolerance +1 ) { +if (item->count == g_cfg.c_inline_xattr_tolerance +1 ) {int ret =shared_xattr_add (item);if (ret <0 )
@@ -382,7 +382,7 @@ static bool erofs_is_skipped_xattr(const char *key) {#ifdef HAVE_LIBSELINUX /* if sehnd is valid, selabels will be overridden */ -if (cfg.sehnd && !strcmp (key,XATTR_SECURITY_PREFIX "selinux" )) +if (g_cfg.sehnd && !strcmp (key,XATTR_SECURITY_PREFIX "selinux" ))return true;#endif return false;
@@ -577,7 +577,7 @@ int erofs_scan_file_xattrs(struct erofs_inode *inode)struct list_head *ixattrs = &inode->i_xattrs;/* check if xattr is disabled */ -if (cfg.c_inline_xattr_tolerance <0 ) +if (g_cfg.c_inline_xattr_tolerance <0 )return 0 ; ret =read_xattrs_from_file (inode->i_srcpath, inode->i_mode, ixattrs);
@@ -885,8 +885,8 @@ int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *perofs_off_t shared_xattrs_size =0 ;/* check if xattr or shared xattr is disabled */ -if (cfg.c_inline_xattr_tolerance <0 || - cfg.c_inline_xattr_tolerance ==INT_MAX ) +if (g_cfg.c_inline_xattr_tolerance <0 || + g_cfg.c_inline_xattr_tolerance ==INT_MAX )return 0 ;if (shared_xattrs_count) {
@@ -972,7 +972,7 @@ char *erofs_export_xattr_ibody(struct erofs_inode *inode) header = (struct erofs_xattr_ibody_header *)buf; header->h_shared_count =0 ; -if (cfg.c_xattr_name_filter) { +if (g_cfg.c_xattr_name_filter) {u32 name_filter =0 ;int hashbit;unsigned int base_len;
mkfs/main.c +114 -114
614 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH 2/2 erofs-utils: get rid of the global `g_cfg`
This patch introduces the per-superblock configuration bt_args to get rid of the global g_cfg.
--- dump/main.c | 4 +- fsck/main.c | 4 +- fuse/main.c | 4 +- include/erofs/compress.h | 2 +- include/erofs/config.h | 22 ++- include/erofs/internal.h | 2 + lib/blobchunk.c | 3 +- lib/block_list.c | 25 +-- lib/compress.c | 95 +++++++----- lib/compress_hints.c | 18 ++- lib/compressor_liblzma.c | 4 +- lib/compressor_libzstd.c | 4 +- lib/config.c | 82 ++++++---- lib/inode.c | 82 ++++++---- lib/io.c | 31 +++- lib/xattr.c | 64 ++++---- mkfs/main.c | 328 +++++++++++++++++++++------------------ 17 files changed, 456 insertions(+), 318 deletions(-)
dump/main.c +2 -2
@@ -676,7 +676,7 @@ int main(int argc, char **argv) {int err; -erofs_init_configure (); +erofs_init_configure (&g_cfg); err =erofsdump_parse_options_cfg (argc, argv);if (err) {if (err == -EINVAL )
@@ -720,6 +720,6 @@ exit_dev_close:erofs_dev_close (&g_sbi); exit:erofs_blob_closeall (&g_sbi); -erofs_exit_configure (); +erofs_exit_configure (&g_cfg);return err; }
fsck/main.c +2 -2
@@ -1049,7 +1049,7 @@ int main(int argc, char *argv[]) {int err; -erofs_init_configure (); +erofs_init_configure (&g_cfg); fsckcfg.physical_blocks =0 ; fsckcfg.logical_blocks =0 ;
@@ -1136,7 +1136,7 @@ exit_dev_close:erofs_dev_close (&g_sbi); exit:erofs_blob_closeall (&g_sbi); -erofs_exit_configure (); +erofs_exit_configure (&g_cfg);return err ?1 :0 ; }
fuse/main.c +2 -2
@@ -642,7 +642,7 @@ int main(int argc, char *argv[]) } opts = {};#endif -erofs_init_configure (); +erofs_init_configure (&g_cfg); fusecfg.debug_lvl = g_cfg.c_dbg_lvl;printf ("erofsfuse %s\n" , g_cfg.c_version);
@@ -752,6 +752,6 @@ err_fuse_free_args:free (opts.mountpoint);fuse_opt_free_args (&args); err: -erofs_exit_configure (); +erofs_exit_configure (&g_cfg);return ret ?EXIT_FAILURE :EXIT_SUCCESS ; }
include/erofs/compress.h +1 -1
@@ -25,7 +25,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx);int z_erofs_compress_init (struct erofs_sb_info *sbi,struct erofs_buffer_head *bh); -int z_erofs_compress_exit (void ); +int z_erofs_compress_exit (struct erofs_sb_info *sbi);const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask);const struct erofs_algorithm *z_erofs_list_available_compressors (int *i);
include/erofs/config.h +16 -6
@@ -98,9 +98,18 @@ struct erofs_configure {extern struct erofs_configure g_cfg; -void erofs_init_configure (void ); -void erofs_show_config (void ); -void erofs_exit_configure (void ); +struct erofs_mkfs_buildtree_args { +struct erofs_configure *cfg; +}; + +struct erofs_sb_info ; + +void erofs_init_configure (struct erofs_configure *cfg); +void erofs_show_config (struct erofs_configure *cfg); +void erofs_exit_configure (struct erofs_configure *cfg); +void erofs_init_buildtree_cfg (struct erofs_sb_info *sbi, +struct erofs_configure *cfg); +void erofs_exit_buildtree_cfg (struct erofs_sb_info *sbi);/* (will be deprecated) temporary helper for updating global the cfg */ struct erofs_configure *erofs_get_configure ();
@@ -109,15 +118,16 @@ void erofs_set_fs_root(const char *rootdir);const char *erofs_fspath (const char *fullpath);#ifdef HAVE_LIBSELINUX -int erofs_selabel_open (const char *file_contexts); +int erofs_selabel_open (struct erofs_sb_info *sbi,const char *file_contexts);#else -static inline int erofs_selabel_open (const char *file_contexts) +static inline int erofs_selabel_open (struct erofs_sb_info *sbi, +const char *file_contexts) {return -EINVAL ; }#endif -void erofs_update_progressinfo (const char *fmt, ...); +void erofs_update_progressinfo (struct erofs_sb_info *sbi,const char *fmt, ...);char *erofs_trim_for_progressinfo (const char *str,int placeholder);unsigned int erofs_get_available_processors (void );
include/erofs/internal.h +2 -0
@@ -27,6 +27,7 @@ typedef unsigned short umode_t;#endif #include "atomic.h" #include "io.h" +#include "config.h" #ifndef PATH_MAX #define PATH_MAX 4096/* # chars in a path name including nul */
@@ -140,6 +141,7 @@ struct erofs_sb_info {#endif struct erofs_bufmgr *bmgr;bool useqpl; +struct erofs_mkfs_buildtree_args *bt_args; };#define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
lib/blobchunk.c +2 -1
@@ -261,7 +261,8 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd, erofs_off_t startoff) {struct erofs_sb_info *sbi = inode->sbi; -unsigned int chunkbits = g_cfg.c_chunkbits; +struct erofs_configure *cfg = sbi->bt_args->cfg; +unsigned int chunkbits = cfg->c_chunkbits;unsigned int count, unit;struct erofs_blobchunk *chunk, *lastch;struct erofs_inode_chunk_index *idx;
lib/block_list.c +16 -9
@@ -42,14 +42,15 @@ void tarerofs_blocklist_write(erofs_blk_t blkaddr, erofs_blk_t nblocks, }#ifdef WITH_ANDROID -static void blocklist_write (const char *path,erofs_blk_t blk_start, +static void blocklist_write (struct erofs_sb_info *sbi,const char *path,erofs_blk_t blk_start,erofs_blk_t nblocks,bool first_extent,bool last_extent) { +struct erofs_configure *cfg = sbi->bt_args->cfg;const char *fspath =erofs_fspath (path);if (first_extent) { -fprintf (block_list_fp,"/%s" , g_cfg.mount_point); +fprintf (block_list_fp,"/%s" , cfg->mount_point);if (fspath[0 ] !='/' )fprintf (block_list_fp,"/" );
@@ -72,7 +73,9 @@ void erofs_droid_blocklist_write_extent(struct erofs_inode *inode, erofs_blk_t nblocks, bool first_extent, bool last_extent) { - if (!block_list_fp || !g_cfg.mount_point) + struct erofs_configure *cfg = inode->sbi->bt_args->cfg; + +if (!block_list_fp || !cfg->mount_point)return ;if (!nblocks) {
@@ -81,24 +84,28 @@ void erofs_droid_blocklist_write_extent(struct erofs_inode *inode,return ; } -blocklist_write (inode->i_srcpath, blk_start, nblocks, first_extent, - last_extent); +blocklist_write (inode->sbi, inode->i_srcpath, blk_start, nblocks, + first_extent, last_extent); }void erofs_droid_blocklist_write (struct erofs_inode *inode,erofs_blk_t blk_start,erofs_blk_t nblocks) { -if (!block_list_fp || !g_cfg.mount_point || !nblocks) +struct erofs_configure *cfg = inode->sbi->bt_args->cfg; + +if (!block_list_fp || !cfg->mount_point || !nblocks)return ; -blocklist_write (inode->i_srcpath, blk_start, nblocks, +blocklist_write (inode->sbi, inode->i_srcpath, blk_start, nblocks, true, !inode->idata_size); }void erofs_droid_blocklist_write_tail_end (struct erofs_inode *inode,erofs_blk_t blkaddr) { -if (!block_list_fp || !g_cfg.mount_point) +struct erofs_configure *cfg = inode->sbi->bt_args->cfg; + +if (!block_list_fp || !cfg->mount_point)return ;/* XXX: a bit hacky.. may need a better approach */
@@ -114,6 +121,6 @@ void erofs_droid_blocklist_write_tail_end(struct erofs_inode *inode, return; }if (blkaddr !=NULL_ADDR ) -blocklist_write (inode->i_srcpath, blkaddr,1 , true, true); +blocklist_write (inode->sbi, inode->i_srcpath, blkaddr,1 , true, true); }#endif
lib/compress.c +53 -42
278 lines not on this page · raw message
lib/compress_hints.c +10 -8
@@ -50,12 +50,13 @@ bool z_erofs_apply_compress_hints(struct erofs_inode *inode)const char *s;struct erofs_compress_hints *r;unsigned int pclusterblks, algorithmtype; +struct erofs_configure *cfg = inode->sbi->bt_args->cfg;if (inode->z_physical_clusterblks)return true; s =erofs_fspath (inode->i_srcpath); - pclusterblks = g_cfg.c_mkfs_pclustersize_def >> inode->sbi->blkszbits; + pclusterblks = cfg->c_mkfs_pclustersize_def >> inode->sbi->blkszbits; algorithmtype =0 ;list_for_each_entry (r, &compress_hints_head, list) {
@@ -92,11 +93,12 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi)FILE *f;unsigned int line, max_pclustersize =0 ;int ret =0 ; +struct erofs_configure *cfg = sbi->bt_args->cfg; -if (!g_cfg.c_compress_hints_file) +if (!cfg->c_compress_hints_file)return 0 ; - f =fopen (g_cfg.c_compress_hints_file,"r" ); + f =fopen (cfg->c_compress_hints_file,"r" );if (!f)return -errno;
@@ -125,7 +127,7 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi) }else { ccfg =atoi (alg);if (ccfg >=EROFS_MAX_COMPR_CFGS || - !g_cfg.c_compr_opts[ccfg].alg) { + !cfg->c_compr_opts[ccfg].alg) {erofs_err ("invalid compressing configuration \"%s\" at line %u" , alg, line); ret = -EINVAL ;
@@ -136,7 +138,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, g_cfg.c_mkfs_pclustersize_def); + pclustersize, cfg->c_mkfs_pclustersize_def);continue ; } erofs_insert_compress_hints(pattern,
@@ -146,10 +148,10 @@ int erofs_load_compress_hints(struct erofs_sb_info *sbi) max_pclustersize = pclustersize; } -if (g_cfg.c_mkfs_pclustersize_max < max_pclustersize) { - g_cfg.c_mkfs_pclustersize_max = max_pclustersize; +if (cfg->c_mkfs_pclustersize_max < max_pclustersize) { + cfg->c_mkfs_pclustersize_max = max_pclustersize;erofs_warn ("update max pclustersize to %u" , - g_cfg.c_mkfs_pclustersize_max); + cfg->c_mkfs_pclustersize_max); } out:fclose (f);
lib/compressor_liblzma.c +3 -1
@@ -70,12 +70,14 @@ static int erofs_compressor_liblzma_setlevel(struct erofs_compress *c,static int erofs_compressor_liblzma_setdictsize (struct erofs_compress *c,u32 dict_size) { +struct erofs_configure *cfg = c->sbi->bt_args->cfg; +if (!dict_size) {if (erofs_compressor_lzma.default_dictsize) { dict_size = erofs_compressor_lzma.default_dictsize; }else { dict_size =min_t (u32,Z_EROFS_LZMA_MAX_DICT_SIZE , - g_cfg.c_mkfs_pclustersize_max <<3 ); + cfg->c_mkfs_pclustersize_max <<3 );if (dict_size <32768 ) dict_size =32768 ; }
lib/compressor_libzstd.c +3 -1
@@ -81,12 +81,14 @@ static int erofs_compressor_libzstd_setlevel(struct erofs_compress *c,static int erofs_compressor_libzstd_setdictsize (struct erofs_compress *c,u32 dict_size) { +struct erofs_configure *cfg = c->sbi->bt_args->cfg; +if (!dict_size) {if (erofs_compressor_libzstd.default_dictsize) { dict_size = erofs_compressor_libzstd.default_dictsize; }else { dict_size =min_t (u32,Z_EROFS_ZSTD_MAX_DICT_SIZE , - g_cfg.c_mkfs_pclustersize_max <<3 ); + cfg->c_mkfs_pclustersize_max <<3 ); dict_size =1 <<ilog2 (dict_size); } }
lib/config.c +52 -30
133 lines not on this page · raw message
lib/inode.c +49 -33
261 lines not on this page · raw message
lib/io.c +25 -6
@@ -28,7 +28,11 @@int erofs_io_fstat (struct erofs_vfile *vf,struct stat *buf) { -if (__erofs_unlikely (g_cfg.c_dry_run)) { + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg; + +if (__erofs_unlikely (cfg->c_dry_run)) { buf->st_size =0 ; buf->st_mode =S_IFREG |0777 ;return 0 ;
@@ -42,9 +46,12 @@ int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf)ssize_t erofs_io_pwrite (struct erofs_vfile *vf,const void *buf,u64 pos,size_t len) { + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg;ssize_t ret, written =0 ; -if (__erofs_unlikely (g_cfg.c_dry_run)) +if (__erofs_unlikely (cfg->c_dry_run))return 0 ;if (vf->ops)
@@ -76,9 +83,12 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf,int erofs_io_fsync (struct erofs_vfile *vf) { + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg;int ret; -if (__erofs_unlikely (g_cfg.c_dry_run)) +if (__erofs_unlikely (cfg->c_dry_run))return 0 ;if (vf->ops)
@@ -95,10 +105,13 @@ int erofs_io_fsync(struct erofs_vfile *vf)ssize_t erofs_io_fallocate (struct erofs_vfile *vf,u64 offset,size_t len,bool zeroout) { + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg;static const char zero[EROFS_MAX_BLOCK_SIZE ] = {0 };ssize_t ret; -if (__erofs_unlikely (g_cfg.c_dry_run)) +if (__erofs_unlikely (cfg->c_dry_run))return 0 ;if (vf->ops)
@@ -123,8 +136,11 @@ int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length) {int ret;struct stat st; + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg; -if (__erofs_unlikely (g_cfg.c_dry_run)) +if (__erofs_unlikely (cfg->c_dry_run))return 0 ;if (vf->ops)
@@ -143,9 +159,12 @@ int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length)ssize_t erofs_io_pread (struct erofs_vfile *vf,void *buf,u64 pos,size_t len) { + struct erofs_sb_info *sbi = container_of(vf, struct erofs_sb_info, + bdev); +struct erofs_configure *cfg = sbi->bt_args->cfg;ssize_t ret, read =0 ; -if (__erofs_unlikely (g_cfg.c_dry_run)) +if (__erofs_unlikely (cfg->c_dry_run))return 0 ;if (vf->ops)
lib/xattr.c +38 -26
196 lines not on this page · raw message
mkfs/main.c +180 -148
835 lines not on this page · raw message
Signature · 1 line
2.43.5
Quoted 2 lines · Hongzhen Luo
Rename the global variable
cfgtog_cfgin preparation for the per-superblock configuration.
I think the global configuration is still needed.
But you need to seperate all mkfs configurations from cfg into a new structure erofs_mkfs_buildtree_args instead.
Thanks,
Gao Xiang