Skip to contentSkip to conversation

erofs-utils: introduce --ishare_key option for local dir to support shared page cache

PATCH New Hongbo Li 1 participant 1 message Nov 18, 2025 Library code

lore
Share & tools
lore

Hongbo Li

author
#0 lore raw

PATCH v2 1/1 erofs-utils: introduce --ishare_key option for local dir to support shared page cache

For uncoming page cache sharing feature, we provide the --ishare_key option to calculate the sha256 on content for localdir. The usage is like:
mkfs.erofs --ishare_key=trusted.erofs.fingerprint foo.img foo/

---
 include/erofs/config.h   |  1 +
 include/erofs/internal.h |  2 ++
 include/erofs/xattr.h    |  3 ++-
 include/erofs_fs.h       |  4 +++-
 lib/inode.c              |  7 ++++++
 lib/super.c              |  4 ++++
 lib/xattr.c              | 48 ++++++++++++++++++++++++++++++++++++++--
 mkfs/main.c              | 26 +++++++++++++++++-----
 8 files changed, 86 insertions(+), 9 deletions(-)
include/erofs/config.h +1 -0
index 525a8cd..dd4fa73 100644
@@ -61,6 +61,7 @@ struct erofs_configure {
 	u64 c_unix_timestamp;
 	const char *mount_point;
 	u32 c_root_xattr_isize;
+	const char *ishare_key;
 #ifdef EROFS_MT_ENABLED
 	u64 c_mkfs_segment_size;
 	u32 c_mt_workers;
include/erofs/internal.h +2 -0
index 62594b8..6d1b7b9 100644
@@ -130,6 +130,7 @@ struct erofs_sb_info {
 
 	u32 xattr_prefix_start;
 	u8 xattr_prefix_count;
+	u8 ishare_xattr_pfx;
 	struct erofs_xattr_prefix_item *xattr_prefixes;
 
 	struct erofs_vfile bdev;
@@ -189,6 +190,7 @@ EROFS_FEATURE_FUNCS(metabox, incompat, INCOMPAT_METABOX)
 EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
 EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
 EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX)
+EROFS_FEATURE_FUNCS(ishare_key, compat, COMPAT_ISHARE_KEY)
 
 #define EROFS_I_EA_INITED_BIT	0
 #define EROFS_I_Z_INITED_BIT	1
include/erofs/xattr.h +2 -1
index ef80123..c1a4205 100644
@@ -46,6 +46,7 @@ static inline unsigned int xattrblock_offset(struct erofs_inode *vi,
 struct erofs_importer;
 
 int erofs_xattr_init(struct erofs_sb_info *sbi);
+int erofs_hook_ishare_xattrs(struct erofs_inode *inode, const char *ishare_key);
 int erofs_scan_file_xattrs(struct erofs_inode *inode);
 int erofs_prepare_xattr_ibody(struct erofs_inode *inode, bool noroom);
 char *erofs_export_xattr_ibody(struct erofs_inode *inode);
@@ -56,7 +57,7 @@ void erofs_xattr_cleanup_name_prefixes(void);
 int erofs_xattr_flush_name_prefixes(struct erofs_importer *im, bool plain);
 int erofs_xattr_prefixes_init(struct erofs_sb_info *sbi);
 
-int erofs_setxattr(struct erofs_inode *inode, char *key,
+int erofs_setxattr(struct erofs_inode *inode, const 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);
include/erofs_fs.h +3 -1
index 887f37f..a379752 100644
@@ -17,6 +17,7 @@
 #define EROFS_FEATURE_COMPAT_MTIME              0x00000002
 #define EROFS_FEATURE_COMPAT_XATTR_FILTER	0x00000004
 #define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX	0x00000010
+#define EROFS_FEATURE_COMPAT_ISHARE_KEY		0x00000020
 
 /*
  * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
@@ -82,7 +83,8 @@ struct erofs_super_block {
 	__le32 xattr_prefix_start;	/* start of long xattr prefixes */
 	__le64 packed_nid;	/* nid of the special packed inode */
 	__u8 xattr_filter_reserved; /* reserved for xattr name filter */
-	__u8 reserved[3];
+	__u8 ishare_xattr_prefix_id;	/* start of ishare key */
+	__u8 reserved[2];
 	__le32 build_time;	/* seconds added to epoch for mkfs time */
 	__le64 rootnid_8b;	/* (48BIT on) nid of root directory */
 	__le64 reserved2;
lib/inode.c +7 -0
index d993c8f..92ecce7 100644
@@ -1899,6 +1899,13 @@ static int erofs_mkfs_handle_inode(struct erofs_importer *im,
 			return ret;
 	}
 
+	if (!rebuild && cfg.ishare_key &&
+	     S_ISREG(inode->i_mode) && inode->i_size) {
+		ret = erofs_hook_ishare_xattrs(inode, cfg.ishare_key);
+		if (ret < 0)
+			return ret;
+	}
+
 	if (!rebuild && !params->no_xattrs) {
 		ret = erofs_scan_file_xattrs(inode);
 		if (ret < 0)
lib/super.c +4 -0
index d626c7c..7e41ef8 100644
@@ -137,6 +137,9 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 	sbi->inos = le64_to_cpu(dsb->inos);
 	sbi->checksum = le32_to_cpu(dsb->checksum);
 
+	if (erofs_sb_has_ishare_key(sbi))
+		sbi->ishare_xattr_pfx =
+			dsb->ishare_xattr_prefix_id & EROFS_XATTR_LONG_PREFIX_MASK;
 	sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
 	sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
 	sbi->build_time = le32_to_cpu(dsb->build_time);
@@ -196,6 +199,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
 		.xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
 		.xattr_prefix_count = sbi->xattr_prefix_count,
 		.xattr_prefix_start = cpu_to_le32(sbi->xattr_prefix_start),
+		.ishare_xattr_prefix_id = sbi->ishare_xattr_pfx,
 		.feature_incompat = cpu_to_le32(sbi->feature_incompat),
 		.feature_compat = cpu_to_le32(sbi->feature_compat &
 					      ~EROFS_FEATURE_COMPAT_SB_CHKSUM),
lib/xattr.c +46 -2

78 lines not on this page · raw message

mkfs/main.c +21 -5
index 76bf843..5eb5bf8 100644
@@ -102,6 +102,7 @@ static struct option long_options[] = {
 #endif
 	{"zD", optional_argument, NULL, 536},
 	{"ZI", optional_argument, NULL, 537},
+	{"ishare_key", required_argument, NULL, 538},
 	{0, 0, 0, 0},
 };
 
@@ -1261,7 +1262,7 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 		case 19:
 			errno = 0;
 			opt = erofs_xattr_insert_name_prefix(optarg);
-			if (opt) {
+			if (opt < 0) {
 				erofs_err("failed to parse xattr name prefix: %s",
 					  erofs_strerror(opt));
 				return opt;
@@ -1421,6 +1422,18 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 			else
 				mkfscfg.inode_metazone = false;
 			break;
+		case 538:
+			opt = erofs_xattr_insert_name_prefix(optarg);
+			if (opt < 0) {
+				erofs_err("failed to parse xattr name prefix: %s",
+					  erofs_strerror(opt));
+				return opt;
+			}
+			cfg.ishare_key = optarg;
+			g_sbi.ishare_xattr_pfx = opt;
+			cfg.c_extra_ea_name_prefixes = true;
+			erofs_sb_set_ishare_key(&g_sbi);
+			break;
 		case 'V':
 			version();
 			exit(0);
@@ -1875,10 +1888,6 @@ int main(int argc, char **argv)
 			goto exit;
 		}
 
-		if (cfg.c_extra_ea_name_prefixes)
-			erofs_xattr_flush_name_prefixes(&importer,
-							mkfs_plain_xattr_pfx);
-
 		root = erofs_new_inode(&g_sbi);
 		if (IS_ERR(root)) {
 			err = PTR_ERR(root);
@@ -1965,6 +1974,13 @@ int main(int argc, char **argv)
 			goto exit;
 	}
 
+	if (cfg.c_extra_ea_name_prefixes) {
+		err = erofs_xattr_flush_name_prefixes(&importer,
+						      mkfs_plain_xattr_pfx);
+		if (err)
+			goto exit;
+	}
+
 	err = erofs_importer_flush_all(&importer);
 	if (err)
 		goto exit;
Signature · 1 line
2.22.0