erofs-utils: lib: get rid of erofs_prepare_dir_layout()
PATCH 1/5 erofs-utils: lib: get rid of erofs_prepare_dir_layout()
Just open-code the previous erofs_prepare_dir_file() and rename erofs_prepare_dir_layout() to erofs_prepare_dir_file().
No logic changes.
--- lib/inode.c | 70 ++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 39 deletions(-)
lib/inode.c +31 -39
@@ -208,8 +208,30 @@ static int comp_subdir(const void *a, const void *b)return strcmp (da->name, db->name); } -static int erofs_prepare_dir_layout (struct erofs_inode *dir, -unsigned int nr_subdirs) +int erofs_init_empty_dir (struct erofs_inode *dir) +{ +struct erofs_dentry *d; + +/* dot is pointed to the current dir inode */ + d =erofs_d_alloc (dir,"." ); +if (IS_ERR (d)) +return PTR_ERR (d); + d->inode =erofs_igrab (dir); + d->type =EROFS_FT_DIR ; + +/* dotdot is pointed to the parent dir */ + d =erofs_d_alloc (dir,".." ); +if (IS_ERR (d)) +return PTR_ERR (d); + d->inode =erofs_igrab (erofs_parent_inode (dir)); + d->type =EROFS_FT_DIR ; + + dir->i_nlink =2 ; +return 0 ; +} + +static int erofs_prepare_dir_file (struct erofs_inode *dir, +unsigned int nr_subdirs) {struct erofs_sb_info *sbi = dir->sbi;struct erofs_dentry *d, *n, **sorted_d;
@@ -248,41 +270,6 @@ static int erofs_prepare_dir_layout(struct erofs_inode *dir,return 0 ; } -int erofs_init_empty_dir (struct erofs_inode *dir) -{ -struct erofs_dentry *d; - -/* dot is pointed to the current dir inode */ - d =erofs_d_alloc (dir,"." ); -if (IS_ERR (d)) -return PTR_ERR (d); - d->inode =erofs_igrab (dir); - d->type =EROFS_FT_DIR ; - -/* dotdot is pointed to the parent dir */ - d =erofs_d_alloc (dir,".." ); -if (IS_ERR (d)) -return PTR_ERR (d); - d->inode =erofs_igrab (erofs_parent_inode (dir)); - d->type =EROFS_FT_DIR ; - - dir->i_nlink =2 ; -return 0 ; -} - -int erofs_prepare_dir_file (struct erofs_inode *dir,unsigned int nr_subdirs) -{ -int ret; - - ret =erofs_init_empty_dir (dir); -if (ret) -return ret; - -/* sort subdirs */ - nr_subdirs +=2 ; -return erofs_prepare_dir_layout (dir, nr_subdirs); -} -static void fill_dirblock (char *buf,unsigned int size,unsigned int q,struct erofs_dentry *head,struct erofs_dentry *end) {
@@ -1358,7 +1345,11 @@ static int erofs_mkfs_handle_directory(struct erofs_inode *dir) }closedir (_dir); - ret =erofs_prepare_dir_file (dir, nr_subdirs); + ret =erofs_init_empty_dir (dir); +if (ret) +return ret; + + ret =erofs_prepare_dir_file (dir, nr_subdirs +2 );/* sort subdirs */ if (ret)return ret;
@@ -1399,7 +1390,8 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir) ++nr_subdirs; } - ret =erofs_prepare_dir_layout (dir, nr_subdirs); +DBG_BUGON (nr_subdirs < i_nlink); + ret =erofs_prepare_dir_file (dir, nr_subdirs);if (ret)return ret;
Signature · 1 line
2.39.3
PATCH 2/5 erofs-utils: lib: use filesystem UUID if the device name is not specified
The device name is not always valid.
--- lib/rebuild.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
lib/rebuild.c +8 -6
@@ -15,6 +15,7 @@#include "erofs/xattr.h" #include "erofs/blobchunk.h" #include "erofs/internal.h" +#include "liberofs_uuid.h" #ifdef HAVE_LINUX_AUFS_TYPE_H #include <linux/aufs_type.h>
@@ -375,16 +376,17 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi) {struct erofs_inode inode = {};struct erofs_rebuild_dir_context ctx; +char uuid_str[37 ]; +char *fsid = sbi->devname;int ret; -if (!sbi->devname) { -erofs_err ("failed to find a device for rebuilding" ); -return -EINVAL ; +if (!fsid) { +erofs_uuid_unparse_lower (sbi->uuid, uuid_str); + fsid = uuid_str; } - ret =erofs_read_superblock (sbi);if (ret) { -erofs_err ("failed to read superblock of %s" , sbi->devname); +erofs_err ("failed to read superblock of %s" , fsid);return ret; }
@@ -392,7 +394,7 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi) inode.sbi = sbi; ret =erofs_read_inode_from_disk (&inode);if (ret) { -erofs_err ("failed to read root inode of %s" , sbi->devname); +erofs_err ("failed to read root inode of %s" , fsid);return ret; } inode.i_srcpath =strdup ("/" );
Signature · 1 line
2.39.3
PATCH 3/5 erofs-utils: wrap up superblock reservation for incremental builds
In reply to Gao XiangRefactor erofs_buffer_init() to wrap up necessary operations for full builds.
Introduce another erofs_buffer_init() to specify start block address for the upcoming incremental builds.
--- include/erofs/cache.h | 2 +- include/erofs/internal.h | 1 + lib/cache.c | 11 ++--------- lib/super.c | 31 +++++++++++++++++++++++++++++++ mkfs/main.c | 17 +---------------- 5 files changed, 36 insertions(+), 26 deletions(-)
include/erofs/cache.h +1 -1
@@ -98,7 +98,7 @@ static inline int erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)return 0 ; } -struct erofs_buffer_head *erofs_buffer_init (void ); +void erofs_buffer_init (erofs_blk_t startblk);int erofs_bh_balloon (struct erofs_buffer_head *bh,erofs_off_t incr); struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size,
include/erofs/internal.h +1 -0
@@ -397,6 +397,7 @@ int erofs_read_superblock(struct erofs_sb_info *sbi);void erofs_put_super (struct erofs_sb_info *sbi);int erofs_writesb (struct erofs_sb_info *sbi,struct erofs_buffer_head *sb_bh,erofs_blk_t *blocks); +struct erofs_buffer_head *erofs_reserve_sb (void );/* namei.c */ int erofs_read_inode_from_disk (struct erofs_inode *vi);
lib/cache.c +2 -9
@@ -38,21 +38,14 @@ const struct erofs_bhops erofs_skip_write_bhops = { .flush = erofs_bh_flush_skip_write, }; -/* return buffer_head of erofs super block (with size 0) */ -struct erofs_buffer_head *erofs_buffer_init (void ) +void erofs_buffer_init (erofs_blk_t startblk) {int i, j; -struct erofs_buffer_head *bh =erofs_balloc (META ,0 ,0 ,0 ); - -if (IS_ERR (bh)) -return bh; - - bh->op = &erofs_skip_write_bhops;for (i =0 ; i <ARRAY_SIZE (mapped_buckets); i++)for (j =0 ; j <ARRAY_SIZE (mapped_buckets[0 ]); j++)init_list_head (&mapped_buckets[i][j]); -return bh; + tail_blkaddr = startblk; }static void erofs_bupdate_mapped (struct erofs_buffer_block *bb)
lib/super.c +31 -0
@@ -201,3 +201,34 @@ int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,erofs_bdrop (sb_bh, false);return ret; } + +struct erofs_buffer_head *erofs_reserve_sb (void ) +{ +struct erofs_buffer_head *bh; +int err; + +erofs_buffer_init (0 ); + bh =erofs_balloc (META ,0 ,0 ,0 ); +if (IS_ERR (bh)) { +erofs_err ("failed to allocate super: %s" ,PTR_ERR (bh)); +return bh; + } + bh->op = &erofs_skip_write_bhops; + err =erofs_bh_balloon (bh,EROFS_SUPER_END ); +if (err <0 ) { +erofs_err ("failed to balloon super: %s" ,erofs_strerror (err)); + goto err_bdrop; + } + +/* make sure that the super block should be the very first blocks */ + (void )erofs_mapbh (bh->block); +if (erofs_btell (bh, false) !=0 ) { +erofs_err ("failed to pin super block @ 0" ); + err = -EFAULT ; + goto err_bdrop; + } +return bh; +err_bdrop: +erofs_bdrop (bh, true); +return ERR_PTR (err); +}
mkfs/main.c +1 -16
@@ -1244,24 +1244,9 @@ int main(int argc, char **argv) sbi.blkszbits = src->blkszbits; } - sb_bh =erofs_buffer_init (); + sb_bh =erofs_reserve_sb ();if (IS_ERR (sb_bh)) { err =PTR_ERR (sb_bh); -erofs_err ("failed to initialize buffers: %s" , -erofs_strerror (err)); - goto exit; - } - err =erofs_bh_balloon (sb_bh,EROFS_SUPER_END ); -if (err <0 ) { -erofs_err ("failed to balloon erofs_super_block: %s" , -erofs_strerror (err)); - goto exit; - } - -/* make sure that the super block should be the very first blocks */ - (void )erofs_mapbh (sb_bh->block); -if (erofs_btell (sb_bh, false) !=0 ) { -erofs_err ("failed to reserve erofs_super_block" ); goto exit; }
Signature · 1 line
2.39.3
PATCH 4/5 erofs-utils: mkfs: assign root NID in the main thread
In reply to Gao XiangThus it could be customized (skiped), especially for incremental builds.
--- lib/inode.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-)
lib/inode.c +26 -10
@@ -1186,8 +1186,6 @@ static int erofs_mkfs_jobfn(struct erofs_mkfs_jobitem *item)if (ret)return ret; inode->bh->op = &erofs_skip_write_bhops; -if (IS_ROOT (inode))/* assign root NID */ -erofs_fixup_meta_blkaddr (inode);return 0 ; }
@@ -1206,20 +1204,31 @@ static int erofs_mkfs_jobfn(struct erofs_mkfs_jobitem *item)struct erofs_mkfs_dfops {pthread_t worker;pthread_mutex_t lock; -pthread_cond_t full, empty; +pthread_cond_t full, empty, drain;struct erofs_mkfs_jobitem *queue;unsigned int entries, head, tail; };#define EROFS_MT_QUEUE_SIZE 128 -void *erofs_mkfs_pop_jobitem (struct erofs_mkfs_dfops *q) +static void erofs_mkfs_flushjobs (struct erofs_sb_info *sbi) +{ +struct erofs_mkfs_dfops *q = sbi->mkfs_dfops; + +pthread_mutex_lock (&q->lock); +pthread_cond_wait (&q->drain, &q->lock); +pthread_mutex_unlock (&q->lock); +} + +static void *erofs_mkfs_pop_jobitem (struct erofs_mkfs_dfops *q) {struct erofs_mkfs_jobitem *item;pthread_mutex_lock (&q->lock); -while (q->head == q->tail) +while (q->head == q->tail) { +pthread_cond_signal (&q->drain);pthread_cond_wait (&q->empty, &q->lock); + } item = q->queue + q->head; q->head = (q->head +1 ) & (q->entries -1 );
@@ -1229,7 +1238,7 @@ void *erofs_mkfs_pop_jobitem(struct erofs_mkfs_dfops *q)return item; } -void *z_erofs_mt_dfops_worker (void *arg) +static void *z_erofs_mt_dfops_worker (void *arg) {struct erofs_sb_info *sbi = arg;int ret =0 ;
@@ -1247,8 +1256,8 @@ void *z_erofs_mt_dfops_worker(void *arg)pthread_exit ((void *)(uintptr_t )ret); } -int erofs_mkfs_go (struct erofs_sb_info *sbi, -enum erofs_mkfs_jobtype type,void *elem,int size) +static int erofs_mkfs_go (struct erofs_sb_info *sbi, +enum erofs_mkfs_jobtype type,void *elem,int size) {struct erofs_mkfs_jobitem *item;struct erofs_mkfs_dfops *q = sbi->mkfs_dfops;
@@ -1268,8 +1277,8 @@ int erofs_mkfs_go(struct erofs_sb_info *sbi, return 0; }#else -int erofs_mkfs_go (struct erofs_sb_info *sbi, -enum erofs_mkfs_jobtype type,void *elem,int size) +static int erofs_mkfs_go (struct erofs_sb_info *sbi, +enum erofs_mkfs_jobtype type,void *elem,int size) {struct erofs_mkfs_jobitem item;
@@ -1277,6 +1286,9 @@ int erofs_mkfs_go(struct erofs_sb_info *sbi,memcpy (&item.u, elem, size); return erofs_mkfs_jobfn(&item); } +static void erofs_mkfs_flushjobs (struct erofs_sb_info *sbi) +{ +}#endif static int erofs_mkfs_handle_directory (struct erofs_inode *dir)
@@ -1537,6 +1549,8 @@ static int erofs_mkfs_dump_tree(struct erofs_inode *root, bool rebuild)if (err)return err; +erofs_mkfs_flushjobs (root->sbi); +erofs_fixup_meta_blkaddr (root);/* assign root NID */ do { int err; struct erofs_inode *dir = dumpdir;
@@ -1635,6 +1649,7 @@ static int erofs_mkfs_build_tree(struct erofs_mkfs_buildtree_ctx *ctx)pthread_mutex_init (&q->lock,NULL );pthread_cond_init (&q->empty,NULL );pthread_cond_init (&q->full,NULL ); +pthread_cond_init (&q->drain,NULL ); q->head =0 ; q->tail =0 ;
@@ -1653,6 +1668,7 @@ static int erofs_mkfs_build_tree(struct erofs_mkfs_buildtree_ctx *ctx) fail:pthread_cond_destroy (&q->empty);pthread_cond_destroy (&q->full); +pthread_cond_destroy (&q->drain);pthread_mutex_destroy (&q->lock);free (q->queue);free (q);
Signature · 1 line
2.39.3
PATCH 5/5 erofs-utils: lib: get rid of global sbi in lib/inode.c
In reply to Gao XiangIn order to prepare for incremental builds.
--- include/erofs/inode.h | 8 +++++--- lib/fragments.c | 2 +- lib/inode.c | 47 +++++++++++++++++++++++-------------------- lib/rebuild.c | 4 ++-- lib/tar.c | 2 +- mkfs/main.c | 37 +++++++++++++++++----------------- 6 files changed, 53 insertions(+), 47 deletions(-)
include/erofs/inode.h +5 -3
@@ -38,9 +38,11 @@ int erofs_rebuild_dump_tree(struct erofs_inode *dir);int erofs_init_empty_dir (struct erofs_inode *dir);int __erofs_fill_inode (struct erofs_inode *inode,struct stat *st,const char *path); -struct erofs_inode *erofs_new_inode (void ); -struct erofs_inode *erofs_mkfs_build_tree_from_path (const char *path); -struct erofs_inode *erofs_mkfs_build_special_from_fd (int fd,const char *name); +struct erofs_inode *erofs_new_inode (struct erofs_sb_info *sbi); +struct erofs_inode *erofs_mkfs_build_tree_from_path (struct erofs_sb_info *sbi, +const char *path); +struct erofs_inode *erofs_mkfs_build_special_from_fd (struct erofs_sb_info *sbi, +int fd,const char *name); #ifdef __cplusplus }
lib/fragments.c +1 -1
@@ -330,7 +330,7 @@ struct erofs_inode *erofs_mkfs_build_packedfile(void) {fflush (packedfile); -return erofs_mkfs_build_special_from_fd (fileno (packedfile), +return erofs_mkfs_build_special_from_fd (&sbi,fileno (packedfile),EROFS_PACKED_INODE ); }
lib/inode.c +25 -22
148 lines not on this page · raw message
lib/rebuild.c +2 -2
@@ -31,7 +31,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir,struct erofs_inode *inode;struct erofs_dentry *d; - inode =erofs_new_inode (); + inode =erofs_new_inode (dir->sbi);if (IS_ERR (inode))return ERR_CAST (inode);
@@ -296,7 +296,7 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx)u64 nid;DBG_BUGON (parent != d->inode); - inode =erofs_new_inode (); + inode =erofs_new_inode (dir->sbi);if (IS_ERR (inode)) { ret =PTR_ERR (inode); goto out;
lib/tar.c +1 -1
@@ -937,7 +937,7 @@ restart: inode = d->inode; }else { new_inode: - inode =erofs_new_inode (); + inode =erofs_new_inode (sbi);if (IS_ERR (inode)) { ret =PTR_ERR (inode); goto out;
mkfs/main.c +19 -18
@@ -1035,11 +1035,12 @@ void erofs_show_progs(int argc, char *argv[])if (cfg.c_dbg_lvl >=EROFS_WARN )printf ("%s %s\n" ,basename (argv[0 ]), cfg.c_version); } -static struct erofs_inode *erofs_alloc_root_inode (void ) + +static struct erofs_inode *erofs_mkfs_alloc_root (struct erofs_sb_info *sbi) {struct erofs_inode *root; - root =erofs_new_inode (); + root =erofs_new_inode (sbi);if (IS_ERR (root))return root; root->i_srcpath =strdup ("/" );
@@ -1135,7 +1136,7 @@ int main(int argc, char **argv) {int err =0 ;struct erofs_buffer_head *sb_bh; -struct erofs_inode *root_inode, *packed_inode; +struct erofs_inode *root, *packed_inode;erofs_blk_t nblocks;struct timeval t;FILE *packedfile =NULL ;
@@ -1297,31 +1298,31 @@ int main(int argc, char **argv)erofs_inode_manager_init ();if (tar_mode) { - root_inode =erofs_alloc_root_inode (); -if (IS_ERR (root_inode)) { - err =PTR_ERR (root_inode); + root =erofs_mkfs_alloc_root (&sbi); +if (IS_ERR (root)) { + err =PTR_ERR (root); goto exit; } -while (!(err =tarerofs_parse_tar (root_inode, &erofstar))); +while (!(err =tarerofs_parse_tar (root, &erofstar)));if (err <0 ) goto exit; - err =erofs_rebuild_dump_tree (root_inode); + err =erofs_rebuild_dump_tree (root);if (err <0 ) goto exit; }else if (rebuild_mode) { - root_inode =erofs_alloc_root_inode (); -if (IS_ERR (root_inode)) { - err =PTR_ERR (root_inode); + root =erofs_mkfs_alloc_root (&sbi); +if (IS_ERR (root)) { + err =PTR_ERR (root); goto exit; } - err =erofs_rebuild_load_trees (root_inode); + err =erofs_rebuild_load_trees (root);if (err) goto exit; - err =erofs_rebuild_dump_tree (root_inode); + err =erofs_rebuild_dump_tree (root);if (err) goto exit; }else {
@@ -1335,14 +1336,14 @@ int main(int argc, char **argv)if (cfg.c_extra_ea_name_prefixes)erofs_xattr_write_name_prefixes (&sbi, packedfile); - root_inode =erofs_mkfs_build_tree_from_path (cfg.c_src_path); -if (IS_ERR (root_inode)) { - err =PTR_ERR (root_inode); + root =erofs_mkfs_build_tree_from_path (&sbi, cfg.c_src_path); +if (IS_ERR (root)) { + err =PTR_ERR (root); goto exit; } } - sbi.root_nid =erofs_lookupnid (root_inode); -erofs_iput (root_inode); + sbi.root_nid =erofs_lookupnid (root); +erofs_iput (root);if (erofstar.index_mode && sbi.extra_devices && !erofstar.mapfile) sbi.devs[0 ].blocks =BLK_ROUND_UP (&sbi, erofstar.offset);
Signature · 1 line
2.39.3