[PATCH v2 02/10] erofs-utils: mkfs: minor cleanup & rearrangement
Gao Xiang
hsiangkao at linux.alibaba.com
Tue Jun 18 18:24:07 AEST 2024
Introduce erofs_flush_packed_inode() and more for exporting liberofs
APIs later.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
v2: should dump blob before erofs_bflush().
include/erofs/fragments.h | 2 +-
lib/fragments.c | 15 ++++++++++++---
lib/inode.c | 11 ++++++-----
mkfs/main.c | 21 +++++++--------------
4 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/include/erofs/fragments.h b/include/erofs/fragments.h
index 4c6f755..65910f5 100644
--- a/include/erofs/fragments.h
+++ b/include/erofs/fragments.h
@@ -17,7 +17,7 @@ extern const char *erofs_frags_packedname;
FILE *erofs_packedfile_init(void);
void erofs_packedfile_exit(void);
-struct erofs_inode *erofs_mkfs_build_packedfile(void);
+int erofs_flush_packed_inode(struct erofs_sb_info *sbi);
int z_erofs_fragments_dedupe(struct erofs_inode *inode, int fd, u32 *tofcrc);
int z_erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofcrc);
diff --git a/lib/fragments.c b/lib/fragments.c
index 4d5478f..7591718 100644
--- a/lib/fragments.c
+++ b/lib/fragments.c
@@ -326,12 +326,21 @@ int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,
return len;
}
-struct erofs_inode *erofs_mkfs_build_packedfile(void)
+int erofs_flush_packed_inode(struct erofs_sb_info *sbi)
{
+ struct erofs_inode *inode;
+
+ if (!erofs_sb_has_fragments(sbi))
+ return -EINVAL;
fflush(packedfile);
+ if (!ftello(packedfile))
+ return 0;
- return erofs_mkfs_build_special_from_fd(&sbi, fileno(packedfile),
- EROFS_PACKED_INODE);
+ inode = erofs_mkfs_build_special_from_fd(sbi, fileno(packedfile),
+ EROFS_PACKED_INODE);
+ sbi->packed_nid = erofs_lookupnid(inode);
+ erofs_iput(inode);
+ return 0;
}
void erofs_packedfile_exit(void)
diff --git a/lib/inode.c b/lib/inode.c
index e27399d..0bfaa56 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1533,21 +1533,22 @@ static void erofs_mark_parent_inode(struct erofs_inode *inode,
static int erofs_mkfs_dump_tree(struct erofs_inode *root, bool rebuild)
{
- struct erofs_inode *dumpdir;
+ struct erofs_sb_info *sbi = root->sbi;
+ struct erofs_inode *dumpdir = erofs_igrab(root);
int err;
erofs_mark_parent_inode(root, root); /* rootdir mark */
root->next_dirwrite = NULL;
- (void)erofs_igrab(root);
- dumpdir = root;
err = !rebuild ? erofs_mkfs_handle_inode(root) :
erofs_rebuild_handle_inode(root);
if (err)
return err;
- erofs_mkfs_flushjobs(root->sbi);
+ erofs_mkfs_flushjobs(sbi);
erofs_fixup_meta_blkaddr(root); /* assign root NID */
+ sbi->root_nid = root->nid;
+
do {
int err;
struct erofs_inode *dir = dumpdir;
@@ -1584,7 +1585,7 @@ static int erofs_mkfs_dump_tree(struct erofs_inode *root, bool rebuild)
}
*last = dumpdir; /* fixup the last (or the only) one */
dumpdir = head;
- err = erofs_mkfs_go(dir->sbi, EROFS_MKFS_JOB_DIR_BH,
+ err = erofs_mkfs_go(sbi, EROFS_MKFS_JOB_DIR_BH,
&dir, sizeof(dir));
if (err)
return err;
diff --git a/mkfs/main.c b/mkfs/main.c
index 1b15bc5..d15b790 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1136,7 +1136,7 @@ int main(int argc, char **argv)
{
int err = 0;
struct erofs_buffer_head *sb_bh;
- struct erofs_inode *root, *packed_inode;
+ struct erofs_inode *root;
erofs_blk_t nblocks;
struct timeval t;
FILE *packedfile = NULL;
@@ -1342,29 +1342,22 @@ int main(int argc, char **argv)
goto exit;
}
}
- 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);
- if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) {
- err = erofs_mkfs_dump_blobs(&sbi);
+ if (erofs_sb_has_fragments(&sbi)) {
+ erofs_update_progressinfo("Handling packed data ...");
+ err = erofs_flush_packed_inode(&sbi);
if (err)
goto exit;
}
- sbi.packed_nid = 0;
- if ((cfg.c_fragments || cfg.c_extra_ea_name_prefixes) &&
- erofs_sb_has_fragments(&sbi)) {
- erofs_update_progressinfo("Handling packed_file ...");
- packed_inode = erofs_mkfs_build_packedfile();
- if (IS_ERR(packed_inode)) {
- err = PTR_ERR(packed_inode);
+ if (erofstar.index_mode || cfg.c_chunkbits || sbi.extra_devices) {
+ err = erofs_mkfs_dump_blobs(&sbi);
+ if (err)
goto exit;
- }
- sbi.packed_nid = erofs_lookupnid(packed_inode);
- erofs_iput(packed_inode);
}
/* flush all buffers except for the superblock */
--
2.39.3
More information about the Linux-erofs
mailing list