From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Jingbo Xu <jefflexu@linux.alibaba.com>,
xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com,
linux-erofs@lists.ozlabs.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 5/5] erofs: use separate xattr parsers for listxattr/getxattr
Date: Mon, 12 Jun 2023 22:27:25 +0800 [thread overview]
Message-ID: <76ecba87-256c-2537-cbee-9cef6c0ce714@linux.alibaba.com> (raw)
In-Reply-To: <20230612123745.36323-6-jefflexu@linux.alibaba.com>
On 2023/6/12 20:37, Jingbo Xu wrote:
> There's a callback styled xattr parser, i.e. xattr_foreach(), which is
> shared among listxattr and getxattr. Convert it to two separate xattr
> parsers for listxattr and getxattr.
Convert it to two separate xattr parsers to serve listxattr and getxattr
for better readability.
>
> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
> ---
...
> +
> +static int erofs_listxattr_foreach(struct erofs_xattr_iter *it)
> {
> - unsigned int base_index = entry->e_name_index;
> - unsigned int prefix_len, infix_len = 0;
> + struct erofs_xattr_entry entry;
> + unsigned int base_index, prefix_len, infix_len = 0;
> const char *prefix, *infix = NULL;
> + int err;
>
> - if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX) {
> + /* 1. handle xattr entry */
> + entry = *(struct erofs_xattr_entry *)
> + (it->kaddr + erofs_blkoff(it->sb, it->pos));
> + it->pos += sizeof(struct erofs_xattr_entry);
> +
> + base_index = entry.e_name_index;
> + if (entry.e_name_index & EROFS_XATTR_LONG_PREFIX) {
> struct erofs_sb_info *sbi = EROFS_SB(it->sb);
> struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
> - (entry->e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
> + (entry.e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
>
> if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
> - return 1;
> + return 0;
> infix = pf->prefix->infix;
> infix_len = pf->infix_len;
> base_index = pf->prefix->base_index;
> @@ -385,53 +225,103 @@ static int xattr_entrylist(struct erofs_xattr_iter *it,
>
> prefix = erofs_xattr_prefix(base_index, it->dentry);
> if (!prefix)
> - return 1;
> + return 0;
> prefix_len = strlen(prefix);
>
> if (!it->buffer) {
> - it->buffer_ofs += prefix_len + infix_len +
> - entry->e_name_len + 1;
> - return 1;
> + it->buffer_ofs += prefix_len + infix_len + entry.e_name_len + 1;
Overly 80 chars?
> + return 0;
> }
>
> if (it->buffer_ofs + prefix_len + infix_len +
> - + entry->e_name_len + 1 > it->buffer_size)
> + entry.e_name_len + 1 > it->buffer_size)
> return -ERANGE;
>
> memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len);
> memcpy(it->buffer + it->buffer_ofs + prefix_len, infix, infix_len);
> it->buffer_ofs += prefix_len + infix_len;
> - return 0;
> -}
>
> -static int xattr_namelist(struct erofs_xattr_iter *it,
> - unsigned int processed, char *buf, unsigned int len)
> -{
> - memcpy(it->buffer + it->buffer_ofs, buf, len);
> - it->buffer_ofs += len;
> + /* 2. handle xattr name */
> + err = erofs_xattr_copy_to_buffer(it, entry.e_name_len);
> + if (err)
> + return err;
> +
> + it->buffer[it->buffer_ofs++] = '\0';
> return 0;
> }
>
> -static int xattr_skipvalue(struct erofs_xattr_iter *it,
> - unsigned int value_sz)
> +static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
> {
> - it->buffer[it->buffer_ofs++] = '\0';
> - return 1;
> -}
> + struct super_block *sb = it->sb;
> + struct erofs_xattr_entry entry;
> + unsigned int slice, processed, value_sz;
> + void *src;
>
> -static const struct xattr_iter_handlers list_xattr_handlers = {
> - .entry = xattr_entrylist,
> - .name = xattr_namelist,
> - .alloc_buffer = xattr_skipvalue,
> - .value = NULL
> -};
> + /* 1. handle xattr entry */
> + entry = *(struct erofs_xattr_entry *)
> + (it->kaddr + erofs_blkoff(sb, it->pos));
> + it->pos += sizeof(struct erofs_xattr_entry);
> + value_sz = le16_to_cpu(entry.e_value_size);
> +
> + /* should also match the infix for long name prefixes */
> + if (entry.e_name_index & EROFS_XATTR_LONG_PREFIX) {
> + struct erofs_sb_info *sbi = EROFS_SB(sb);
> + struct erofs_xattr_prefix_item *pf = sbi->xattr_prefixes +
> + (entry.e_name_index & EROFS_XATTR_LONG_PREFIX_MASK);
> +
> + if (pf >= sbi->xattr_prefixes + sbi->xattr_prefix_count)
> + return -ENOATTR;
> +
> + if (it->index != pf->prefix->base_index ||
> + it->name.len != entry.e_name_len + pf->infix_len)
> + return -ENOATTR;
> +
> + if (memcmp(it->name.name, pf->prefix->infix, pf->infix_len))
> + return -ENOATTR;
> +
> + it->infix_len = pf->infix_len;
> + } else {
> + if (it->index != entry.e_name_index ||
> + it->name.len != entry.e_name_len)
> + return -ENOATTR;
> +
> + it->infix_len = 0;
> + }
> +
> + /* 2. handle xattr name */
> + for (processed = 0; processed < entry.e_name_len; processed += slice) {
> + it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos),
> + EROFS_KMAP);
> + if (IS_ERR(it->kaddr))
> + return PTR_ERR(it->kaddr);
> +
> + src = it->kaddr + erofs_blkoff(sb, it->pos);
> + slice = min_t(unsigned int,
> + sb->s_blocksize - erofs_blkoff(sb, it->pos),
> + entry.e_name_len - processed);
> + if (memcmp(it->name.name + it->infix_len + processed, src, slice))
Overly 80 chars?
Thanks,
Gao Xiang
prev parent reply other threads:[~2023-06-12 14:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-12 12:37 [PATCH v7 0/5] erofs: cleanup of xattr handling Jingbo Xu
2023-06-12 12:37 ` [PATCH v7 1/5] erofs: use absolute position in xattr iterator Jingbo Xu
2023-06-12 14:15 ` Gao Xiang
2023-06-12 12:37 ` [PATCH v7 2/5] erofs: unify xattr_iter structures Jingbo Xu
2023-06-12 12:37 ` [PATCH v7 3/5] erofs: make the size of read data stored in buffer_ofs Jingbo Xu
2023-06-12 12:37 ` [PATCH v7 4/5] erofs: unify inline/shared xattr iterators for listxattr/getxattr Jingbo Xu
2023-06-12 14:17 ` Gao Xiang
2023-06-12 12:37 ` [PATCH v7 5/5] erofs: use separate xattr parsers " Jingbo Xu
2023-06-12 14:27 ` Gao Xiang [this message]
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=76ecba87-256c-2537-cbee-9cef6c0ce714@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=huyue2@coolpad.com \
--cc=jefflexu@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox