@@ -108,84 +108,100 @@ static void wake_up_inode(struct inode *inode)
108108 wake_up_bit (& inode -> i_state , __I_LOCK );
109109}
110110
111- static struct inode * alloc_inode (struct super_block * sb )
111+ /**
112+ * inode_init_always - perform inode structure intialisation
113+ * @sb - superblock inode belongs to.
114+ * @inode - inode to initialise
115+ *
116+ * These are initializations that need to be done on every inode
117+ * allocation as the fields are not initialised by slab allocation.
118+ */
119+ struct inode * inode_init_always (struct super_block * sb , struct inode * inode )
112120{
113121 static const struct address_space_operations empty_aops ;
114122 static struct inode_operations empty_iops ;
115123 static const struct file_operations empty_fops ;
116- struct inode * inode ;
117-
118- if (sb -> s_op -> alloc_inode )
119- inode = sb -> s_op -> alloc_inode (sb );
120- else
121- inode = (struct inode * ) kmem_cache_alloc (inode_cachep , GFP_KERNEL );
122124
123- if (inode ) {
124- struct address_space * const mapping = & inode -> i_data ;
125-
126- inode -> i_sb = sb ;
127- inode -> i_blkbits = sb -> s_blocksize_bits ;
128- inode -> i_flags = 0 ;
129- atomic_set (& inode -> i_count , 1 );
130- inode -> i_op = & empty_iops ;
131- inode -> i_fop = & empty_fops ;
132- inode -> i_nlink = 1 ;
133- atomic_set (& inode -> i_writecount , 0 );
134- inode -> i_size = 0 ;
135- inode -> i_blocks = 0 ;
136- inode -> i_bytes = 0 ;
137- inode -> i_generation = 0 ;
125+ struct address_space * const mapping = & inode -> i_data ;
126+
127+ inode -> i_sb = sb ;
128+ inode -> i_blkbits = sb -> s_blocksize_bits ;
129+ inode -> i_flags = 0 ;
130+ atomic_set (& inode -> i_count , 1 );
131+ inode -> i_op = & empty_iops ;
132+ inode -> i_fop = & empty_fops ;
133+ inode -> i_nlink = 1 ;
134+ atomic_set (& inode -> i_writecount , 0 );
135+ inode -> i_size = 0 ;
136+ inode -> i_blocks = 0 ;
137+ inode -> i_bytes = 0 ;
138+ inode -> i_generation = 0 ;
138139#ifdef CONFIG_QUOTA
139- memset (& inode -> i_dquot , 0 , sizeof (inode -> i_dquot ));
140+ memset (& inode -> i_dquot , 0 , sizeof (inode -> i_dquot ));
140141#endif
141- inode -> i_pipe = NULL ;
142- inode -> i_bdev = NULL ;
143- inode -> i_cdev = NULL ;
144- inode -> i_rdev = 0 ;
145- inode -> dirtied_when = 0 ;
146- if (security_inode_alloc (inode )) {
147- if (inode -> i_sb -> s_op -> destroy_inode )
148- inode -> i_sb -> s_op -> destroy_inode (inode );
149- else
150- kmem_cache_free (inode_cachep , (inode ));
151- return NULL ;
152- }
142+ inode -> i_pipe = NULL ;
143+ inode -> i_bdev = NULL ;
144+ inode -> i_cdev = NULL ;
145+ inode -> i_rdev = 0 ;
146+ inode -> dirtied_when = 0 ;
147+ if (security_inode_alloc (inode )) {
148+ if (inode -> i_sb -> s_op -> destroy_inode )
149+ inode -> i_sb -> s_op -> destroy_inode (inode );
150+ else
151+ kmem_cache_free (inode_cachep , (inode ));
152+ return NULL ;
153+ }
153154
154- spin_lock_init (& inode -> i_lock );
155- lockdep_set_class (& inode -> i_lock , & sb -> s_type -> i_lock_key );
155+ spin_lock_init (& inode -> i_lock );
156+ lockdep_set_class (& inode -> i_lock , & sb -> s_type -> i_lock_key );
156157
157- mutex_init (& inode -> i_mutex );
158- lockdep_set_class (& inode -> i_mutex , & sb -> s_type -> i_mutex_key );
158+ mutex_init (& inode -> i_mutex );
159+ lockdep_set_class (& inode -> i_mutex , & sb -> s_type -> i_mutex_key );
159160
160- init_rwsem (& inode -> i_alloc_sem );
161- lockdep_set_class (& inode -> i_alloc_sem , & sb -> s_type -> i_alloc_sem_key );
161+ init_rwsem (& inode -> i_alloc_sem );
162+ lockdep_set_class (& inode -> i_alloc_sem , & sb -> s_type -> i_alloc_sem_key );
162163
163- mapping -> a_ops = & empty_aops ;
164- mapping -> host = inode ;
165- mapping -> flags = 0 ;
166- mapping_set_gfp_mask (mapping , GFP_HIGHUSER_PAGECACHE );
167- mapping -> assoc_mapping = NULL ;
168- mapping -> backing_dev_info = & default_backing_dev_info ;
169- mapping -> writeback_index = 0 ;
164+ mapping -> a_ops = & empty_aops ;
165+ mapping -> host = inode ;
166+ mapping -> flags = 0 ;
167+ mapping_set_gfp_mask (mapping , GFP_HIGHUSER_PAGECACHE );
168+ mapping -> assoc_mapping = NULL ;
169+ mapping -> backing_dev_info = & default_backing_dev_info ;
170+ mapping -> writeback_index = 0 ;
170171
171- /*
172- * If the block_device provides a backing_dev_info for client
173- * inodes then use that. Otherwise the inode share the bdev's
174- * backing_dev_info.
175- */
176- if (sb -> s_bdev ) {
177- struct backing_dev_info * bdi ;
172+ /*
173+ * If the block_device provides a backing_dev_info for client
174+ * inodes then use that. Otherwise the inode share the bdev's
175+ * backing_dev_info.
176+ */
177+ if (sb -> s_bdev ) {
178+ struct backing_dev_info * bdi ;
178179
179- bdi = sb -> s_bdev -> bd_inode_backing_dev_info ;
180- if (!bdi )
181- bdi = sb -> s_bdev -> bd_inode -> i_mapping -> backing_dev_info ;
182- mapping -> backing_dev_info = bdi ;
183- }
184- inode -> i_private = NULL ;
185- inode -> i_mapping = mapping ;
180+ bdi = sb -> s_bdev -> bd_inode_backing_dev_info ;
181+ if (!bdi )
182+ bdi = sb -> s_bdev -> bd_inode -> i_mapping -> backing_dev_info ;
183+ mapping -> backing_dev_info = bdi ;
186184 }
185+ inode -> i_private = NULL ;
186+ inode -> i_mapping = mapping ;
187+
187188 return inode ;
188189}
190+ EXPORT_SYMBOL (inode_init_always );
191+
192+ static struct inode * alloc_inode (struct super_block * sb )
193+ {
194+ struct inode * inode ;
195+
196+ if (sb -> s_op -> alloc_inode )
197+ inode = sb -> s_op -> alloc_inode (sb );
198+ else
199+ inode = kmem_cache_alloc (inode_cachep , GFP_KERNEL );
200+
201+ if (inode )
202+ return inode_init_always (sb , inode );
203+ return NULL ;
204+ }
189205
190206void destroy_inode (struct inode * inode )
191207{
@@ -196,6 +212,7 @@ void destroy_inode(struct inode *inode)
196212 else
197213 kmem_cache_free (inode_cachep , (inode ));
198214}
215+ EXPORT_SYMBOL (destroy_inode );
199216
200217
201218/*
@@ -534,6 +551,49 @@ static struct inode * find_inode_fast(struct super_block * sb, struct hlist_head
534551 return node ? inode : NULL ;
535552}
536553
554+ static unsigned long hash (struct super_block * sb , unsigned long hashval )
555+ {
556+ unsigned long tmp ;
557+
558+ tmp = (hashval * (unsigned long )sb ) ^ (GOLDEN_RATIO_PRIME + hashval ) /
559+ L1_CACHE_BYTES ;
560+ tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME ) >> I_HASHBITS );
561+ return tmp & I_HASHMASK ;
562+ }
563+
564+ static inline void
565+ __inode_add_to_lists (struct super_block * sb , struct hlist_head * head ,
566+ struct inode * inode )
567+ {
568+ inodes_stat .nr_inodes ++ ;
569+ list_add (& inode -> i_list , & inode_in_use );
570+ list_add (& inode -> i_sb_list , & sb -> s_inodes );
571+ if (head )
572+ hlist_add_head (& inode -> i_hash , head );
573+ }
574+
575+ /**
576+ * inode_add_to_lists - add a new inode to relevant lists
577+ * @sb - superblock inode belongs to.
578+ * @inode - inode to mark in use
579+ *
580+ * When an inode is allocated it needs to be accounted for, added to the in use
581+ * list, the owning superblock and the inode hash. This needs to be done under
582+ * the inode_lock, so export a function to do this rather than the inode lock
583+ * itself. We calculate the hash list to add to here so it is all internal
584+ * which requires the caller to have already set up the inode number in the
585+ * inode to add.
586+ */
587+ void inode_add_to_lists (struct super_block * sb , struct inode * inode )
588+ {
589+ struct hlist_head * head = inode_hashtable + hash (sb , inode -> i_ino );
590+
591+ spin_lock (& inode_lock );
592+ __inode_add_to_lists (sb , head , inode );
593+ spin_unlock (& inode_lock );
594+ }
595+ EXPORT_SYMBOL_GPL (inode_add_to_lists );
596+
537597/**
538598 * new_inode - obtain an inode
539599 * @sb: superblock
@@ -561,9 +621,7 @@ struct inode *new_inode(struct super_block *sb)
561621 inode = alloc_inode (sb );
562622 if (inode ) {
563623 spin_lock (& inode_lock );
564- inodes_stat .nr_inodes ++ ;
565- list_add (& inode -> i_list , & inode_in_use );
566- list_add (& inode -> i_sb_list , & sb -> s_inodes );
624+ __inode_add_to_lists (sb , NULL , inode );
567625 inode -> i_ino = ++ last_ino ;
568626 inode -> i_state = 0 ;
569627 spin_unlock (& inode_lock );
@@ -622,10 +680,7 @@ static struct inode * get_new_inode(struct super_block *sb, struct hlist_head *h
622680 if (set (inode , data ))
623681 goto set_failed ;
624682
625- inodes_stat .nr_inodes ++ ;
626- list_add (& inode -> i_list , & inode_in_use );
627- list_add (& inode -> i_sb_list , & sb -> s_inodes );
628- hlist_add_head (& inode -> i_hash , head );
683+ __inode_add_to_lists (sb , head , inode );
629684 inode -> i_state = I_LOCK |I_NEW ;
630685 spin_unlock (& inode_lock );
631686
@@ -671,10 +726,7 @@ static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_he
671726 old = find_inode_fast (sb , head , ino );
672727 if (!old ) {
673728 inode -> i_ino = ino ;
674- inodes_stat .nr_inodes ++ ;
675- list_add (& inode -> i_list , & inode_in_use );
676- list_add (& inode -> i_sb_list , & sb -> s_inodes );
677- hlist_add_head (& inode -> i_hash , head );
729+ __inode_add_to_lists (sb , head , inode );
678730 inode -> i_state = I_LOCK |I_NEW ;
679731 spin_unlock (& inode_lock );
680732
@@ -698,16 +750,6 @@ static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_he
698750 return inode ;
699751}
700752
701- static unsigned long hash (struct super_block * sb , unsigned long hashval )
702- {
703- unsigned long tmp ;
704-
705- tmp = (hashval * (unsigned long )sb ) ^ (GOLDEN_RATIO_PRIME + hashval ) /
706- L1_CACHE_BYTES ;
707- tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME ) >> I_HASHBITS );
708- return tmp & I_HASHMASK ;
709- }
710-
711753/**
712754 * iunique - get a unique inode number
713755 * @sb: superblock
@@ -1292,6 +1334,7 @@ int inode_wait(void *word)
12921334 schedule ();
12931335 return 0 ;
12941336}
1337+ EXPORT_SYMBOL (inode_wait );
12951338
12961339/*
12971340 * If we try to find an inode in the inode hash while it is being
0 commit comments