From nobody Sun Feb 8 14:10:21 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