From nobody Mon Feb 9 17:56:13 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 25DCEC761AF for ; Thu, 30 Mar 2023 08:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230400AbjC3I3T (ORCPT ); Thu, 30 Mar 2023 04:29:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbjC3I3Q (ORCPT ); Thu, 30 Mar 2023 04:29:16 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3352A18C for ; Thu, 30 Mar 2023 01:29:15 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;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_---0VezocA0_1680164951; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VezocA0_1680164951) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:12 +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 v2 1/8] erofs: move several xattr helpers into xattr.c Date: Thu, 30 Mar 2023 16:29:03 +0800 Message-Id: <20230330082910.125374-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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" Move xattrblock_addr() and xattrblock_offset() helpers into xattr.c, as they are not used outside of xattr.c. inlinexattr_header_size() has only one caller, and thus make it inlined into the caller directly. Signed-off-by: Jingbo Xu Acked-by: Chao Yu Reviewed-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/xattr.c | 48 +++++++++++++++++++++++++++++------------------- fs/erofs/xattr.h | 23 ----------------------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 459caa3cd65d..9ccd57581bc7 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) @@ -562,20 +574,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..a65158cba14f 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -13,29 +13,6 @@ /* 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; --=20 2.19.1.6.gb485710b From nobody Mon Feb 9 17:56:13 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 BE94CC761AF for ; Thu, 30 Mar 2023 08:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjC3I3X (ORCPT ); Thu, 30 Mar 2023 04:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjC3I3S (ORCPT ); Thu, 30 Mar 2023 04:29:18 -0400 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D880018C for ; Thu, 30 Mar 2023 01:29:16 -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_---0VezvKme_1680164952; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VezvKme_1680164952) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:13 +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 v2 2/8] erofs: rename init_inode_xattrs with erofs_ prefix Date: Thu, 30 Mar 2023 16:29:04 +0800 Message-Id: <20230330082910.125374-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 Acked-by: Chao Yu Reviewed-by: Yue Hu --- 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 9ccd57581bc7..dc36a0c0919c 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; @@ -405,7 +405,7 @@ int erofs_getxattr(struct inode *inode, int index, if (!name) return -EINVAL; =20 - ret =3D init_inode_xattrs(inode); + ret =3D erofs_init_inode_xattrs(inode); if (ret) return ret; =20 @@ -600,7 +600,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 Mon Feb 9 17:56:13 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 6BDE7C6FD1D for ; Thu, 30 Mar 2023 08:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230446AbjC3I3V (ORCPT ); Thu, 30 Mar 2023 04:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbjC3I3S (ORCPT ); Thu, 30 Mar 2023 04:29:18 -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 CF025E4 for ; Thu, 30 Mar 2023 01:29:16 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R641e4;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_---0Vezpke1_1680164953; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vezpke1_1680164953) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:14 +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 v2 3/8] erofs: simplify erofs_xattr_generic_get() Date: Thu, 30 Mar 2023 16:29:05 +0800 Message-Id: <20230330082910.125374-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 Reviewed-by: Chao Yu Reviewed-by: Yue Hu --- 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 dc36a0c0919c..d76b74ece2e5 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -432,20 +432,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 Mon Feb 9 17:56:13 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 C28F6C6FD1D for ; Thu, 30 Mar 2023 08:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbjC3I3Z (ORCPT ); Thu, 30 Mar 2023 04:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230412AbjC3I3T (ORCPT ); Thu, 30 Mar 2023 04:29:19 -0400 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35375B92 for ; Thu, 30 Mar 2023 01:29:17 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;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_---0Vezs-DU_1680164954; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vezs-DU_1680164954) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:15 +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 v2 4/8] erofs: introduce erofs_xattr_iter_fixup_aligned() helper Date: Thu, 30 Mar 2023 16:29:06 +0800 Message-Id: <20230330082910.125374-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 d76b74ece2e5..f77d938613cc 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 Mon Feb 9 17:56:13 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 4A6F7C77B61 for ; Thu, 30 Mar 2023 08:29:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230142AbjC3I3b (ORCPT ); Thu, 30 Mar 2023 04:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbjC3I3U (ORCPT ); Thu, 30 Mar 2023 04:29:20 -0400 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A7D61AD for ; Thu, 30 Mar 2023 01:29:18 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R971e4;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_---0Vezms4H_1680164955; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vezms4H_1680164955) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:16 +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 v2 5/8] erofs: unify xattr_iter structures Date: Thu, 30 Mar 2023 16:29:07 +0800 Message-Id: <20230330082910.125374-6-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 f77d938613cc..c9a893f84250 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; } @@ -388,31 +378,30 @@ int erofs_getxattr(struct inode *inode, int index, 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 @@ -462,19 +451,9 @@ const struct xattr_handler *erofs_xattr_handlers[] =3D= { 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 @@ -501,23 +480,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; } @@ -529,42 +502,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; } @@ -575,7 +547,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) @@ -583,18 +555,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 Mon Feb 9 17:56:13 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 50534C6FD1D for ; Thu, 30 Mar 2023 08:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230489AbjC3I3d (ORCPT ); Thu, 30 Mar 2023 04:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230423AbjC3I3V (ORCPT ); Thu, 30 Mar 2023 04:29:21 -0400 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDF0F6A5F for ; Thu, 30 Mar 2023 01:29:19 -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=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VezvKoc_1680164956; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VezvKoc_1680164956) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:17 +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 v2 6/8] erofs: make the size of read data stored in buffer_ofs Date: Thu, 30 Mar 2023 16:29:08 +0800 Message-Id: <20230330082910.125374-7-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 c9a893f84250..5bd2c2fcbafd 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 Mon Feb 9 17:56:13 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 C5EE9C77B61 for ; Thu, 30 Mar 2023 08:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229867AbjC3I3g (ORCPT ); Thu, 30 Mar 2023 04:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbjC3I3W (ORCPT ); Thu, 30 Mar 2023 04:29:22 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A92F072B2 for ; Thu, 30 Mar 2023 01:29:20 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R881e4;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_---0VezvKp4_1680164957; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VezvKp4_1680164957) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:17 +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 v2 7/8] erofs: unify inline/share xattr iterators for listxattr/getxattr Date: Thu, 30 Mar 2023 16:29:09 +0800 Message-Id: <20230330082910.125374-8-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 | 211 ++++++++++++++++++----------------------------- 1 file changed, 80 insertions(+), 131 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 5bd2c2fcbafd..541d508e7758 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -7,19 +7,6 @@ #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 erofs_xattr_iter { struct super_block *sb; struct erofs_buf buf; @@ -33,6 +20,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 +157,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 +288,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,38 +298,6 @@ static bool erofs_xattr_trusted_list(struct dentry *de= ntry) return capable(CAP_SYS_ADMIN); } =20 -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) @@ -502,45 +395,97 @@ 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; +} + +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, @@ -559,15 +504,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 Mon Feb 9 17:56:13 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 75B99C6FD1D for ; Thu, 30 Mar 2023 08:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbjC3I34 (ORCPT ); Thu, 30 Mar 2023 04:29:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjC3I32 (ORCPT ); Thu, 30 Mar 2023 04:29:28 -0400 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44577769C for ; Thu, 30 Mar 2023 01:29:22 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R791e4;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_---0Vezms5K_1680164958; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vezms5K_1680164958) by smtp.aliyun-inc.com; Thu, 30 Mar 2023 16:29:18 +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 v2 8/8] erofs: use separate xattr parsers for listxattr/getxattr Date: Thu, 30 Mar 2023 16:29:10 +0800 Message-Id: <20230330082910.125374-9-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230330082910.125374-1-jefflexu@linux.alibaba.com> References: <20230330082910.125374-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 541d508e7758..8851c38e8ca7 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -21,6 +21,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 @@ -141,153 +142,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); @@ -344,62 +198,178 @@ const struct xattr_handler *erofs_xattr_handlers[] = =3D { 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; +} + +/* + * Wen returning 0 or ENOATTR, 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 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 ENOATTR) */ + err =3D erofs_xattr_body(it, value_sz, erofs_xattr_copy); +out: + it->ofs =3D EROFS_XATTR_ALIGN(it->ofs); + return err; +} =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 @@ -417,11 +387,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; } @@ -432,12 +403,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 + @@ -447,7 +415,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