[PATCH 2/2] erofs-utils: lib: refactor extended attribute name prefixes

Gao Xiang hsiangkao at linux.alibaba.com
Tue Sep 12 20:06:29 AEST 2023



On 2023/9/12 16:00, Jingbo Xu wrote:
> Previously, when an extended attribute (xattr) name matches a long name
> prefix, the attribute name after stripping the long name prefix is
> cached in xattr_item.  This is somewhat different with those that don't
> match any long name prefix or when long name prefixes feature is not
> enabled, in which case the attribute name after stripping the predefined
> short name prefix is cached in xattr_item.
> 
> The implementation described above makes it clumsy when stripping or
> deleting specific attribute from one file, if the attribute name is in
> the long name prefix format.
> 
> To fix this, for those attribute names that match the long name prefix,
> make the attribute name with the predefined short name prefix stripped
> cached in xattr_item just like normal attribute names.
> 
> To achieve this, add two new members `index` and `infix_len` to
> xattr_item.  The semantics of the original `prefix` member is unchanged,
> i.e. representing the index of the matched predefined short name prefix,
> while `index` member represents the index of the long name prefix if
> any, or it's the same as `prefix` otherwise.  The `infix_len` member
> represents the length of the infix of the long name preifx if any, or 0
> otherwise.
> 
> Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
> ---
>   lib/xattr.c | 253 +++++++++++++++++++---------------------------------
>   1 file changed, 94 insertions(+), 159 deletions(-)
> 
> diff --git a/lib/xattr.c b/lib/xattr.c
> index 54a6ae2..cac8db8 100644
> --- a/lib/xattr.c
> +++ b/lib/xattr.c
> @@ -75,9 +75,9 @@
>   struct xattr_item {
>   	struct xattr_item *next_shared_xattr;
>   	const char *kvbuf;
> -	unsigned int hash[2], len[2], count;
> +	unsigned int hash[2], len[2], count, infix_len;
>   	int shared_xattr_id;
> -	u8 prefix;
> +	u8 prefix, index;
>   	struct hlist_node node;
>   };
>   
> @@ -115,9 +115,11 @@ static struct xattr_prefix {
>   
>   struct ea_type_node {
>   	struct list_head list;
> -	struct xattr_prefix type;
> -	u8 index;
> +	u8 index, base_index;
> +	const char *infix;
> +	u8 infix_len;
>   };
> +
>   static LIST_HEAD(ea_name_prefixes);
>   static unsigned int ea_prefix_count;
>   
> @@ -154,7 +156,8 @@ static struct xattr_item *get_xattritem(u8 prefix, char *kvbuf,
>   					unsigned int len[2])

As discussed offline, I tend to drop u8 prefix here, and move match_prefix() in.

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list