From nobody Sun Feb 8 17:42:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 070C0C6FD1C for ; Thu, 23 Mar 2023 00:10:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbjCWAKw (ORCPT ); Wed, 22 Mar 2023 20:10:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbjCWAKj (ORCPT ); Wed, 22 Mar 2023 20:10:39 -0400 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1904E171A for ; Wed, 22 Mar 2023 17:10:06 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS-F5N_1679530194; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS-F5N_1679530194) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:55 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 5/8] erofs: unify xattr_iter structures Date: Thu, 23 Mar 2023 08:09:46 +0800 Message-Id: <20230323000949.57608-6-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230323000949.57608-1-jefflexu@linux.alibaba.com> References: <20230323000949.57608-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- fs/erofs/xattr.c | 166 ++++++++++++++++++++--------------------------- 1 file changed, 69 insertions(+), 97 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index bdd9393145ce..e58996b039f1 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -20,16 +20,22 @@ static inline unsigned int erofs_xattr_blkoff(struct su= per_block *sb, return erofs_blkoff(sb, xattr_id * sizeof(__u32)); } =20 -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; + + int index; + struct qstr name; + struct dentry *dentry; }; =20 -static inline int erofs_xattr_iter_fixup(struct xattr_iter *it) +static inline int erofs_xattr_iter_fixup(struct erofs_xattr_iter *it) { if (it->ofs < it->sb->s_blocksize) return 0; @@ -42,7 +48,7 @@ static inline int erofs_xattr_iter_fixup(struct xattr_ite= r *it) return 0; } =20 -static inline int erofs_xattr_iter_fixup_aligned(struct xattr_iter *it) +static inline int erofs_xattr_iter_fixup_aligned(struct erofs_xattr_iter *= it) { DBG_BUGON(it->ofs > it->sb->s_blocksize); return erofs_xattr_iter_fixup(it); @@ -51,7 +57,7 @@ static inline int erofs_xattr_iter_fixup_aligned(struct x= attr_iter *it) static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi =3D 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 =3D inode->i_sb; @@ -154,15 +160,15 @@ static int erofs_init_inode_xattrs(struct inode *inod= e) * 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 *bu= f, 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); }; =20 -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 =3D EROFS_I(inode); @@ -190,7 +196,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *i= t, * 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) { @@ -281,47 +287,32 @@ static int xattr_foreach(struct xattr_iter *it, return err < 0 ? err : 0; } =20 -struct getxattr_iter { - struct xattr_iter it; - - char *buffer; - int buffer_size, index; - struct qstr name; -}; - -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 =3D container_of(_it, struct getxattr_iter, it); - return (it->index !=3D entry->e_name_index || it->name.len !=3D entry->e_name_len) ? -ENOATTR : 0; } =20 -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 =3D container_of(_it, struct getxattr_iter, it); - return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0; } =20 -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 =3D container_of(_it, struct getxattr_iter, it); int err =3D it->buffer_size < value_sz ? -ERANGE : 0; =20 it->buffer_size =3D value_sz; return !it->buffer ? 1 : err; } =20 -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 =3D container_of(_it, struct getxattr_iter, it); - memcpy(it->buffer + processed, buf, len); } =20 @@ -332,41 +323,40 @@ static const struct xattr_iter_handlers find_xattr_ha= ndlers =3D { .value =3D xattr_copyvalue }; =20 -static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) +static int inline_getxattr(struct inode *inode, struct erofs_xattr_iter *i= t) { int ret; unsigned int remaining; =20 - ret =3D inline_xattr_iter_begin(&it->it, inode); + ret =3D inline_xattr_iter_begin(it, inode); if (ret < 0) return ret; =20 remaining =3D ret; while (remaining) { - ret =3D xattr_foreach(&it->it, &find_xattr_handlers, &remaining); + ret =3D xattr_foreach(it, &find_xattr_handlers, &remaining); if (ret !=3D -ENOATTR) break; } return ret ? ret : it->buffer_size; } =20 -static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) +static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *i= t) { struct erofs_inode *const vi =3D EROFS_I(inode); - struct super_block *const sb =3D it->it.sb; + struct super_block *const sb =3D it->sb; unsigned int i, xsid; int ret =3D -ENOATTR; =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; - it->it.blkaddr =3D erofs_xattr_blkaddr(sb, xsid); - it->it.ofs =3D erofs_xattr_blkoff(sb, xsid); - it->it.kaddr =3D 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 =3D xattr_foreach(&it->it, &find_xattr_handlers, NULL); + it->blkaddr =3D erofs_xattr_blkaddr(sb, xsid); + it->ofs =3D erofs_xattr_blkoff(sb, xsid); + it->kaddr =3D erofs_read_metabuf(&it->buf, sb, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + + ret =3D xattr_foreach(it, &find_xattr_handlers, NULL); if (ret !=3D -ENOATTR) break; } @@ -387,31 +377,30 @@ static int erofs_getxattr(struct inode *inode, int in= dex, const char *name, void *buffer, size_t buffer_size) { int ret; - struct getxattr_iter it; + struct erofs_xattr_iter it; =20 if (!name) return -EINVAL; + if (strlen(name) > EROFS_NAME_LEN) + return -ERANGE; =20 ret =3D erofs_init_inode_xattrs(inode); if (ret) return ret; =20 - it.index =3D index; - it.name.len =3D strlen(name); - if (it.name.len > EROFS_NAME_LEN) - return -ERANGE; - - it.it.buf =3D __EROFS_BUF_INITIALIZER; - it.name.name =3D name; - - it.buffer =3D buffer; - it.buffer_size =3D buffer_size; + it =3D (struct erofs_xattr_iter) { + .buf =3D __EROFS_BUF_INITIALIZER, + .sb =3D inode->i_sb, + .name =3D QSTR_INIT(name, strlen(name)), + .index =3D index, + .buffer =3D buffer, + .buffer_size =3D buffer_size, + }; =20 - it.it.sb =3D inode->i_sb; ret =3D inline_getxattr(inode, &it); if (ret =3D=3D -ENOATTR) ret =3D shared_getxattr(inode, &it); - erofs_put_metabuf(&it.it.buf); + erofs_put_metabuf(&it.buf); return ret; } =20 @@ -481,19 +470,9 @@ static inline const struct xattr_handler *erofs_xattr_= handler(unsigned int idx) xattr_handler_map[idx] : NULL; } =20 -struct listxattr_iter { - struct xattr_iter it; - - struct dentry *dentry; - char *buffer; - int buffer_size, buffer_ofs; -}; - -static int xattr_entrylist(struct xattr_iter *_it, +static int xattr_entrylist(struct erofs_xattr_iter *it, struct erofs_xattr_entry *entry) { - struct listxattr_iter *it =3D - container_of(_it, struct listxattr_iter, it); unsigned int prefix_len; const char *prefix; =20 @@ -520,23 +499,17 @@ static int xattr_entrylist(struct xattr_iter *_it, return 0; } =20 -static int xattr_namelist(struct xattr_iter *_it, +static int xattr_namelist(struct erofs_xattr_iter *it, unsigned int processed, char *buf, unsigned int len) { - struct listxattr_iter *it =3D - container_of(_it, struct listxattr_iter, it); - memcpy(it->buffer + it->buffer_ofs, buf, len); it->buffer_ofs +=3D len; return 0; } =20 -static int xattr_skipvalue(struct xattr_iter *_it, +static int xattr_skipvalue(struct erofs_xattr_iter *it, unsigned int value_sz) { - struct listxattr_iter *it =3D - container_of(_it, struct listxattr_iter, it); - it->buffer[it->buffer_ofs++] =3D '\0'; return 1; } @@ -548,42 +521,41 @@ static const struct xattr_iter_handlers list_xattr_ha= ndlers =3D { .value =3D NULL }; =20 -static int inline_listxattr(struct listxattr_iter *it) +static int inline_listxattr(struct erofs_xattr_iter *it) { int ret; unsigned int remaining; =20 - ret =3D inline_xattr_iter_begin(&it->it, d_inode(it->dentry)); + ret =3D inline_xattr_iter_begin(it, d_inode(it->dentry)); if (ret < 0) return ret; =20 remaining =3D ret; while (remaining) { - ret =3D xattr_foreach(&it->it, &list_xattr_handlers, &remaining); + ret =3D xattr_foreach(it, &list_xattr_handlers, &remaining); if (ret) break; } return ret ? ret : it->buffer_ofs; } =20 -static int shared_listxattr(struct listxattr_iter *it) +static int shared_listxattr(struct erofs_xattr_iter *it) { struct inode *const inode =3D d_inode(it->dentry); struct erofs_inode *const vi =3D EROFS_I(inode); - struct super_block *const sb =3D it->it.sb; + struct super_block *const sb =3D it->sb; unsigned int i, xsid; int ret =3D 0; =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; - it->it.blkaddr =3D erofs_xattr_blkaddr(sb, xsid); - it->it.ofs =3D erofs_xattr_blkoff(sb, xsid); - it->it.kaddr =3D 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 =3D xattr_foreach(&it->it, &list_xattr_handlers, NULL); + it->blkaddr =3D erofs_xattr_blkaddr(sb, xsid); + it->ofs =3D erofs_xattr_blkoff(sb, xsid); + it->kaddr =3D erofs_read_metabuf(&it->buf, sb, it->blkaddr, EROFS_KMAP); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + + ret =3D xattr_foreach(it, &list_xattr_handlers, NULL); if (ret) break; } @@ -594,7 +566,7 @@ ssize_t erofs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) { int ret; - struct listxattr_iter it; + struct erofs_xattr_iter it; =20 ret =3D erofs_init_inode_xattrs(d_inode(dentry)); if (ret =3D=3D -ENOATTR) @@ -602,18 +574,18 @@ ssize_t erofs_listxattr(struct dentry *dentry, if (ret) return ret; =20 - it.it.buf =3D __EROFS_BUF_INITIALIZER; - it.dentry =3D dentry; - it.buffer =3D buffer; - it.buffer_size =3D buffer_size; - it.buffer_ofs =3D 0; - - it.it.sb =3D dentry->d_sb; + it =3D (struct erofs_xattr_iter) { + .buf =3D __EROFS_BUF_INITIALIZER, + .sb =3D dentry->d_sb, + .dentry =3D dentry, + .buffer =3D buffer, + .buffer_size =3D buffer_size, + }; =20 ret =3D inline_listxattr(&it); if (ret >=3D 0 || ret =3D=3D -ENOATTR) ret =3D shared_listxattr(&it); - erofs_put_metabuf(&it.it.buf); + erofs_put_metabuf(&it.buf); return ret; } =20 --=20 2.19.1.6.gb485710b