From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: hsiangkao@linux.alibaba.com, linux-erofs@lists.ozlabs.org
Subject: [PATCH v8 8/8] erofs-utils: mkfs: add `--ovlfs-strip` option
Date: Wed, 13 Sep 2023 20:03:03 +0800 [thread overview]
Message-ID: <20230913120304.15741-9-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230913120304.15741-1-jefflexu@linux.alibaba.com>
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>
---
include/erofs/config.h | 1 +
include/erofs/xattr.h | 1 +
lib/inode.c | 17 ++++++++++++++---
lib/xattr.c | 18 ++++++++++++++++++
mkfs/main.c | 8 ++++++++
5 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 5d3bfba..e342722 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_ovlfs_strip;
#ifdef HAVE_LIBSELINUX
struct selabel_handle *sehnd;
diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index 0364f24..0f76037 100644
--- a/include/erofs/xattr.h
+++ b/include/erofs/xattr.h
@@ -57,6 +57,7 @@ int erofs_xattr_prefixes_init(struct erofs_sb_info *sbi);
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);
diff --git a/lib/inode.c b/lib/inode.c
index 93e6b23..37aa79e 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;
@@ -1341,7 +1341,10 @@ int erofs_rebuild_dump_tree(struct erofs_inode *dir)
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);
@@ -1373,8 +1376,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_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)
diff --git a/lib/xattr.c b/lib/xattr.c
index e3a1b44..fffccb4 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -499,11 +499,29 @@ int erofs_setxattr(struct erofs_inode *inode, char *key,
return erofs_xattr_add(&inode->i_xattrs, item);
}
+static void erofs_clearxattr(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_clearxattr(inode, OVL_XATTR_OPAQUE);
+}
+
int erofs_set_origin_xattr(struct erofs_inode *inode)
{
return erofs_setxattr(inode, OVL_XATTR_ORIGIN, NULL, 0);
diff --git a/mkfs/main.c b/mkfs/main.c
index ce2b0e2..389bb1b 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -64,6 +64,7 @@ static struct option long_options[] = {
{"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},
};
@@ -115,6 +116,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"
+ " --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"
@@ -516,6 +518,12 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
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);
--
2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-09-13 12:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 12:02 [PATCH v8 0/8] erofs-utils: mkfs: introduce rebuild mode Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 1/8] erofs-utils: lib: add list_splice_tail() helper Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 2/8] erofs-utils: lib: make erofs_get_unhashed_chunk() global Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 3/8] erofs-utils: lib: add erofs_read_xattrs_from_disk() helper Jingbo Xu
2023-09-13 12:02 ` [PATCH v8 4/8] erofs-utils: lib: add erofs_insert_ihash() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 5/8] erofs-utils: lib: add erofs_rebuild_get_dentry() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 6/8] erofs-utils: lib: add erofs_rebuild_load_tree() helper Jingbo Xu
2023-09-13 12:03 ` [PATCH v8 7/8] erofs-utils: mkfs: introduce rebuild mode Jingbo Xu
2023-09-14 7:49 ` Gao Xiang
2023-09-13 12:03 ` Jingbo Xu [this message]
2023-09-13 13:47 ` [PATCH v8 8/8] erofs-utils: mkfs: add `--ovlfs-strip` option Gao Xiang
2023-09-13 12:03 ` [PATCH v3] erofs-utils: lib: refactor extended attribute name prefixes Jingbo Xu
2023-09-13 12:13 ` Jingbo Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230913120304.15741-9-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.