static struct hlist_head *
inode_hashtable __read_mostly;
/*
* Initialize the waitqueues and inode hash table.
*/
void __init
inode_init_early(void)
{
unsigned int loop;
/* If hashes are distributed across NUMA nodes, defer
* hash allocation until vmalloc space is available.
*/
if (hashdist)
return;
inode_hashtable =
alloc_large_system_hash("Inode-cache",
sizeof(struct hlist_head),
ihash_entries,
14,
HASH_EARLY,
&i_hash_shift,
&i_hash_mask,
0,
0);
for (loop = 0; loop < (1U << i_hash_shift); loop++)
INIT_HLIST_HEAD(&inode_hashtable[loop]);
}
static inline void
insert_inode_hash(struct inode *inode)
{
__insert_inode_hash(inode, inode->
i_ino);
}
static unsigned long hash(struct super_block *sb, unsigned long hashval)
{
unsigned long tmp;
tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) /
L1_CACHE_BYTES;
tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> i_hash_shift);
return tmp & i_hash_mask;
}
/**
*
__insert_inode_hash - hash an inode
*
@inode: unhashed inode
*
@hashval: unsigned long value used to locate this object in the
*
inode_hashtable.
*
*
Add an inode to the inode hash for this superblock.
*/
void
__insert_inode_hash(struct inode *inode, unsigned long hashval)
{
struct hlist_head *b = inode_hashtable + hash(inode->i_sb, hashval);
spin_lock(&inode_hash_lock);
spin_lock(&inode->i_lock);
hlist_add_head(&inode->i_hash, b);
spin_unlock(&inode->i_lock);
spin_unlock(&inode_hash_lock);
}
EXPORT_SYMBOL(__insert_inode_hash);
/** *
__remove_inode_hash -
remove an inode from the hash *
@inode: inode to unhash * *
Remove an inode from the superblock. */void
__remove_inode_hash(struct inode *inode){
spin_lock(&inode_hash_lock);
spin_lock(&inode->i_lock);
hlist_del_init(&inode->i_hash);
spin_unlock(&inode->i_lock);
spin_unlock(&inode_hash_lock);}EXPORT_SYMBOL(__remove_inode_hash);
转载请注明原文地址: https://ju.6miu.com/read-36903.html