From nobody Sat Feb 7 19:41:25 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 F309BC74A5B for ; Thu, 23 Mar 2023 00:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbjCWAKn (ORCPT ); Wed, 22 Mar 2023 20:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbjCWAKc (ORCPT ); Wed, 22 Mar 2023 20:10:32 -0400 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE29B32CDF for ; Wed, 22 Mar 2023 17:10:01 -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=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS0V1H_1679530190; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS0V1H_1679530190) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:50 +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 1/8] erofs: move several xattr helpers into xattr.c Date: Thu, 23 Mar 2023 08:09:42 +0800 Message-Id: <20230323000949.57608-2-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" There are several xattr helpers not used outside xattr.c, thus move them into xattr.c as a cleanup. inlinexattr_header_size() has only one caller, and thus make it inlined into the caller directly. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 73 +++++++++++++++++++++++++++++++++--------------- fs/erofs/xattr.h | 56 ------------------------------------- 2 files changed, 51 insertions(+), 78 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 459caa3cd65d..760ec864a39c 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -7,6 +7,19 @@ #include #include "xattr.h" =20 +static inline erofs_blk_t erofs_xattr_blkaddr(struct super_block *sb, + unsigned int xattr_id) +{ + return EROFS_SB(sb)->xattr_blkaddr + + erofs_blknr(sb, xattr_id * sizeof(__u32)); +} + +static inline unsigned int erofs_xattr_blkoff(struct super_block *sb, + unsigned int xattr_id) +{ + return erofs_blkoff(sb, xattr_id * sizeof(__u32)); +} + struct xattr_iter { struct super_block *sb; struct erofs_buf buf; @@ -157,7 +170,8 @@ static int inline_xattr_iter_begin(struct xattr_iter *i= t, struct erofs_inode *const vi =3D EROFS_I(inode); unsigned int xattr_header_sz, inline_xattr_ofs; =20 - xattr_header_sz =3D inlinexattr_header_size(inode); + xattr_header_sz =3D sizeof(struct erofs_xattr_ibody_header) + + sizeof(u32) * vi->xattr_shared_count; if (xattr_header_sz >=3D vi->xattr_isize) { DBG_BUGON(xattr_header_sz > vi->xattr_isize); return -ENOATTR; @@ -351,20 +365,18 @@ static int inline_getxattr(struct inode *inode, struc= t getxattr_iter *it) static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) { struct erofs_inode *const vi =3D EROFS_I(inode); - struct super_block *const sb =3D inode->i_sb; - unsigned int i; + struct super_block *const sb =3D it->it.sb; + unsigned int i, xsid; int ret =3D -ENOATTR; =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { - erofs_blk_t blkaddr =3D - xattrblock_addr(sb, vi->xattr_shared_xattrs[i]); - - it->it.ofs =3D xattrblock_offset(sb, vi->xattr_shared_xattrs[i]); - it->it.kaddr =3D erofs_read_metabuf(&it->it.buf, sb, blkaddr, - EROFS_KMAP); + 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); - it->it.blkaddr =3D blkaddr; =20 ret =3D xattr_foreach(&it->it, &find_xattr_handlers, NULL); if (ret !=3D -ENOATTR) @@ -383,9 +395,8 @@ static bool erofs_xattr_trusted_list(struct dentry *den= try) return capable(CAP_SYS_ADMIN); } =20 -int erofs_getxattr(struct inode *inode, int index, - const char *name, - void *buffer, size_t buffer_size) +static int erofs_getxattr(struct inode *inode, int index, const char *name, + void *buffer, size_t buffer_size) { int ret; struct getxattr_iter it; @@ -473,6 +484,26 @@ const struct xattr_handler *erofs_xattr_handlers[] =3D= { NULL, }; =20 +static inline const struct xattr_handler *erofs_xattr_handler(unsigned int= idx) +{ + static const struct xattr_handler *xattr_handler_map[] =3D { + [EROFS_XATTR_INDEX_USER] =3D &erofs_xattr_user_handler, +#ifdef CONFIG_EROFS_FS_POSIX_ACL + [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =3D + &posix_acl_access_xattr_handler, + [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =3D + &posix_acl_default_xattr_handler, +#endif + [EROFS_XATTR_INDEX_TRUSTED] =3D &erofs_xattr_trusted_handler, +#ifdef CONFIG_EROFS_FS_SECURITY + [EROFS_XATTR_INDEX_SECURITY] =3D &erofs_xattr_security_handler, +#endif + }; + + return idx && idx < ARRAY_SIZE(xattr_handler_map) ? + xattr_handler_map[idx] : NULL; +} + struct listxattr_iter { struct xattr_iter it; =20 @@ -562,20 +593,18 @@ static int shared_listxattr(struct listxattr_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 inode->i_sb; - unsigned int i; + struct super_block *const sb =3D it->it.sb; + unsigned int i, xsid; int ret =3D 0; =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { - erofs_blk_t blkaddr =3D - xattrblock_addr(sb, vi->xattr_shared_xattrs[i]); - - it->it.ofs =3D xattrblock_offset(sb, vi->xattr_shared_xattrs[i]); - it->it.kaddr =3D erofs_read_metabuf(&it->it.buf, sb, blkaddr, - EROFS_KMAP); + 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); - it->it.blkaddr =3D blkaddr; =20 ret =3D xattr_foreach(&it->it, &list_xattr_handlers, NULL); if (ret) diff --git a/fs/erofs/xattr.h b/fs/erofs/xattr.h index f7a21aaa9755..cc9ef97dbf8e 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -13,66 +13,10 @@ /* Attribute not found */ #define ENOATTR ENODATA =20 -static inline unsigned int inlinexattr_header_size(struct inode *inode) -{ - return sizeof(struct erofs_xattr_ibody_header) + - sizeof(u32) * EROFS_I(inode)->xattr_shared_count; -} - -static inline erofs_blk_t xattrblock_addr(struct super_block *sb, - unsigned int xattr_id) -{ #ifdef CONFIG_EROFS_FS_XATTR - return EROFS_SB(sb)->xattr_blkaddr + - xattr_id * sizeof(__u32) / sb->s_blocksize; -#else - return 0; -#endif -} - -static inline unsigned int xattrblock_offset(struct super_block *sb, - unsigned int xattr_id) -{ - return (xattr_id * sizeof(__u32)) % sb->s_blocksize; -} - -#ifdef CONFIG_EROFS_FS_XATTR -extern const struct xattr_handler erofs_xattr_user_handler; -extern const struct xattr_handler erofs_xattr_trusted_handler; -extern const struct xattr_handler erofs_xattr_security_handler; - -static inline const struct xattr_handler *erofs_xattr_handler(unsigned int= idx) -{ - static const struct xattr_handler *xattr_handler_map[] =3D { - [EROFS_XATTR_INDEX_USER] =3D &erofs_xattr_user_handler, -#ifdef CONFIG_EROFS_FS_POSIX_ACL - [EROFS_XATTR_INDEX_POSIX_ACL_ACCESS] =3D - &posix_acl_access_xattr_handler, - [EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT] =3D - &posix_acl_default_xattr_handler, -#endif - [EROFS_XATTR_INDEX_TRUSTED] =3D &erofs_xattr_trusted_handler, -#ifdef CONFIG_EROFS_FS_SECURITY - [EROFS_XATTR_INDEX_SECURITY] =3D &erofs_xattr_security_handler, -#endif - }; - - return idx && idx < ARRAY_SIZE(xattr_handler_map) ? - xattr_handler_map[idx] : NULL; -} - extern const struct xattr_handler *erofs_xattr_handlers[]; - -int erofs_getxattr(struct inode *, int, const char *, void *, size_t); ssize_t erofs_listxattr(struct dentry *, char *, size_t); #else -static inline int erofs_getxattr(struct inode *inode, int index, - const char *name, void *buffer, - size_t buffer_size) -{ - return -EOPNOTSUPP; -} - #define erofs_listxattr (NULL) #define erofs_xattr_handlers (NULL) #endif /* !CONFIG_EROFS_FS_XATTR */ --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 7D124C6FD1F for ; Thu, 23 Mar 2023 00:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230413AbjCWAKr (ORCPT ); Wed, 22 Mar 2023 20:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjCWAKd (ORCPT ); Wed, 22 Mar 2023 20:10:33 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C8231BD2 for ; Wed, 22 Mar 2023 17:10:02 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeRymBp_1679530191; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeRymBp_1679530191) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:52 +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 2/8] erofs: rename init_inode_xattrs with erofs_ prefix Date: Thu, 23 Mar 2023 08:09:43 +0800 Message-Id: <20230323000949.57608-3-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" Rename init_inode_xattrs() to erofs_init_inode_xattrs() without logic change. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 760ec864a39c..ab4517e5ec84 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -29,7 +29,7 @@ struct xattr_iter { unsigned int ofs; }; =20 -static int init_inode_xattrs(struct inode *inode) +static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi =3D EROFS_I(inode); struct xattr_iter it; @@ -404,7 +404,7 @@ static int erofs_getxattr(struct inode *inode, int inde= x, const char *name, if (!name) return -EINVAL; =20 - ret =3D init_inode_xattrs(inode); + ret =3D erofs_init_inode_xattrs(inode); if (ret) return ret; =20 @@ -619,7 +619,7 @@ ssize_t erofs_listxattr(struct dentry *dentry, int ret; struct listxattr_iter it; =20 - ret =3D init_inode_xattrs(d_inode(dentry)); + ret =3D erofs_init_inode_xattrs(d_inode(dentry)); if (ret =3D=3D -ENOATTR) return 0; if (ret) --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 A97BFC6FD1C for ; Thu, 23 Mar 2023 00:10:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbjCWAKp (ORCPT ); Wed, 22 Mar 2023 20:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbjCWAKd (ORCPT ); Wed, 22 Mar 2023 20:10:33 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49A5332CD8 for ; Wed, 22 Mar 2023 17:10:03 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS2z75_1679530192; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS2z75_1679530192) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:53 +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 3/8] erofs: simplify erofs_xattr_generic_get() Date: Thu, 23 Mar 2023 08:09:44 +0800 Message-Id: <20230323000949.57608-4-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" erofs_xattr_generic_get() won't be called from xattr handlers other than user/trusted/security xattr handler, and thus there's no need of extra checking. Signed-off-by: Jingbo Xu Reviewed-by: Gao Xiang --- fs/erofs/xattr.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index ab4517e5ec84..b83331a694f3 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -431,20 +431,9 @@ static int erofs_xattr_generic_get(const struct xattr_= handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *buffer, size_t size) { - struct erofs_sb_info *const sbi =3D EROFS_I_SB(inode); - - switch (handler->flags) { - case EROFS_XATTR_INDEX_USER: - if (!test_opt(&sbi->opt, XATTR_USER)) - return -EOPNOTSUPP; - break; - case EROFS_XATTR_INDEX_TRUSTED: - break; - case EROFS_XATTR_INDEX_SECURITY: - break; - default: - return -EINVAL; - } + if (handler->flags =3D=3D EROFS_XATTR_INDEX_USER && + !test_opt(&EROFS_I_SB(inode)->opt, XATTR_USER)) + return -EOPNOTSUPP; =20 return erofs_getxattr(inode, handler->flags, name, buffer, size); } --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 9DEE4C6FD1F for ; Thu, 23 Mar 2023 00:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbjCWAKt (ORCPT ); Wed, 22 Mar 2023 20:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbjCWAKh (ORCPT ); Wed, 22 Mar 2023 20:10:37 -0400 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 081B12E0F9 for ; Wed, 22 Mar 2023 17:10:04 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS2z7O_1679530193; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS2z7O_1679530193) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:54 +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 4/8] erofs: introduce erofs_xattr_iter_fixup_aligned() helper Date: Thu, 23 Mar 2023 08:09:45 +0800 Message-Id: <20230323000949.57608-5-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" Introduce erofs_xattr_iter_fixup_aligned() helper where it.ofs <=3D EROFS_BLKSIZ is mandatory. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 76 ++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index b83331a694f3..bdd9393145ce 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -29,6 +29,25 @@ struct xattr_iter { unsigned int ofs; }; =20 +static inline int erofs_xattr_iter_fixup(struct xattr_iter *it) +{ + if (it->ofs < it->sb->s_blocksize) + return 0; + + it->blkaddr +=3D erofs_blknr(it->sb, it->ofs); + it->kaddr =3D erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, EROFS_KMA= P); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + it->ofs =3D erofs_blkoff(it->sb, it->ofs); + return 0; +} + +static inline int erofs_xattr_iter_fixup_aligned(struct xattr_iter *it) +{ + DBG_BUGON(it->ofs > it->sb->s_blocksize); + return erofs_xattr_iter_fixup(it); +} + static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi =3D EROFS_I(inode); @@ -80,6 +99,7 @@ static int erofs_init_inode_xattrs(struct inode *inode) goto out_unlock; } =20 + it.sb =3D sb; it.buf =3D __EROFS_BUF_INITIALIZER; it.blkaddr =3D erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); it.ofs =3D erofs_blkoff(sb, erofs_iloc(inode) + vi->inode_isize); @@ -105,19 +125,11 @@ static int erofs_init_inode_xattrs(struct inode *inod= e) it.ofs +=3D sizeof(struct erofs_xattr_ibody_header); =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { - if (it.ofs >=3D sb->s_blocksize) { - /* cannot be unaligned */ - DBG_BUGON(it.ofs !=3D sb->s_blocksize); - - it.kaddr =3D erofs_read_metabuf(&it.buf, sb, ++it.blkaddr, - EROFS_KMAP); - if (IS_ERR(it.kaddr)) { - kfree(vi->xattr_shared_xattrs); - vi->xattr_shared_xattrs =3D NULL; - ret =3D PTR_ERR(it.kaddr); - goto out_unlock; - } - it.ofs =3D 0; + ret =3D erofs_xattr_iter_fixup_aligned(&it); + if (ret) { + kfree(vi->xattr_shared_xattrs); + vi->xattr_shared_xattrs =3D NULL; + goto out_unlock; } vi->xattr_shared_xattrs[i] =3D le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs)); @@ -150,20 +162,6 @@ struct xattr_iter_handlers { unsigned int len); }; =20 -static inline int xattr_iter_fixup(struct xattr_iter *it) -{ - if (it->ofs < it->sb->s_blocksize) - return 0; - - it->blkaddr +=3D erofs_blknr(it->sb, it->ofs); - it->kaddr =3D erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, - EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - it->ofs =3D erofs_blkoff(it->sb, it->ofs); - return 0; -} - static int inline_xattr_iter_begin(struct xattr_iter *it, struct inode *inode) { @@ -201,7 +199,7 @@ static int xattr_foreach(struct xattr_iter *it, int err; =20 /* 0. fixup blkaddr, ofs, ipage */ - err =3D xattr_iter_fixup(it); + err =3D erofs_xattr_iter_fixup(it); if (err) return err; =20 @@ -236,14 +234,9 @@ static int xattr_foreach(struct xattr_iter *it, processed =3D 0; =20 while (processed < entry.e_name_len) { - if (it->ofs >=3D it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err =3D xattr_iter_fixup(it); - if (err) - goto out; - it->ofs =3D 0; - } + err =3D erofs_xattr_iter_fixup_aligned(it); + if (err) + goto out; =20 slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, entry.e_name_len - processed); @@ -271,14 +264,9 @@ static int xattr_foreach(struct xattr_iter *it, } =20 while (processed < value_sz) { - if (it->ofs >=3D it->sb->s_blocksize) { - DBG_BUGON(it->ofs > it->sb->s_blocksize); - - err =3D xattr_iter_fixup(it); - if (err) - goto out; - it->ofs =3D 0; - } + err =3D erofs_xattr_iter_fixup_aligned(it); + if (err) + goto out; =20 slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, value_sz - processed); --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 From nobody Sat Feb 7 19:41:25 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 B7B3EC74A5B for ; Thu, 23 Mar 2023 00:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjCWAKz (ORCPT ); Wed, 22 Mar 2023 20:10:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230400AbjCWAKq (ORCPT ); Wed, 22 Mar 2023 20:10:46 -0400 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C47303F6 for ; Wed, 22 Mar 2023 17:10:09 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeRymCt_1679530195; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeRymCt_1679530195) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:56 +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 6/8] erofs: make the size of read data stored in buffer_ofs Date: Thu, 23 Mar 2023 08:09:47 +0800 Message-Id: <20230323000949.57608-7-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" Since now xattr_iter structures have been unified, make the size of the read data stored in buffer_ofs. Don't bother reusing buffer_size for this use, which may be confusing. This is in preparation for the following further cleanup. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index e58996b039f1..264561ccaa44 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -305,7 +305,7 @@ static int xattr_checkbuffer(struct erofs_xattr_iter *i= t, { int err =3D it->buffer_size < value_sz ? -ERANGE : 0; =20 - it->buffer_size =3D value_sz; + it->buffer_ofs =3D value_sz; return !it->buffer ? 1 : err; } =20 @@ -338,7 +338,7 @@ static int inline_getxattr(struct inode *inode, struct = erofs_xattr_iter *it) if (ret !=3D -ENOATTR) break; } - return ret ? ret : it->buffer_size; + return ret ? ret : it->buffer_ofs; } =20 static int shared_getxattr(struct inode *inode, struct erofs_xattr_iter *i= t) @@ -360,7 +360,7 @@ static int shared_getxattr(struct inode *inode, struct = erofs_xattr_iter *it) if (ret !=3D -ENOATTR) break; } - return ret ? ret : it->buffer_size; + return ret ? ret : it->buffer_ofs; } =20 static bool erofs_xattr_user_list(struct dentry *dentry) --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 11B16C6FD1C for ; Thu, 23 Mar 2023 00:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbjCWAK5 (ORCPT ); Wed, 22 Mar 2023 20:10:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbjCWAKu (ORCPT ); Wed, 22 Mar 2023 20:10:50 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E0DA32E6B for ; Wed, 22 Mar 2023 17:10:11 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R801e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS2z8._1679530196; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS2z8._1679530196) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:57 +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 7/8] erofs: unify inline/share xattr iterators for listxattr/getxattr Date: Thu, 23 Mar 2023 08:09:48 +0800 Message-Id: <20230323000949.57608-8-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" Make inline_getxattr() and inline_listxattr() unified as iter_inline_xattr(), shared_getxattr() and shared_listxattr() unified as iter_shared_xattr(). After the unification, both iter_inline_xattr() and iter_shared_xattr() return 0 on success, and negative error on failure. One thing worth noting is that, the logic of returning it->buffer_ofs when there's no shared xattrs in shared_listxattr() is moved to erofs_listxattr() to make the unification possible. The only difference is that, semantically the old behavior will return ENOATTR rather than it->buffer_ofs if ENOATTR encountered when listxattr is parsing upon a specific shared xattr, while now the new behavior will return it->buffer_ofs in this case. This is not an issue, as listxattr upon a specific xattr won't return ENOATTR. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 210 ++++++++++++++++++----------------------------- 1 file changed, 81 insertions(+), 129 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 264561ccaa44..196b2eb59e29 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -7,18 +7,8 @@ #include #include "xattr.h" =20 -static inline erofs_blk_t erofs_xattr_blkaddr(struct super_block *sb, - unsigned int xattr_id) -{ - return EROFS_SB(sb)->xattr_blkaddr + - erofs_blknr(sb, xattr_id * sizeof(__u32)); -} - -static inline unsigned int erofs_xattr_blkoff(struct super_block *sb, - unsigned int xattr_id) -{ - return erofs_blkoff(sb, xattr_id * sizeof(__u32)); -} +static int erofs_getxattr(struct inode *inode, int index, const char *name, + void *buffer, size_t buffer_size); =20 struct erofs_xattr_iter { struct super_block *sb; @@ -33,6 +23,8 @@ struct erofs_xattr_iter { int index; struct qstr name; struct dentry *dentry; + struct inode *inode; + bool getxattr; }; =20 static inline int erofs_xattr_iter_fixup(struct erofs_xattr_iter *it) @@ -168,30 +160,6 @@ struct xattr_iter_handlers { unsigned int len); }; =20 -static int inline_xattr_iter_begin(struct erofs_xattr_iter *it, - struct inode *inode) -{ - struct erofs_inode *const vi =3D EROFS_I(inode); - unsigned int xattr_header_sz, inline_xattr_ofs; - - xattr_header_sz =3D sizeof(struct erofs_xattr_ibody_header) + - sizeof(u32) * vi->xattr_shared_count; - if (xattr_header_sz >=3D vi->xattr_isize) { - DBG_BUGON(xattr_header_sz > vi->xattr_isize); - return -ENOATTR; - } - - inline_xattr_ofs =3D vi->inode_isize + xattr_header_sz; - - it->blkaddr =3D erofs_blknr(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->ofs =3D erofs_blkoff(it->sb, erofs_iloc(inode) + inline_xattr_ofs); - it->kaddr =3D erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr, - EROFS_KMAP); - if (IS_ERR(it->kaddr)) - return PTR_ERR(it->kaddr); - return vi->xattr_isize - xattr_header_sz; -} - /* * Regardless of success or failure, `xattr_foreach' will end up with * `ofs' pointing to the next xattr item rather than an arbitrary position. @@ -323,46 +291,6 @@ static const struct xattr_iter_handlers find_xattr_han= dlers =3D { .value =3D xattr_copyvalue }; =20 -static int inline_getxattr(struct inode *inode, struct erofs_xattr_iter *i= t) -{ - int ret; - unsigned int remaining; - - ret =3D inline_xattr_iter_begin(it, inode); - if (ret < 0) - return ret; - - remaining =3D ret; - while (remaining) { - ret =3D xattr_foreach(it, &find_xattr_handlers, &remaining); - if (ret !=3D -ENOATTR) - break; - } - return ret ? ret : it->buffer_ofs; -} - -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->sb; - unsigned int i, xsid; - int ret =3D -ENOATTR; - - for (i =3D 0; i < vi->xattr_shared_count; ++i) { - xsid =3D vi->xattr_shared_xattrs[i]; - 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; - } - return ret ? ret : it->buffer_ofs; -} - static bool erofs_xattr_user_list(struct dentry *dentry) { return test_opt(&EROFS_SB(dentry->d_sb)->opt, XATTR_USER); @@ -373,37 +301,6 @@ static bool erofs_xattr_trusted_list(struct dentry *de= ntry) return capable(CAP_SYS_ADMIN); } =20 -static int erofs_getxattr(struct inode *inode, int index, const char *name, - void *buffer, size_t buffer_size) -{ - int ret; - struct erofs_xattr_iter it; - - if (!name) - return -EINVAL; - if (strlen(name) > EROFS_NAME_LEN) - return -ERANGE; - - ret =3D erofs_init_inode_xattrs(inode); - if (ret) - return ret; - - 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, - }; - - ret =3D inline_getxattr(inode, &it); - if (ret =3D=3D -ENOATTR) - ret =3D shared_getxattr(inode, &it); - erofs_put_metabuf(&it.buf); - return ret; -} - static int erofs_xattr_generic_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *buffer, size_t size) @@ -521,45 +418,96 @@ static const struct xattr_iter_handlers list_xattr_ha= ndlers =3D { .value =3D NULL }; =20 -static int inline_listxattr(struct erofs_xattr_iter *it) +static int erofs_iter_inline_xattr(struct erofs_xattr_iter *it) { + struct erofs_inode *const vi =3D EROFS_I(it->inode); + const struct xattr_iter_handlers *op; + unsigned int xattr_header_sz, remaining; + erofs_off_t pos; int ret; - unsigned int remaining; =20 - ret =3D inline_xattr_iter_begin(it, d_inode(it->dentry)); - if (ret < 0) - return ret; + xattr_header_sz =3D sizeof(struct erofs_xattr_ibody_header) + + sizeof(u32) * vi->xattr_shared_count; + if (xattr_header_sz >=3D vi->xattr_isize) { + DBG_BUGON(xattr_header_sz > vi->xattr_isize); + return -ENOATTR; + } + + pos =3D erofs_iloc(it->inode) + vi->inode_isize + xattr_header_sz; + it->blkaddr =3D erofs_blknr(it->sb, pos); + it->ofs =3D erofs_blkoff(it->sb, pos); + it->kaddr =3D erofs_read_metabuf(&it->buf, it->sb, it->blkaddr, EROFS_KMA= P); + if (IS_ERR(it->kaddr)) + return PTR_ERR(it->kaddr); + + remaining =3D vi->xattr_isize - xattr_header_sz; + op =3D it->getxattr ? &find_xattr_handlers : &list_xattr_handlers; =20 - remaining =3D ret; while (remaining) { - ret =3D xattr_foreach(it, &list_xattr_handlers, &remaining); - if (ret) + ret =3D xattr_foreach(it, op, &remaining); + if ((it->getxattr && ret !=3D -ENOATTR) || (!it->getxattr && ret)) break; } - return ret ? ret : it->buffer_ofs; + return ret; } =20 -static int shared_listxattr(struct erofs_xattr_iter *it) +static int erofs_iter_shared_xattr(struct erofs_xattr_iter *it) { - struct inode *const inode =3D d_inode(it->dentry); - struct erofs_inode *const vi =3D EROFS_I(inode); + struct erofs_inode *const vi =3D EROFS_I(it->inode); struct super_block *const sb =3D it->sb; + const struct xattr_iter_handlers *op; unsigned int i, xsid; - int ret =3D 0; + int ret =3D -ENOATTR; + + op =3D it->getxattr ? &find_xattr_handlers : &list_xattr_handlers; =20 for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; - it->blkaddr =3D erofs_xattr_blkaddr(sb, xsid); - it->ofs =3D erofs_xattr_blkoff(sb, xsid); + it->blkaddr =3D EROFS_SB(sb)->xattr_blkaddr + + erofs_blknr(sb, xsid * sizeof(__u32)); + it->ofs =3D erofs_blkoff(sb, xsid * sizeof(__u32)); it->kaddr =3D erofs_read_metabuf(&it->buf, sb, it->blkaddr, EROFS_KMAP); if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); =20 - ret =3D xattr_foreach(it, &list_xattr_handlers, NULL); - if (ret) + ret =3D xattr_foreach(it, op, NULL); + if ((it->getxattr && ret !=3D -ENOATTR) || (!it->getxattr && ret)) break; } - return ret ? ret : it->buffer_ofs; + return ret; +} + +static int erofs_getxattr(struct inode *inode, int index, const char *name, + void *buffer, size_t buffer_size) +{ + int ret; + struct erofs_xattr_iter it; + + if (!name) + return -EINVAL; + if (strlen(name) > EROFS_NAME_LEN) + return -ERANGE; + + ret =3D erofs_init_inode_xattrs(inode); + if (ret) + return ret; + + it =3D (struct erofs_xattr_iter) { + .buf =3D __EROFS_BUF_INITIALIZER, + .sb =3D inode->i_sb, + .inode =3D inode, + .name =3D QSTR_INIT(name, strlen(name)), + .index =3D index, + .buffer =3D buffer, + .buffer_size =3D buffer_size, + .getxattr =3D true, + }; + + ret =3D erofs_iter_inline_xattr(&it); + if (ret =3D=3D -ENOATTR) + ret =3D erofs_iter_shared_xattr(&it); + erofs_put_metabuf(&it.buf); + return ret ? ret : it.buffer_ofs; } =20 ssize_t erofs_listxattr(struct dentry *dentry, @@ -578,15 +526,19 @@ ssize_t erofs_listxattr(struct dentry *dentry, .buf =3D __EROFS_BUF_INITIALIZER, .sb =3D dentry->d_sb, .dentry =3D dentry, + .inode =3D d_inode(dentry), .buffer =3D buffer, .buffer_size =3D buffer_size, + .getxattr =3D false, }; =20 - ret =3D inline_listxattr(&it); - if (ret >=3D 0 || ret =3D=3D -ENOATTR) - ret =3D shared_listxattr(&it); + ret =3D erofs_iter_inline_xattr(&it); + if (!ret || ret =3D=3D -ENOATTR) + ret =3D erofs_iter_shared_xattr(&it); + if (ret =3D=3D -ENOATTR) + ret =3D 0; erofs_put_metabuf(&it.buf); - return ret; + return ret ? ret : it.buffer_ofs; } =20 #ifdef CONFIG_EROFS_FS_POSIX_ACL --=20 2.19.1.6.gb485710b From nobody Sat Feb 7 19:41:25 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 601A3C6FD1C for ; Thu, 23 Mar 2023 00:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbjCWALD (ORCPT ); Wed, 22 Mar 2023 20:11:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbjCWAKv (ORCPT ); Wed, 22 Mar 2023 20:10:51 -0400 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E65B233447 for ; Wed, 22 Mar 2023 17:10:11 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VeS0V4I_1679530197; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VeS0V4I_1679530197) by smtp.aliyun-inc.com; Thu, 23 Mar 2023 08:09:58 +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 8/8] erofs: use separate xattr parsers for listxattr/getxattr Date: Thu, 23 Mar 2023 08:09:49 +0800 Message-Id: <20230323000949.57608-9-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" 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. Signed-off-by: Jingbo Xu --- fs/erofs/xattr.c | 347 ++++++++++++++++++++++------------------------- 1 file changed, 159 insertions(+), 188 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 196b2eb59e29..eac5b7b69691 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -24,6 +24,7 @@ struct erofs_xattr_iter { struct qstr name; struct dentry *dentry; struct inode *inode; + unsigned int remaining; /* size of inline xattrs to be iterated */ bool getxattr; }; =20 @@ -144,153 +145,6 @@ static int erofs_init_inode_xattrs(struct inode *inod= e) return ret; } =20 -/* - * the general idea for these return values is - * if 0 is returned, go on processing the current xattr; - * 1 (> 0) is returned, skip this round to process the next xattr; - * -err (< 0) is returned, an error (maybe ENOXATTR) occurred - * and need to be handled - */ -struct xattr_iter_handlers { - 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 erofs_xattr_iter *it, unsigned int value_sz); - void (*value)(struct erofs_xattr_iter *it, unsigned int processed, char *= buf, - unsigned int len); -}; - -/* - * 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 erofs_xattr_iter *it, - const struct xattr_iter_handlers *op, - unsigned int *tlimit) -{ - struct erofs_xattr_entry entry; - unsigned int value_sz, processed, slice; - int err; - - /* 0. fixup blkaddr, ofs, ipage */ - err =3D erofs_xattr_iter_fixup(it); - if (err) - return err; - - /* - * 1. read xattr entry to the memory, - * since we do EROFS_XATTR_ALIGN - * therefore entry should be in the page - */ - entry =3D *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); - if (tlimit) { - unsigned int entry_sz =3D erofs_xattr_entry_size(&entry); - - /* xattr on-disk corruption: xattr entry beyond xattr_isize */ - if (*tlimit < entry_sz) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - *tlimit -=3D entry_sz; - } - - it->ofs +=3D sizeof(struct erofs_xattr_entry); - value_sz =3D le16_to_cpu(entry.e_value_size); - - /* handle entry */ - err =3D op->entry(it, &entry); - if (err) { - it->ofs +=3D entry.e_name_len + value_sz; - goto out; - } - - /* 2. handle xattr name (ofs will finally be at the end of name) */ - processed =3D 0; - - while (processed < entry.e_name_len) { - err =3D erofs_xattr_iter_fixup_aligned(it); - if (err) - goto out; - - slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, - entry.e_name_len - processed); - - /* handle name */ - err =3D op->name(it, processed, it->kaddr + it->ofs, slice); - if (err) { - it->ofs +=3D entry.e_name_len - processed + value_sz; - goto out; - } - - it->ofs +=3D slice; - processed +=3D slice; - } - - /* 3. handle xattr value */ - processed =3D 0; - - if (op->alloc_buffer) { - err =3D op->alloc_buffer(it, value_sz); - if (err) { - it->ofs +=3D value_sz; - goto out; - } - } - - while (processed < value_sz) { - err =3D erofs_xattr_iter_fixup_aligned(it); - if (err) - goto out; - - slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, - value_sz - processed); - op->value(it, processed, it->kaddr + it->ofs, slice); - it->ofs +=3D slice; - processed +=3D slice; - } - -out: - /* xattrs should be 4-byte aligned (on-disk constraint) */ - it->ofs =3D EROFS_XATTR_ALIGN(it->ofs); - return err < 0 ? err : 0; -} - -static int xattr_entrymatch(struct erofs_xattr_iter *it, - struct erofs_xattr_entry *entry) -{ - return (it->index !=3D entry->e_name_index || - it->name.len !=3D entry->e_name_len) ? -ENOATTR : 0; -} - -static int xattr_namematch(struct erofs_xattr_iter *it, - unsigned int processed, char *buf, unsigned int len) -{ - return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0; -} - -static int xattr_checkbuffer(struct erofs_xattr_iter *it, - unsigned int value_sz) -{ - int err =3D it->buffer_size < value_sz ? -ERANGE : 0; - - it->buffer_ofs =3D value_sz; - return !it->buffer ? 1 : err; -} - -static void xattr_copyvalue(struct erofs_xattr_iter *it, - unsigned int processed, - char *buf, unsigned int len) -{ - memcpy(it->buffer + processed, buf, len); -} - -static const struct xattr_iter_handlers find_xattr_handlers =3D { - .entry =3D xattr_entrymatch, - .name =3D xattr_namematch, - .alloc_buffer =3D xattr_checkbuffer, - .value =3D xattr_copyvalue -}; - static bool erofs_xattr_user_list(struct dentry *dentry) { return test_opt(&EROFS_SB(dentry->d_sb)->opt, XATTR_USER); @@ -367,62 +221,178 @@ static inline const struct xattr_handler *erofs_xatt= r_handler(unsigned int idx) xattr_handler_map[idx] : NULL; } =20 -static int xattr_entrylist(struct erofs_xattr_iter *it, - struct erofs_xattr_entry *entry) +/* + * the general idea for these return values is + * if 0 is returned, go on processing the current xattr; + * 1 (> 0) is returned, skip this round to process the next xattr; + * -err (< 0) is returned, an error (maybe ENOXATTR) occurred + * and need to be handled + */ +typedef int (*erofs_xattr_body_handler)(struct erofs_xattr_iter *it, + unsigned int processed, + char *buf, unsigned int len); + +static int erofs_xattr_namematch(struct erofs_xattr_iter *it, + unsigned int processed, char *buf, unsigned int len) +{ + return memcmp(buf, it->name.name + processed, len) ? -ENOATTR : 0; +} + +static int erofs_xattr_copy(struct erofs_xattr_iter *it, + unsigned int unused, char *buf, unsigned int len) +{ + memcpy(it->buffer + it->buffer_ofs, buf, len); + it->buffer_ofs +=3D len; + return 0; +} + +static int erofs_xattr_body(struct erofs_xattr_iter *it, unsigned int len, + erofs_xattr_body_handler handler) +{ + unsigned int slice, processed =3D 0; + + while (processed < len) { + int err =3D erofs_xattr_iter_fixup_aligned(it); + if (err) + return err; + + slice =3D min_t(unsigned int, it->sb->s_blocksize - it->ofs, + len - processed); + err =3D handler(it, processed, it->kaddr + it->ofs, slice); + if (err) { + it->ofs +=3D len - processed; + return err; + } + + it->ofs +=3D slice; + processed +=3D slice; + } + return 0; +} + +static int erofs_xattr_check_entry(struct erofs_xattr_iter *it) { - unsigned int prefix_len; + int err; + + err =3D erofs_xattr_iter_fixup(it); + if (err) + return err; + + if (it->remaining) { + struct erofs_xattr_entry *entry =3D it->kaddr + it->ofs; + unsigned int entry_sz =3D erofs_xattr_entry_size(entry); + /* xattr on-disk corruption: xattr entry beyond xattr_isize */ + if (it->remaining < entry_sz) { + DBG_BUGON(1); + return -EFSCORRUPTED; + } + it->remaining -=3D entry_sz; + } + return 0; +} + +/* + * Regardless of success or failure, erofs_[get|list]xattr_foreach() will = end up + * with `ofs' pointing to the next xattr item rather than an arbitrary pos= ition. + */ +static int erofs_listxattr_foreach(struct erofs_xattr_iter *it) +{ + struct erofs_xattr_entry entry; + const struct xattr_handler *h; const char *prefix; + unsigned int value_sz, prefix_len, name_sz; + int err; =20 - const struct xattr_handler *h =3D - erofs_xattr_handler(entry->e_name_index); + err =3D erofs_xattr_check_entry(it); + if (err) + return err; =20 - if (!h || (h->list && !h->list(it->dentry))) - return 1; + /* 1. handle xattr entry */ + entry =3D *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); + it->ofs +=3D sizeof(struct erofs_xattr_entry); + value_sz =3D le16_to_cpu(entry.e_value_size); + + h =3D erofs_xattr_handler(entry.e_name_index); + if (!h || (h->list && !h->list(it->dentry))) { + it->ofs +=3D entry.e_name_len + value_sz; + goto out; + } =20 prefix =3D xattr_prefix(h); prefix_len =3D strlen(prefix); + name_sz =3D prefix_len + entry.e_name_len + 1; =20 if (!it->buffer) { - it->buffer_ofs +=3D prefix_len + entry->e_name_len + 1; - return 1; + it->buffer_ofs +=3D name_sz; + it->ofs +=3D entry.e_name_len + value_sz; + goto out; } - - if (it->buffer_ofs + prefix_len - + entry->e_name_len + 1 > it->buffer_size) + if (it->buffer_ofs + name_sz > it->buffer_size) return -ERANGE; =20 memcpy(it->buffer + it->buffer_ofs, prefix, prefix_len); it->buffer_ofs +=3D prefix_len; - return 0; -} =20 -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 +=3D len; + /* 2. handle xattr name (err can't be 1 or ENOATTR) */ + err =3D erofs_xattr_body(it, entry.e_name_len, erofs_xattr_copy); + if (err) + return err; + + it->buffer[it->buffer_ofs++] =3D '\0'; + it->ofs +=3D value_sz; +out: + it->ofs =3D EROFS_XATTR_ALIGN(it->ofs); return 0; } =20 -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++] =3D '\0'; - return 1; -} + struct erofs_xattr_entry entry; + unsigned int value_sz; + int err; =20 -static const struct xattr_iter_handlers list_xattr_handlers =3D { - .entry =3D xattr_entrylist, - .name =3D xattr_namelist, - .alloc_buffer =3D xattr_skipvalue, - .value =3D NULL -}; + err =3D erofs_xattr_check_entry(it); + if (err) + return err; + + /* 1. handle xattr entry */ + entry =3D *(struct erofs_xattr_entry *)(it->kaddr + it->ofs); + it->ofs +=3D sizeof(struct erofs_xattr_entry); + value_sz =3D le16_to_cpu(entry.e_value_size); + + if (it->index !=3D entry.e_name_index || it->name.len !=3D entry.e_name_l= en) { + it->ofs +=3D entry.e_name_len + value_sz; + err =3D -ENOATTR; + goto out; + } + + /* 2. handle xattr name */ + err =3D erofs_xattr_body(it, entry.e_name_len, erofs_xattr_namematch); + if (err) { + it->ofs +=3D value_sz; + goto out; + } + + /* 3. handle xattr value */ + if (!it->buffer) { + it->buffer_ofs =3D value_sz; + it->ofs +=3D value_sz; + goto out; /* err =3D=3D 0 */ + } + if (it->buffer_size < value_sz) + return -ERANGE; + + /* no need updating ofs on error (err can't be 1 or ENOATTR) */ + err =3D erofs_xattr_body(it, value_sz, erofs_xattr_copy); +out: + it->ofs =3D EROFS_XATTR_ALIGN(it->ofs); + return err < 0 ? err : 0; +} =20 static int erofs_iter_inline_xattr(struct erofs_xattr_iter *it) { struct erofs_inode *const vi =3D EROFS_I(it->inode); - const struct xattr_iter_handlers *op; - unsigned int xattr_header_sz, remaining; + unsigned int xattr_header_sz; erofs_off_t pos; int ret; =20 @@ -440,11 +410,12 @@ static int erofs_iter_inline_xattr(struct erofs_xattr= _iter *it) if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); =20 - remaining =3D vi->xattr_isize - xattr_header_sz; - op =3D it->getxattr ? &find_xattr_handlers : &list_xattr_handlers; - - while (remaining) { - ret =3D xattr_foreach(it, op, &remaining); + it->remaining =3D vi->xattr_isize - xattr_header_sz; + while (it->remaining) { + if (it->getxattr) + ret =3D erofs_getxattr_foreach(it); + else + ret =3D erofs_listxattr_foreach(it); if ((it->getxattr && ret !=3D -ENOATTR) || (!it->getxattr && ret)) break; } @@ -455,12 +426,9 @@ static int erofs_iter_shared_xattr(struct erofs_xattr_= iter *it) { struct erofs_inode *const vi =3D EROFS_I(it->inode); struct super_block *const sb =3D it->sb; - const struct xattr_iter_handlers *op; unsigned int i, xsid; int ret =3D -ENOATTR; =20 - op =3D it->getxattr ? &find_xattr_handlers : &list_xattr_handlers; - for (i =3D 0; i < vi->xattr_shared_count; ++i) { xsid =3D vi->xattr_shared_xattrs[i]; it->blkaddr =3D EROFS_SB(sb)->xattr_blkaddr + @@ -470,7 +438,10 @@ static int erofs_iter_shared_xattr(struct erofs_xattr_= iter *it) if (IS_ERR(it->kaddr)) return PTR_ERR(it->kaddr); =20 - ret =3D xattr_foreach(it, op, NULL); + if (it->getxattr) + ret =3D erofs_getxattr_foreach(it); + else + ret =3D erofs_listxattr_foreach(it); if ((it->getxattr && ret !=3D -ENOATTR) || (!it->getxattr && ret)) break; } --=20 2.19.1.6.gb485710b