[PATCH v2] erofs-utils: mkfs: enable xattr name filter feature by default

Jingbo Xu jefflexu at linux.alibaba.com
Thu Aug 31 20:29:49 AEST 2023


From: Gao Xiang <hsiangkao at linux.alibaba.com>

Turn it on by default since it's a compatible feature.  Instead,
it can be disabled explicitly with "-E^xattr-name-filter".

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
changes: flush inode bhs prior to erofs_mkfs_update_super_block(),
otherwise the xattr filter feature bit may has not been set when
erofs_mkfs_update_super_block() is called.

v1: https://lore.kernel.org/all/ZO4z5%2Fl3bVC6aE+8@debian/
---
 include/erofs/xattr.h |  2 +-
 lib/inode.c           |  4 ++--
 lib/xattr.c           |  6 +++++-
 mkfs/main.c           | 19 +++++++++++++++++--
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index 748442a..cf02257 100644
--- a/include/erofs/xattr.h
+++ b/include/erofs/xattr.h
@@ -76,7 +76,7 @@ static inline unsigned int xattrblock_offset(struct erofs_inode *vi,
 
 int erofs_scan_file_xattrs(struct erofs_inode *inode);
 int erofs_prepare_xattr_ibody(struct erofs_inode *inode);
-char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int size);
+char *erofs_export_xattr_ibody(struct erofs_inode *inode);
 int erofs_build_shared_xattrs_from_path(struct erofs_sb_info *sbi, const char *path);
 
 int erofs_xattr_insert_name_prefix(const char *prefix);
diff --git a/lib/inode.c b/lib/inode.c
index d54f84f..85eacab 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -574,8 +574,8 @@ static bool erofs_bh_flush_write_inode(struct erofs_buffer_head *bh)
 	off += inode->inode_isize;
 
 	if (inode->xattr_isize) {
-		char *xattrs = erofs_export_xattr_ibody(&inode->i_xattrs,
-							inode->xattr_isize);
+		char *xattrs = erofs_export_xattr_ibody(inode);
+
 		if (IS_ERR(xattrs))
 			return false;
 
diff --git a/lib/xattr.c b/lib/xattr.c
index 65dd9a0..0cab29f 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -843,8 +843,10 @@ static u32 erofs_xattr_filter_map(struct list_head *ixattrs)
 	return EROFS_XATTR_FILTER_DEFAULT & ~name_filter;
 }
 
-char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int size)
+char *erofs_export_xattr_ibody(struct erofs_inode *inode)
 {
+	struct list_head *ixattrs = &inode->i_xattrs;
+	unsigned int size = inode->xattr_isize;
 	struct inode_xattr_node *node, *n;
 	struct erofs_xattr_ibody_header *header;
 	LIST_HEAD(ilst);
@@ -860,6 +862,8 @@ char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int size)
 	if (cfg.c_xattr_name_filter) {
 		header->h_name_filter =
 			cpu_to_le32(erofs_xattr_filter_map(ixattrs));
+		if (header->h_name_filter)
+			erofs_sb_set_xattr_filter(inode->sbi);
 	}
 
 	p = sizeof(struct erofs_xattr_ibody_header);
diff --git a/mkfs/main.c b/mkfs/main.c
index fad80b1..843a658 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -145,6 +145,7 @@ static int parse_extended_opts(const char *opts)
 
 	value = NULL;
 	for (token = opts; *token != '\0'; token = next) {
+		bool clear = false;
 		const char *p = strchr(token, ',');
 
 		next = NULL;
@@ -168,6 +169,14 @@ static int parse_extended_opts(const char *opts)
 			vallen = 0;
 		}
 
+		if (token[0] == '^') {
+			if (keylen < 2)
+				return -EINVAL;
+			++token;
+			--keylen;
+			clear = true;
+		}
+
 		if (MATCH_EXTENTED_OPT("legacy-compress", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
@@ -249,8 +258,7 @@ handle_fragment:
 		if (MATCH_EXTENTED_OPT("xattr-name-filter", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
-			cfg.c_xattr_name_filter = true;
-			erofs_sb_set_xattr_filter(&sbi);
+			cfg.c_xattr_name_filter = !clear;
 		}
 	}
 	return 0;
@@ -695,6 +703,7 @@ static void erofs_mkfs_default_options(void)
 {
 	cfg.c_showprogress = true;
 	cfg.c_legacy_compress = false;
+	cfg.c_xattr_name_filter = true;
 	sbi.blkszbits = ilog2(EROFS_MAX_BLOCK_SIZE);
 	sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_ZERO_PADDING;
 	sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
@@ -983,6 +992,12 @@ int main(int argc, char **argv)
 		erofs_iput(packed_inode);
 	}
 
+	/* flush all buffers except for the superblock */
+	if (!erofs_bflush(NULL)) {
+		err = -EIO;
+		goto exit;
+	}
+
 	err = erofs_mkfs_update_super_block(sb_bh, root_nid, &nblocks,
 					    packed_nid);
 	if (err)
-- 
2.19.1.6.gb485710b



More information about the Linux-erofs mailing list