[PATCH 1/3] erofs-utils: lib: introduce erofs_importer_flush_all()
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Aug 20 15:38:04 AEST 2025
As a new formal API for external users, it flushes all dirty metadata
except the superblock.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs/cache.h | 1 +
include/erofs/importer.h | 2 ++
lib/importer.c | 39 +++++++++++++++++++++++++++++++++++++++
mkfs/main.c | 29 ++---------------------------
4 files changed, 44 insertions(+), 27 deletions(-)
diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index d5618c0..c248b73 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -13,6 +13,7 @@ extern "C"
{
#endif
+#include <stdlib.h>
#include "internal.h"
struct erofs_buffer_head;
diff --git a/include/erofs/importer.h b/include/erofs/importer.h
index e83c3e3..28d29bd 100644
--- a/include/erofs/importer.h
+++ b/include/erofs/importer.h
@@ -19,6 +19,7 @@ struct erofs_importer_params {
u32 fixed_gid;
u32 uid_offset;
u32 gid_offset;
+ u32 fsalignblks;
bool no_datainline;
bool hard_dereference;
bool ovlfs_strip;
@@ -33,6 +34,7 @@ struct erofs_importer {
void erofs_importer_preset(struct erofs_importer_params *params);
int erofs_importer_init(struct erofs_importer *im);
+int erofs_importer_flush_all(struct erofs_importer *im);
void erofs_importer_exit(struct erofs_importer *im);
#ifdef __cplusplus
diff --git a/lib/importer.c b/lib/importer.c
index 8e86993..a65fa39 100644
--- a/lib/importer.c
+++ b/lib/importer.c
@@ -4,6 +4,7 @@
*/
#include "erofs/fragments.h"
#include "erofs/importer.h"
+#include "erofs/cache.h"
#include "erofs/config.h"
#include "erofs/dedupe.h"
#include "erofs/inode.h"
@@ -19,6 +20,7 @@ void erofs_importer_preset(struct erofs_importer_params *params)
*params = (struct erofs_importer_params) {
.fixed_uid = -1,
.fixed_gid = -1,
+ .fsalignblks = 1,
};
}
@@ -72,6 +74,43 @@ out_err:
return err;
}
+int erofs_importer_flush_all(struct erofs_importer *im)
+{
+ struct erofs_sb_info *sbi = im->sbi;
+ unsigned int fsalignblks;
+ int err;
+
+ if (erofs_sb_has_metabox(sbi)) {
+ erofs_update_progressinfo("Handling metabox ...");
+ err = erofs_metabox_iflush(im);
+ if (err)
+ return err;
+ }
+
+ if ((cfg.c_fragments || cfg.c_extra_ea_name_prefixes) &&
+ erofs_sb_has_fragments(sbi)) {
+ erofs_update_progressinfo("Handling packed data ...");
+ err = erofs_flush_packed_inode(im);
+ if (err)
+ return err;
+ }
+
+ fsalignblks = im->params->fsalignblks ?
+ roundup_pow_of_two(im->params->fsalignblks) : 1;
+ sbi->primarydevice_blocks = roundup(erofs_mapbh(sbi->bmgr, NULL),
+ fsalignblks);
+ err = erofs_write_device_table(sbi);
+ if (err)
+ return err;
+
+ /* flush all buffers except for the superblock */
+ err = erofs_bflush(sbi->bmgr, NULL);
+ if (err)
+ return err;
+
+ return erofs_fixup_root_inode(im->root);
+}
+
void erofs_importer_exit(struct erofs_importer *im)
{
struct erofs_sb_info *sbi = im->sbi;
diff --git a/mkfs/main.c b/mkfs/main.c
index a11134e..0a8f477 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -281,7 +281,6 @@ static LIST_HEAD(rebuild_src_list);
static u8 fixeduuid[16];
static bool valid_fixeduuid;
static unsigned int dsunit;
-static unsigned int fsalignblks = 1;
static int tarerofs_decoder;
static FILE *vmdk_dcf;
@@ -1203,7 +1202,7 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
break;
#endif
case 531:
- fsalignblks = strtoul(optarg, &endptr, 0);
+ params->fsalignblks = strtoul(optarg, &endptr, 0);
if (*endptr != '\0') {
erofs_err("invalid fsalignblks %s", optarg);
return -EINVAL;
@@ -1760,39 +1759,15 @@ int main(int argc, char **argv)
}
}
- if (erofs_sb_has_metabox(&g_sbi)) {
- erofs_update_progressinfo("Handling metabox ...");
- erofs_metabox_iflush(&importer);
- if (err)
- goto exit;
- }
-
- if ((cfg.c_fragments || cfg.c_extra_ea_name_prefixes) &&
- erofs_sb_has_fragments(&g_sbi)) {
- erofs_update_progressinfo("Handling packed data ...");
- err = erofs_flush_packed_inode(&importer);
- if (err)
- goto exit;
- }
-
if (erofstar.index_mode || cfg.c_chunkbits || g_sbi.extra_devices) {
err = erofs_mkfs_dump_blobs(&g_sbi);
if (err)
goto exit;
}
- g_sbi.primarydevice_blocks =
- roundup(erofs_mapbh(g_sbi.bmgr, NULL), fsalignblks);
- err = erofs_write_device_table(&g_sbi);
- if (err)
- goto exit;
-
- /* flush all buffers except for the superblock */
- err = erofs_bflush(g_sbi.bmgr, NULL);
+ err = erofs_importer_flush_all(&importer);
if (err)
goto exit;
-
- erofs_fixup_root_inode(root);
erofs_iput(root);
root = NULL;
--
2.43.5
More information about the Linux-erofs
mailing list