erofs-utils: implement the FULLDATA rebuild mode
v4 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_io_xcopy() is used to leverage the copy_file_range(2) if available. This bypasses userspace buffering and enables kernel side data transfers.
Verification: Built same image with default rebuild and rebuild with FULLDATA. Then ran F-i-f/tdiff comparing the two.
changes in v4:
- fixed inline inodes.
- removed unneeded header.
- spelling mistakes & spurious new line.
changes in v3:
- adhere to uniaddress semantics.
- take advantage of existing infrastructure which allows us to drop a significant amount of complexity + code.
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 (2):
erofs-utils: mkfs: add rebuild FULLDATA for combined EROFS images
erofs-utils: manpage: update to reflect fulldata support
include/erofs/internal.h | 3 +++ lib/inode.c | 38 ++++++++++++++++++++++----- lib/rebuild.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ man/mkfs.erofs.1 | 7 ++++- mkfs/main.c | 7 +++-- 5 files changed, 114 insertions(+), 9 deletions(-)
---
base-commit: fa1aa7d3c22a3ee26956cea24156735f96ee8f9c
change-id: 20260220-merge-fs-e6231a3a3a1c
Best regards,
Signature · 1 line
Lucas Karpinski <[email protected]>
PATCH v4 1/2 erofs-utils: mkfs: add rebuild FULLDATA for combined EROFS images
Add experimental support for merging multiple source images in mkfs. Each regular file record the source image path and its byte offset. During the blob mkfs opens the blob and pulls the payload in via erofs_io_xcopy.
This does not yet support chunk-based files or compressed images.
--- include/erofs/internal.h | 3 +++ lib/inode.c | 38 ++++++++++++++++++++++----- lib/rebuild.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ mkfs/main.c | 7 +++-- 4 files changed, 108 insertions(+), 8 deletions(-)
include/erofs/internal.h +3 -0
@@ -208,6 +208,7 @@ struct erofs_diskbuf;#define EROFS_INODE_DATA_SOURCE_LOCALPATH 1#define EROFS_INODE_DATA_SOURCE_DISKBUF 2#define EROFS_INODE_DATA_SOURCE_RESVSP 3 +#define EROFS_INODE_DATA_SOURCE_REBUILD_BLOB 4#define EROFS_I_BLKADDR_DEV_ID_BIT 48
@@ -253,6 +254,8 @@ struct erofs_inode {char *i_link;struct erofs_diskbuf *i_diskbuf; }; +char *rebuild_blobpath; +erofs_off_t rebuild_src_dataoff;unsigned char datalayout;unsigned char inode_isize;/* inline tail-end packing size */
lib/inode.c +32 -6
@@ -158,6 +158,8 @@ unsigned int erofs_iput(struct erofs_inode *inode)if (inode->datasource ==EROFS_INODE_DATA_SOURCE_DISKBUF ) {erofs_diskbuf_close (inode->i_diskbuf);free (inode->i_diskbuf); + }else if (inode->datasource ==EROFS_INODE_DATA_SOURCE_REBUILD_BLOB ) { +free (inode->rebuild_blobpath); }else {free (inode->i_link); }
@@ -679,8 +681,11 @@ static int erofs_write_unencoded_data(struct erofs_inode *inode, }while (remaining); } -/* read the tail-end data */ -if (inode->idata_size) { +/* +* Read the tail-end data if inode->idata is NULL; if the tail data +* has been prepared then nothing more needs to be done here. +*/ +if (inode->idata_size && !inode->idata) { inode->idata =malloc (inode->idata_size);if (!inode->idata)return -ENOMEM ;
@@ -697,7 +702,10 @@ static int erofs_write_unencoded_data(struct erofs_inode *inode,int erofs_write_unencoded_file (struct erofs_inode *inode,int fd,u64 fpos) { -if (cfg.c_chunkbits) { +struct erofs_vfile vf = { .fd = fd }; + +if (cfg.c_chunkbits && + inode->datasource !=EROFS_INODE_DATA_SOURCE_REBUILD_BLOB ) { inode->u.chunkbits = cfg.c_chunkbits;/* chunk indexes when explicitly specified */ inode->u.chunkformat =0 ;
@@ -706,10 +714,15 @@ int erofs_write_unencoded_file(struct erofs_inode *inode, int fd, u64 fpos)return erofs_blob_write_chunked_file (inode, fd, fpos); } +if (inode->datasource ==EROFS_INODE_DATA_SOURCE_REBUILD_BLOB ) { +if (erofs_io_lseek (&vf, fpos,SEEK_SET ) != (off_t )fpos) +return -EIO ; +return erofs_write_unencoded_data (inode, &vf, fpos, true, false); + } + inode->datalayout =EROFS_INODE_FLAT_INLINE ;/* fallback to all data uncompressed */ -return erofs_write_unencoded_data (inode, - &(struct erofs_vfile ){ .fd = fd }, fpos, +return erofs_write_unencoded_data (inode, &vf, fpos, inode->datasource ==EROFS_INODE_DATA_SOURCE_DISKBUF , false); }
@@ -1508,6 +1521,12 @@ out:free (inode->i_diskbuf); inode->i_diskbuf =NULL ; inode->datasource =EROFS_INODE_DATA_SOURCE_NONE ; + }else if (inode->datasource ==EROFS_INODE_DATA_SOURCE_REBUILD_BLOB ) { +free (inode->rebuild_blobpath); + inode->rebuild_blobpath =NULL ; + inode->datasource =EROFS_INODE_DATA_SOURCE_NONE ; +DBG_BUGON (ctx->fd <0 ); +close (ctx->fd); }else {DBG_BUGON (ctx->fd <0 );close (ctx->fd);
@@ -2014,6 +2033,12 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,if (ctx.fd <0 )return -errno;break ; +case EROFS_INODE_DATA_SOURCE_REBUILD_BLOB : + ctx.fd =open (inode->rebuild_blobpath,O_RDONLY |O_BINARY ); +if (ctx.fd <0 ) +return -errno; + ctx.fpos = inode->rebuild_src_dataoff; +break ;default : goto out; }
@@ -2022,7 +2047,8 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,if (ret <0 )return ret; -if (inode->sbi->available_compr_algs && +if (inode->datasource !=EROFS_INODE_DATA_SOURCE_REBUILD_BLOB && + inode->sbi->available_compr_algs &&erofs_file_is_compressible (im, inode)) { ctx.ictx =erofs_prepare_compressed_file (im, inode);if (IS_ERR (ctx.ictx))
lib/rebuild.c +68 -0
86 lines not on this page · raw message
mkfs/main.c +5 -2
@@ -1756,7 +1756,7 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root) extra_devices += src->extra_devices; } -if (datamode !=EROFS_REBUILD_DATA_BLOB_INDEX ) +if (datamode ==EROFS_REBUILD_DATA_RESVSP )return 0 ;/* Each blob has either no extra device or only one device for TarFS */
@@ -1766,6 +1766,9 @@ static int erofs_mkfs_rebuild_load_trees(struct erofs_inode *root)return -EOPNOTSUPP ; } +if (datamode ==EROFS_REBUILD_DATA_FULL ) +return 0 ; + ret =erofs_mkfs_init_devices (&g_sbi, rebuild_src_count);if (ret)return ret;
@@ -1788,7 +1791,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 */ - erofs_uuid_unparse_as_tag(src->uuid, (char *)g_sbi.devs[idx].tag); + erofs_uuid_unparse_as_tag(src->uuid, (char *)devs[idx].tag); }return 0 ; }
Signature · 1 line
Git-155)
PATCH v4 2/2 erofs-utils: manpage: update to reflect fulldata support
In reply to Lucas KarpinskiSpecify that data (fulldata) mode are now supported alongside rvsp when using --clean={data|rvsp}.
--- 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)