• Home
  • Raw
  • Download

Lines Matching refs:dentry

107 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,  in d_hash()
203 struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); in __d_free() local
205 WARN_ON(!list_empty(&dentry->d_alias)); in __d_free()
206 if (dname_external(dentry)) in __d_free()
207 kfree(dentry->d_name.name); in __d_free()
208 kmem_cache_free(dentry_cache, dentry); in __d_free()
214 static void d_free(struct dentry *dentry) in d_free() argument
216 BUG_ON(dentry->d_count); in d_free()
218 if (dentry->d_op && dentry->d_op->d_release) in d_free()
219 dentry->d_op->d_release(dentry); in d_free()
222 if (!(dentry->d_flags & DCACHE_RCUACCESS)) in d_free()
223 __d_free(&dentry->d_u.d_rcu); in d_free()
225 call_rcu(&dentry->d_u.d_rcu, __d_free); in d_free()
235 static inline void dentry_rcuwalk_barrier(struct dentry *dentry) in dentry_rcuwalk_barrier() argument
237 assert_spin_locked(&dentry->d_lock); in dentry_rcuwalk_barrier()
239 write_seqcount_barrier(&dentry->d_seq); in dentry_rcuwalk_barrier()
247 static void dentry_iput(struct dentry * dentry) in dentry_iput() argument
248 __releases(dentry->d_lock) in dentry_iput()
249 __releases(dentry->d_inode->i_lock) in dentry_iput()
251 struct inode *inode = dentry->d_inode; in dentry_iput()
253 dentry->d_inode = NULL; in dentry_iput()
254 list_del_init(&dentry->d_alias); in dentry_iput()
255 spin_unlock(&dentry->d_lock); in dentry_iput()
259 if (dentry->d_op && dentry->d_op->d_iput) in dentry_iput()
260 dentry->d_op->d_iput(dentry, inode); in dentry_iput()
264 spin_unlock(&dentry->d_lock); in dentry_iput()
272 static void dentry_unlink_inode(struct dentry * dentry) in dentry_unlink_inode() argument
273 __releases(dentry->d_lock) in dentry_unlink_inode()
274 __releases(dentry->d_inode->i_lock) in dentry_unlink_inode()
276 struct inode *inode = dentry->d_inode; in dentry_unlink_inode()
277 dentry->d_inode = NULL; in dentry_unlink_inode()
278 list_del_init(&dentry->d_alias); in dentry_unlink_inode()
279 dentry_rcuwalk_barrier(dentry); in dentry_unlink_inode()
280 spin_unlock(&dentry->d_lock); in dentry_unlink_inode()
284 if (dentry->d_op && dentry->d_op->d_iput) in dentry_unlink_inode()
285 dentry->d_op->d_iput(dentry, inode); in dentry_unlink_inode()
293 static void dentry_lru_add(struct dentry *dentry) in dentry_lru_add() argument
295 if (list_empty(&dentry->d_lru)) { in dentry_lru_add()
297 list_add(&dentry->d_lru, &dentry->d_sb->s_dentry_lru); in dentry_lru_add()
298 dentry->d_sb->s_nr_dentry_unused++; in dentry_lru_add()
304 static void __dentry_lru_del(struct dentry *dentry) in __dentry_lru_del() argument
306 list_del_init(&dentry->d_lru); in __dentry_lru_del()
307 dentry->d_flags &= ~DCACHE_SHRINK_LIST; in __dentry_lru_del()
308 dentry->d_sb->s_nr_dentry_unused--; in __dentry_lru_del()
315 static void dentry_lru_del(struct dentry *dentry) in dentry_lru_del() argument
317 if (!list_empty(&dentry->d_lru)) { in dentry_lru_del()
319 __dentry_lru_del(dentry); in dentry_lru_del()
329 static void dentry_lru_prune(struct dentry *dentry) in dentry_lru_prune() argument
331 if (!list_empty(&dentry->d_lru)) { in dentry_lru_prune()
332 if (dentry->d_flags & DCACHE_OP_PRUNE) in dentry_lru_prune()
333 dentry->d_op->d_prune(dentry); in dentry_lru_prune()
336 __dentry_lru_del(dentry); in dentry_lru_prune()
341 static void dentry_lru_move_list(struct dentry *dentry, struct list_head *list) in dentry_lru_move_list() argument
344 if (list_empty(&dentry->d_lru)) { in dentry_lru_move_list()
345 list_add_tail(&dentry->d_lru, list); in dentry_lru_move_list()
346 dentry->d_sb->s_nr_dentry_unused++; in dentry_lru_move_list()
349 list_move_tail(&dentry->d_lru, list); in dentry_lru_move_list()
366 static struct dentry *d_kill(struct dentry *dentry, struct dentry *parent) in d_kill() argument
367 __releases(dentry->d_lock) in d_kill()
369 __releases(dentry->d_inode->i_lock) in d_kill()
371 list_del(&dentry->d_u.d_child); in d_kill()
376 dentry->d_flags |= DCACHE_DENTRY_KILLED; in d_kill()
379 dentry_iput(dentry); in d_kill()
384 d_free(dentry); in d_kill()
393 static void __d_shrink(struct dentry *dentry) in __d_shrink() argument
395 if (!d_unhashed(dentry)) { in __d_shrink()
397 if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED)) in __d_shrink()
398 b = &dentry->d_sb->s_anon; in __d_shrink()
400 b = d_hash(dentry->d_parent, dentry->d_name.hash); in __d_shrink()
403 __hlist_bl_del(&dentry->d_hash); in __d_shrink()
404 dentry->d_hash.pprev = NULL; in __d_shrink()
424 void __d_drop(struct dentry *dentry) in __d_drop() argument
426 if (!d_unhashed(dentry)) { in __d_drop()
427 __d_shrink(dentry); in __d_drop()
428 dentry_rcuwalk_barrier(dentry); in __d_drop()
433 void d_drop(struct dentry *dentry) in d_drop() argument
435 spin_lock(&dentry->d_lock); in d_drop()
436 __d_drop(dentry); in d_drop()
437 spin_unlock(&dentry->d_lock); in d_drop()
450 void d_clear_need_lookup(struct dentry *dentry) in d_clear_need_lookup() argument
452 spin_lock(&dentry->d_lock); in d_clear_need_lookup()
453 __d_drop(dentry); in d_clear_need_lookup()
454 dentry->d_flags &= ~DCACHE_NEED_LOOKUP; in d_clear_need_lookup()
455 spin_unlock(&dentry->d_lock); in d_clear_need_lookup()
465 static inline struct dentry *dentry_kill(struct dentry *dentry, int ref) in dentry_kill() argument
466 __releases(dentry->d_lock) in dentry_kill()
469 struct dentry *parent; in dentry_kill()
471 inode = dentry->d_inode; in dentry_kill()
474 spin_unlock(&dentry->d_lock); in dentry_kill()
476 return dentry; /* try again with same dentry */ in dentry_kill()
478 if (IS_ROOT(dentry)) in dentry_kill()
481 parent = dentry->d_parent; in dentry_kill()
489 dentry->d_count--; in dentry_kill()
495 dentry_lru_prune(dentry); in dentry_kill()
497 __d_drop(dentry); in dentry_kill()
498 return d_kill(dentry, parent); in dentry_kill()
527 void dput(struct dentry *dentry) in dput() argument
529 if (!dentry) in dput()
533 if (dentry->d_count == 1) in dput()
535 spin_lock(&dentry->d_lock); in dput()
536 BUG_ON(!dentry->d_count); in dput()
537 if (dentry->d_count > 1) { in dput()
538 dentry->d_count--; in dput()
539 spin_unlock(&dentry->d_lock); in dput()
543 if (dentry->d_flags & DCACHE_OP_DELETE) { in dput()
544 if (dentry->d_op->d_delete(dentry)) in dput()
549 if (d_unhashed(dentry)) in dput()
557 if (!d_need_lookup(dentry)) in dput()
558 dentry->d_flags |= DCACHE_REFERENCED; in dput()
559 dentry_lru_add(dentry); in dput()
561 dentry->d_count--; in dput()
562 spin_unlock(&dentry->d_lock); in dput()
566 dentry = dentry_kill(dentry, 1); in dput()
567 if (dentry) in dput()
584 int d_invalidate(struct dentry * dentry) in d_invalidate() argument
589 spin_lock(&dentry->d_lock); in d_invalidate()
590 if (d_unhashed(dentry)) { in d_invalidate()
591 spin_unlock(&dentry->d_lock); in d_invalidate()
598 if (!list_empty(&dentry->d_subdirs)) { in d_invalidate()
599 spin_unlock(&dentry->d_lock); in d_invalidate()
600 shrink_dcache_parent(dentry); in d_invalidate()
601 spin_lock(&dentry->d_lock); in d_invalidate()
616 if (dentry->d_count > 1 && dentry->d_inode) { in d_invalidate()
617 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) { in d_invalidate()
618 spin_unlock(&dentry->d_lock); in d_invalidate()
623 __d_drop(dentry); in d_invalidate()
624 spin_unlock(&dentry->d_lock); in d_invalidate()
630 static inline void __dget_dlock(struct dentry *dentry) in __dget_dlock() argument
632 dentry->d_count++; in __dget_dlock()
635 static inline void __dget(struct dentry *dentry) in __dget() argument
637 spin_lock(&dentry->d_lock); in __dget()
638 __dget_dlock(dentry); in __dget()
639 spin_unlock(&dentry->d_lock); in __dget()
642 struct dentry *dget_parent(struct dentry *dentry) in dget_parent() argument
644 struct dentry *ret; in dget_parent()
652 ret = dentry->d_parent; in dget_parent()
654 if (unlikely(ret != dentry->d_parent)) { in dget_parent()
683 static struct dentry *__d_find_alias(struct inode *inode, int want_discon) in __d_find_alias()
685 struct dentry *alias, *discon_alias; in __d_find_alias()
720 struct dentry *d_find_alias(struct inode *inode) in d_find_alias()
722 struct dentry *de = NULL; in d_find_alias()
739 struct dentry *dentry; in d_prune_aliases() local
742 list_for_each_entry(dentry, &inode->i_dentry, d_alias) { in d_prune_aliases()
743 spin_lock(&dentry->d_lock); in d_prune_aliases()
744 if (!dentry->d_count) { in d_prune_aliases()
745 __dget_dlock(dentry); in d_prune_aliases()
746 __d_drop(dentry); in d_prune_aliases()
747 spin_unlock(&dentry->d_lock); in d_prune_aliases()
749 dput(dentry); in d_prune_aliases()
752 spin_unlock(&dentry->d_lock); in d_prune_aliases()
765 static void try_prune_one_dentry(struct dentry *dentry) in try_prune_one_dentry() argument
766 __releases(dentry->d_lock) in try_prune_one_dentry()
768 struct dentry *parent; in try_prune_one_dentry()
770 parent = dentry_kill(dentry, 0); in try_prune_one_dentry()
783 if (parent == dentry) in try_prune_one_dentry()
787 dentry = parent; in try_prune_one_dentry()
788 while (dentry) { in try_prune_one_dentry()
789 spin_lock(&dentry->d_lock); in try_prune_one_dentry()
790 if (dentry->d_count > 1) { in try_prune_one_dentry()
791 dentry->d_count--; in try_prune_one_dentry()
792 spin_unlock(&dentry->d_lock); in try_prune_one_dentry()
795 dentry = dentry_kill(dentry, 1); in try_prune_one_dentry()
801 struct dentry *dentry; in shrink_dentry_list() local
805 dentry = list_entry_rcu(list->prev, struct dentry, d_lru); in shrink_dentry_list()
806 if (&dentry->d_lru == list) in shrink_dentry_list()
808 spin_lock(&dentry->d_lock); in shrink_dentry_list()
809 if (dentry != list_entry(list->prev, struct dentry, d_lru)) { in shrink_dentry_list()
810 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
819 if (dentry->d_count) { in shrink_dentry_list()
820 dentry_lru_del(dentry); in shrink_dentry_list()
821 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
827 try_prune_one_dentry(dentry); in shrink_dentry_list()
848 struct dentry *dentry; in prune_dcache_sb() local
855 dentry = list_entry(sb->s_dentry_lru.prev, in prune_dcache_sb()
856 struct dentry, d_lru); in prune_dcache_sb()
857 BUG_ON(dentry->d_sb != sb); in prune_dcache_sb()
859 if (!spin_trylock(&dentry->d_lock)) { in prune_dcache_sb()
865 if (dentry->d_flags & DCACHE_REFERENCED) { in prune_dcache_sb()
866 dentry->d_flags &= ~DCACHE_REFERENCED; in prune_dcache_sb()
867 list_move(&dentry->d_lru, &referenced); in prune_dcache_sb()
868 spin_unlock(&dentry->d_lock); in prune_dcache_sb()
870 list_move_tail(&dentry->d_lru, &tmp); in prune_dcache_sb()
871 dentry->d_flags |= DCACHE_SHRINK_LIST; in prune_dcache_sb()
872 spin_unlock(&dentry->d_lock); in prune_dcache_sb()
912 static void shrink_dcache_for_umount_subtree(struct dentry *dentry) in shrink_dcache_for_umount_subtree() argument
914 struct dentry *parent; in shrink_dcache_for_umount_subtree()
916 BUG_ON(!IS_ROOT(dentry)); in shrink_dcache_for_umount_subtree()
920 while (!list_empty(&dentry->d_subdirs)) in shrink_dcache_for_umount_subtree()
921 dentry = list_entry(dentry->d_subdirs.next, in shrink_dcache_for_umount_subtree()
922 struct dentry, d_u.d_child); in shrink_dcache_for_umount_subtree()
934 dentry_lru_prune(dentry); in shrink_dcache_for_umount_subtree()
935 __d_shrink(dentry); in shrink_dcache_for_umount_subtree()
937 if (dentry->d_count != 0) { in shrink_dcache_for_umount_subtree()
942 dentry, in shrink_dcache_for_umount_subtree()
943 dentry->d_inode ? in shrink_dcache_for_umount_subtree()
944 dentry->d_inode->i_ino : 0UL, in shrink_dcache_for_umount_subtree()
945 dentry->d_name.name, in shrink_dcache_for_umount_subtree()
946 dentry->d_count, in shrink_dcache_for_umount_subtree()
947 dentry->d_sb->s_type->name, in shrink_dcache_for_umount_subtree()
948 dentry->d_sb->s_id); in shrink_dcache_for_umount_subtree()
952 if (IS_ROOT(dentry)) { in shrink_dcache_for_umount_subtree()
954 list_del(&dentry->d_u.d_child); in shrink_dcache_for_umount_subtree()
956 parent = dentry->d_parent; in shrink_dcache_for_umount_subtree()
958 list_del(&dentry->d_u.d_child); in shrink_dcache_for_umount_subtree()
961 inode = dentry->d_inode; in shrink_dcache_for_umount_subtree()
963 dentry->d_inode = NULL; in shrink_dcache_for_umount_subtree()
964 list_del_init(&dentry->d_alias); in shrink_dcache_for_umount_subtree()
965 if (dentry->d_op && dentry->d_op->d_iput) in shrink_dcache_for_umount_subtree()
966 dentry->d_op->d_iput(dentry, inode); in shrink_dcache_for_umount_subtree()
971 d_free(dentry); in shrink_dcache_for_umount_subtree()
978 dentry = parent; in shrink_dcache_for_umount_subtree()
979 } while (list_empty(&dentry->d_subdirs)); in shrink_dcache_for_umount_subtree()
981 dentry = list_entry(dentry->d_subdirs.next, in shrink_dcache_for_umount_subtree()
982 struct dentry, d_u.d_child); in shrink_dcache_for_umount_subtree()
998 struct dentry *dentry; in shrink_dcache_for_umount() local
1003 dentry = sb->s_root; in shrink_dcache_for_umount()
1005 dentry->d_count--; in shrink_dcache_for_umount()
1006 shrink_dcache_for_umount_subtree(dentry); in shrink_dcache_for_umount()
1009 dentry = hlist_bl_entry(hlist_bl_first(&sb->s_anon), struct dentry, d_hash); in shrink_dcache_for_umount()
1010 shrink_dcache_for_umount_subtree(dentry); in shrink_dcache_for_umount()
1020 static struct dentry *try_to_ascend(struct dentry *old, int locked, unsigned seq) in try_to_ascend()
1022 struct dentry *new = old->d_parent; in try_to_ascend()
1056 int have_submounts(struct dentry *parent) in have_submounts()
1058 struct dentry *this_parent; in have_submounts()
1075 struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); in have_submounts() local
1078 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in have_submounts()
1080 if (d_mountpoint(dentry)) { in have_submounts()
1081 spin_unlock(&dentry->d_lock); in have_submounts()
1085 if (!list_empty(&dentry->d_subdirs)) { in have_submounts()
1087 spin_release(&dentry->d_lock.dep_map, 1, _RET_IP_); in have_submounts()
1088 this_parent = dentry; in have_submounts()
1092 spin_unlock(&dentry->d_lock); in have_submounts()
1098 struct dentry *child = this_parent; in have_submounts()
1141 static int select_parent(struct dentry *parent, struct list_head *dispose) in select_parent()
1143 struct dentry *this_parent; in select_parent()
1158 struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); in select_parent() local
1161 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in select_parent()
1171 if (dentry->d_count) { in select_parent()
1172 dentry_lru_del(dentry); in select_parent()
1173 } else if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) { in select_parent()
1174 dentry_lru_move_list(dentry, dispose); in select_parent()
1175 dentry->d_flags |= DCACHE_SHRINK_LIST; in select_parent()
1184 spin_unlock(&dentry->d_lock); in select_parent()
1191 if (!list_empty(&dentry->d_subdirs)) { in select_parent()
1193 spin_release(&dentry->d_lock.dep_map, 1, _RET_IP_); in select_parent()
1194 this_parent = dentry; in select_parent()
1199 spin_unlock(&dentry->d_lock); in select_parent()
1205 struct dentry *child = this_parent; in select_parent()
1236 void shrink_dcache_parent(struct dentry * parent) in shrink_dcache_parent()
1258 struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) in __d_alloc()
1260 struct dentry *dentry; in __d_alloc() local
1263 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); in __d_alloc()
1264 if (!dentry) in __d_alloc()
1270 kmem_cache_free(dentry_cache, dentry); in __d_alloc()
1274 dname = dentry->d_iname; in __d_alloc()
1276 dentry->d_name.name = dname; in __d_alloc()
1278 dentry->d_name.len = name->len; in __d_alloc()
1279 dentry->d_name.hash = name->hash; in __d_alloc()
1283 dentry->d_count = 1; in __d_alloc()
1284 dentry->d_flags = 0; in __d_alloc()
1285 spin_lock_init(&dentry->d_lock); in __d_alloc()
1286 seqcount_init(&dentry->d_seq); in __d_alloc()
1287 dentry->d_inode = NULL; in __d_alloc()
1288 dentry->d_parent = dentry; in __d_alloc()
1289 dentry->d_sb = sb; in __d_alloc()
1290 dentry->d_op = NULL; in __d_alloc()
1291 dentry->d_fsdata = NULL; in __d_alloc()
1292 INIT_HLIST_BL_NODE(&dentry->d_hash); in __d_alloc()
1293 INIT_LIST_HEAD(&dentry->d_lru); in __d_alloc()
1294 INIT_LIST_HEAD(&dentry->d_subdirs); in __d_alloc()
1295 INIT_LIST_HEAD(&dentry->d_alias); in __d_alloc()
1296 INIT_LIST_HEAD(&dentry->d_u.d_child); in __d_alloc()
1297 d_set_d_op(dentry, dentry->d_sb->s_d_op); in __d_alloc()
1301 return dentry; in __d_alloc()
1313 struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) in d_alloc()
1315 struct dentry *dentry = __d_alloc(parent->d_sb, name); in d_alloc() local
1316 if (!dentry) in d_alloc()
1325 dentry->d_parent = parent; in d_alloc()
1326 list_add(&dentry->d_u.d_child, &parent->d_subdirs); in d_alloc()
1329 return dentry; in d_alloc()
1333 struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name) in d_alloc_pseudo()
1335 struct dentry *dentry = __d_alloc(sb, name); in d_alloc_pseudo() local
1336 if (dentry) in d_alloc_pseudo()
1337 dentry->d_flags |= DCACHE_DISCONNECTED; in d_alloc_pseudo()
1338 return dentry; in d_alloc_pseudo()
1342 struct dentry *d_alloc_name(struct dentry *parent, const char *name) in d_alloc_name()
1353 void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op) in d_set_d_op() argument
1355 WARN_ON_ONCE(dentry->d_op); in d_set_d_op()
1356 WARN_ON_ONCE(dentry->d_flags & (DCACHE_OP_HASH | in d_set_d_op()
1360 dentry->d_op = op; in d_set_d_op()
1364 dentry->d_flags |= DCACHE_OP_HASH; in d_set_d_op()
1366 dentry->d_flags |= DCACHE_OP_COMPARE; in d_set_d_op()
1368 dentry->d_flags |= DCACHE_OP_REVALIDATE; in d_set_d_op()
1370 dentry->d_flags |= DCACHE_OP_DELETE; in d_set_d_op()
1372 dentry->d_flags |= DCACHE_OP_PRUNE; in d_set_d_op()
1377 static void __d_instantiate(struct dentry *dentry, struct inode *inode) in __d_instantiate() argument
1379 spin_lock(&dentry->d_lock); in __d_instantiate()
1382 dentry->d_flags |= DCACHE_NEED_AUTOMOUNT; in __d_instantiate()
1383 list_add(&dentry->d_alias, &inode->i_dentry); in __d_instantiate()
1385 dentry->d_inode = inode; in __d_instantiate()
1386 dentry_rcuwalk_barrier(dentry); in __d_instantiate()
1387 spin_unlock(&dentry->d_lock); in __d_instantiate()
1388 fsnotify_d_instantiate(dentry, inode); in __d_instantiate()
1406 void d_instantiate(struct dentry *entry, struct inode * inode) in d_instantiate()
1434 static struct dentry *__d_instantiate_unique(struct dentry *entry, in __d_instantiate_unique()
1437 struct dentry *alias; in __d_instantiate_unique()
1469 struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode) in d_instantiate_unique()
1471 struct dentry *result; in d_instantiate_unique()
1493 struct dentry *d_make_root(struct inode *root_inode) in d_make_root()
1495 struct dentry *res = NULL; in d_make_root()
1510 static struct dentry * __d_find_any_alias(struct inode *inode) in __d_find_any_alias()
1512 struct dentry *alias; in __d_find_any_alias()
1516 alias = list_first_entry(&inode->i_dentry, struct dentry, d_alias); in __d_find_any_alias()
1528 struct dentry *d_find_any_alias(struct inode *inode) in d_find_any_alias()
1530 struct dentry *de; in d_find_any_alias()
1557 struct dentry *d_obtain_alias(struct inode *inode) in d_obtain_alias()
1560 struct dentry *tmp; in d_obtain_alias()
1561 struct dentry *res; in d_obtain_alias()
1624 struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) in d_splice_alias() argument
1626 struct dentry *new = NULL; in d_splice_alias()
1638 d_move(new, dentry); in d_splice_alias()
1642 __d_instantiate(dentry, inode); in d_splice_alias()
1644 security_d_instantiate(dentry, inode); in d_splice_alias()
1645 d_rehash(dentry); in d_splice_alias()
1648 d_add(dentry, inode); in d_splice_alias()
1669 struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, in d_add_ci() argument
1673 struct dentry *found; in d_add_ci()
1674 struct dentry *new; in d_add_ci()
1680 found = d_hash_and_lookup(dentry->d_parent, name); in d_add_ci()
1682 new = d_alloc(dentry->d_parent, name); in d_add_ci()
1763 struct dentry *__d_lookup_rcu(const struct dentry *parent, in __d_lookup_rcu()
1772 struct dentry *dentry; in __d_lookup_rcu() local
1794 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup_rcu()
1800 if (dentry->d_name.hash != hash) in __d_lookup_rcu()
1804 seq = read_seqcount_begin(&dentry->d_seq); in __d_lookup_rcu()
1805 if (dentry->d_parent != parent) in __d_lookup_rcu()
1807 if (d_unhashed(dentry)) in __d_lookup_rcu()
1809 tlen = dentry->d_name.len; in __d_lookup_rcu()
1810 tname = dentry->d_name.name; in __d_lookup_rcu()
1811 i = dentry->d_inode; in __d_lookup_rcu()
1819 if (read_seqcount_retry(&dentry->d_seq, seq)) in __d_lookup_rcu()
1823 dentry, i, in __d_lookup_rcu()
1838 return dentry; in __d_lookup_rcu()
1854 struct dentry *d_lookup(struct dentry *parent, struct qstr *name) in d_lookup()
1856 struct dentry *dentry; in d_lookup() local
1861 dentry = __d_lookup(parent, name); in d_lookup()
1862 if (dentry) in d_lookup()
1865 return dentry; in d_lookup()
1884 struct dentry *__d_lookup(struct dentry *parent, struct qstr *name) in __d_lookup()
1891 struct dentry *found = NULL; in __d_lookup()
1892 struct dentry *dentry; in __d_lookup() local
1916 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup()
1920 if (dentry->d_name.hash != hash) in __d_lookup()
1923 spin_lock(&dentry->d_lock); in __d_lookup()
1924 if (dentry->d_parent != parent) in __d_lookup()
1926 if (d_unhashed(dentry)) in __d_lookup()
1933 tlen = dentry->d_name.len; in __d_lookup()
1934 tname = dentry->d_name.name; in __d_lookup()
1937 dentry, dentry->d_inode, in __d_lookup()
1945 dentry->d_count++; in __d_lookup()
1946 found = dentry; in __d_lookup()
1947 spin_unlock(&dentry->d_lock); in __d_lookup()
1950 spin_unlock(&dentry->d_lock); in __d_lookup()
1964 struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name) in d_hash_and_lookup()
1966 struct dentry *dentry = NULL; in d_hash_and_lookup() local
1978 dentry = d_lookup(dir, name); in d_hash_and_lookup()
1980 return dentry; in d_hash_and_lookup()
1994 int d_validate(struct dentry *dentry, struct dentry *dparent) in d_validate() argument
1996 struct dentry *child; in d_validate()
2000 if (dentry == child) { in d_validate()
2001 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_validate()
2002 __dget_dlock(dentry); in d_validate()
2003 spin_unlock(&dentry->d_lock); in d_validate()
2035 void d_delete(struct dentry * dentry) in d_delete() argument
2043 spin_lock(&dentry->d_lock); in d_delete()
2044 inode = dentry->d_inode; in d_delete()
2046 if (dentry->d_count == 1) { in d_delete()
2048 spin_unlock(&dentry->d_lock); in d_delete()
2052 dentry->d_flags &= ~DCACHE_CANT_MOUNT; in d_delete()
2053 dentry_unlink_inode(dentry); in d_delete()
2054 fsnotify_nameremove(dentry, isdir); in d_delete()
2058 if (!d_unhashed(dentry)) in d_delete()
2059 __d_drop(dentry); in d_delete()
2061 spin_unlock(&dentry->d_lock); in d_delete()
2063 fsnotify_nameremove(dentry, isdir); in d_delete()
2067 static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b) in __d_rehash()
2076 static void _d_rehash(struct dentry * entry) in _d_rehash()
2088 void d_rehash(struct dentry * entry) in d_rehash()
2110 void dentry_update_name_case(struct dentry *dentry, struct qstr *name) in dentry_update_name_case() argument
2112 BUG_ON(!mutex_is_locked(&dentry->d_parent->d_inode->i_mutex)); in dentry_update_name_case()
2113 BUG_ON(dentry->d_name.len != name->len); /* d_lookup gives this */ in dentry_update_name_case()
2115 spin_lock(&dentry->d_lock); in dentry_update_name_case()
2116 write_seqcount_begin(&dentry->d_seq); in dentry_update_name_case()
2117 memcpy((unsigned char *)dentry->d_name.name, name->name, name->len); in dentry_update_name_case()
2118 write_seqcount_end(&dentry->d_seq); in dentry_update_name_case()
2119 spin_unlock(&dentry->d_lock); in dentry_update_name_case()
2123 static void switch_names(struct dentry *dentry, struct dentry *target) in switch_names() argument
2126 if (dname_external(dentry)) { in switch_names()
2130 swap(target->d_name.name, dentry->d_name.name); in switch_names()
2136 memcpy(target->d_iname, dentry->d_name.name, in switch_names()
2137 dentry->d_name.len + 1); in switch_names()
2138 dentry->d_name.name = target->d_name.name; in switch_names()
2142 if (dname_external(dentry)) { in switch_names()
2147 memcpy(dentry->d_iname, target->d_name.name, in switch_names()
2149 target->d_name.name = dentry->d_name.name; in switch_names()
2150 dentry->d_name.name = dentry->d_iname; in switch_names()
2155 memcpy(dentry->d_iname, target->d_name.name, in switch_names()
2157 dentry->d_name.len = target->d_name.len; in switch_names()
2161 swap(dentry->d_name.len, target->d_name.len); in switch_names()
2164 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) in dentry_lock_for_move() argument
2169 if (IS_ROOT(dentry) || dentry->d_parent == target->d_parent) in dentry_lock_for_move()
2172 if (d_ancestor(dentry->d_parent, target->d_parent)) { in dentry_lock_for_move()
2173 spin_lock(&dentry->d_parent->d_lock); in dentry_lock_for_move()
2178 spin_lock_nested(&dentry->d_parent->d_lock, in dentry_lock_for_move()
2182 if (target < dentry) { in dentry_lock_for_move()
2184 spin_lock_nested(&dentry->d_lock, 3); in dentry_lock_for_move()
2186 spin_lock_nested(&dentry->d_lock, 2); in dentry_lock_for_move()
2191 static void dentry_unlock_parents_for_move(struct dentry *dentry, in dentry_unlock_parents_for_move() argument
2192 struct dentry *target) in dentry_unlock_parents_for_move()
2194 if (target->d_parent != dentry->d_parent) in dentry_unlock_parents_for_move()
2195 spin_unlock(&dentry->d_parent->d_lock); in dentry_unlock_parents_for_move()
2221 static void __d_move(struct dentry * dentry, struct dentry * target) in __d_move() argument
2223 if (!dentry->d_inode) in __d_move()
2226 BUG_ON(d_ancestor(dentry, target)); in __d_move()
2227 BUG_ON(d_ancestor(target, dentry)); in __d_move()
2229 dentry_lock_for_move(dentry, target); in __d_move()
2231 write_seqcount_begin(&dentry->d_seq); in __d_move()
2240 __d_drop(dentry); in __d_move()
2241 __d_rehash(dentry, d_hash(target->d_parent, target->d_name.hash)); in __d_move()
2246 list_del(&dentry->d_u.d_child); in __d_move()
2250 switch_names(dentry, target); in __d_move()
2251 swap(dentry->d_name.hash, target->d_name.hash); in __d_move()
2254 if (IS_ROOT(dentry)) { in __d_move()
2255 dentry->d_parent = target->d_parent; in __d_move()
2259 swap(dentry->d_parent, target->d_parent); in __d_move()
2265 list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); in __d_move()
2268 write_seqcount_end(&dentry->d_seq); in __d_move()
2270 dentry_unlock_parents_for_move(dentry, target); in __d_move()
2272 fsnotify_d_move(dentry); in __d_move()
2273 spin_unlock(&dentry->d_lock); in __d_move()
2285 void d_move(struct dentry *dentry, struct dentry *target) in d_move() argument
2288 __d_move(dentry, target); in d_move()
2301 struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2) in d_ancestor()
2303 struct dentry *p; in d_ancestor()
2321 static struct dentry *__d_unalias(struct inode *inode, in __d_unalias()
2322 struct dentry *dentry, struct dentry *alias) in __d_unalias() argument
2325 struct dentry *ret; in __d_unalias()
2328 if (alias->d_parent == dentry->d_parent) in __d_unalias()
2333 if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex)) in __d_unalias()
2335 m1 = &dentry->d_sb->s_vfs_rename_mutex; in __d_unalias()
2340 __d_move(alias, dentry); in __d_unalias()
2356 static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon) in __d_materialise_dentry() argument
2358 struct dentry *dparent, *aparent; in __d_materialise_dentry()
2360 dentry_lock_for_move(anon, dentry); in __d_materialise_dentry()
2362 write_seqcount_begin(&dentry->d_seq); in __d_materialise_dentry()
2365 dparent = dentry->d_parent; in __d_materialise_dentry()
2368 switch_names(dentry, anon); in __d_materialise_dentry()
2369 swap(dentry->d_name.hash, anon->d_name.hash); in __d_materialise_dentry()
2371 dentry->d_parent = (aparent == anon) ? dentry : aparent; in __d_materialise_dentry()
2372 list_del(&dentry->d_u.d_child); in __d_materialise_dentry()
2373 if (!IS_ROOT(dentry)) in __d_materialise_dentry()
2374 list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); in __d_materialise_dentry()
2376 INIT_LIST_HEAD(&dentry->d_u.d_child); in __d_materialise_dentry()
2378 anon->d_parent = (dparent == dentry) ? anon : dparent; in __d_materialise_dentry()
2385 write_seqcount_end(&dentry->d_seq); in __d_materialise_dentry()
2388 dentry_unlock_parents_for_move(anon, dentry); in __d_materialise_dentry()
2389 spin_unlock(&dentry->d_lock); in __d_materialise_dentry()
2404 struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode) in d_materialise_unique() argument
2406 struct dentry *actual; in d_materialise_unique()
2408 BUG_ON(!d_unhashed(dentry)); in d_materialise_unique()
2411 actual = dentry; in d_materialise_unique()
2412 __d_instantiate(dentry, NULL); in d_materialise_unique()
2420 struct dentry *alias; in d_materialise_unique()
2428 if (d_ancestor(alias, dentry)) { in d_materialise_unique()
2435 __d_materialise_dentry(dentry, alias); in d_materialise_unique()
2442 actual = __d_unalias(inode, dentry, alias); in d_materialise_unique()
2450 dentry->d_name.name, in d_materialise_unique()
2460 actual = __d_instantiate_unique(dentry, inode); in d_materialise_unique()
2462 actual = dentry; in d_materialise_unique()
2472 if (actual == dentry) { in d_materialise_unique()
2473 security_d_instantiate(dentry, inode); in d_materialise_unique()
2510 struct dentry *dentry = path->dentry; in prepend_path() local
2517 while (dentry != root->dentry || vfsmnt != root->mnt) { in prepend_path()
2518 struct dentry * parent; in prepend_path()
2520 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { in prepend_path()
2524 dentry = mnt->mnt_mountpoint; in prepend_path()
2529 parent = dentry->d_parent; in prepend_path()
2531 spin_lock(&dentry->d_lock); in prepend_path()
2532 error = prepend_name(buffer, buflen, &dentry->d_name); in prepend_path()
2533 spin_unlock(&dentry->d_lock); in prepend_path()
2540 dentry = parent; in prepend_path()
2555 if (IS_ROOT(dentry) && in prepend_path()
2556 (dentry->d_name.len != 1 || dentry->d_name.name[0] != '/')) { in prepend_path()
2558 (int) dentry->d_name.len, dentry->d_name.name); in prepend_path()
2629 if (d_unlinked(path->dentry)) { in path_with_deleted()
2672 if (path->dentry->d_op && path->dentry->d_op->d_dname) in d_path()
2673 return path->dentry->d_op->d_dname(path->dentry, buf, buflen); in d_path()
2701 if (path->dentry->d_op && path->dentry->d_op->d_dname) in d_path_with_unreachable()
2702 return path->dentry->d_op->d_dname(path->dentry, buf, buflen); in d_path_with_unreachable()
2720 char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen, in dynamic_dname() argument
2741 static char *__dentry_path(struct dentry *dentry, char *buf, int buflen) in __dentry_path() argument
2753 while (!IS_ROOT(dentry)) { in __dentry_path()
2754 struct dentry *parent = dentry->d_parent; in __dentry_path()
2758 spin_lock(&dentry->d_lock); in __dentry_path()
2759 error = prepend_name(&end, &buflen, &dentry->d_name); in __dentry_path()
2760 spin_unlock(&dentry->d_lock); in __dentry_path()
2765 dentry = parent; in __dentry_path()
2772 char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen) in dentry_path_raw() argument
2777 retval = __dentry_path(dentry, buf, buflen); in dentry_path_raw()
2784 char *dentry_path(struct dentry *dentry, char *buf, int buflen) in dentry_path() argument
2790 if (d_unlinked(dentry)) { in dentry_path()
2796 retval = __dentry_path(dentry, buf, buflen); in dentry_path()
2836 if (!d_unlinked(pwd.dentry)) { in SYSCALL_DEFINE2()
2889 int is_subdir(struct dentry *new_dentry, struct dentry *old_dentry) in is_subdir()
2915 void d_genocide(struct dentry *root) in d_genocide()
2917 struct dentry *this_parent; in d_genocide()
2931 struct dentry *dentry = list_entry(tmp, struct dentry, d_u.d_child); in d_genocide() local
2934 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_genocide()
2935 if (d_unhashed(dentry) || !dentry->d_inode) { in d_genocide()
2936 spin_unlock(&dentry->d_lock); in d_genocide()
2939 if (!list_empty(&dentry->d_subdirs)) { in d_genocide()
2941 spin_release(&dentry->d_lock.dep_map, 1, _RET_IP_); in d_genocide()
2942 this_parent = dentry; in d_genocide()
2946 if (!(dentry->d_flags & DCACHE_GENOCIDE)) { in d_genocide()
2947 dentry->d_flags |= DCACHE_GENOCIDE; in d_genocide()
2948 dentry->d_count--; in d_genocide()
2950 spin_unlock(&dentry->d_lock); in d_genocide()
2953 struct dentry *child = this_parent; in d_genocide()
2993 ino_t find_inode_number(struct dentry *dir, struct qstr *name) in find_inode_number()
2995 struct dentry * dentry; in find_inode_number() local
2998 dentry = d_hash_and_lookup(dir, name); in find_inode_number()
2999 if (dentry) { in find_inode_number()
3000 if (dentry->d_inode) in find_inode_number()
3001 ino = dentry->d_inode->i_ino; in find_inode_number()
3002 dput(dentry); in find_inode_number()
3051 dentry_cache = KMEM_CACHE(dentry, in dcache_init()