@@ -1275,16 +1275,16 @@ static struct shrinker dcache_shrinker = {
12751275};
12761276
12771277/**
1278- * d_alloc - allocate a dcache entry
1279- * @parent: parent of entry to allocate
1278+ * __d_alloc - allocate a dcache entry
1279+ * @sb: filesystem it will belong to
12801280 * @name: qstr of the name
12811281 *
12821282 * Allocates a dentry. It returns %NULL if there is insufficient memory
12831283 * available. On a success the dentry is returned. The name passed in is
12841284 * copied and the copy passed in may be reused after this call.
12851285 */
12861286
1287- struct dentry * d_alloc (struct dentry * parent , const struct qstr * name )
1287+ struct dentry * __d_alloc (struct super_block * sb , const struct qstr * name )
12881288{
12891289 struct dentry * dentry ;
12901290 char * dname ;
@@ -1314,45 +1314,56 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
13141314 spin_lock_init (& dentry -> d_lock );
13151315 seqcount_init (& dentry -> d_seq );
13161316 dentry -> d_inode = NULL ;
1317- dentry -> d_parent = NULL ;
1318- dentry -> d_sb = NULL ;
1317+ dentry -> d_parent = dentry ;
1318+ dentry -> d_sb = sb ;
13191319 dentry -> d_op = NULL ;
13201320 dentry -> d_fsdata = NULL ;
13211321 INIT_HLIST_BL_NODE (& dentry -> d_hash );
13221322 INIT_LIST_HEAD (& dentry -> d_lru );
13231323 INIT_LIST_HEAD (& dentry -> d_subdirs );
13241324 INIT_LIST_HEAD (& dentry -> d_alias );
13251325 INIT_LIST_HEAD (& dentry -> d_u .d_child );
1326-
1327- if (parent ) {
1328- spin_lock (& parent -> d_lock );
1329- /*
1330- * don't need child lock because it is not subject
1331- * to concurrency here
1332- */
1333- __dget_dlock (parent );
1334- dentry -> d_parent = parent ;
1335- dentry -> d_sb = parent -> d_sb ;
1336- d_set_d_op (dentry , dentry -> d_sb -> s_d_op );
1337- list_add (& dentry -> d_u .d_child , & parent -> d_subdirs );
1338- spin_unlock (& parent -> d_lock );
1339- }
1326+ d_set_d_op (dentry , dentry -> d_sb -> s_d_op );
13401327
13411328 this_cpu_inc (nr_dentry );
13421329
13431330 return dentry ;
13441331}
1332+
1333+ /**
1334+ * d_alloc - allocate a dcache entry
1335+ * @parent: parent of entry to allocate
1336+ * @name: qstr of the name
1337+ *
1338+ * Allocates a dentry. It returns %NULL if there is insufficient memory
1339+ * available. On a success the dentry is returned. The name passed in is
1340+ * copied and the copy passed in may be reused after this call.
1341+ */
1342+ struct dentry * d_alloc (struct dentry * parent , const struct qstr * name )
1343+ {
1344+ struct dentry * dentry = __d_alloc (parent -> d_sb , name );
1345+ if (!dentry )
1346+ return NULL ;
1347+
1348+ spin_lock (& parent -> d_lock );
1349+ /*
1350+ * don't need child lock because it is not subject
1351+ * to concurrency here
1352+ */
1353+ __dget_dlock (parent );
1354+ dentry -> d_parent = parent ;
1355+ list_add (& dentry -> d_u .d_child , & parent -> d_subdirs );
1356+ spin_unlock (& parent -> d_lock );
1357+
1358+ return dentry ;
1359+ }
13451360EXPORT_SYMBOL (d_alloc );
13461361
13471362struct dentry * d_alloc_pseudo (struct super_block * sb , const struct qstr * name )
13481363{
1349- struct dentry * dentry = d_alloc (NULL , name );
1350- if (dentry ) {
1351- dentry -> d_sb = sb ;
1352- d_set_d_op (dentry , dentry -> d_sb -> s_d_op );
1353- dentry -> d_parent = dentry ;
1364+ struct dentry * dentry = __d_alloc (sb , name );
1365+ if (dentry )
13541366 dentry -> d_flags |= DCACHE_DISCONNECTED ;
1355- }
13561367 return dentry ;
13571368}
13581369EXPORT_SYMBOL (d_alloc_pseudo );
@@ -1522,13 +1533,9 @@ struct dentry * d_alloc_root(struct inode * root_inode)
15221533 if (root_inode ) {
15231534 static const struct qstr name = { .name = "/" , .len = 1 };
15241535
1525- res = d_alloc (NULL , & name );
1526- if (res ) {
1527- res -> d_sb = root_inode -> i_sb ;
1528- d_set_d_op (res , res -> d_sb -> s_d_op );
1529- res -> d_parent = res ;
1536+ res = __d_alloc (root_inode -> i_sb , & name );
1537+ if (res )
15301538 d_instantiate (res , root_inode );
1531- }
15321539 }
15331540 return res ;
15341541}
@@ -1589,13 +1596,11 @@ struct dentry *d_obtain_alias(struct inode *inode)
15891596 if (res )
15901597 goto out_iput ;
15911598
1592- tmp = d_alloc ( NULL , & anonstring );
1599+ tmp = __d_alloc ( inode -> i_sb , & anonstring );
15931600 if (!tmp ) {
15941601 res = ERR_PTR (- ENOMEM );
15951602 goto out_iput ;
15961603 }
1597- tmp -> d_parent = tmp ; /* make sure dput doesn't croak */
1598-
15991604
16001605 spin_lock (& inode -> i_lock );
16011606 res = __d_find_any_alias (inode );
@@ -1607,8 +1612,6 @@ struct dentry *d_obtain_alias(struct inode *inode)
16071612
16081613 /* attach a disconnected dentry */
16091614 spin_lock (& tmp -> d_lock );
1610- tmp -> d_sb = inode -> i_sb ;
1611- d_set_d_op (tmp , tmp -> d_sb -> s_d_op );
16121615 tmp -> d_inode = inode ;
16131616 tmp -> d_flags |= DCACHE_DISCONNECTED ;
16141617 list_add (& tmp -> d_alias , & inode -> i_dentry );
0 commit comments