erofs-utils: mkfs: fix incremental builds with 48-bit layout
PATCH 1/3 erofs-utils: mkfs: fix incremental builds with 48-bit layout
Fix erofs_lookupnid() because the root inode can be relocated in the 48-bit layout.
Fixes d41a717721a2 ("erofs-utils: mkfs: support 48-bit block addressing for unencoded inodes")
Signed-off-by Gao Xiang <[email protected]>
--- lib/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/inode.c +1 -1
@@ -414,7 +414,7 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode)if (__erofs_unlikely (IS_ROOT (inode))) {if (inode->in_metabox)DBG_BUGON (!erofs_sb_has_48bit (sbi)); -else if (inode->nid >0xffff ) +else if (!erofs_sb_has_48bit (sbi) && inode->nid >0xffff )return sbi->root_nid; }return inode->nid;
Signature · 1 line
2.43.5
PATCH 2/3 erofs-utils: lib: unexport "erofs/rebuild.h"
Disallow external users to use those unstable APIs for now.
Signed-off-by Gao Xiang <[email protected]>
--- lib/Makefile.am | 2 +- lib/inode.c | 3 +-- include/erofs/rebuild.h => lib/liberofs_rebuild.h | 15 ++++----------- lib/rebuild.c | 2 +- lib/remotes/s3.c | 2 +- lib/tar.c | 2 +- mkfs/main.c | 2 +- 7 files changed, 10 insertions(+), 18 deletions(-) rename include/erofs/rebuild.h => lib/liberofs_rebuild.h (73%)
lib/Makefile.am +1 -1
@@ -24,12 +24,12 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/xattr.h \ $(top_srcdir)/include/erofs/compress_hints.h \ $(top_srcdir)/include/erofs/fragments.h \ - $(top_srcdir)/include/erofs/rebuild.h \ $(top_srcdir)/include/erofs/importer.h \ $(top_srcdir)/lib/liberofs_base64.h \ $(top_srcdir)/lib/liberofs_cache.h \ $(top_srcdir)/lib/liberofs_compress.h \ $(top_srcdir)/lib/liberofs_private.h \ + $(top_srcdir)/lib/liberofs_rebuild.h \ $(top_srcdir)/lib/liberofs_xxhash.h \ $(top_srcdir)/lib/liberofs_gzran.h \ $(top_srcdir)/lib/liberofs_metabox.h \
lib/inode.c +1 -2
@@ -30,6 +30,7 @@#include "liberofs_compress.h" #include "liberofs_private.h" #include "liberofs_metabox.h" +#include "liberofs_rebuild.h" static inline bool erofs_is_special_identifier (const char *path) {
@@ -1684,8 +1685,6 @@ err_closedir:return ret; } -int erofs_rebuild_load_basedir (struct erofs_inode *dir); -bool erofs_dentry_is_wht (struct erofs_sb_info *sbi,struct erofs_dentry *d) {if (!d->validnid)
lib/liberofs_rebuild.h renamed from include/erofs/rebuild.h +4 -11
@@ -1,13 +1,8 @@/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ -#ifndef __EROFS_REBUILD_H -#define __EROFS_REBUILD_H +#ifndef __EROFS_LIB_LIBEROFS_REBUILD_H +#define __EROFS_LIB_LIBEROFS_REBUILD_H -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "internal.h" +#include "erofs/internal.h" enum erofs_rebuild_datamode { EROFS_REBUILD_DATA_BLOB_INDEX,
@@ -21,8 +16,6 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi,enum erofs_rebuild_datamode mode); -#ifdef __cplusplus -} -#endif +int erofs_rebuild_load_basedir (struct erofs_inode *dir);#endif
lib/rebuild.c +1 -1
@@ -10,11 +10,11 @@#endif #include "erofs/print.h" #include "erofs/inode.h" -#include "erofs/rebuild.h" #include "erofs/dir.h" #include "erofs/xattr.h" #include "erofs/blobchunk.h" #include "erofs/internal.h" +#include "liberofs_rebuild.h" #include "liberofs_uuid.h" #ifdef HAVE_LINUX_AUFS_TYPE_H
lib/remotes/s3.c +1 -1
@@ -16,8 +16,8 @@#include "erofs/inode.h" #include "erofs/blobchunk.h" #include "erofs/diskbuf.h" -#include "erofs/rebuild.h" #include "erofs/importer.h" +#include "liberofs_rebuild.h" #include "liberofs_s3.h" #define S3EROFS_PATH_MAX 1024
lib/tar.c +1 -1
@@ -10,7 +10,6 @@#include "erofs/tar.h" #include "erofs/xattr.h" #include "erofs/blobchunk.h" -#include "erofs/rebuild.h" #include "erofs/importer.h" #if defined(HAVE_ZLIB )#include <zlib.h>
@@ -18,6 +17,7 @@#include "liberofs_base64.h" #include "liberofs_cache.h" #include "liberofs_gzran.h" +#include "liberofs_rebuild.h" /* This file is a tape/volume header. Ignore it on extraction. */ #define GNUTYPE_VOLHDR 'V'
mkfs/main.c +1 -1
@@ -26,12 +26,12 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" #include "erofs/fragments.h" -#include "erofs/rebuild.h" #include "../lib/compressor.h" #include "../lib/liberofs_gzran.h" #include "../lib/liberofs_metabox.h" #include "../lib/liberofs_oci.h" #include "../lib/liberofs_private.h" +#include "../lib/liberofs_rebuild.h" #include "../lib/liberofs_s3.h" #include "../lib/liberofs_uuid.h"
Signature · 1 line
2.43.5
PATCH 3/3 erofs-utils: mkfs: enable incremental builds for local files
In reply to Gao XiangEROFS supports incremental-style builds without rewriting the entire filesystem metadata, since it does not have classic centralized inode tables or SquashFS-style directory tables.
This commit adds incremental build support for local files:
$ mkfs.erofs foo.erofs layer0/ $ mkfs.erofs --incremental=data foo.erofs layer1/ ...
OverlayFS whiteouts are supported for replacing specific directory entries. Additionally, these extra whiteouts can be dropped from the final image using --ovlfs-strip
Signed-off-by Gao Xiang <[email protected]>
--- lib/inode.c | 54 +++++++++++++++++++++++++++--------------- lib/liberofs_rebuild.h | 4 ++-- lib/rebuild.c | 26 +++++++++++++------- mkfs/main.c | 1 - 4 files changed, 54 insertions(+), 31 deletions(-)
lib/inode.c +35 -19
@@ -1294,6 +1294,7 @@ struct erofs_inode *erofs_new_inode(struct erofs_sb_info *sbi)static struct erofs_inode *erofs_iget_from_local (struct erofs_importer *im,const char *path) { +const struct erofs_importer_params *params = im->params;struct erofs_sb_info *sbi = im->sbi;struct erofs_inode *inode;struct stat st;
@@ -1308,7 +1309,7 @@ static struct erofs_inode *erofs_iget_from_local(struct erofs_importer *im,* hard-link, just return it. Also don't lookup for directories * since hard-link directory isn't allowed. */ -if (!S_ISDIR (st.st_mode) && !im->params->hard_dereference) { +if (!S_ISDIR (st.st_mode) && !params->hard_dereference) { inode =erofs_iget (st.st_dev, st.st_ino);if (inode)return inode;
@@ -1669,6 +1670,8 @@ static int erofs_mkfs_import_localdir(struct erofs_importer *im, struct erofs_in ret =PTR_ERR (inode); goto err_closedir; } +if (!dir->whiteouts &&erofs_inode_is_whiteout (inode)) + dir->whiteouts = true; d->inode = inode; d->type =erofs_mode_to_ftype (inode->i_mode); __nlink +=S_ISDIR (inode->i_mode);
@@ -1712,16 +1715,15 @@ static void erofs_dentry_kill(struct erofs_dentry *d)free (d); } -static int erofs_mkfs_handle_directory (struct erofs_importer *im, -struct erofs_inode *dir, -bool rebuild, -bool incremental) +static int erofs_prepare_dir_inode (struct erofs_importer *im, +struct erofs_inode *dir, +bool rebuild, +bool incremental) {struct erofs_sb_info *sbi = im->sbi;struct erofs_dentry *d, *n;unsigned int i_nlink;u64 nr_subdirs; -bool delwht = im->params->ovlfs_strip && dir->whiteouts;int ret; nr_subdirs =0 ;
@@ -1733,11 +1735,6 @@ static int erofs_mkfs_handle_directory(struct erofs_importer *im,erofs_dentry_kill (d);continue ; } -if (delwht &&erofs_dentry_is_wht (sbi, d)) { -erofs_dbg ("remove whiteout %s" , d->inode->i_srcpath); -erofs_dentry_kill (d); -continue ; - } i_nlink += (d->type ==EROFS_FT_DIR ); ++nr_subdirs; }
@@ -1749,6 +1746,22 @@ static int erofs_mkfs_handle_directory(struct erofs_importer *im,return ret; } +if (incremental && dir->dev == sbi->dev && !dir->opaque) { + ret =erofs_rebuild_load_basedir (dir, &nr_subdirs, &i_nlink); +if (ret) +return ret; + } +if (im->params->ovlfs_strip && dir->whiteouts) { +list_for_each_entry_safe (d, n, &dir->i_subdirs, d_child) { +if (erofs_dentry_is_wht (sbi, d)) { +erofs_dbg ("remove whiteout %s" , + d->inode->i_srcpath); +erofs_dentry_kill (d); + --nr_subdirs; +continue ; + } + } + }DBG_BUGON (nr_subdirs +2 < i_nlink); ret =erofs_prepare_dir_file (im, dir, nr_subdirs);if (ret)
@@ -1769,8 +1782,7 @@ static int erofs_mkfs_handle_directory(struct erofs_importer *im,else dir->i_nlink =1 ; } - -return erofs_mkfs_go (im,EROFS_MKFS_JOB_DIR , &dir,sizeof (dir)); +return 0 ; } static int erofs_mkfs_begin_nondirectory(struct erofs_importer *im,
@@ -1830,10 +1842,9 @@ static int erofs_mkfs_handle_inode(struct erofs_importer *im, inode->inode_isize =sizeof (struct erofs_inode_compact ); } -if (incremental &&S_ISDIR (inode->i_mode) && - inode->dev == inode->sbi->dev && !inode->opaque) { - ret =erofs_rebuild_load_basedir (inode); -if (ret) +if (S_ISDIR (inode->i_mode)) { + ret =erofs_prepare_dir_inode (im, inode, rebuild, incremental); +if (ret <0 )return ret; }
@@ -1856,8 +1867,8 @@ static int erofs_mkfs_handle_inode(struct erofs_importer *im,if (!S_ISDIR (inode->i_mode)) { ret =erofs_mkfs_begin_nondirectory (im, inode); }else { - ret =erofs_mkfs_handle_directory (im, inode, - rebuild, incremental); + ret =erofs_mkfs_go (im,EROFS_MKFS_JOB_DIR , &inode, +sizeof (inode)); }erofs_info ("file %s dumped (mode %05o)" , *relpath ? relpath :"/" , inode->i_mode);
@@ -2071,6 +2082,11 @@ fail:int erofs_importer_load_tree (struct erofs_importer *im,bool rebuild,bool incremental) { +if (__erofs_unlikely (incremental &&erofs_sb_has_metabox (im->sbi))) { +erofs_err ("Metadata-compressed filesystems don't support incremental builds for now" ); +return -EOPNOTSUPP ; + } + return erofs_mkfs_build_tree(&((struct erofs_mkfs_buildtree_ctx) { .im = im, .rebuild = rebuild,
lib/liberofs_rebuild.h +2 -2
@@ -16,6 +16,6 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,int erofs_rebuild_load_tree (struct erofs_inode *root,struct erofs_sb_info *sbi,enum erofs_rebuild_datamode mode); -int erofs_rebuild_load_basedir (struct erofs_inode *dir); - +int erofs_rebuild_load_basedir (struct erofs_inode *dir,u64 *nr_subdirs, +unsigned int *i_nlink);#endif
lib/rebuild.c +17 -9
@@ -274,15 +274,18 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,return err; } -/* -* @mergedir: parent directory in the merged tree -* @ctx.dir: parent directory when itering erofs_iterate_dir() -* @datamode: indicate how to import inode data -*/ struct erofs_rebuild_dir_context { +/* @ctx.dir: parent directory when itering erofs_iterate_dir() */ struct erofs_dir_context ctx; -struct erofs_inode *mergedir; -enum erofs_rebuild_datamode datamode; +struct erofs_inode *mergedir;/* parent directory in the merged tree */ +union { +/* indicate how to import inode data */ +enum erofs_rebuild_datamode datamode; +struct { +u64 *nr_subdirs; +unsigned int *i_nlink; + }; + }; };static int erofs_rebuild_dirent_iter (struct erofs_dir_context *ctx)
@@ -458,8 +461,8 @@ int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi,static int erofs_rebuild_basedir_dirent_iter (struct erofs_dir_context *ctx) {struct erofs_rebuild_dir_context *rctx = (void *)ctx; -struct erofs_inode *dir = ctx->dir;struct erofs_inode *mergedir = rctx->mergedir; +struct erofs_inode *dir = ctx->dir;struct erofs_dentry *d;char *dname;bool dumb;
@@ -484,6 +487,8 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx) d->validnid = true;if (!mergedir->whiteouts &&erofs_dentry_is_wht (dir->sbi, d)) mergedir->whiteouts = true; + *rctx->i_nlink += (ctx->de_ftype ==EROFS_FT_DIR ); + ++*rctx->nr_subdirs; }else if (__erofs_unlikely (d->validnid)) {/* The base image appears to be corrupted */ DBG_BUGON (1 );
@@ -508,7 +513,8 @@ out:return ret; } -int erofs_rebuild_load_basedir (struct erofs_inode *dir) +int erofs_rebuild_load_basedir (struct erofs_inode *dir,u64 *nr_subdirs, +unsigned int *i_nlink) {struct erofs_inode fakeinode = { .sbi = dir->sbi,
@@ -540,6 +546,8 @@ int erofs_rebuild_load_basedir(struct erofs_inode *dir) .ctx.dir = &fakeinode, .ctx.cb = erofs_rebuild_basedir_dirent_iter, .mergedir = dir, + .nr_subdirs = nr_subdirs, + .i_nlink = i_nlink, };return erofs_iterate_dir (&ctx.ctx, false); }
mkfs/main.c +0 -1
@@ -1835,7 +1835,6 @@ int main(int argc, char **argv) err =PTR_ERR (root); goto exit; } - incremental_mode = false; }else { root =erofs_rebuild_make_root (&g_sbi);if (IS_ERR (root)) {
Signature · 1 line
2.43.5