aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2010-10-23 07:00:16 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2010-10-25 21:26:10 -0400
commitad5e195ac9fdf4e2b28b8cf14937e5b9384dac2e (patch)
tree0345280d9095f5046c03ed25893aad229fae9369 /fs
parent4c51acbc66f754e536e1c9e3331656b69bce86d0 (diff)
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/inode.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 5e5bafe70ceb..a8035e8576df 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -884,6 +884,27 @@ static struct inode *get_new_inode_fast(struct super_block *sb,
884 return inode; 884 return inode;
885} 885}
886 886
887/*
888 * search the inode cache for a matching inode number.
889 * If we find one, then the inode number we are trying to
890 * allocate is not unique and so we should not use it.
891 *
892 * Returns 1 if the inode number is unique, 0 if it is not.
893 */
894static int test_inode_iunique(struct super_block *sb, unsigned long ino)
895{
896 struct hlist_head *b = inode_hashtable + hash(sb, ino);
897 struct hlist_node *node;
898 struct inode *inode;
899
900 hlist_for_each_entry(inode, node, b, i_hash) {
901 if (inode->i_ino == ino && inode->i_sb == sb)
902 return 0;
903 }
904
905 return 1;
906}
907
887/** 908/**
888 * iunique - get a unique inode number 909 * iunique - get a unique inode number
889 * @sb: superblock 910 * @sb: superblock
@@ -905,19 +926,18 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
905 * error if st_ino won't fit in target struct field. Use 32bit counter 926 * error if st_ino won't fit in target struct field. Use 32bit counter
906 * here to attempt to avoid that. 927 * here to attempt to avoid that.
907 */ 928 */
929 static DEFINE_SPINLOCK(iunique_lock);
908 static unsigned int counter; 930 static unsigned int counter;
909 struct inode *inode;
910 struct hlist_head *head;
911 ino_t res; 931 ino_t res;
912 932
913 spin_lock(&inode_lock); 933 spin_lock(&inode_lock);
934 spin_lock(&iunique_lock);
914 do { 935 do {
915 if (counter <= max_reserved) 936 if (counter <= max_reserved)
916 counter = max_reserved + 1; 937 counter = max_reserved + 1;
917 res = counter++; 938 res = counter++;
918 head = inode_hashtable + hash(sb, res); 939 } while (!test_inode_iunique(sb, res));
919 inode = find_inode_fast(sb, head, res); 940 spin_unlock(&iunique_lock);
920 } while (inode != NULL);
921 spin_unlock(&inode_lock); 941 spin_unlock(&inode_lock);
922 942
923 return res; 943 return res;