erofs-utils: lib: export packedfile APIs
PATCH v2 1/3 erofs-utils: lib: export packedfile APIs
Later packed_inode will be used in other scenarios other than compressed fragments. Let's separate packedfile APIs for future use.
--- include/erofs/fragments.h | 13 ++++++++----- lib/fragments.c | 24 ++++++++++-------------- mkfs/main.c | 14 +++++++++++--- 3 files changed, 29 insertions(+), 22 deletions(-)
include/erofs/fragments.h +8 -5
@@ -12,17 +12,20 @@ extern "C"#include "erofs/internal.h" -extern const char *frags_packedname; -#define EROFS_PACKED_INODE frags_packedname +extern const char *erofs_frags_packedname; +#define EROFS_PACKED_INODE erofs_frags_packedname + +FILE *erofs_packedfile_init (void ); +void erofs_packedfile_exit (void ); +struct erofs_inode *erofs_mkfs_build_packedfile (void );int z_erofs_fragments_dedupe (struct erofs_inode *inode,int fd,u32 *tofcrc);int z_erofs_pack_file_from_fd (struct erofs_inode *inode,int fd,u32 tofcrc);int z_erofs_pack_fragments (struct erofs_inode *inode,void *data,unsigned int len,u32 tofcrc);void z_erofs_fragments_commit (struct erofs_inode *inode); -struct erofs_inode *erofs_mkfs_build_fragments (void ); -int erofs_fragments_init (void ); -void erofs_fragments_exit (void ); +int z_erofs_fragments_init (void ); +void z_erofs_fragments_exit (void ); #ifdef __cplusplus }
lib/fragments.c +10 -14
@@ -38,9 +38,8 @@ struct erofs_fragment_dedupe_item {#define FRAGMENT_HASH (c) ((c) & (FRAGMENT_HASHSIZE - 1))static struct list_head dupli_frags[FRAGMENT_HASHSIZE ]; -static FILE *packedfile; -const char *frags_packedname ="packed_file" ; +const char *erofs_frags_packedname ="packed_file" ;#ifndef HAVE_LSEEK64 #define erofs_lseek64 lseek
@@ -195,15 +194,16 @@ static int z_erofs_fragments_dedupe_insert(void *data, unsigned int len,return 0 ; } -static void z_erofs_fragments_dedupe_init (void ) +int z_erofs_fragments_init (void ) {unsigned int i;for (i =0 ; i <FRAGMENT_HASHSIZE ; ++i)init_list_head (&dupli_frags[i]); +return 0 ; } -static void z_erofs_fragments_dedupe_exit (void ) +void z_erofs_fragments_exit (void ) {struct erofs_fragment_dedupe_item *di, *n;struct list_head *head;
@@ -324,23 +324,21 @@ int z_erofs_pack_fragments(struct erofs_inode *inode, void *data,return len; } -struct erofs_inode *erofs_mkfs_build_fragments (void ) +struct erofs_inode *erofs_mkfs_build_packedfile (void ) {fflush (packedfile);return erofs_mkfs_build_special_from_fd (fileno (packedfile), - frags_packedname); +EROFS_PACKED_INODE ); } -void erofs_fragments_exit (void ) +void erofs_packedfile_exit (void ) {if (packedfile)fclose (packedfile); - -z_erofs_fragments_dedupe_exit (); } -int erofs_fragments_init (void ) +FILE *erofs_packedfile_init (void ) {#ifdef HAVE_TMPFILE64 packedfile =tmpfile64 ();
@@ -348,8 +346,6 @@ int erofs_fragments_init(void) packedfile =tmpfile ();#endif if (!packedfile) -return -ENOMEM ; - -z_erofs_fragments_dedupe_init (); -return 0 ; +return ERR_PTR (-ENOMEM ); +return packedfile; }
mkfs/main.c +11 -3
@@ -715,6 +715,7 @@ int main(int argc, char **argv)erofs_blk_t nblocks;struct timeval t;char uuid_str[37 ] ="not available" ; +FILE *packedfile =NULL ;erofs_init_configure ();erofs_mkfs_default_options ();
@@ -774,7 +775,13 @@ int main(int argc, char **argv)if (!cfg.c_pclusterblks_packed) cfg.c_pclusterblks_packed = cfg.c_pclusterblks_def; - err =erofs_fragments_init (); + packedfile =erofs_packedfile_init (); +if (IS_ERR (packedfile)) { +erofs_err ("failed to initialize packedfile" ); +return 1 ; + } + + err =z_erofs_fragments_init ();if (err) {erofs_err ("failed to initialize fragments" );return 1 ;
@@ -882,7 +889,7 @@ int main(int argc, char **argv) packed_nid =0 ;if (cfg.c_fragments &&erofs_sb_has_fragments ()) {erofs_update_progressinfo ("Handling packed_file ..." ); - packed_inode =erofs_mkfs_build_fragments (); + packed_inode =erofs_mkfs_build_packedfile ();if (IS_ERR (packed_inode)) { err =PTR_ERR (packed_inode); goto exit;
@@ -916,7 +923,8 @@ exit:if (cfg.c_chunkbits)erofs_blob_exit ();if (cfg.c_fragments) -erofs_fragments_exit (); +z_erofs_fragments_exit (); +erofs_packedfile_exit ();erofs_exit_configure ();if (err) {
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 2/3 erofs-utils: introduce on-disk format for long xattr name prefixes
Besides the predefined xattr name prefixes, introduces long xattr name prefixes, which work similarly as the predefined name prefixes, except that they are user specified.
It is especially useful for use cases together with overlayfs like Composefs model, which introduces diverse xattr values with only a few common xattr names (trusted.overlay.redirect, trusted.overlay.digest, and maybe more in the future). That makes the existing predefined prefixes ineffective in both image size and runtime performance.
When a user specified long xattr name prefix is used, only the trailing part of the xattr name apart from the long xattr name prefix will be stored in erofs_xattr_entry.e_name. e_name is empty if the xattr name matches exactly as the long xattr name prefix. All long xattr prefixes are stored in the packed or meta inode, which depends if fragments feature is enabled or not.
For each long xattr name prefix, the on-disk format is kept as the same as the unique metadata format: ALIGN({__le16 len, data}, 4), where len represents the total size of struct erofs_xattr_long_prefix, followed by data of struct erofs_xattr_long_prefix itself.
Each erofs_xattr_long_prefix keeps predefined prefixes (base_index) and the remaining prefix string without the trailing '\0'.
Two fields are introduced to the on-disk superblock, where xattr_prefix_count represents the total number of the long xattr name prefixes recorded, and xattr_prefix_start represents the start offset of recorded name prefixes in the packed/meta inode divided by 4.
When referring to a long xattr name prefix, the highest bit (bit 7) of erofs_xattr_entry.e_name_index is set, while the lower bits (bit 0-6) as a whole represents the index of the referred long name prefix among all long xattr name prefixes.
--- include/erofs_fs.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
include/erofs_fs.h +16 -1
@@ -77,7 +77,9 @@ struct erofs_super_block { }__packed u1;__le16 extra_devices;/* # of devices besides the primary device */ __le16 devt_slotoff;/* startoff = devt_slotoff * devt_slotsize */ -__u8 reserved[6 ]; +__u8 reserved; +__u8 xattr_prefix_count;/* # of long xattr name prefixes */ +__le32 xattr_prefix_start;/* start of long xattr prefixes */ __le64 packed_nid;/* nid of the special packed inode */ __u8 reserved2[24 ]; };
@@ -228,6 +230,13 @@ struct erofs_xattr_ibody_header {#define EROFS_XATTR_INDEX_LUSTRE 5#define EROFS_XATTR_INDEX_SECURITY 6 +/* +* bit 7 of e_name_index is set when it refers to a long xattr name prefix, +* while the remained lower bits represent the index of the prefix. +*/ +#define EROFS_XATTR_LONG_PREFIX 0x80 +#define EROFS_XATTR_LONG_PREFIX_MASK 0x7f +/* xattr entry (for both inline & shared xattrs) */ struct erofs_xattr_entry {__u8 e_name_len;/* length of name */
@@ -237,6 +246,12 @@ struct erofs_xattr_entry {char e_name[0 ];/* attribute name */ }; +/* long xattr name prefixes */ +struct erofs_xattr_long_prefix { +__u8 base_index;/* short xattr name prefix index */ +char infix[];/* infix apart from short prefix */ +}; +static inline unsigned int erofs_xattr_ibody_size (__le16 i_xattr_icount) {if (!i_xattr_icount)
Signature · 1 line
2.19.1.6.gb485710b
PATCH v2 3/3 erofs-utils: build xattrs upon extra long name prefixes
In reply to Jingbo XuExtra long xattr name prefixes are also considered when generating xattr entries.
Note that the given user-specified extra long xattr name prefixes are preferred to the pre-defined xattr name prefixes.
--- include/erofs/config.h | 1 + include/erofs/internal.h | 4 ++ include/erofs/xattr.h | 4 ++ include/erofs_fs.h | 4 +- lib/xattr.c | 134 +++++++++++++++++++++++++++++++++++++++ mkfs/main.c | 24 ++++++- 6 files changed, 168 insertions(+), 3 deletions(-)
include/erofs/config.h +1 -0
@@ -52,6 +52,7 @@ struct erofs_configure {bool c_dedupe;bool c_ignore_mtime;bool c_showprogress; +bool c_extra_ea_name_prefixes;#ifdef HAVE_LIBSELINUX struct selabel_handle *sehnd;
include/erofs/internal.h +4 -0
@@ -102,6 +102,9 @@ struct erofs_sb_info {u16 device_id_mask;/* used for others */ };erofs_nid_t packed_nid; + +u32 xattr_prefix_start; +u8 xattr_prefix_count; };/* make sure that any user of the erofs headers has atleast 64bit off_t type */
@@ -134,6 +137,7 @@ EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE) EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) +EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)#define EROFS_I_EA_INITED (1 << 0)
include/erofs/xattr.h +4 -0
@@ -70,6 +70,10 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode);char *erofs_export_xattr_ibody (struct list_head *ixattrs,unsigned int size);int erofs_build_shared_xattrs_from_path (const char *path); +int erofs_xattr_insert_name_prefix (const char *prefix); +void erofs_xattr_cleanup_name_prefixes (void ); +int erofs_xattr_write_name_prefixes (FILE *f); + #ifdef __cplusplus }#endif
include/erofs_fs.h +3 -1
@@ -27,6 +27,7 @@#define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010#define EROFS_FEATURE_INCOMPAT_FRAGMENTS 0x00000020#define EROFS_FEATURE_INCOMPAT_DEDUPE 0x00000020 +#define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES 0x00000040#define EROFS_ALL_FEATURE_INCOMPAT \ (EROFS_FEATURE_INCOMPAT_LZ4_0PADDING | \ EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \
@@ -35,7 +36,8 @@EROFS_FEATURE_INCOMPAT_DEVICE_TABLE | \EROFS_FEATURE_INCOMPAT_ZTAILPACKING | \EROFS_FEATURE_INCOMPAT_FRAGMENTS | \ - EROFS_FEATURE_INCOMPAT_DEDUPE) +EROFS_FEATURE_INCOMPAT_DEDUPE | \ + EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES) #define EROFS_SB_EXTSLOT_SIZE 16
lib/xattr.c +134 -0
162 lines not on this page · raw message
mkfs/main.c +22 -2
@@ -57,6 +57,7 @@ static struct option long_options[] = { {"uid-offset", required_argument, NULL, 16}, {"gid-offset", required_argument, NULL, 17}, {"mount-point", required_argument, NULL, 512}, + {"xattr-prefix", required_argument, NULL, 19}, #ifdef WITH_ANDROID {"product-out", required_argument, NULL, 513}, {"fs-config-file", required_argument, NULL, 514},
@@ -116,6 +117,7 @@ static void usage(void)" --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n" " --random-algorithms randomize per-file algorithms (debugging only)\n"#endif +" --xattr-prefix=X X=extra xattr name prefix\n" " --mount-point=X X=prefix of target fs path (default: /)\n" #ifdef WITH_ANDROID"\nwith following android-specific options:\n"
@@ -475,6 +477,16 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])return -EINVAL ; }break ; +case 19 : + errno =0 ; + opt =erofs_xattr_insert_name_prefix (optarg); +if (opt) { +erofs_err ("failed to parse xattr name prefix: %s" , +erofs_strerror (opt)); +return opt; + } + cfg.c_extra_ea_name_prefixes = true; +break ;case 1 :usage ();exit (0 );
@@ -572,6 +584,8 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh, .blocks = 0, .meta_blkaddr = sbi.meta_blkaddr, .xattr_blkaddr = sbi.xattr_blkaddr, + .xattr_prefix_count = sbi.xattr_prefix_count, + .xattr_prefix_start = cpu_to_le32(sbi.xattr_prefix_start), .feature_incompat = cpu_to_le32(sbi.feature_incompat), .feature_compat =cpu_to_le32 (sbi.feature_compat & ~EROFS_FEATURE_COMPAT_SB_CHKSUM),
@@ -771,7 +785,7 @@ int main(int argc, char **argv) }#endif erofs_show_config (); -if (cfg.c_fragments) { +if (cfg.c_fragments || cfg.c_extra_ea_name_prefixes) {if (!cfg.c_pclusterblks_packed) cfg.c_pclusterblks_packed = cfg.c_pclusterblks_def;
@@ -780,7 +794,9 @@ int main(int argc, char **argv)erofs_err ("failed to initialize packedfile" );return 1 ; } + } +if (cfg.c_fragments) { err =z_erofs_fragments_init ();if (err) {erofs_err ("failed to initialize fragments" );
@@ -876,6 +892,9 @@ int main(int argc, char **argv) goto exit; } +if (cfg.c_extra_ea_name_prefixes) +erofs_xattr_write_name_prefixes (packedfile); + root_nid =erofs_lookupnid (root_inode);erofs_iput (root_inode);
@@ -887,7 +906,7 @@ int main(int argc, char **argv) } packed_nid =0 ; -if (cfg.c_fragments &&erofs_sb_has_fragments ()) { +if (erofs_sb_has_fragments ()) {erofs_update_progressinfo ("Handling packed_file ..." ); packed_inode =erofs_mkfs_build_packedfile ();if (IS_ERR (packed_inode)) {
@@ -925,6 +944,7 @@ exit:if (cfg.c_fragments)z_erofs_fragments_exit ();erofs_packedfile_exit (); +erofs_xattr_cleanup_name_prefixes ();erofs_exit_configure ();if (err) {
Signature · 1 line
2.19.1.6.gb485710b