@@ -276,15 +276,15 @@ static void dentry_lru_prune(struct dentry *dentry)
276276 }
277277}
278278
279- static void dentry_lru_move_tail (struct dentry * dentry )
279+ static void dentry_lru_move_list (struct dentry * dentry , struct list_head * list )
280280{
281281 spin_lock (& dcache_lru_lock );
282282 if (list_empty (& dentry -> d_lru )) {
283- list_add_tail (& dentry -> d_lru , & dentry -> d_sb -> s_dentry_lru );
283+ list_add_tail (& dentry -> d_lru , list );
284284 dentry -> d_sb -> s_nr_dentry_unused ++ ;
285285 dentry_stat .nr_unused ++ ;
286286 } else {
287- list_move_tail (& dentry -> d_lru , & dentry -> d_sb -> s_dentry_lru );
287+ list_move_tail (& dentry -> d_lru , list );
288288 }
289289 spin_unlock (& dcache_lru_lock );
290290}
@@ -770,14 +770,18 @@ static void shrink_dentry_list(struct list_head *list)
770770}
771771
772772/**
773- * __shrink_dcache_sb - shrink the dentry LRU on a given superblock
774- * @sb: superblock to shrink dentry LRU.
775- * @count: number of entries to prune
776- * @flags: flags to control the dentry processing
773+ * prune_dcache_sb - shrink the dcache
774+ * @sb: superblock
775+ * @count: number of entries to try to free
776+ *
777+ * Attempt to shrink the superblock dcache LRU by @count entries. This is
778+ * done when we need more memory an called from the superblock shrinker
779+ * function.
777780 *
778- * If flags contains DCACHE_REFERENCED reference dentries will not be pruned.
781+ * This function may fail to free any resources if all the dentries are in
782+ * use.
779783 */
780- static void __shrink_dcache_sb (struct super_block * sb , int count , int flags )
784+ void prune_dcache_sb (struct super_block * sb , int count )
781785{
782786 struct dentry * dentry ;
783787 LIST_HEAD (referenced );
@@ -796,13 +800,7 @@ static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
796800 goto relock ;
797801 }
798802
799- /*
800- * If we are honouring the DCACHE_REFERENCED flag and the
801- * dentry has this flag set, don't free it. Clear the flag
802- * and put it back on the LRU.
803- */
804- if (flags & DCACHE_REFERENCED &&
805- dentry -> d_flags & DCACHE_REFERENCED ) {
803+ if (dentry -> d_flags & DCACHE_REFERENCED ) {
806804 dentry -> d_flags &= ~DCACHE_REFERENCED ;
807805 list_move (& dentry -> d_lru , & referenced );
808806 spin_unlock (& dentry -> d_lock );
@@ -821,23 +819,6 @@ static void __shrink_dcache_sb(struct super_block *sb, int count, int flags)
821819 shrink_dentry_list (& tmp );
822820}
823821
824- /**
825- * prune_dcache_sb - shrink the dcache
826- * @sb: superblock
827- * @nr_to_scan: number of entries to try to free
828- *
829- * Attempt to shrink the superblock dcache LRU by @nr_to_scan entries. This is
830- * done when we need more memory an called from the superblock shrinker
831- * function.
832- *
833- * This function may fail to free any resources if all the dentries are in
834- * use.
835- */
836- void prune_dcache_sb (struct super_block * sb , int nr_to_scan )
837- {
838- __shrink_dcache_sb (sb , nr_to_scan , DCACHE_REFERENCED );
839- }
840-
841822/**
842823 * shrink_dcache_sb - shrink dcache for a superblock
843824 * @sb: superblock
@@ -1092,7 +1073,7 @@ EXPORT_SYMBOL(have_submounts);
10921073 * drop the lock and return early due to latency
10931074 * constraints.
10941075 */
1095- static int select_parent (struct dentry * parent )
1076+ static int select_parent (struct dentry * parent , struct list_head * dispose )
10961077{
10971078 struct dentry * this_parent ;
10981079 struct list_head * next ;
@@ -1114,12 +1095,11 @@ static int select_parent(struct dentry * parent)
11141095
11151096 spin_lock_nested (& dentry -> d_lock , DENTRY_D_LOCK_NESTED );
11161097
1117- /*
1118- * move only zero ref count dentries to the end
1119- * of the unused list for prune_dcache
1098+ /*
1099+ * move only zero ref count dentries to the dispose list.
11201100 */
11211101 if (!dentry -> d_count ) {
1122- dentry_lru_move_tail (dentry );
1102+ dentry_lru_move_list (dentry , dispose );
11231103 found ++ ;
11241104 } else {
11251105 dentry_lru_del (dentry );
@@ -1181,14 +1161,13 @@ static int select_parent(struct dentry * parent)
11811161 *
11821162 * Prune the dcache to remove unused children of the parent dentry.
11831163 */
1184-
11851164void shrink_dcache_parent (struct dentry * parent )
11861165{
1187- struct super_block * sb = parent -> d_sb ;
1166+ LIST_HEAD ( dispose ) ;
11881167 int found ;
11891168
1190- while ((found = select_parent (parent )) != 0 )
1191- __shrink_dcache_sb ( sb , found , 0 );
1169+ while ((found = select_parent (parent , & dispose )) != 0 )
1170+ shrink_dentry_list ( & dispose );
11921171}
11931172EXPORT_SYMBOL (shrink_dcache_parent );
11941173
@@ -1461,6 +1440,23 @@ struct dentry * d_alloc_root(struct inode * root_inode)
14611440}
14621441EXPORT_SYMBOL (d_alloc_root );
14631442
1443+ struct dentry * d_make_root (struct inode * root_inode )
1444+ {
1445+ struct dentry * res = NULL ;
1446+
1447+ if (root_inode ) {
1448+ static const struct qstr name = { .name = "/" , .len = 1 };
1449+
1450+ res = __d_alloc (root_inode -> i_sb , & name );
1451+ if (res )
1452+ d_instantiate (res , root_inode );
1453+ else
1454+ iput (root_inode );
1455+ }
1456+ return res ;
1457+ }
1458+ EXPORT_SYMBOL (d_make_root );
1459+
14641460static struct dentry * __d_find_any_alias (struct inode * inode )
14651461{
14661462 struct dentry * alias ;
0 commit comments