fs: Stop abusing find_inode_fast in iunique
Stop abusing find_inode_fast for iunique and opencode the inode hash walk. Introduce a new iunique_lock to protect the iunique counters once inode_lock is removed. Based on a patch originally from Nick Piggin. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
committed by
Al Viro
parent
4c51acbc66
commit
ad5e195ac9
30
fs/inode.c
30
fs/inode.c
@@ -884,6 +884,27 @@ static struct inode *get_new_inode_fast(struct super_block *sb,
|
|||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* search the inode cache for a matching inode number.
|
||||||
|
* If we find one, then the inode number we are trying to
|
||||||
|
* allocate is not unique and so we should not use it.
|
||||||
|
*
|
||||||
|
* Returns 1 if the inode number is unique, 0 if it is not.
|
||||||
|
*/
|
||||||
|
static int test_inode_iunique(struct super_block *sb, unsigned long ino)
|
||||||
|
{
|
||||||
|
struct hlist_head *b = inode_hashtable + hash(sb, ino);
|
||||||
|
struct hlist_node *node;
|
||||||
|
struct inode *inode;
|
||||||
|
|
||||||
|
hlist_for_each_entry(inode, node, b, i_hash) {
|
||||||
|
if (inode->i_ino == ino && inode->i_sb == sb)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* iunique - get a unique inode number
|
* iunique - get a unique inode number
|
||||||
* @sb: superblock
|
* @sb: superblock
|
||||||
@@ -905,19 +926,18 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
|
|||||||
* error if st_ino won't fit in target struct field. Use 32bit counter
|
* error if st_ino won't fit in target struct field. Use 32bit counter
|
||||||
* here to attempt to avoid that.
|
* here to attempt to avoid that.
|
||||||
*/
|
*/
|
||||||
|
static DEFINE_SPINLOCK(iunique_lock);
|
||||||
static unsigned int counter;
|
static unsigned int counter;
|
||||||
struct inode *inode;
|
|
||||||
struct hlist_head *head;
|
|
||||||
ino_t res;
|
ino_t res;
|
||||||
|
|
||||||
spin_lock(&inode_lock);
|
spin_lock(&inode_lock);
|
||||||
|
spin_lock(&iunique_lock);
|
||||||
do {
|
do {
|
||||||
if (counter <= max_reserved)
|
if (counter <= max_reserved)
|
||||||
counter = max_reserved + 1;
|
counter = max_reserved + 1;
|
||||||
res = counter++;
|
res = counter++;
|
||||||
head = inode_hashtable + hash(sb, res);
|
} while (!test_inode_iunique(sb, res));
|
||||||
inode = find_inode_fast(sb, head, res);
|
spin_unlock(&iunique_lock);
|
||||||
} while (inode != NULL);
|
|
||||||
spin_unlock(&inode_lock);
|
spin_unlock(&inode_lock);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user