inode节点查找

    xiaoxiao2021-03-25  50

    节点查找,查找是利用前面介绍的hash值进行: /**  * ilookup - search for an inode in the inode cache  * @sb: super block of file system to search  * @ino: inode number to search for  *  * Search for the inode @ino in the inode cache, and if the inode is in the  * cache, the inode is returned with an incremented reference count.  */ struct inode *ilookup(struct super_block *sb, unsigned long ino) { struct hlist_head *head = inode_hashtable + hash(sb, ino); struct inode *inode; again: spin_lock(&inode_hash_lock); inode = find_inode_fast(sb, head, ino); spin_unlock(&inode_hash_lock); if (inode) { wait_on_inode(inode); if (unlikely(inode_unhashed(inode))) { iput(inode); goto again; } } return inode; } /**  * ilookup5 - search for an inode in the inode cache  * @sb: super block of file system to search  * @hashval: hash value (usually inode number) to search for  * @test: callback used for comparisons between inodes  * @data: opaque data pointer to pass to @test  *  * Search for the inode specified by @hashval and @data in the inode cache,  * and if the inode is in the cache, return the inode with an incremented  * reference count.  Waits on I_NEW before returning the inode.  * returned with an incremented reference count.  *  * This is a generalized version of ilookup() for file systems where the  * inode number is not sufficient for unique identification of an inode.  *  * Note: @test is called with the inode_hash_lock held, so can't sleep.  */ struct inode *ilookup5(struct super_block *sb, unsigned long hashval, int (*test)(struct inode *, void *), void *data) { struct inode *inode; again: inode = ilookup5_nowait(sb, hashval, test, data); if (inode) { wait_on_inode(inode); if (unlikely(inode_unhashed(inode))) { iput(inode); goto again; } } return inode; } /**  * ilookup5_nowait - search for an inode in the inode cache  * @sb: super block of file system to search  * @hashval: hash value (usually inode number) to search for  * @test: callback used for comparisons between inodes  * @data: opaque data pointer to pass to @test  *  * Search for the inode specified by @hashval and @data in the inode cache.  * If the inode is in the cache, the inode is returned with an incremented  * reference count.  *  * Note: I_NEW is not waited upon so you have to be very careful what you do  * with the returned inode.  You probably should be using ilookup5() instead.  *  * Note2: @test is called with the inode_hash_lock held, so can't sleep.  */ struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, int (*test)(struct inode *, void *), void *data) { struct hlist_head *head = inode_hashtable + hash(sb, hashval); struct inode *inode; spin_lock(&inode_hash_lock); inode = find_inode(sb, head, test, data); spin_unlock(&inode_hash_lock); return inode; } EXPORT_SYMBOL(ilookup5_nowait); /**  * find_inode_nowait - find an inode in the inode cache  * @sb: super block of file system to search  * @hashval: hash value (usually inode number) to search for  * @match: callback used for comparisons between inodes  * @data: opaque data pointer to pass to @match  *  * Search for the inode specified by @hashval and @data in the inode  * cache, where the helper function @match will return 0 if the inode  * does not match, 1 if the inode does match, and -1 if the search  * should be stopped.  The @match function must be responsible for  * taking the i_lock spin_lock and checking i_state for an inode being  * freed or being initialized, and incrementing the reference count  * before returning 1.  It also must not sleep, since it is called with  * the inode_hash_lock spinlock held.  *  * This is a even more generalized version of ilookup5() when the  * function must never block --- find_inode() can block in  * __wait_on_freeing_inode() --- or when the caller can not increment  * the reference count because the resulting iput() might cause an  * inode eviction.  The tradeoff is that the @match funtion must be  * very carefully implemented.  */ struct inode *find_inode_nowait(struct super_block *sb, unsigned long hashval, int (*match)(struct inode *, unsigned long,     void *), void *data) { struct hlist_head *head = inode_hashtable + hash(sb, hashval); struct inode *inode, *ret_inode = NULL; int mval; spin_lock(&inode_hash_lock); hlist_for_each_entry(inode, head, i_hash) { if (inode->i_sb != sb) continue; mval = match(inode, hashval, data); if (mval == 0) continue; if (mval == 1) ret_inode = inode; goto out; } out: spin_unlock(&inode_hash_lock); return ret_inode; }
    转载请注明原文地址: https://ju.6miu.com/read-36844.html

    最新回复(0)