Lines Matching refs:dentry
107 static inline struct hlist_bl_head *d_hash(const struct dentry *parent, in d_hash()
216 static inline int dentry_cmp(const struct dentry *dentry, const unsigned char *ct, unsigned tcount) in dentry_cmp() argument
235 cs = ACCESS_ONCE(dentry->d_name.name); in dentry_cmp()
248 static inline struct external_name *external_name(struct dentry *dentry) in external_name() argument
250 return container_of(dentry->d_name.name, struct external_name, name[0]); in external_name()
255 struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); in __d_free() local
257 kmem_cache_free(dentry_cache, dentry); in __d_free()
262 struct dentry *dentry = container_of(head, struct dentry, d_u.d_rcu); in __d_free_external() local
263 kfree(external_name(dentry)); in __d_free_external()
264 kmem_cache_free(dentry_cache, dentry); in __d_free_external()
267 static inline int dname_external(const struct dentry *dentry) in dname_external() argument
269 return dentry->d_name.name != dentry->d_iname; in dname_external()
272 static inline void __d_set_inode_and_type(struct dentry *dentry, in __d_set_inode_and_type() argument
278 dentry->d_inode = inode; in __d_set_inode_and_type()
279 flags = READ_ONCE(dentry->d_flags); in __d_set_inode_and_type()
282 WRITE_ONCE(dentry->d_flags, flags); in __d_set_inode_and_type()
285 static inline void __d_clear_type_and_inode(struct dentry *dentry) in __d_clear_type_and_inode() argument
287 unsigned flags = READ_ONCE(dentry->d_flags); in __d_clear_type_and_inode()
290 WRITE_ONCE(dentry->d_flags, flags); in __d_clear_type_and_inode()
291 dentry->d_inode = NULL; in __d_clear_type_and_inode()
294 static void dentry_free(struct dentry *dentry) in dentry_free() argument
296 WARN_ON(!hlist_unhashed(&dentry->d_u.d_alias)); in dentry_free()
297 if (unlikely(dname_external(dentry))) { in dentry_free()
298 struct external_name *p = external_name(dentry); in dentry_free()
300 call_rcu(&dentry->d_u.d_rcu, __d_free_external); in dentry_free()
305 if (!(dentry->d_flags & DCACHE_RCUACCESS)) in dentry_free()
306 __d_free(&dentry->d_u.d_rcu); in dentry_free()
308 call_rcu(&dentry->d_u.d_rcu, __d_free); in dentry_free()
318 static inline void dentry_rcuwalk_invalidate(struct dentry *dentry) in dentry_rcuwalk_invalidate() argument
320 lockdep_assert_held(&dentry->d_lock); in dentry_rcuwalk_invalidate()
322 write_seqcount_invalidate(&dentry->d_seq); in dentry_rcuwalk_invalidate()
330 static void dentry_iput(struct dentry * dentry) in dentry_iput() argument
331 __releases(dentry->d_lock) in dentry_iput()
332 __releases(dentry->d_inode->i_lock) in dentry_iput()
334 struct inode *inode = dentry->d_inode; in dentry_iput()
336 __d_clear_type_and_inode(dentry); in dentry_iput()
337 hlist_del_init(&dentry->d_u.d_alias); in dentry_iput()
338 spin_unlock(&dentry->d_lock); in dentry_iput()
342 if (dentry->d_op && dentry->d_op->d_iput) in dentry_iput()
343 dentry->d_op->d_iput(dentry, inode); in dentry_iput()
347 spin_unlock(&dentry->d_lock); in dentry_iput()
355 static void dentry_unlink_inode(struct dentry * dentry) in dentry_unlink_inode() argument
356 __releases(dentry->d_lock) in dentry_unlink_inode()
357 __releases(dentry->d_inode->i_lock) in dentry_unlink_inode()
359 struct inode *inode = dentry->d_inode; in dentry_unlink_inode()
361 raw_write_seqcount_begin(&dentry->d_seq); in dentry_unlink_inode()
362 __d_clear_type_and_inode(dentry); in dentry_unlink_inode()
363 hlist_del_init(&dentry->d_u.d_alias); in dentry_unlink_inode()
364 raw_write_seqcount_end(&dentry->d_seq); in dentry_unlink_inode()
365 spin_unlock(&dentry->d_lock); in dentry_unlink_inode()
369 if (dentry->d_op && dentry->d_op->d_iput) in dentry_unlink_inode()
370 dentry->d_op->d_iput(dentry, inode); in dentry_unlink_inode()
389 #define D_FLAG_VERIFY(dentry,x) WARN_ON_ONCE(((dentry)->d_flags & (DCACHE_LRU_LIST | DCACHE_SHRINK_… argument
390 static void d_lru_add(struct dentry *dentry) in d_lru_add() argument
392 D_FLAG_VERIFY(dentry, 0); in d_lru_add()
393 dentry->d_flags |= DCACHE_LRU_LIST; in d_lru_add()
395 WARN_ON_ONCE(!list_lru_add(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); in d_lru_add()
398 static void d_lru_del(struct dentry *dentry) in d_lru_del() argument
400 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_del()
401 dentry->d_flags &= ~DCACHE_LRU_LIST; in d_lru_del()
403 WARN_ON_ONCE(!list_lru_del(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); in d_lru_del()
406 static void d_shrink_del(struct dentry *dentry) in d_shrink_del() argument
408 D_FLAG_VERIFY(dentry, DCACHE_SHRINK_LIST | DCACHE_LRU_LIST); in d_shrink_del()
409 list_del_init(&dentry->d_lru); in d_shrink_del()
410 dentry->d_flags &= ~(DCACHE_SHRINK_LIST | DCACHE_LRU_LIST); in d_shrink_del()
414 static void d_shrink_add(struct dentry *dentry, struct list_head *list) in d_shrink_add() argument
416 D_FLAG_VERIFY(dentry, 0); in d_shrink_add()
417 list_add(&dentry->d_lru, list); in d_shrink_add()
418 dentry->d_flags |= DCACHE_SHRINK_LIST | DCACHE_LRU_LIST; in d_shrink_add()
428 static void d_lru_isolate(struct list_lru_one *lru, struct dentry *dentry) in d_lru_isolate() argument
430 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_isolate()
431 dentry->d_flags &= ~DCACHE_LRU_LIST; in d_lru_isolate()
433 list_lru_isolate(lru, &dentry->d_lru); in d_lru_isolate()
436 static void d_lru_shrink_move(struct list_lru_one *lru, struct dentry *dentry, in d_lru_shrink_move() argument
439 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_shrink_move()
440 dentry->d_flags |= DCACHE_SHRINK_LIST; in d_lru_shrink_move()
441 list_lru_isolate_move(lru, &dentry->d_lru, list); in d_lru_shrink_move()
447 static void dentry_lru_add(struct dentry *dentry) in dentry_lru_add() argument
449 if (unlikely(!(dentry->d_flags & DCACHE_LRU_LIST))) in dentry_lru_add()
450 d_lru_add(dentry); in dentry_lru_add()
468 void __d_drop(struct dentry *dentry) in __d_drop() argument
470 if (!d_unhashed(dentry)) { in __d_drop()
477 if (unlikely(IS_ROOT(dentry))) in __d_drop()
478 b = &dentry->d_sb->s_anon; in __d_drop()
480 b = d_hash(dentry->d_parent, dentry->d_name.hash); in __d_drop()
483 __hlist_bl_del(&dentry->d_hash); in __d_drop()
484 dentry->d_hash.pprev = NULL; in __d_drop()
486 dentry_rcuwalk_invalidate(dentry); in __d_drop()
491 void d_drop(struct dentry *dentry) in d_drop() argument
493 spin_lock(&dentry->d_lock); in d_drop()
494 __d_drop(dentry); in d_drop()
495 spin_unlock(&dentry->d_lock); in d_drop()
499 static void __dentry_kill(struct dentry *dentry) in __dentry_kill() argument
501 struct dentry *parent = NULL; in __dentry_kill()
503 if (!IS_ROOT(dentry)) in __dentry_kill()
504 parent = dentry->d_parent; in __dentry_kill()
509 lockref_mark_dead(&dentry->d_lockref); in __dentry_kill()
515 if (dentry->d_flags & DCACHE_OP_PRUNE) in __dentry_kill()
516 dentry->d_op->d_prune(dentry); in __dentry_kill()
518 if (dentry->d_flags & DCACHE_LRU_LIST) { in __dentry_kill()
519 if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) in __dentry_kill()
520 d_lru_del(dentry); in __dentry_kill()
523 __d_drop(dentry); in __dentry_kill()
524 __list_del_entry(&dentry->d_child); in __dentry_kill()
529 dentry->d_flags |= DCACHE_DENTRY_KILLED; in __dentry_kill()
532 dentry_iput(dentry); in __dentry_kill()
537 BUG_ON(dentry->d_lockref.count > 0); in __dentry_kill()
539 if (dentry->d_op && dentry->d_op->d_release) in __dentry_kill()
540 dentry->d_op->d_release(dentry); in __dentry_kill()
542 spin_lock(&dentry->d_lock); in __dentry_kill()
543 if (dentry->d_flags & DCACHE_SHRINK_LIST) { in __dentry_kill()
544 dentry->d_flags |= DCACHE_MAY_FREE; in __dentry_kill()
547 spin_unlock(&dentry->d_lock); in __dentry_kill()
549 dentry_free(dentry); in __dentry_kill()
558 static struct dentry *dentry_kill(struct dentry *dentry) in dentry_kill() argument
559 __releases(dentry->d_lock) in dentry_kill()
561 struct inode *inode = dentry->d_inode; in dentry_kill()
562 struct dentry *parent = NULL; in dentry_kill()
567 if (!IS_ROOT(dentry)) { in dentry_kill()
568 parent = dentry->d_parent; in dentry_kill()
576 __dentry_kill(dentry); in dentry_kill()
580 spin_unlock(&dentry->d_lock); in dentry_kill()
582 return dentry; /* try again with same dentry */ in dentry_kill()
585 static inline struct dentry *lock_parent(struct dentry *dentry) in lock_parent() argument
587 struct dentry *parent = dentry->d_parent; in lock_parent()
588 if (IS_ROOT(dentry)) in lock_parent()
590 if (unlikely(dentry->d_lockref.count < 0)) in lock_parent()
595 spin_unlock(&dentry->d_lock); in lock_parent()
597 parent = ACCESS_ONCE(dentry->d_parent); in lock_parent()
607 if (unlikely(parent != dentry->d_parent)) { in lock_parent()
612 if (parent != dentry) in lock_parent()
613 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in lock_parent()
627 static inline bool fast_dput(struct dentry *dentry) in fast_dput() argument
636 if (unlikely(dentry->d_flags & DCACHE_OP_DELETE)) in fast_dput()
637 return lockref_put_or_lock(&dentry->d_lockref); in fast_dput()
643 ret = lockref_put_return(&dentry->d_lockref); in fast_dput()
651 spin_lock(&dentry->d_lock); in fast_dput()
652 if (dentry->d_lockref.count > 1) { in fast_dput()
653 dentry->d_lockref.count--; in fast_dput()
654 spin_unlock(&dentry->d_lock); in fast_dput()
688 d_flags = ACCESS_ONCE(dentry->d_flags); in fast_dput()
692 if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry)) in fast_dput()
700 spin_lock(&dentry->d_lock); in fast_dput()
708 if (dentry->d_lockref.count) { in fast_dput()
709 spin_unlock(&dentry->d_lock); in fast_dput()
718 dentry->d_lockref.count = 1; in fast_dput()
749 void dput(struct dentry *dentry) in dput() argument
751 if (unlikely(!dentry)) in dput()
756 if (likely(fast_dput(dentry))) { in dput()
765 if (unlikely(d_unhashed(dentry))) in dput()
768 if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED)) in dput()
771 if (unlikely(dentry->d_flags & DCACHE_OP_DELETE)) { in dput()
772 if (dentry->d_op->d_delete(dentry)) in dput()
776 if (!(dentry->d_flags & DCACHE_REFERENCED)) in dput()
777 dentry->d_flags |= DCACHE_REFERENCED; in dput()
778 dentry_lru_add(dentry); in dput()
780 dentry->d_lockref.count--; in dput()
781 spin_unlock(&dentry->d_lock); in dput()
785 dentry = dentry_kill(dentry); in dput()
786 if (dentry) in dput()
793 static inline void __dget_dlock(struct dentry *dentry) in __dget_dlock() argument
795 dentry->d_lockref.count++; in __dget_dlock()
798 static inline void __dget(struct dentry *dentry) in __dget() argument
800 lockref_get(&dentry->d_lockref); in __dget()
803 struct dentry *dget_parent(struct dentry *dentry) in dget_parent() argument
806 struct dentry *ret; in dget_parent()
813 ret = ACCESS_ONCE(dentry->d_parent); in dget_parent()
817 if (likely(ret == ACCESS_ONCE(dentry->d_parent))) in dget_parent()
828 ret = dentry->d_parent; in dget_parent()
830 if (unlikely(ret != dentry->d_parent)) { in dget_parent()
857 static struct dentry *__d_find_alias(struct inode *inode) in __d_find_alias()
859 struct dentry *alias, *discon_alias; in __d_find_alias()
891 struct dentry *d_find_alias(struct inode *inode) in d_find_alias()
893 struct dentry *de = NULL; in d_find_alias()
910 struct dentry *dentry; in d_prune_aliases() local
913 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) { in d_prune_aliases()
914 spin_lock(&dentry->d_lock); in d_prune_aliases()
915 if (!dentry->d_lockref.count) { in d_prune_aliases()
916 struct dentry *parent = lock_parent(dentry); in d_prune_aliases()
917 if (likely(!dentry->d_lockref.count)) { in d_prune_aliases()
918 __dentry_kill(dentry); in d_prune_aliases()
925 spin_unlock(&dentry->d_lock); in d_prune_aliases()
933 struct dentry *dentry, *parent; in shrink_dentry_list() local
937 dentry = list_entry(list->prev, struct dentry, d_lru); in shrink_dentry_list()
938 spin_lock(&dentry->d_lock); in shrink_dentry_list()
939 parent = lock_parent(dentry); in shrink_dentry_list()
946 d_shrink_del(dentry); in shrink_dentry_list()
952 if (dentry->d_lockref.count > 0) { in shrink_dentry_list()
953 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
960 if (unlikely(dentry->d_flags & DCACHE_DENTRY_KILLED)) { in shrink_dentry_list()
961 bool can_free = dentry->d_flags & DCACHE_MAY_FREE; in shrink_dentry_list()
962 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
966 dentry_free(dentry); in shrink_dentry_list()
970 inode = dentry->d_inode; in shrink_dentry_list()
972 d_shrink_add(dentry, list); in shrink_dentry_list()
973 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
979 __dentry_kill(dentry); in shrink_dentry_list()
987 dentry = parent; in shrink_dentry_list()
988 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) { in shrink_dentry_list()
989 parent = lock_parent(dentry); in shrink_dentry_list()
990 if (dentry->d_lockref.count != 1) { in shrink_dentry_list()
991 dentry->d_lockref.count--; in shrink_dentry_list()
992 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
997 inode = dentry->d_inode; /* can't be NULL */ in shrink_dentry_list()
999 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
1005 __dentry_kill(dentry); in shrink_dentry_list()
1006 dentry = parent; in shrink_dentry_list()
1015 struct dentry *dentry = container_of(item, struct dentry, d_lru); in dentry_lru_isolate() local
1023 if (!spin_trylock(&dentry->d_lock)) in dentry_lru_isolate()
1031 if (dentry->d_lockref.count) { in dentry_lru_isolate()
1032 d_lru_isolate(lru, dentry); in dentry_lru_isolate()
1033 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1037 if (dentry->d_flags & DCACHE_REFERENCED) { in dentry_lru_isolate()
1038 dentry->d_flags &= ~DCACHE_REFERENCED; in dentry_lru_isolate()
1039 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1063 d_lru_shrink_move(lru, dentry, freeable); in dentry_lru_isolate()
1064 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1096 struct dentry *dentry = container_of(item, struct dentry, d_lru); in dentry_lru_isolate_shrink() local
1103 if (!spin_trylock(&dentry->d_lock)) in dentry_lru_isolate_shrink()
1106 d_lru_shrink_move(lru, dentry, freeable); in dentry_lru_isolate_shrink()
1107 spin_unlock(&dentry->d_lock); in dentry_lru_isolate_shrink()
1159 static void d_walk(struct dentry *parent, void *data, in d_walk()
1160 enum d_walk_ret (*enter)(void *, struct dentry *), in d_walk() argument
1163 struct dentry *this_parent; in d_walk()
1190 struct dentry *dentry = list_entry(tmp, struct dentry, d_child); in d_walk() local
1193 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_walk()
1195 ret = enter(data, dentry); in d_walk()
1200 spin_unlock(&dentry->d_lock); in d_walk()
1206 spin_unlock(&dentry->d_lock); in d_walk()
1210 if (!list_empty(&dentry->d_subdirs)) { in d_walk()
1212 spin_release(&dentry->d_lock.dep_map, 1, _RET_IP_); in d_walk()
1213 this_parent = dentry; in d_walk()
1217 spin_unlock(&dentry->d_lock); in d_walk()
1225 struct dentry *child = this_parent; in d_walk()
1239 child = list_entry(next, struct dentry, d_child); in d_walk()
1271 static enum d_walk_ret check_mount(void *data, struct dentry *dentry) in check_mount() argument
1274 if (d_mountpoint(dentry)) { in check_mount()
1288 int have_submounts(struct dentry *parent) in have_submounts()
1306 int d_set_mounted(struct dentry *dentry) in d_set_mounted() argument
1308 struct dentry *p; in d_set_mounted()
1311 for (p = dentry->d_parent; !IS_ROOT(p); p = p->d_parent) { in d_set_mounted()
1320 spin_lock(&dentry->d_lock); in d_set_mounted()
1321 if (!d_unlinked(dentry)) { in d_set_mounted()
1322 dentry->d_flags |= DCACHE_MOUNTED; in d_set_mounted()
1325 spin_unlock(&dentry->d_lock); in d_set_mounted()
1347 struct dentry *start;
1352 static enum d_walk_ret select_collect(void *_data, struct dentry *dentry) in select_collect() argument
1357 if (data->start == dentry) in select_collect()
1360 if (dentry->d_flags & DCACHE_SHRINK_LIST) { in select_collect()
1363 if (dentry->d_flags & DCACHE_LRU_LIST) in select_collect()
1364 d_lru_del(dentry); in select_collect()
1365 if (!dentry->d_lockref.count) { in select_collect()
1366 d_shrink_add(dentry, &data->dispose); in select_collect()
1387 void shrink_dcache_parent(struct dentry *parent) in shrink_dcache_parent()
1406 static enum d_walk_ret umount_check(void *_data, struct dentry *dentry) in umount_check() argument
1409 if (!list_empty(&dentry->d_subdirs)) in umount_check()
1413 if (dentry == _data && dentry->d_lockref.count == 1) in umount_check()
1418 dentry, in umount_check()
1419 dentry->d_inode ? in umount_check()
1420 dentry->d_inode->i_ino : 0UL, in umount_check()
1421 dentry, in umount_check()
1422 dentry->d_lockref.count, in umount_check()
1423 dentry->d_sb->s_type->name, in umount_check()
1424 dentry->d_sb->s_id); in umount_check()
1429 static void do_one_tree(struct dentry *dentry) in do_one_tree() argument
1431 shrink_dcache_parent(dentry); in do_one_tree()
1432 d_walk(dentry, dentry, umount_check, NULL); in do_one_tree()
1433 d_drop(dentry); in do_one_tree()
1434 dput(dentry); in do_one_tree()
1442 struct dentry *dentry; in shrink_dcache_for_umount() local
1446 dentry = sb->s_root; in shrink_dcache_for_umount()
1448 do_one_tree(dentry); in shrink_dcache_for_umount()
1451 dentry = dget(hlist_bl_entry(hlist_bl_first(&sb->s_anon), struct dentry, d_hash)); in shrink_dcache_for_umount()
1452 do_one_tree(dentry); in shrink_dcache_for_umount()
1458 struct dentry *mountpoint;
1460 static enum d_walk_ret detach_and_collect(void *_data, struct dentry *dentry) in detach_and_collect() argument
1464 if (d_mountpoint(dentry)) { in detach_and_collect()
1465 __dget_dlock(dentry); in detach_and_collect()
1466 data->mountpoint = dentry; in detach_and_collect()
1470 return select_collect(&data->select, dentry); in detach_and_collect()
1491 void d_invalidate(struct dentry *dentry) in d_invalidate() argument
1496 spin_lock(&dentry->d_lock); in d_invalidate()
1497 if (d_unhashed(dentry)) { in d_invalidate()
1498 spin_unlock(&dentry->d_lock); in d_invalidate()
1501 spin_unlock(&dentry->d_lock); in d_invalidate()
1504 if (!dentry->d_inode) { in d_invalidate()
1505 d_drop(dentry); in d_invalidate()
1514 data.select.start = dentry; in d_invalidate()
1517 d_walk(dentry, &data, detach_and_collect, check_and_drop); in d_invalidate()
1545 struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) in __d_alloc()
1547 struct dentry *dentry; in __d_alloc() local
1550 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); in __d_alloc()
1551 if (!dentry) in __d_alloc()
1560 dentry->d_iname[DNAME_INLINE_LEN-1] = 0; in __d_alloc()
1565 kmem_cache_free(dentry_cache, dentry); in __d_alloc()
1574 dname = dentry->d_iname; in __d_alloc()
1577 dentry->d_name.len = name->len; in __d_alloc()
1578 dentry->d_name.hash = name->hash; in __d_alloc()
1584 dentry->d_name.name = dname; in __d_alloc()
1586 dentry->d_lockref.count = 1; in __d_alloc()
1587 dentry->d_flags = 0; in __d_alloc()
1588 spin_lock_init(&dentry->d_lock); in __d_alloc()
1589 seqcount_init(&dentry->d_seq); in __d_alloc()
1590 dentry->d_inode = NULL; in __d_alloc()
1591 dentry->d_parent = dentry; in __d_alloc()
1592 dentry->d_sb = sb; in __d_alloc()
1593 dentry->d_op = NULL; in __d_alloc()
1594 dentry->d_fsdata = NULL; in __d_alloc()
1595 INIT_HLIST_BL_NODE(&dentry->d_hash); in __d_alloc()
1596 INIT_LIST_HEAD(&dentry->d_lru); in __d_alloc()
1597 INIT_LIST_HEAD(&dentry->d_subdirs); in __d_alloc()
1598 INIT_HLIST_NODE(&dentry->d_u.d_alias); in __d_alloc()
1599 INIT_LIST_HEAD(&dentry->d_child); in __d_alloc()
1600 d_set_d_op(dentry, dentry->d_sb->s_d_op); in __d_alloc()
1604 return dentry; in __d_alloc()
1616 struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) in d_alloc()
1618 struct dentry *dentry = __d_alloc(parent->d_sb, name); in d_alloc() local
1619 if (!dentry) in d_alloc()
1621 dentry->d_flags |= DCACHE_RCUACCESS; in d_alloc()
1628 dentry->d_parent = parent; in d_alloc()
1629 list_add(&dentry->d_child, &parent->d_subdirs); in d_alloc()
1632 return dentry; in d_alloc()
1644 struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name) in d_alloc_pseudo()
1650 struct dentry *d_alloc_name(struct dentry *parent, const char *name) in d_alloc_name()
1661 void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op) in d_set_d_op() argument
1663 WARN_ON_ONCE(dentry->d_op); in d_set_d_op()
1664 WARN_ON_ONCE(dentry->d_flags & (DCACHE_OP_HASH | in d_set_d_op()
1670 dentry->d_op = op; in d_set_d_op()
1674 dentry->d_flags |= DCACHE_OP_HASH; in d_set_d_op()
1676 dentry->d_flags |= DCACHE_OP_COMPARE; in d_set_d_op()
1678 dentry->d_flags |= DCACHE_OP_REVALIDATE; in d_set_d_op()
1680 dentry->d_flags |= DCACHE_OP_WEAK_REVALIDATE; in d_set_d_op()
1682 dentry->d_flags |= DCACHE_OP_DELETE; in d_set_d_op()
1684 dentry->d_flags |= DCACHE_OP_PRUNE; in d_set_d_op()
1686 dentry->d_flags |= DCACHE_OP_SELECT_INODE; in d_set_d_op()
1699 void d_set_fallthru(struct dentry *dentry) in d_set_fallthru() argument
1701 spin_lock(&dentry->d_lock); in d_set_fallthru()
1702 dentry->d_flags |= DCACHE_FALLTHRU; in d_set_fallthru()
1703 spin_unlock(&dentry->d_lock); in d_set_fallthru()
1742 static void __d_instantiate(struct dentry *dentry, struct inode *inode) in __d_instantiate() argument
1746 spin_lock(&dentry->d_lock); in __d_instantiate()
1748 hlist_add_head(&dentry->d_u.d_alias, &inode->i_dentry); in __d_instantiate()
1749 raw_write_seqcount_begin(&dentry->d_seq); in __d_instantiate()
1750 __d_set_inode_and_type(dentry, inode, add_flags); in __d_instantiate()
1751 raw_write_seqcount_end(&dentry->d_seq); in __d_instantiate()
1752 spin_unlock(&dentry->d_lock); in __d_instantiate()
1753 fsnotify_d_instantiate(dentry, inode); in __d_instantiate()
1771 void d_instantiate(struct dentry *entry, struct inode * inode) in d_instantiate()
1799 static struct dentry *__d_instantiate_unique(struct dentry *entry, in __d_instantiate_unique()
1802 struct dentry *alias; in __d_instantiate_unique()
1834 struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode) in d_instantiate_unique()
1836 struct dentry *result; in d_instantiate_unique()
1867 int d_instantiate_no_diralias(struct dentry *entry, struct inode *inode) in d_instantiate_no_diralias()
1885 struct dentry *d_make_root(struct inode *root_inode) in d_make_root()
1887 struct dentry *res = NULL; in d_make_root()
1902 static struct dentry * __d_find_any_alias(struct inode *inode) in __d_find_any_alias()
1904 struct dentry *alias; in __d_find_any_alias()
1908 alias = hlist_entry(inode->i_dentry.first, struct dentry, d_u.d_alias); in __d_find_any_alias()
1920 struct dentry *d_find_any_alias(struct inode *inode) in d_find_any_alias()
1922 struct dentry *de; in d_find_any_alias()
1931 static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) in __d_obtain_alias()
1934 struct dentry *tmp; in __d_obtain_alias()
1935 struct dentry *res; in __d_obtain_alias()
2004 struct dentry *d_obtain_alias(struct inode *inode) in d_obtain_alias()
2025 struct dentry *d_obtain_root(struct inode *inode) in d_obtain_root()
2047 struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, in d_add_ci() argument
2050 struct dentry *found; in d_add_ci()
2051 struct dentry *new; in d_add_ci()
2057 found = d_hash_and_lookup(dentry->d_parent, name); in d_add_ci()
2059 new = d_alloc(dentry->d_parent, name); in d_add_ci()
2097 const struct dentry *parent, in slow_dentry_cmp()
2098 struct dentry *dentry, in slow_dentry_cmp() argument
2102 int tlen = dentry->d_name.len; in slow_dentry_cmp()
2103 const char *tname = dentry->d_name.name; in slow_dentry_cmp()
2105 if (read_seqcount_retry(&dentry->d_seq, seq)) { in slow_dentry_cmp()
2109 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name)) in slow_dentry_cmp()
2143 struct dentry *__d_lookup_rcu(const struct dentry *parent, in __d_lookup_rcu()
2151 struct dentry *dentry; in __d_lookup_rcu() local
2173 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup_rcu()
2191 seq = raw_seqcount_begin(&dentry->d_seq); in __d_lookup_rcu()
2192 if (dentry->d_parent != parent) in __d_lookup_rcu()
2194 if (d_unhashed(dentry)) in __d_lookup_rcu()
2198 if (dentry->d_name.hash != hashlen_hash(hashlen)) in __d_lookup_rcu()
2201 switch (slow_dentry_cmp(parent, dentry, seq, name)) { in __d_lookup_rcu()
2203 return dentry; in __d_lookup_rcu()
2211 if (dentry->d_name.hash_len != hashlen) in __d_lookup_rcu()
2214 if (!dentry_cmp(dentry, str, hashlen_len(hashlen))) in __d_lookup_rcu()
2215 return dentry; in __d_lookup_rcu()
2231 struct dentry *d_lookup(const struct dentry *parent, const struct qstr *name) in d_lookup()
2233 struct dentry *dentry; in d_lookup() local
2238 dentry = __d_lookup(parent, name); in d_lookup()
2239 if (dentry) in d_lookup()
2242 return dentry; in d_lookup()
2261 struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name) in __d_lookup()
2268 struct dentry *found = NULL; in __d_lookup()
2269 struct dentry *dentry; in __d_lookup() local
2293 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup()
2295 if (dentry->d_name.hash != hash) in __d_lookup()
2298 spin_lock(&dentry->d_lock); in __d_lookup()
2299 if (dentry->d_parent != parent) in __d_lookup()
2301 if (d_unhashed(dentry)) in __d_lookup()
2309 int tlen = dentry->d_name.len; in __d_lookup()
2310 const char *tname = dentry->d_name.name; in __d_lookup()
2311 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name)) in __d_lookup()
2314 if (dentry->d_name.len != len) in __d_lookup()
2316 if (dentry_cmp(dentry, str, len)) in __d_lookup()
2320 dentry->d_lockref.count++; in __d_lookup()
2321 found = dentry; in __d_lookup()
2322 spin_unlock(&dentry->d_lock); in __d_lookup()
2325 spin_unlock(&dentry->d_lock); in __d_lookup()
2339 struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name) in d_hash_and_lookup()
2377 void d_delete(struct dentry * dentry) in d_delete() argument
2385 spin_lock(&dentry->d_lock); in d_delete()
2386 inode = dentry->d_inode; in d_delete()
2388 if (dentry->d_lockref.count == 1) { in d_delete()
2390 spin_unlock(&dentry->d_lock); in d_delete()
2394 dentry->d_flags &= ~DCACHE_CANT_MOUNT; in d_delete()
2395 dentry_unlink_inode(dentry); in d_delete()
2396 fsnotify_nameremove(dentry, isdir); in d_delete()
2400 if (!d_unhashed(dentry)) in d_delete()
2401 __d_drop(dentry); in d_delete()
2403 spin_unlock(&dentry->d_lock); in d_delete()
2405 fsnotify_nameremove(dentry, isdir); in d_delete()
2409 static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b) in __d_rehash()
2417 static void _d_rehash(struct dentry * entry) in _d_rehash()
2429 void d_rehash(struct dentry * entry) in d_rehash()
2451 void dentry_update_name_case(struct dentry *dentry, struct qstr *name) in dentry_update_name_case() argument
2453 BUG_ON(!mutex_is_locked(&dentry->d_parent->d_inode->i_mutex)); in dentry_update_name_case()
2454 BUG_ON(dentry->d_name.len != name->len); /* d_lookup gives this */ in dentry_update_name_case()
2456 spin_lock(&dentry->d_lock); in dentry_update_name_case()
2457 write_seqcount_begin(&dentry->d_seq); in dentry_update_name_case()
2458 memcpy((unsigned char *)dentry->d_name.name, name->name, name->len); in dentry_update_name_case()
2459 write_seqcount_end(&dentry->d_seq); in dentry_update_name_case()
2460 spin_unlock(&dentry->d_lock); in dentry_update_name_case()
2464 static void swap_names(struct dentry *dentry, struct dentry *target) in swap_names() argument
2467 if (unlikely(dname_external(dentry))) { in swap_names()
2471 swap(target->d_name.name, dentry->d_name.name); in swap_names()
2477 memcpy(target->d_iname, dentry->d_name.name, in swap_names()
2478 dentry->d_name.len + 1); in swap_names()
2479 dentry->d_name.name = target->d_name.name; in swap_names()
2483 if (unlikely(dname_external(dentry))) { in swap_names()
2488 memcpy(dentry->d_iname, target->d_name.name, in swap_names()
2490 target->d_name.name = dentry->d_name.name; in swap_names()
2491 dentry->d_name.name = dentry->d_iname; in swap_names()
2498 kmemcheck_mark_initialized(dentry->d_iname, DNAME_INLINE_LEN); in swap_names()
2501 swap(((long *) &dentry->d_iname)[i], in swap_names()
2506 swap(dentry->d_name.hash_len, target->d_name.hash_len); in swap_names()
2509 static void copy_name(struct dentry *dentry, struct dentry *target) in copy_name() argument
2512 if (unlikely(dname_external(dentry))) in copy_name()
2513 old_name = external_name(dentry); in copy_name()
2516 dentry->d_name = target->d_name; in copy_name()
2518 memcpy(dentry->d_iname, target->d_name.name, in copy_name()
2520 dentry->d_name.name = dentry->d_iname; in copy_name()
2521 dentry->d_name.hash_len = target->d_name.hash_len; in copy_name()
2527 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) in dentry_lock_for_move() argument
2532 if (IS_ROOT(dentry) || dentry->d_parent == target->d_parent) in dentry_lock_for_move()
2535 if (d_ancestor(dentry->d_parent, target->d_parent)) { in dentry_lock_for_move()
2536 spin_lock(&dentry->d_parent->d_lock); in dentry_lock_for_move()
2541 spin_lock_nested(&dentry->d_parent->d_lock, in dentry_lock_for_move()
2545 if (target < dentry) { in dentry_lock_for_move()
2547 spin_lock_nested(&dentry->d_lock, 3); in dentry_lock_for_move()
2549 spin_lock_nested(&dentry->d_lock, 2); in dentry_lock_for_move()
2554 static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target) in dentry_unlock_for_move() argument
2556 if (target->d_parent != dentry->d_parent) in dentry_unlock_for_move()
2557 spin_unlock(&dentry->d_parent->d_lock); in dentry_unlock_for_move()
2561 spin_unlock(&dentry->d_lock); in dentry_unlock_for_move()
2589 static void __d_move(struct dentry *dentry, struct dentry *target, in __d_move() argument
2592 if (!dentry->d_inode) in __d_move()
2595 BUG_ON(d_ancestor(dentry, target)); in __d_move()
2596 BUG_ON(d_ancestor(target, dentry)); in __d_move()
2598 dentry_lock_for_move(dentry, target); in __d_move()
2600 write_seqcount_begin(&dentry->d_seq); in __d_move()
2609 __d_drop(dentry); in __d_move()
2610 __d_rehash(dentry, d_hash(target->d_parent, target->d_name.hash)); in __d_move()
2619 d_hash(dentry->d_parent, dentry->d_name.hash)); in __d_move()
2624 swap_names(dentry, target); in __d_move()
2626 copy_name(dentry, target); in __d_move()
2629 if (IS_ROOT(dentry)) { in __d_move()
2631 dentry->d_flags |= DCACHE_RCUACCESS; in __d_move()
2632 dentry->d_parent = target->d_parent; in __d_move()
2635 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); in __d_move()
2638 swap(dentry->d_parent, target->d_parent); in __d_move()
2640 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); in __d_move()
2643 fsnotify_d_move(dentry); in __d_move()
2647 write_seqcount_end(&dentry->d_seq); in __d_move()
2649 dentry_unlock_for_move(dentry, target); in __d_move()
2661 void d_move(struct dentry *dentry, struct dentry *target) in d_move() argument
2664 __d_move(dentry, target, false); in d_move()
2674 void d_exchange(struct dentry *dentry1, struct dentry *dentry2) in d_exchange()
2696 struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2) in d_ancestor()
2698 struct dentry *p; in d_ancestor()
2717 struct dentry *dentry, struct dentry *alias) in __d_unalias() argument
2723 if (alias->d_parent == dentry->d_parent) in __d_unalias()
2727 if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex)) in __d_unalias()
2729 m1 = &dentry->d_sb->s_vfs_rename_mutex; in __d_unalias()
2734 __d_move(alias, dentry, false); in __d_unalias()
2768 struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) in d_splice_alias() argument
2773 BUG_ON(!d_unhashed(dentry)); in d_splice_alias()
2776 __d_instantiate(dentry, NULL); in d_splice_alias()
2781 struct dentry *new = __d_find_any_alias(inode); in d_splice_alias()
2784 if (unlikely(d_ancestor(new, dentry))) { in d_splice_alias()
2792 dentry->d_name.name, in d_splice_alias()
2796 int err = __d_unalias(inode, dentry, new); in d_splice_alias()
2803 __d_move(new, dentry, false); in d_splice_alias()
2813 __d_instantiate(dentry, inode); in d_splice_alias()
2816 security_d_instantiate(dentry, inode); in d_splice_alias()
2817 d_rehash(dentry); in d_splice_alias()
2893 struct dentry *dentry; in prepend_path() local
2910 dentry = path->dentry; in prepend_path()
2914 while (dentry != root->dentry || vfsmnt != root->mnt) { in prepend_path()
2915 struct dentry * parent; in prepend_path()
2917 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { in prepend_path()
2920 if (dentry != vfsmnt->mnt_root) { in prepend_path()
2928 dentry = ACCESS_ONCE(mnt->mnt_mountpoint); in prepend_path()
2937 parent = dentry->d_parent; in prepend_path()
2939 error = prepend_name(&bptr, &blen, &dentry->d_name); in prepend_path()
2943 dentry = parent; in prepend_path()
3030 if (d_unlinked(path->dentry)) { in path_with_deleted()
3087 if (path->dentry->d_op && path->dentry->d_op->d_dname && in d_path()
3088 (!IS_ROOT(path->dentry) || path->dentry != path->mnt->mnt_root)) in d_path()
3089 return path->dentry->d_op->d_dname(path->dentry, buf, buflen); in d_path()
3105 char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen, in dynamic_dname() argument
3123 char *simple_dname(struct dentry *dentry, char *buffer, int buflen) in simple_dname() argument
3128 prepend(&end, &buflen, dentry->d_name.name, dentry->d_name.len) || in simple_dname()
3138 static char *__dentry_path(struct dentry *d, char *buf, int buflen) in __dentry_path()
3140 struct dentry *dentry; in __dentry_path() local
3150 dentry = d; in __dentry_path()
3158 while (!IS_ROOT(dentry)) { in __dentry_path()
3159 struct dentry *parent = dentry->d_parent; in __dentry_path()
3162 error = prepend_name(&end, &len, &dentry->d_name); in __dentry_path()
3167 dentry = parent; in __dentry_path()
3183 char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen) in dentry_path_raw() argument
3185 return __dentry_path(dentry, buf, buflen); in dentry_path_raw()
3189 char *dentry_path(struct dentry *dentry, char *buf, int buflen) in dentry_path() argument
3194 if (d_unlinked(dentry)) { in dentry_path()
3200 retval = __dentry_path(dentry, buf, buflen); in dentry_path()
3251 if (!d_unlinked(pwd.dentry)) { in SYSCALL_DEFINE2()
3302 int is_subdir(struct dentry *new_dentry, struct dentry *old_dentry) in is_subdir()
3328 static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry) in d_genocide_kill() argument
3330 struct dentry *root = data; in d_genocide_kill()
3331 if (dentry != root) { in d_genocide_kill()
3332 if (d_unhashed(dentry) || !dentry->d_inode) in d_genocide_kill()
3335 if (!(dentry->d_flags & DCACHE_GENOCIDE)) { in d_genocide_kill()
3336 dentry->d_flags |= DCACHE_GENOCIDE; in d_genocide_kill()
3337 dentry->d_lockref.count--; in d_genocide_kill()
3343 void d_genocide(struct dentry *parent) in d_genocide()
3348 void d_tmpfile(struct dentry *dentry, struct inode *inode) in d_tmpfile() argument
3351 BUG_ON(dentry->d_name.name != dentry->d_iname || in d_tmpfile()
3352 !hlist_unhashed(&dentry->d_u.d_alias) || in d_tmpfile()
3353 !d_unlinked(dentry)); in d_tmpfile()
3354 spin_lock(&dentry->d_parent->d_lock); in d_tmpfile()
3355 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_tmpfile()
3356 dentry->d_name.len = sprintf(dentry->d_iname, "#%llu", in d_tmpfile()
3358 spin_unlock(&dentry->d_lock); in d_tmpfile()
3359 spin_unlock(&dentry->d_parent->d_lock); in d_tmpfile()
3360 d_instantiate(dentry, inode); in d_tmpfile()
3408 dentry_cache = KMEM_CACHE(dentry, in dcache_init()