Add `--ovlfs-strip=[0|1]` option for tarfs and rebuild mode for now
in order to control whether some overlayfs related stuffs (e.g.
whiteout files, OVL_XATTR_OPAQUE and OVL_XATTR_ORIGIN xattrs) are
finally stripped.
This option is disabled by default for mkfs, that is, the overlayfs
related stuffs described above are kept in the image by default.
Specify `--ovlfs-strip=1` explicitly to strip these stuffs.
Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230913120304.15741-9-jefflexu@linux.alibaba.com
bool c_showprogress;
bool c_extra_ea_name_prefixes;
bool c_xattr_name_filter;
+ bool c_ovlfs_strip;
#ifdef HAVE_LIBSELINUX
struct selabel_handle *sehnd;
int erofs_setxattr(struct erofs_inode *inode, char *key,
const void *value, size_t size);
int erofs_set_opaque_xattr(struct erofs_inode *inode);
+void erofs_clear_opaque_xattr(struct erofs_inode *inode);
int erofs_set_origin_xattr(struct erofs_inode *inode);
int erofs_read_xattrs_from_disk(struct erofs_inode *inode);
int erofs_rebuild_dump_tree(struct erofs_inode *dir)
{
- struct erofs_dentry *d;
+ struct erofs_dentry *d, *n;
unsigned int nr_subdirs;
int ret;
dir->inode_isize = sizeof(struct erofs_inode_compact);
}
- if (dir->whiteouts)
+ /* strip all unnecessary overlayfs xattrs when ovlfs_strip is enabled */
+ if (cfg.c_ovlfs_strip)
+ erofs_clear_opaque_xattr(dir);
+ else if (dir->whiteouts)
erofs_set_origin_xattr(dir);
ret = erofs_prepare_xattr_ibody(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_ovlfs_strip && erofs_inode_is_whiteout(d->inode)) {
+ erofs_dbg("remove 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)
return erofs_xattr_add(&inode->i_xattrs, item);
}
+static void erofs_removexattr(struct erofs_inode *inode, const char *key)
+{
+ struct inode_xattr_node *node, *n;
+
+ list_for_each_entry_safe(node, n, &inode->i_xattrs, list) {
+ if (!strcmp(node->item->kvbuf, key)) {
+ list_del(&node->list);
+ put_xattritem(node->item);
+ free(node);
+ }
+ }
+}
+
int erofs_set_opaque_xattr(struct erofs_inode *inode)
{
return erofs_setxattr(inode, OVL_XATTR_OPAQUE, "y", 1);
}
+void erofs_clear_opaque_xattr(struct erofs_inode *inode)
+{
+ erofs_removexattr(inode, OVL_XATTR_OPAQUE);
+}
+
int erofs_set_origin_xattr(struct erofs_inode *inode)
{
return erofs_setxattr(inode, OVL_XATTR_ORIGIN, NULL, 0);
{"fs-config-file", required_argument, NULL, 514},
{"block-list-file", required_argument, NULL, 515},
#endif
+ {"ovlfs-strip", optional_argument, NULL, 516},
{0, 0, 0, 0},
};
" --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"
+ " --ovlfs-strip=[01] strip overlayfs metadata in the target image (e.g. whiteouts)\n"
" --quiet quiet execution (do not write anything to standard output.)\n"
#ifndef NDEBUG
" --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n"
case 21:
erofstar.aufs = true;
break;
+ case 516:
+ if (!optarg || !strcmp(optarg, "1"))
+ cfg.c_ovlfs_strip = true;
+ else
+ cfg.c_ovlfs_strip = false;
+ break;
case 1:
usage();
exit(0);