[PATCH v6 11/11] erofs-utils: mkfs: add --overlay-strip option for tarfs and rebuild mode
Jingbo Xu
jefflexu at linux.alibaba.com
Tue Sep 5 20:02:27 AEST 2023
Add "--overlay-strip=[0|1]" option for tarfs and rebuild mode,
controlling whether overlayfs related stuff, e.g. whiteout files and
origin xattrs, are stripped from the generated image.
This option is disabled by default for both tarfs and rebuild mode, that
is, whiteout files and origin xattrs are kept in the image by default.
Specify "--overlay-strip=1" explicitly to strip these stuff.
Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
include/erofs/config.h | 1 +
lib/inode.c | 12 ++++++++++--
lib/rebuild.c | 10 ++++++----
lib/tar.c | 16 +++++++++-------
lib/xattr.c | 5 +++++
mkfs/main.c | 12 ++++++++++++
6 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index c51f0cd..f244607 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -54,6 +54,7 @@ struct erofs_configure {
bool c_showprogress;
bool c_extra_ea_name_prefixes;
bool c_xattr_name_filter;
+ bool c_overlay_strip;
#ifdef HAVE_LIBSELINUX
struct selabel_handle *sehnd;
diff --git a/lib/inode.c b/lib/inode.c
index 7e5d464..42a4c2f 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1326,7 +1326,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name)
int erofs_rebuild_dump_tree(struct erofs_inode *dir)
{
- struct erofs_dentry *d;
+ struct erofs_dentry *d, *n;
unsigned int nr_subdirs;
int ret;
@@ -1370,8 +1370,16 @@ int erofs_rebuild_dump_tree(struct erofs_inode *dir)
}
nr_subdirs = 0;
- list_for_each_entry(d, &dir->i_subdirs, d_child)
+ list_for_each_entry_safe(d, n, &dir->i_subdirs, d_child) {
+ if (cfg.c_overlay_strip && erofs_inode_is_whiteout(d->inode)) {
+ erofs_dbg("strip whiteout %s", d->inode->i_srcpath);
+ list_del(&d->d_child);
+ erofs_d_invalidate(d);
+ free(d);
+ continue;
+ }
++nr_subdirs;
+ }
ret = erofs_prepare_dir_layout(dir, nr_subdirs);
if (ret)
diff --git a/lib/rebuild.c b/lib/rebuild.c
index b254dea..1d8c7bc 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -200,10 +200,12 @@ static int erofs_rebuild_fill_inode(struct erofs_inode *inode)
switch (inode->i_mode & S_IFMT) {
case S_IFCHR:
- if (erofs_inode_is_whiteout(inode)) {
- ret = erofs_set_origin_xattr(inode->i_parent);
- if (ret)
- break;
+ if (!cfg.c_overlay_strip) {
+ if (erofs_inode_is_whiteout(inode)) {
+ ret = erofs_set_origin_xattr(inode->i_parent);
+ if (ret)
+ break;
+ }
}
/* fallthrough */
case S_IFBLK:
diff --git a/lib/tar.c b/lib/tar.c
index b75b723..3389bf6 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -740,13 +740,15 @@ new_inode:
inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFCHR;
inode->u.i_rdev = EROFS_WHITEOUT_DEV;
d->type = EROFS_FT_CHRDEV;
- /*
- * Mark parent directory as copied-up to avoid exposing
- * whiteouts in the overlayfs mount.
- */
- ret = erofs_set_origin_xattr(inode->i_parent);
- if (ret)
- goto out;
+ if (!cfg.c_overlay_strip) {
+ /*
+ * Mark parent directory as copied-up to avoid exposing
+ * whiteouts in the overlayfs mount.
+ */
+ ret = erofs_set_origin_xattr(inode->i_parent);
+ if (ret)
+ goto out;
+ }
} else {
inode->i_mode = st.st_mode;
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode))
diff --git a/lib/xattr.c b/lib/xattr.c
index feafe96..d7f4e3a 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -601,6 +601,11 @@ int erofs_read_xattrs_from_disk(struct erofs_inode *inode)
inode->opaque = true;
}
+ if (cfg.c_overlay_strip && !strcmp(key, OVL_XATTR_ORIGIN)) {
+ ret = 0;
+ continue;
+ }
+
ret = erofs_getxattr(inode, key, NULL, 0);
if (ret < 0)
goto out;
diff --git a/mkfs/main.c b/mkfs/main.c
index b51ef37..4af07f2 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -57,6 +57,7 @@ static struct option long_options[] = {
{"gid-offset", required_argument, NULL, 17},
{"tar", optional_argument, NULL, 20},
{"aufs", no_argument, NULL, 21},
+ {"overlay-strip", required_argument, NULL, 22},
{"mount-point", required_argument, NULL, 512},
{"xattr-prefix", required_argument, NULL, 19},
#ifdef WITH_ANDROID
@@ -121,6 +122,7 @@ static void usage(void)
" --preserve-mtime keep per-file modification time strictly\n"
" --aufs replace aufs special files with overlayfs metadata\n"
" --tar=[fi] generate an image from tarball(s)\n"
+ " --overlay-strip=[01] strip overlayfs stuff e.g. whiteout in tarfs or rebuild mode\n"
" --quiet quiet execution (do not write anything to standard output.)\n"
#ifndef NDEBUG
" --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n"
@@ -538,6 +540,16 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
case 21:
erofstar.aufs = true;
break;
+ case 22:
+ if (!strcmp(optarg, "0"))
+ cfg.c_overlay_strip = false;
+ else if (!strcmp(optarg, "1"))
+ cfg.c_overlay_strip = true;
+ else {
+ erofs_err("invalid overlay-strip %s", optarg);
+ return -EINVAL;
+ }
+ break;
case 1:
usage();
exit(0);
--
2.19.1.6.gb485710b
More information about the Linux-erofs
mailing list