public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: Gao Xiang <hsiangkao@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 v4 2/5] erofs: unify xattr_iter structures
Date: Wed, 31 May 2023 16:37:54 +0800	[thread overview]
Message-ID: <42ae7d2b-5d2d-bf91-ec2d-265f26a52602@linux.alibaba.com> (raw)
In-Reply-To: <577b11e6-75f5-c07d-76c3-bb2f166a601b@linux.alibaba.com>



On 5/31/23 2:53 PM, Gao Xiang wrote:
> 
> 
> On 2023/5/31 11:13, Jingbo Xu wrote:
>> Unify xattr_iter/listxattr_iter/getxattr_iter structures into
>> erofs_xattr_iter structure.
>>
>> This is in preparation for the following further cleanup.
>>
>> Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
>> ---
>>   fs/erofs/xattr.c | 155 ++++++++++++++++++++---------------------------
>>   1 file changed, 65 insertions(+), 90 deletions(-)
>>
>> diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
>> index df6c4e6f1f4e..dffca38a46fd 100644
>> --- a/fs/erofs/xattr.c
>> +++ b/fs/erofs/xattr.c
>> @@ -20,16 +20,25 @@ static inline unsigned int
>> erofs_xattr_blkoff(struct super_block *sb,
>>       return erofs_blkoff(sb, xattr_id * sizeof(__u32));
>>   }
>>   -struct xattr_iter {
>> +struct erofs_xattr_iter {
>>       struct super_block *sb;
>>       struct erofs_buf buf;
>>       void *kaddr;
>> -
>>       erofs_blk_t blkaddr;
>>       unsigned int ofs;
>> +
>> +    char *buffer;
>> +    int buffer_size, buffer_ofs;
>> +
>> +    /* getxattr */
>> +    int index, infix_len;
>> +    struct qstr name;
>> +
>> +    /* listxattr */
>> +    struct dentry *dentry;
>>   };
>>   -static inline int erofs_xattr_iter_fixup(struct xattr_iter *it,
>> bool nospan)
>> +static inline int erofs_xattr_iter_fixup(struct erofs_xattr_iter *it,
>> bool nospan)
>>   {
>>       if (it->ofs < it->sb->s_blocksize)
>>           return 0;
>> @@ -50,7 +59,7 @@ static inline int erofs_xattr_iter_fixup(struct
>> xattr_iter *it, bool nospan)
>>   static int erofs_init_inode_xattrs(struct inode *inode)
>>   {
>>       struct erofs_inode *const vi = EROFS_I(inode);
>> -    struct xattr_iter it;
>> +    struct erofs_xattr_iter it;
>>       unsigned int i;
>>       struct erofs_xattr_ibody_header *ih;
>>       struct super_block *sb = inode->i_sb;
>> @@ -153,15 +162,15 @@ static int erofs_init_inode_xattrs(struct inode
>> *inode)
>>    *                            and need to be handled
>>    */
>>   struct xattr_iter_handlers {
>> -    int (*entry)(struct xattr_iter *_it, struct erofs_xattr_entry
>> *entry);
>> -    int (*name)(struct xattr_iter *_it, unsigned int processed, char
>> *buf,
>> +    int (*entry)(struct erofs_xattr_iter *it, struct
>> erofs_xattr_entry *entry);
>> +    int (*name)(struct erofs_xattr_iter *it, unsigned int processed,
>> char *buf,
>>               unsigned int len);
>> -    int (*alloc_buffer)(struct xattr_iter *_it, unsigned int value_sz);
>> -    void (*value)(struct xattr_iter *_it, unsigned int processed,
>> char *buf,
>> +    int (*alloc_buffer)(struct erofs_xattr_iter *it, unsigned int
>> value_sz);
>> +    void (*value)(struct erofs_xattr_iter *it, unsigned int
>> processed, char *buf,
>>                 unsigned int len);
>>   };
>>   -static int inline_xattr_iter_begin(struct xattr_iter *it,
>> +static int inline_xattr_iter_begin(struct erofs_xattr_iter *it,
>>                      struct inode *inode)
>>   {
>>       struct erofs_inode *const vi = EROFS_I(inode);
>> @@ -189,7 +198,7 @@ static int inline_xattr_iter_begin(struct
>> xattr_iter *it,
>>    * Regardless of success or failure, `xattr_foreach' will end up with
>>    * `ofs' pointing to the next xattr item rather than an arbitrary
>> position.
>>    */
>> -static int xattr_foreach(struct xattr_iter *it,
>> +static int xattr_foreach(struct erofs_xattr_iter *it,
>>                const struct xattr_iter_handlers *op,
>>                unsigned int *tlimit)
>>   {
>> @@ -280,18 +289,10 @@ static int xattr_foreach(struct xattr_iter *it,
>>       return err < 0 ? err : 0;
>>   }
>>   -struct getxattr_iter {
>> -    struct xattr_iter it;
>> -
>> -    char *buffer;
>> -    int buffer_size, index, infix_len;
>> -    struct qstr name;
>> -};
>> -
>> -static int erofs_xattr_long_entrymatch(struct getxattr_iter *it,
>> +static int erofs_xattr_long_entrymatch(struct erofs_xattr_iter *it,
>>                          struct erofs_xattr_entry *entry)
>>   {
>> -    struct erofs_sb_info *sbi = EROFS_SB(it->it.sb);
>> +    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);
>>   @@ -309,11 +310,9 @@ static int erofs_xattr_long_entrymatch(struct
>> getxattr_iter *it,
>>       return 0;
>>   }
>>   -static int xattr_entrymatch(struct xattr_iter *_it,
>> +static int xattr_entrymatch(struct erofs_xattr_iter *it,
>>                   struct erofs_xattr_entry *entry)
>>   {
>> -    struct getxattr_iter *it = container_of(_it, struct
>> getxattr_iter, it);
>> -
>>       /* should also match the infix for long name prefixes */
>>       if (entry->e_name_index & EROFS_XATTR_LONG_PREFIX)
>>           return erofs_xattr_long_entrymatch(it, entry);
>> @@ -325,32 +324,27 @@ static int xattr_entrymatch(struct xattr_iter *_it,
>>       return 0;
>>   }
>>   -static int xattr_namematch(struct xattr_iter *_it,
>> +static int xattr_namematch(struct erofs_xattr_iter *it,
>>                  unsigned int processed, char *buf, unsigned int len)
>>   {
>> -    struct getxattr_iter *it = container_of(_it, struct
>> getxattr_iter, it);
>> -
>>       if (memcmp(buf, it->name.name + it->infix_len + processed, len))
>>           return -ENOATTR;
>>       return 0;
>>   }
>>   -static int xattr_checkbuffer(struct xattr_iter *_it,
>> +static int xattr_checkbuffer(struct erofs_xattr_iter *it,
>>                    unsigned int value_sz)
>>   {
>> -    struct getxattr_iter *it = container_of(_it, struct
>> getxattr_iter, it);
>>       int err = it->buffer_size < value_sz ? -ERANGE : 0;
>>         it->buffer_size = value_sz;
>>       return !it->buffer ? 1 : err;
>>   }
>>   -static void xattr_copyvalue(struct xattr_iter *_it,
>> +static void xattr_copyvalue(struct erofs_xattr_iter *it,
>>                   unsigned int processed,
>>                   char *buf, unsigned int len)
>>   {
>> -    struct getxattr_iter *it = container_of(_it, struct
>> getxattr_iter, it);
>> -
>>       memcpy(it->buffer + processed, buf, len);
>>   }
>>   @@ -361,41 +355,40 @@ static const struct xattr_iter_handlers
>> find_xattr_handlers = {
>>       .value = xattr_copyvalue
>>   };
>>   -static int inline_getxattr(struct inode *inode, struct
>> getxattr_iter *it)
>> +static int inline_getxattr(struct inode *inode, struct
>> erofs_xattr_iter *it)
>>   {
>>       int ret;
>>       unsigned int remaining;
>>   -    ret = inline_xattr_iter_begin(&it->it, inode);
>> +    ret = inline_xattr_iter_begin(it, inode);
>>       if (ret < 0)
>>           return ret;
>>         remaining = ret;
>>       while (remaining) {
>> -        ret = xattr_foreach(&it->it, &find_xattr_handlers, &remaining);
>> +        ret = xattr_foreach(it, &find_xattr_handlers, &remaining);
>>           if (ret != -ENOATTR)
>>               break;
>>       }
>>       return ret ? ret : it->buffer_size;
>>   }
>>   -static int shared_getxattr(struct inode *inode, struct
>> getxattr_iter *it)
>> +static int shared_getxattr(struct inode *inode, struct
>> erofs_xattr_iter *it)
>>   {
>>       struct erofs_inode *const vi = EROFS_I(inode);
>> -    struct super_block *const sb = it->it.sb;
>> +    struct super_block *const sb = it->sb;
>>       unsigned int i, xsid;
>>       int ret = -ENOATTR;
>>         for (i = 0; i < vi->xattr_shared_count; ++i) {
>>           xsid = vi->xattr_shared_xattrs[i];
>> -        it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid);
>> -        it->it.ofs = erofs_xattr_blkoff(sb, xsid);
>> -        it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb,
>> -                          it->it.blkaddr, EROFS_KMAP);
>> -        if (IS_ERR(it->it.kaddr))
>> -            return PTR_ERR(it->it.kaddr);
>> -
>> -        ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL);
>> +        it->blkaddr = erofs_xattr_blkaddr(sb, xsid);
>> +        it->ofs = erofs_xattr_blkoff(sb, xsid);
>> +        it->kaddr = erofs_read_metabuf(&it->buf, sb, it->blkaddr,
>> EROFS_KMAP);
> 
> could we use erofs_bread() here?

Okay I will make all the conversions to erofs_bread() a separate patch.



-- 
Thanks,
Jingbo

  reply	other threads:[~2023-05-31  8:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  3:13 [PATCH v4 0/5] erofs: cleanup of xattr handling Jingbo Xu
2023-05-31  3:13 ` [PATCH v4 1/5] erofs: enhance erofs_xattr_iter_fixup() helper Jingbo Xu
2023-05-31  4:27   ` Gao Xiang
2023-05-31  3:13 ` [PATCH v4 2/5] erofs: unify xattr_iter structures Jingbo Xu
2023-05-31  6:53   ` Gao Xiang
2023-05-31  8:37     ` Jingbo Xu [this message]
2023-05-31  3:13 ` [PATCH v4 3/5] erofs: make the size of read data stored in buffer_ofs Jingbo Xu
2023-05-31  3:13 ` [PATCH v4 4/5] erofs: unify inline/share xattr iterators for listxattr/getxattr Jingbo Xu
2023-05-31  6:57   ` Gao Xiang
2023-05-31  8:16     ` Jingbo Xu
2023-05-31  8:31       ` Gao Xiang
2023-05-31  3:13 ` [PATCH v4 5/5] erofs: use separate xattr parsers " Jingbo Xu
2023-05-31  7:18   ` Gao Xiang
2023-05-31  8:31     ` Jingbo Xu

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=42ae7d2b-5d2d-bf91-ec2d-265f26a52602@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=huyue2@coolpad.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