Commit 7c3511a2 authored by Gao Xiang's avatar Gao Xiang

erofs: clean up erofs_iget()

Move inode hash function into inode.c and simplify erofs_iget().

Link: https://lore.kernel.org/r/20230113065226.68801-1-hsiangkao@linux.alibaba.comReviewed-by: default avatarYue Hu <huyue2@coolpad.com>
Reviewed-by: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 2241ab53
...@@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode) ...@@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
} }
/* /*
* erofs nid is 64bits, but i_ino is 'unsigned long', therefore * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
* we should do more for 32-bit platform to find the right inode. * so that it will fit.
*/ */
static int erofs_ilookup_test_actor(struct inode *inode, void *opaque) static ino_t erofs_squash_ino(erofs_nid_t nid)
{ {
const erofs_nid_t nid = *(erofs_nid_t *)opaque; ino_t ino = (ino_t)nid;
if (sizeof(ino_t) < sizeof(erofs_nid_t))
ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
return ino;
}
return EROFS_I(inode)->nid == nid; static int erofs_iget5_eq(struct inode *inode, void *opaque)
{
return EROFS_I(inode)->nid == *(erofs_nid_t *)opaque;
} }
static int erofs_iget_set_actor(struct inode *inode, void *opaque) static int erofs_iget5_set(struct inode *inode, void *opaque)
{ {
const erofs_nid_t nid = *(erofs_nid_t *)opaque; const erofs_nid_t nid = *(erofs_nid_t *)opaque;
inode->i_ino = erofs_inode_hash(nid); inode->i_ino = erofs_squash_ino(nid);
EROFS_I(inode)->nid = nid;
return 0; return 0;
} }
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid) struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
{ {
const unsigned long hashval = erofs_inode_hash(nid);
struct inode *inode; struct inode *inode;
inode = iget5_locked(sb, hashval, erofs_ilookup_test_actor, inode = iget5_locked(sb, erofs_squash_ino(nid), erofs_iget5_eq,
erofs_iget_set_actor, &nid); erofs_iget5_set, &nid);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (inode->i_state & I_NEW) { if (inode->i_state & I_NEW) {
int err; int err = erofs_fill_inode(inode);
struct erofs_inode *vi = EROFS_I(inode);
vi->nid = nid;
err = erofs_fill_inode(inode); if (err) {
if (!err) {
unlock_new_inode(inode);
} else {
iget_failed(inode); iget_failed(inode);
inode = ERR_PTR(err); return ERR_PTR(err);
} }
unlock_new_inode(inode);
} }
return inode; return inode;
} }
......
...@@ -480,15 +480,6 @@ int erofs_map_blocks(struct inode *inode, ...@@ -480,15 +480,6 @@ int erofs_map_blocks(struct inode *inode,
struct erofs_map_blocks *map, int flags); struct erofs_map_blocks *map, int flags);
/* inode.c */ /* inode.c */
static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
{
#if BITS_PER_LONG == 32
return (nid >> 32) ^ (nid & 0xffffffff);
#else
return nid;
#endif
}
extern const struct inode_operations erofs_generic_iops; extern const struct inode_operations erofs_generic_iops;
extern const struct inode_operations erofs_symlink_iops; extern const struct inode_operations erofs_symlink_iops;
extern const struct inode_operations erofs_fast_symlink_iops; extern const struct inode_operations erofs_fast_symlink_iops;
......
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