Commit 399f36d8 authored by Jingbo Xu's avatar Jingbo Xu Committed by Gao Xiang

erofs: move several xattr helpers into xattr.c

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: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
Reviewed-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230330082910.125374-2-jefflexu@linux.alibaba.comReviewed-by: default avatarYue Hu <huyue2@coolpad.com>
Acked-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 1c7f49a7
...@@ -7,6 +7,19 @@ ...@@ -7,6 +7,19 @@
#include <linux/security.h> #include <linux/security.h>
#include "xattr.h" #include "xattr.h"
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 xattr_iter {
struct super_block *sb; struct super_block *sb;
struct erofs_buf buf; struct erofs_buf buf;
...@@ -157,7 +170,8 @@ static int inline_xattr_iter_begin(struct xattr_iter *it, ...@@ -157,7 +170,8 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
struct erofs_inode *const vi = EROFS_I(inode); struct erofs_inode *const vi = EROFS_I(inode);
unsigned int xattr_header_sz, inline_xattr_ofs; unsigned int xattr_header_sz, inline_xattr_ofs;
xattr_header_sz = inlinexattr_header_size(inode); xattr_header_sz = sizeof(struct erofs_xattr_ibody_header) +
sizeof(u32) * vi->xattr_shared_count;
if (xattr_header_sz >= vi->xattr_isize) { if (xattr_header_sz >= vi->xattr_isize) {
DBG_BUGON(xattr_header_sz > vi->xattr_isize); DBG_BUGON(xattr_header_sz > vi->xattr_isize);
return -ENOATTR; return -ENOATTR;
...@@ -351,20 +365,18 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it) ...@@ -351,20 +365,18 @@ static int inline_getxattr(struct inode *inode, struct getxattr_iter *it)
static int shared_getxattr(struct inode *inode, struct getxattr_iter *it) static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
{ {
struct erofs_inode *const vi = EROFS_I(inode); struct erofs_inode *const vi = EROFS_I(inode);
struct super_block *const sb = inode->i_sb; struct super_block *const sb = it->it.sb;
unsigned int i; unsigned int i, xsid;
int ret = -ENOATTR; int ret = -ENOATTR;
for (i = 0; i < vi->xattr_shared_count; ++i) { for (i = 0; i < vi->xattr_shared_count; ++i) {
erofs_blk_t blkaddr = xsid = vi->xattr_shared_xattrs[i];
xattrblock_addr(sb, vi->xattr_shared_xattrs[i]); it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid);
it->it.ofs = erofs_xattr_blkoff(sb, xsid);
it->it.ofs = xattrblock_offset(sb, vi->xattr_shared_xattrs[i]); it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb,
it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr, it->it.blkaddr, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->it.kaddr)) if (IS_ERR(it->it.kaddr))
return PTR_ERR(it->it.kaddr); return PTR_ERR(it->it.kaddr);
it->it.blkaddr = blkaddr;
ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL); ret = xattr_foreach(&it->it, &find_xattr_handlers, NULL);
if (ret != -ENOATTR) if (ret != -ENOATTR)
...@@ -562,20 +574,18 @@ static int shared_listxattr(struct listxattr_iter *it) ...@@ -562,20 +574,18 @@ static int shared_listxattr(struct listxattr_iter *it)
{ {
struct inode *const inode = d_inode(it->dentry); struct inode *const inode = d_inode(it->dentry);
struct erofs_inode *const vi = EROFS_I(inode); struct erofs_inode *const vi = EROFS_I(inode);
struct super_block *const sb = inode->i_sb; struct super_block *const sb = it->it.sb;
unsigned int i; unsigned int i, xsid;
int ret = 0; int ret = 0;
for (i = 0; i < vi->xattr_shared_count; ++i) { for (i = 0; i < vi->xattr_shared_count; ++i) {
erofs_blk_t blkaddr = xsid = vi->xattr_shared_xattrs[i];
xattrblock_addr(sb, vi->xattr_shared_xattrs[i]); it->it.blkaddr = erofs_xattr_blkaddr(sb, xsid);
it->it.ofs = erofs_xattr_blkoff(sb, xsid);
it->it.ofs = xattrblock_offset(sb, vi->xattr_shared_xattrs[i]); it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb,
it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr, it->it.blkaddr, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->it.kaddr)) if (IS_ERR(it->it.kaddr))
return PTR_ERR(it->it.kaddr); return PTR_ERR(it->it.kaddr);
it->it.blkaddr = blkaddr;
ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL); ret = xattr_foreach(&it->it, &list_xattr_handlers, NULL);
if (ret) if (ret)
......
...@@ -13,29 +13,6 @@ ...@@ -13,29 +13,6 @@
/* Attribute not found */ /* Attribute not found */
#define ENOATTR ENODATA #define ENOATTR ENODATA
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 #ifdef CONFIG_EROFS_FS_XATTR
extern const struct xattr_handler erofs_xattr_user_handler; 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_trusted_handler;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment