erofs-utils: implement the FULLDATA rebuild mode
v2 cover erofs-utils: implement the FULLDATA rebuild mode
Currently, erofs-utils supports backing blobs for multi-image setups. This implements the FULLDATA import which allows for the merging of multiple source images into a single self-contained erofs image.
To optimize the rebuild process, erofs_copy_file_range() is used to leverage the copy_file_range(2) if available. This bypasses userspace buffering and enables kernel side data transfers.
Verification:
1. Created a source directory containing flat inodes, inline inodes, symlinks and absolute symlinks. Verified data integrity by comparing checksums of files within the mounted image.
2. Built same image with default rebuild and rebuild with FULLDATA. Then ran F-i-f/tdiff comparing the two.
changes in v2:
- reworked erofs_rebuild_load_trees_full into erofs_mkfs_rebuild_load_trees.
- removed --merge option (use --clean=data instead).
- updated man.
---
Lucas Karpinski (5):
erofs-utils: lib: pass uniaddr_offset to erofs_rebuild_load_tree
erofs-utils: lib: add helper function erofs_uuid_unparse_as_tag
erofs-utils: lib: preserve primarydevice_blocks if already larger
erofs-utils: mfks: add rebuild FULLDATA for combined EROFS images
erofs-utils: manpages: update to reflect fulldata support
lib/cache.c | 6 +++ lib/importer.c | 5 ++- lib/liberofs_cache.h | 1 + lib/liberofs_rebuild.h | 7 ++- lib/liberofs_uuid.h | 1 + lib/rebuild.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++-- lib/uuid_unparse.c | 16 ++++++- man/mkfs.erofs.1 | 7 ++- mkfs/main.c | 53 ++++++++++++++-------- 9 files changed, 185 insertions(+), 28 deletions(-)
---
PATCH v2 1/5 erofs-utils: lib: pass uniaddr_offset to erofs_rebuild_load_tree
uniaddr_offset will be needed for rebuild fulldata mode. Add a parameter to erofs_rebuild_load_tree and include it in the erofs_rebuild_dir_context struct as well.
--- lib/liberofs_rebuild.h | 3 ++- lib/rebuild.c | 5 ++++- mkfs/main.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-)
lib/liberofs_rebuild.h +2 -1
@@ -14,7 +14,8 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd, char *path, bool aufs, bool *whout, bool *opq, bool to_head);int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi, -enum erofs_rebuild_datamode mode); +enum erofs_rebuild_datamode mode, +erofs_blk_t uniaddr_offset);int erofs_rebuild_load_basedir (struct erofs_inode *dir,u64 *nr_subdirs,unsigned int *i_nlink);
lib/rebuild.c +4 -1
@@ -286,6 +286,7 @@ struct erofs_rebuild_dir_context {unsigned int *i_nlink; }; }; +erofs_blk_t uniaddr_offset;/* unified addressing offset for FULL mode */ };static int erofs_rebuild_dirent_iter (struct erofs_dir_context *ctx)
@@ -419,7 +420,8 @@ out: }int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi, -enum erofs_rebuild_datamode mode) +enum erofs_rebuild_datamode mode, +erofs_blk_t uniaddr_offset) {struct erofs_inode inode = {};struct erofs_rebuild_dir_context ctx;
@@ -452,6 +454,7 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi, .ctx.cb = erofs_rebuild_dirent_iter, .mergedir = root, .datamode = mode, + .uniaddr_offset = uniaddr_offset, }; ret =erofs_iterate_dir (&ctx.ctx, false);free (inode.i_srcpath);
mkfs/main.c +1 -1
@@ -1736,7 +1736,7 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)list_for_each_entry (src, &rebuild_src_list, list) { src->xamgr = g_sbi.xamgr; - ret =erofs_rebuild_load_tree (root, src, datamode); + ret =erofs_rebuild_load_tree (root, src, datamode,0 ); src->xamgr =NULL ;if (ret) {erofs_err ("failed to load %s" , src->devname);
Signature · 1 line
Git-155)
PATCH v2 2/5 erofs-utils: lib: add helper function erofs_uuid_unparse_as_tag
In reply to Lucas KarpinskiAdd helper function for converting uuid to tag. This will also be used in rebuild FULLDATA mode.
--- lib/liberofs_uuid.h | 1 + lib/uuid_unparse.c | 16 +++++++++++++++- mkfs/main.c | 11 +---------- 3 files changed, 17 insertions(+), 11 deletions(-)
lib/liberofs_uuid.h +1 -0
@@ -4,6 +4,7 @@void erofs_uuid_generate (unsigned char *out);void erofs_uuid_unparse_lower (const unsigned char *buf,char *out); +void erofs_uuid_unparse_as_tag (const unsigned char *buf,char *out);int erofs_uuid_parse (const char *in,unsigned char *uu);#endif
lib/uuid_unparse.c +15 -1
@@ -8,7 +8,8 @@#include "erofs/config.h" #include "liberofs_uuid.h" -void erofs_uuid_unparse_lower (const unsigned char *buf,char *out) { +void erofs_uuid_unparse_lower (const unsigned char *buf,char *out) +{ sprintf(out, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", (buf[0] << 8) | buf[1], (buf[2] << 8) | buf[3],
@@ -19,3 +20,16 @@ void erofs_uuid_unparse_lower(const unsigned char *buf, char *out) { (buf[12 ] <<8 ) | buf[13 ], (buf[14] << 8) | buf[15]); } + +void erofs_uuid_unparse_as_tag (const unsigned char *buf,char *out) +{ +sprintf (out,"%04x%04x%04x%04x%04x%04x%04x%04x" , + (buf[0 ] <<8 ) | buf[1 ], + (buf[2 ] <<8 ) | buf[3 ], + (buf[4 ] <<8 ) | buf[5 ], + (buf[6 ] <<8 ) | buf[7 ], + (buf[8 ] <<8 ) | buf[9 ], + (buf[10 ] <<8 ) | buf[11 ], + (buf[12 ] <<8 ) | buf[13 ], + (buf[14 ] <<8 ) | buf[15 ]); +}
mkfs/main.c +1 -10
@@ -1782,16 +1782,7 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)memcpy (devs[idx].tag, tag,sizeof (devs[0 ].tag)); else/* convert UUID of the source image to a hex string */ - sprintf((char *)g_sbi.devs[idx].tag, -"%04x%04x%04x%04x%04x%04x%04x%04x" , - (src->uuid[0 ] <<8 ) | src->uuid[1 ], - (src->uuid[2 ] <<8 ) | src->uuid[3 ], - (src->uuid[4 ] <<8 ) | src->uuid[5 ], - (src->uuid[6 ] <<8 ) | src->uuid[7 ], - (src->uuid[8 ] <<8 ) | src->uuid[9 ], - (src->uuid[10 ] <<8 ) | src->uuid[11 ], - (src->uuid[12 ] <<8 ) | src->uuid[13 ], - (src->uuid[14] << 8) | src->uuid[15]); + erofs_uuid_unparse_as_tag(src->uuid, (char *)g_sbi.devs[idx].tag); }return 0 ; }
Signature · 1 line
Git-155)
PATCH v2 3/5 erofs-utils: lib: preserve primarydevice_blocks if already larger
In reply to Lucas KarpinskiChange erofs_importer_flush_all() to use max(). This allows callers to pre-allocate space for data beyond the metadata region.
--- lib/importer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
lib/importer.c +3 -2
@@ -126,8 +126,9 @@ int erofs_importer_flush_all(struct erofs_importer *im) fsalignblks = im->params->fsalignblks ?roundup_pow_of_two (im->params->fsalignblks) :1 ; - sbi->primarydevice_blocks =roundup (erofs_mapbh (sbi->bmgr,NULL ), - fsalignblks); + sbi->primarydevice_blocks =max_t (erofs_blk_t, sbi->primarydevice_blocks, +roundup (erofs_mapbh (sbi->bmgr,NULL ), + fsalignblks)); err =erofs_write_device_table (sbi);if (err)return err;
Signature · 1 line
Git-155)
PATCH v2 4/5 erofs-utils: mfks: add rebuild FULLDATA for combined EROFS images
In reply to Lucas KarpinskiThis patch introduces experimental support for merging multiple source images in mkfs. Each source image becomes a directory directly under root and keeps its UUID stored as a device table tag. The raw block data from each source is copied using erofs_copy_file_range. We preserve the file metadata and layout (FLAT_PLAIN and FLAT_INLINE). Symlink paths are handled by reading and copy link targets.
This does not yet support chunk-based files at this time or compressed images.
--- lib/cache.c | 6 +++ lib/liberofs_cache.h | 1 + lib/liberofs_rebuild.h | 4 ++ lib/rebuild.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++-- mkfs/main.c | 44 ++++++++++++++----- 5 files changed, 154 insertions(+), 13 deletions(-)
lib/cache.c +6 -0
@@ -544,6 +544,12 @@ erofs_blk_t erofs_total_metablocks(struct erofs_bufmgr *bmgr)return bmgr->metablkcnt; } +void erofs_bset_tail (struct erofs_bufmgr *bmgr,erofs_blk_t blkaddr) +{ +if (blkaddr > bmgr->tail_blkaddr) + bmgr->tail_blkaddr = blkaddr; +} +void erofs_buffer_exit (struct erofs_bufmgr *bmgr) {DBG_BUGON (__erofs_bflush (bmgr,NULL , true));
lib/liberofs_cache.h +1 -0
@@ -138,6 +138,7 @@ int erofs_bflush(struct erofs_bufmgr *bmgr, struct erofs_buffer_block *bb);void erofs_bdrop (struct erofs_buffer_head *bh,bool tryrevoke); +void erofs_bset_tail (struct erofs_bufmgr *bmgr,erofs_blk_t blkaddr);void erofs_buffer_exit (struct erofs_bufmgr *bmgr);#ifdef __cplusplus
lib/liberofs_rebuild.h +4 -0
@@ -17,6 +17,10 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi,enum erofs_rebuild_datamode mode, erofs_blk_t uniaddr_offset); +int erofs_rebuild_copy_src (struct erofs_sb_info *sbi, +struct erofs_sb_info *src, +struct erofs_device_info *dev); +int erofs_rebuild_load_basedir (struct erofs_inode *dir,u64 *nr_subdirs,unsigned int *i_nlink);#endif
lib/rebuild.c +109 -3
164 lines not on this page · raw message
mkfs/main.c +34 -10
99 lines not on this page · raw message
Signature · 1 line
Git-155)
Re: [PATCH v2 4/5] erofs-utils: mfks: add rebuild FULLDATA for combined EROFS images
Hi Lucas,
Quoted 11 lines · Lucas Karpinski
This patch introduces experimental support for merging multiple source images in mkfs. Each source image becomes a directory directly under root and keeps its UUID stored as a device table tag. The raw block data from each source is copied using
erofs_copy_file_range. We preserve the file metadata and layout (FLAT_PLAINandFLAT_INLINE). Symlink paths are handled by reading and copy link targets.This does not yet support chunk-based files at this time or compressed images.
Signed-off-by Lucas Karpinski <[email protected]>
Thanks for your effort, I finally get the time to look into this new feature.
So you'd like to cleanly rebuild a new filesystem with given sub filesystems?
I think first, yes, that is what --clean=data is used instead.
But I think uniaddr shouldn't be used like this (uniaddr is used to give a flat mapping for multiple blobs, in addition to the device id + offset ones, which is mainly used for compressed data multi blob support), instead, I think we need to find a way to wrap up the data source into a valid vfile (so that erofs_pread can be called to get the source data) , and make erofs_mkfs_job_write_file() to write (un)compressed data from its source instead.
Thanks,
Gao Xiang
PATCH v2 5/5 erofs-utils: manpages: update to reflect fulldata support
In reply to Lucas KarpinskiSpecify that data (fulldata) mode is now supporting alongside rsvp when using --clean={data|rsvp}.
--- man/mkfs.erofs.1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
man/mkfs.erofs.1 +6 -1
@@ -229,7 +229,7 @@ Only \fBdata\fR is supported. \fBrvsp\fR and \fB0\fR will be ignored. Note that \fBrvsp\fR takes precedence over \fB--tar=i\fR or \fB--tar=headerball\fR. .TP .I Rebuild mode -Only \fBrvsp\fR is supported. +\fBdata\fR and \fBrvsp\fR are supported. .TP .I S3 source (\fB\-\-s3\fR) \fBdata\fR and \fB0\fR are supported.
@@ -521,6 +521,11 @@ source images, which act as external blob devices. This creates a compact metadata layer suitable for layered filesystem scenarios, similar to container image layers. .TP +.I data mode +\fB\-\-clean=data\fR: Import complete file data from all source images into +the destination image, producing a fully self-contained EROFS image that does +not depend on external blob devices. +.TP .I rvsp mode \fB\-\-clean=rvsp\fR or \fB\-\-incremental=rvsp\fR: Reserve space for file data without copying actual content, useful for creating sparse images.
Signature · 1 line
Git-155)