3939
4040/*
4141 * Usage:
42- * dcache_inode_lock protects:
43- * - i_dentry, d_alias, d_inode
42+ * dcache->d_inode->i_lock protects:
43+ * - i_dentry, d_alias, d_inode of aliases
4444 * dcache_hash_bucket lock protects:
4545 * - the dcache hash table
4646 * s_anon bl list spinlock protects:
5858 * - d_alias, d_inode
5959 *
6060 * Ordering:
61- * dcache_inode_lock
61+ * dentry->d_inode->i_lock
6262 * dentry->d_lock
6363 * dcache_lru_lock
6464 * dcache_hash_bucket lock
7878int sysctl_vfs_cache_pressure __read_mostly = 100 ;
7979EXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure );
8080
81- __cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_inode_lock );
8281static __cacheline_aligned_in_smp DEFINE_SPINLOCK (dcache_lru_lock );
8382__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock );
8483
8584EXPORT_SYMBOL (rename_lock );
86- EXPORT_SYMBOL (dcache_inode_lock );
8785
8886static struct kmem_cache * dentry_cache __read_mostly ;
8987
@@ -196,14 +194,14 @@ static inline void dentry_rcuwalk_barrier(struct dentry *dentry)
196194 */
197195static void dentry_iput (struct dentry * dentry )
198196 __releases (dentry - > d_lock )
199- __releases (dcache_inode_lock )
197+ __releases (dentry - > d_inode - > i_lock )
200198{
201199 struct inode * inode = dentry -> d_inode ;
202200 if (inode ) {
203201 dentry -> d_inode = NULL ;
204202 list_del_init (& dentry -> d_alias );
205203 spin_unlock (& dentry -> d_lock );
206- spin_unlock (& dcache_inode_lock );
204+ spin_unlock (& inode -> i_lock );
207205 if (!inode -> i_nlink )
208206 fsnotify_inoderemove (inode );
209207 if (dentry -> d_op && dentry -> d_op -> d_iput )
@@ -212,7 +210,6 @@ static void dentry_iput(struct dentry * dentry)
212210 iput (inode );
213211 } else {
214212 spin_unlock (& dentry -> d_lock );
215- spin_unlock (& dcache_inode_lock );
216213 }
217214}
218215
@@ -222,14 +219,14 @@ static void dentry_iput(struct dentry * dentry)
222219 */
223220static void dentry_unlink_inode (struct dentry * dentry )
224221 __releases (dentry - > d_lock )
225- __releases (dcache_inode_lock )
222+ __releases (dentry - > d_inode - > i_lock )
226223{
227224 struct inode * inode = dentry -> d_inode ;
228225 dentry -> d_inode = NULL ;
229226 list_del_init (& dentry -> d_alias );
230227 dentry_rcuwalk_barrier (dentry );
231228 spin_unlock (& dentry -> d_lock );
232- spin_unlock (& dcache_inode_lock );
229+ spin_unlock (& inode -> i_lock );
233230 if (!inode -> i_nlink )
234231 fsnotify_inoderemove (inode );
235232 if (dentry -> d_op && dentry -> d_op -> d_iput )
@@ -295,7 +292,7 @@ static void dentry_lru_move_tail(struct dentry *dentry)
295292static struct dentry * d_kill (struct dentry * dentry , struct dentry * parent )
296293 __releases (dentry - > d_lock )
297294 __releases (parent - > d_lock )
298- __releases (dcache_inode_lock )
295+ __releases (dentry - > d_inode - > i_lock )
299296{
300297 dentry -> d_parent = NULL ;
301298 list_del (& dentry -> d_u .d_child );
@@ -370,9 +367,11 @@ EXPORT_SYMBOL(d_drop);
370367static inline struct dentry * dentry_kill (struct dentry * dentry , int ref )
371368 __releases (dentry - > d_lock )
372369{
370+ struct inode * inode ;
373371 struct dentry * parent ;
374372
375- if (!spin_trylock (& dcache_inode_lock )) {
373+ inode = dentry -> d_inode ;
374+ if (inode && !spin_trylock (& inode -> i_lock )) {
376375relock :
377376 spin_unlock (& dentry -> d_lock );
378377 cpu_relax ();
@@ -383,7 +382,8 @@ static inline struct dentry *dentry_kill(struct dentry *dentry, int ref)
383382 else
384383 parent = dentry -> d_parent ;
385384 if (parent && !spin_trylock (& parent -> d_lock )) {
386- spin_unlock (& dcache_inode_lock );
385+ if (inode )
386+ spin_unlock (& inode -> i_lock );
387387 goto relock ;
388388 }
389389
@@ -618,9 +618,9 @@ struct dentry *d_find_alias(struct inode *inode)
618618 struct dentry * de = NULL ;
619619
620620 if (!list_empty (& inode -> i_dentry )) {
621- spin_lock (& dcache_inode_lock );
621+ spin_lock (& inode -> i_lock );
622622 de = __d_find_alias (inode , 0 );
623- spin_unlock (& dcache_inode_lock );
623+ spin_unlock (& inode -> i_lock );
624624 }
625625 return de ;
626626}
@@ -634,20 +634,20 @@ void d_prune_aliases(struct inode *inode)
634634{
635635 struct dentry * dentry ;
636636restart :
637- spin_lock (& dcache_inode_lock );
637+ spin_lock (& inode -> i_lock );
638638 list_for_each_entry (dentry , & inode -> i_dentry , d_alias ) {
639639 spin_lock (& dentry -> d_lock );
640640 if (!dentry -> d_count ) {
641641 __dget_dlock (dentry );
642642 __d_drop (dentry );
643643 spin_unlock (& dentry -> d_lock );
644- spin_unlock (& dcache_inode_lock );
644+ spin_unlock (& inode -> i_lock );
645645 dput (dentry );
646646 goto restart ;
647647 }
648648 spin_unlock (& dentry -> d_lock );
649649 }
650- spin_unlock (& dcache_inode_lock );
650+ spin_unlock (& inode -> i_lock );
651651}
652652EXPORT_SYMBOL (d_prune_aliases );
653653
@@ -1392,9 +1392,11 @@ static void __d_instantiate(struct dentry *dentry, struct inode *inode)
13921392void d_instantiate (struct dentry * entry , struct inode * inode )
13931393{
13941394 BUG_ON (!list_empty (& entry -> d_alias ));
1395- spin_lock (& dcache_inode_lock );
1395+ if (inode )
1396+ spin_lock (& inode -> i_lock );
13961397 __d_instantiate (entry , inode );
1397- spin_unlock (& dcache_inode_lock );
1398+ if (inode )
1399+ spin_unlock (& inode -> i_lock );
13981400 security_d_instantiate (entry , inode );
13991401}
14001402EXPORT_SYMBOL (d_instantiate );
@@ -1458,9 +1460,11 @@ struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode)
14581460
14591461 BUG_ON (!list_empty (& entry -> d_alias ));
14601462
1461- spin_lock (& dcache_inode_lock );
1463+ if (inode )
1464+ spin_lock (& inode -> i_lock );
14621465 result = __d_instantiate_unique (entry , inode );
1463- spin_unlock (& dcache_inode_lock );
1466+ if (inode )
1467+ spin_unlock (& inode -> i_lock );
14641468
14651469 if (!result ) {
14661470 security_d_instantiate (entry , inode );
@@ -1542,10 +1546,10 @@ struct dentry *d_obtain_alias(struct inode *inode)
15421546 tmp -> d_parent = tmp ; /* make sure dput doesn't croak */
15431547
15441548
1545- spin_lock (& dcache_inode_lock );
1549+ spin_lock (& inode -> i_lock );
15461550 res = __d_find_alias (inode , 0 );
15471551 if (res ) {
1548- spin_unlock (& dcache_inode_lock );
1552+ spin_unlock (& inode -> i_lock );
15491553 dput (tmp );
15501554 goto out_iput ;
15511555 }
@@ -1561,7 +1565,7 @@ struct dentry *d_obtain_alias(struct inode *inode)
15611565 hlist_bl_add_head (& tmp -> d_hash , & tmp -> d_sb -> s_anon );
15621566 __bit_spin_unlock (0 , (unsigned long * )& tmp -> d_sb -> s_anon .first );
15631567 spin_unlock (& tmp -> d_lock );
1564- spin_unlock (& dcache_inode_lock );
1568+ spin_unlock (& inode -> i_lock );
15651569
15661570 return tmp ;
15671571
@@ -1592,18 +1596,18 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
15921596 struct dentry * new = NULL ;
15931597
15941598 if (inode && S_ISDIR (inode -> i_mode )) {
1595- spin_lock (& dcache_inode_lock );
1599+ spin_lock (& inode -> i_lock );
15961600 new = __d_find_alias (inode , 1 );
15971601 if (new ) {
15981602 BUG_ON (!(new -> d_flags & DCACHE_DISCONNECTED ));
1599- spin_unlock (& dcache_inode_lock );
1603+ spin_unlock (& inode -> i_lock );
16001604 security_d_instantiate (new , inode );
16011605 d_move (new , dentry );
16021606 iput (inode );
16031607 } else {
1604- /* already got dcache_inode_lock , so d_add() by hand */
1608+ /* already taking inode->i_lock , so d_add() by hand */
16051609 __d_instantiate (dentry , inode );
1606- spin_unlock (& dcache_inode_lock );
1610+ spin_unlock (& inode -> i_lock );
16071611 security_d_instantiate (dentry , inode );
16081612 d_rehash (dentry );
16091613 }
@@ -1676,10 +1680,10 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
16761680 * Negative dentry: instantiate it unless the inode is a directory and
16771681 * already has a dentry.
16781682 */
1679- spin_lock (& dcache_inode_lock );
1683+ spin_lock (& inode -> i_lock );
16801684 if (!S_ISDIR (inode -> i_mode ) || list_empty (& inode -> i_dentry )) {
16811685 __d_instantiate (found , inode );
1682- spin_unlock (& dcache_inode_lock );
1686+ spin_unlock (& inode -> i_lock );
16831687 security_d_instantiate (found , inode );
16841688 return found ;
16851689 }
@@ -1690,7 +1694,7 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
16901694 */
16911695 new = list_entry (inode -> i_dentry .next , struct dentry , d_alias );
16921696 __dget (new );
1693- spin_unlock (& dcache_inode_lock );
1697+ spin_unlock (& inode -> i_lock );
16941698 security_d_instantiate (found , inode );
16951699 d_move (new , found );
16961700 iput (inode );
@@ -2004,15 +2008,17 @@ EXPORT_SYMBOL(d_validate);
20042008
20052009void d_delete (struct dentry * dentry )
20062010{
2011+ struct inode * inode ;
20072012 int isdir = 0 ;
20082013 /*
20092014 * Are we the only user?
20102015 */
20112016again :
20122017 spin_lock (& dentry -> d_lock );
2013- isdir = S_ISDIR (dentry -> d_inode -> i_mode );
2018+ inode = dentry -> d_inode ;
2019+ isdir = S_ISDIR (inode -> i_mode );
20142020 if (dentry -> d_count == 1 ) {
2015- if (!spin_trylock (& dcache_inode_lock )) {
2021+ if (inode && !spin_trylock (& inode -> i_lock )) {
20162022 spin_unlock (& dentry -> d_lock );
20172023 cpu_relax ();
20182024 goto again ;
@@ -2266,13 +2272,13 @@ struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2)
22662272 * This helper attempts to cope with remotely renamed directories
22672273 *
22682274 * It assumes that the caller is already holding
2269- * dentry->d_parent->d_inode->i_mutex and the dcache_inode_lock
2275+ * dentry->d_parent->d_inode->i_mutex and the inode->i_lock
22702276 *
22712277 * Note: If ever the locking in lock_rename() changes, then please
22722278 * remember to update this too...
22732279 */
2274- static struct dentry * __d_unalias (struct dentry * dentry , struct dentry * alias )
2275- __releases ( dcache_inode_lock )
2280+ static struct dentry * __d_unalias (struct inode * inode ,
2281+ struct dentry * dentry , struct dentry * alias )
22762282{
22772283 struct mutex * m1 = NULL , * m2 = NULL ;
22782284 struct dentry * ret ;
@@ -2298,7 +2304,7 @@ static struct dentry *__d_unalias(struct dentry *dentry, struct dentry *alias)
22982304 d_move (alias , dentry );
22992305 ret = alias ;
23002306out_err :
2301- spin_unlock (& dcache_inode_lock );
2307+ spin_unlock (& inode -> i_lock );
23022308 if (m2 )
23032309 mutex_unlock (m2 );
23042310 if (m1 )
@@ -2371,7 +2377,7 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
23712377 goto out_nolock ;
23722378 }
23732379
2374- spin_lock (& dcache_inode_lock );
2380+ spin_lock (& inode -> i_lock );
23752381
23762382 if (S_ISDIR (inode -> i_mode )) {
23772383 struct dentry * alias ;
@@ -2388,7 +2394,7 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
23882394 goto found ;
23892395 }
23902396 /* Nope, but we must(!) avoid directory aliasing */
2391- actual = __d_unalias (dentry , alias );
2397+ actual = __d_unalias (inode , dentry , alias );
23922398 if (IS_ERR (actual ))
23932399 dput (alias );
23942400 goto out_nolock ;
@@ -2406,7 +2412,7 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
24062412found :
24072413 _d_rehash (actual );
24082414 spin_unlock (& actual -> d_lock );
2409- spin_unlock (& dcache_inode_lock );
2415+ spin_unlock (& inode -> i_lock );
24102416out_nolock :
24112417 if (actual == dentry ) {
24122418 security_d_instantiate (dentry , inode );
0 commit comments