• Home
  • Raw
  • Download

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 void take_dentry_name_snapshot(struct name_snapshot *name, struct dentry *dentry) in take_dentry_name_snapshot() argument
274 spin_lock(&dentry->d_lock); in take_dentry_name_snapshot()
275 if (unlikely(dname_external(dentry))) { in take_dentry_name_snapshot()
276 struct external_name *p = external_name(dentry); in take_dentry_name_snapshot()
278 spin_unlock(&dentry->d_lock); in take_dentry_name_snapshot()
281 memcpy(name->inline_name, dentry->d_iname, in take_dentry_name_snapshot()
282 dentry->d_name.len + 1); in take_dentry_name_snapshot()
283 spin_unlock(&dentry->d_lock); in take_dentry_name_snapshot()
300 static inline void __d_set_inode_and_type(struct dentry *dentry, in __d_set_inode_and_type() argument
306 dentry->d_inode = inode; in __d_set_inode_and_type()
307 flags = READ_ONCE(dentry->d_flags); in __d_set_inode_and_type()
310 WRITE_ONCE(dentry->d_flags, flags); in __d_set_inode_and_type()
313 static inline void __d_clear_type_and_inode(struct dentry *dentry) in __d_clear_type_and_inode() argument
315 unsigned flags = READ_ONCE(dentry->d_flags); in __d_clear_type_and_inode()
318 WRITE_ONCE(dentry->d_flags, flags); in __d_clear_type_and_inode()
319 dentry->d_inode = NULL; in __d_clear_type_and_inode()
322 static void dentry_free(struct dentry *dentry) in dentry_free() argument
324 WARN_ON(!hlist_unhashed(&dentry->d_u.d_alias)); in dentry_free()
325 if (unlikely(dname_external(dentry))) { in dentry_free()
326 struct external_name *p = external_name(dentry); in dentry_free()
328 call_rcu(&dentry->d_u.d_rcu, __d_free_external); in dentry_free()
333 if (!(dentry->d_flags & DCACHE_RCUACCESS)) in dentry_free()
334 __d_free(&dentry->d_u.d_rcu); in dentry_free()
336 call_rcu(&dentry->d_u.d_rcu, __d_free); in dentry_free()
346 static inline void dentry_rcuwalk_invalidate(struct dentry *dentry) in dentry_rcuwalk_invalidate() argument
348 lockdep_assert_held(&dentry->d_lock); in dentry_rcuwalk_invalidate()
350 write_seqcount_invalidate(&dentry->d_seq); in dentry_rcuwalk_invalidate()
358 static void dentry_iput(struct dentry * dentry) in dentry_iput() argument
359 __releases(dentry->d_lock) in dentry_iput()
360 __releases(dentry->d_inode->i_lock) in dentry_iput()
362 struct inode *inode = dentry->d_inode; in dentry_iput()
364 __d_clear_type_and_inode(dentry); in dentry_iput()
365 hlist_del_init(&dentry->d_u.d_alias); in dentry_iput()
366 spin_unlock(&dentry->d_lock); in dentry_iput()
370 if (dentry->d_op && dentry->d_op->d_iput) in dentry_iput()
371 dentry->d_op->d_iput(dentry, inode); in dentry_iput()
375 spin_unlock(&dentry->d_lock); in dentry_iput()
383 static void dentry_unlink_inode(struct dentry * dentry) in dentry_unlink_inode() argument
384 __releases(dentry->d_lock) in dentry_unlink_inode()
385 __releases(dentry->d_inode->i_lock) in dentry_unlink_inode()
387 struct inode *inode = dentry->d_inode; in dentry_unlink_inode()
389 raw_write_seqcount_begin(&dentry->d_seq); in dentry_unlink_inode()
390 __d_clear_type_and_inode(dentry); in dentry_unlink_inode()
391 hlist_del_init(&dentry->d_u.d_alias); in dentry_unlink_inode()
392 raw_write_seqcount_end(&dentry->d_seq); in dentry_unlink_inode()
393 spin_unlock(&dentry->d_lock); in dentry_unlink_inode()
397 if (dentry->d_op && dentry->d_op->d_iput) in dentry_unlink_inode()
398 dentry->d_op->d_iput(dentry, inode); in dentry_unlink_inode()
417 #define D_FLAG_VERIFY(dentry,x) WARN_ON_ONCE(((dentry)->d_flags & (DCACHE_LRU_LIST | DCACHE_SHRINK_… argument
418 static void d_lru_add(struct dentry *dentry) in d_lru_add() argument
420 D_FLAG_VERIFY(dentry, 0); in d_lru_add()
421 dentry->d_flags |= DCACHE_LRU_LIST; in d_lru_add()
423 WARN_ON_ONCE(!list_lru_add(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); in d_lru_add()
426 static void d_lru_del(struct dentry *dentry) in d_lru_del() argument
428 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_del()
429 dentry->d_flags &= ~DCACHE_LRU_LIST; in d_lru_del()
431 WARN_ON_ONCE(!list_lru_del(&dentry->d_sb->s_dentry_lru, &dentry->d_lru)); in d_lru_del()
434 static void d_shrink_del(struct dentry *dentry) in d_shrink_del() argument
436 D_FLAG_VERIFY(dentry, DCACHE_SHRINK_LIST | DCACHE_LRU_LIST); in d_shrink_del()
437 list_del_init(&dentry->d_lru); in d_shrink_del()
438 dentry->d_flags &= ~(DCACHE_SHRINK_LIST | DCACHE_LRU_LIST); in d_shrink_del()
442 static void d_shrink_add(struct dentry *dentry, struct list_head *list) in d_shrink_add() argument
444 D_FLAG_VERIFY(dentry, 0); in d_shrink_add()
445 list_add(&dentry->d_lru, list); in d_shrink_add()
446 dentry->d_flags |= DCACHE_SHRINK_LIST | DCACHE_LRU_LIST; in d_shrink_add()
456 static void d_lru_isolate(struct list_lru_one *lru, struct dentry *dentry) in d_lru_isolate() argument
458 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_isolate()
459 dentry->d_flags &= ~DCACHE_LRU_LIST; in d_lru_isolate()
461 list_lru_isolate(lru, &dentry->d_lru); in d_lru_isolate()
464 static void d_lru_shrink_move(struct list_lru_one *lru, struct dentry *dentry, in d_lru_shrink_move() argument
467 D_FLAG_VERIFY(dentry, DCACHE_LRU_LIST); in d_lru_shrink_move()
468 dentry->d_flags |= DCACHE_SHRINK_LIST; in d_lru_shrink_move()
469 list_lru_isolate_move(lru, &dentry->d_lru, list); in d_lru_shrink_move()
475 static void dentry_lru_add(struct dentry *dentry) in dentry_lru_add() argument
477 if (unlikely(!(dentry->d_flags & DCACHE_LRU_LIST))) in dentry_lru_add()
478 d_lru_add(dentry); in dentry_lru_add()
496 void __d_drop(struct dentry *dentry) in __d_drop() argument
498 if (!d_unhashed(dentry)) { in __d_drop()
505 if (unlikely(IS_ROOT(dentry))) in __d_drop()
506 b = &dentry->d_sb->s_anon; in __d_drop()
508 b = d_hash(dentry->d_parent, dentry->d_name.hash); in __d_drop()
511 __hlist_bl_del(&dentry->d_hash); in __d_drop()
512 dentry->d_hash.pprev = NULL; in __d_drop()
514 dentry_rcuwalk_invalidate(dentry); in __d_drop()
519 void d_drop(struct dentry *dentry) in d_drop() argument
521 spin_lock(&dentry->d_lock); in d_drop()
522 __d_drop(dentry); in d_drop()
523 spin_unlock(&dentry->d_lock); in d_drop()
527 static void __dentry_kill(struct dentry *dentry) in __dentry_kill() argument
529 struct dentry *parent = NULL; in __dentry_kill()
531 if (!IS_ROOT(dentry)) in __dentry_kill()
532 parent = dentry->d_parent; in __dentry_kill()
537 lockref_mark_dead(&dentry->d_lockref); in __dentry_kill()
543 if (dentry->d_flags & DCACHE_OP_PRUNE) in __dentry_kill()
544 dentry->d_op->d_prune(dentry); in __dentry_kill()
546 if (dentry->d_flags & DCACHE_LRU_LIST) { in __dentry_kill()
547 if (!(dentry->d_flags & DCACHE_SHRINK_LIST)) in __dentry_kill()
548 d_lru_del(dentry); in __dentry_kill()
551 __d_drop(dentry); in __dentry_kill()
552 __list_del_entry(&dentry->d_child); in __dentry_kill()
557 dentry->d_flags |= DCACHE_DENTRY_KILLED; in __dentry_kill()
560 dentry_iput(dentry); in __dentry_kill()
565 BUG_ON(dentry->d_lockref.count > 0); in __dentry_kill()
567 if (dentry->d_op && dentry->d_op->d_release) in __dentry_kill()
568 dentry->d_op->d_release(dentry); in __dentry_kill()
570 spin_lock(&dentry->d_lock); in __dentry_kill()
571 if (dentry->d_flags & DCACHE_SHRINK_LIST) { in __dentry_kill()
572 dentry->d_flags |= DCACHE_MAY_FREE; in __dentry_kill()
575 spin_unlock(&dentry->d_lock); in __dentry_kill()
577 dentry_free(dentry); in __dentry_kill()
586 static struct dentry *dentry_kill(struct dentry *dentry) in dentry_kill() argument
587 __releases(dentry->d_lock) in dentry_kill()
589 struct inode *inode = dentry->d_inode; in dentry_kill()
590 struct dentry *parent = NULL; in dentry_kill()
595 if (!IS_ROOT(dentry)) { in dentry_kill()
596 parent = dentry->d_parent; in dentry_kill()
604 __dentry_kill(dentry); in dentry_kill()
608 spin_unlock(&dentry->d_lock); in dentry_kill()
609 return dentry; /* try again with same dentry */ in dentry_kill()
612 static inline struct dentry *lock_parent(struct dentry *dentry) in lock_parent() argument
614 struct dentry *parent = dentry->d_parent; in lock_parent()
615 if (IS_ROOT(dentry)) in lock_parent()
617 if (unlikely(dentry->d_lockref.count < 0)) in lock_parent()
622 spin_unlock(&dentry->d_lock); in lock_parent()
624 parent = ACCESS_ONCE(dentry->d_parent); in lock_parent()
634 if (unlikely(parent != dentry->d_parent)) { in lock_parent()
638 if (parent != dentry) { in lock_parent()
639 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in lock_parent()
640 if (unlikely(dentry->d_lockref.count < 0)) { in lock_parent()
659 static inline bool fast_dput(struct dentry *dentry) in fast_dput() argument
668 if (unlikely(dentry->d_flags & DCACHE_OP_DELETE)) in fast_dput()
669 return lockref_put_or_lock(&dentry->d_lockref); in fast_dput()
675 ret = lockref_put_return(&dentry->d_lockref); in fast_dput()
683 spin_lock(&dentry->d_lock); in fast_dput()
684 if (dentry->d_lockref.count > 1) { in fast_dput()
685 dentry->d_lockref.count--; in fast_dput()
686 spin_unlock(&dentry->d_lock); in fast_dput()
720 d_flags = ACCESS_ONCE(dentry->d_flags); in fast_dput()
724 if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry)) in fast_dput()
732 spin_lock(&dentry->d_lock); in fast_dput()
740 if (dentry->d_lockref.count) { in fast_dput()
741 spin_unlock(&dentry->d_lock); in fast_dput()
750 dentry->d_lockref.count = 1; in fast_dput()
781 void dput(struct dentry *dentry) in dput() argument
783 if (unlikely(!dentry)) in dput()
790 if (likely(fast_dput(dentry))) { in dput()
799 if (unlikely(d_unhashed(dentry))) in dput()
802 if (unlikely(dentry->d_flags & DCACHE_DISCONNECTED)) in dput()
805 if (unlikely(dentry->d_flags & DCACHE_OP_DELETE)) { in dput()
806 if (dentry->d_op->d_delete(dentry)) in dput()
810 if (!(dentry->d_flags & DCACHE_REFERENCED)) in dput()
811 dentry->d_flags |= DCACHE_REFERENCED; in dput()
812 dentry_lru_add(dentry); in dput()
814 dentry->d_lockref.count--; in dput()
815 spin_unlock(&dentry->d_lock); in dput()
819 dentry = dentry_kill(dentry); in dput()
820 if (dentry) { in dput()
829 static inline void __dget_dlock(struct dentry *dentry) in __dget_dlock() argument
831 dentry->d_lockref.count++; in __dget_dlock()
834 static inline void __dget(struct dentry *dentry) in __dget() argument
836 lockref_get(&dentry->d_lockref); in __dget()
839 struct dentry *dget_parent(struct dentry *dentry) in dget_parent() argument
842 struct dentry *ret; in dget_parent()
849 ret = ACCESS_ONCE(dentry->d_parent); in dget_parent()
853 if (likely(ret == ACCESS_ONCE(dentry->d_parent))) in dget_parent()
864 ret = dentry->d_parent; in dget_parent()
866 if (unlikely(ret != dentry->d_parent)) { in dget_parent()
893 static struct dentry *__d_find_alias(struct inode *inode) in __d_find_alias()
895 struct dentry *alias, *discon_alias; in __d_find_alias()
927 struct dentry *d_find_alias(struct inode *inode) in d_find_alias()
929 struct dentry *de = NULL; in d_find_alias()
946 struct dentry *dentry; in d_prune_aliases() local
949 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) { in d_prune_aliases()
950 spin_lock(&dentry->d_lock); in d_prune_aliases()
951 if (!dentry->d_lockref.count) { in d_prune_aliases()
952 struct dentry *parent = lock_parent(dentry); in d_prune_aliases()
953 if (likely(!dentry->d_lockref.count)) { in d_prune_aliases()
954 __dentry_kill(dentry); in d_prune_aliases()
961 spin_unlock(&dentry->d_lock); in d_prune_aliases()
969 struct dentry *dentry, *parent; in shrink_dentry_list() local
973 dentry = list_entry(list->prev, struct dentry, d_lru); in shrink_dentry_list()
974 spin_lock(&dentry->d_lock); in shrink_dentry_list()
975 parent = lock_parent(dentry); in shrink_dentry_list()
982 d_shrink_del(dentry); in shrink_dentry_list()
988 if (dentry->d_lockref.count > 0) { in shrink_dentry_list()
989 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
996 if (unlikely(dentry->d_flags & DCACHE_DENTRY_KILLED)) { in shrink_dentry_list()
997 bool can_free = dentry->d_flags & DCACHE_MAY_FREE; in shrink_dentry_list()
998 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
1002 dentry_free(dentry); in shrink_dentry_list()
1006 inode = dentry->d_inode; in shrink_dentry_list()
1008 d_shrink_add(dentry, list); in shrink_dentry_list()
1009 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
1015 __dentry_kill(dentry); in shrink_dentry_list()
1023 dentry = parent; in shrink_dentry_list()
1024 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) { in shrink_dentry_list()
1025 parent = lock_parent(dentry); in shrink_dentry_list()
1026 if (dentry->d_lockref.count != 1) { in shrink_dentry_list()
1027 dentry->d_lockref.count--; in shrink_dentry_list()
1028 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
1033 inode = dentry->d_inode; /* can't be NULL */ in shrink_dentry_list()
1035 spin_unlock(&dentry->d_lock); in shrink_dentry_list()
1041 __dentry_kill(dentry); in shrink_dentry_list()
1042 dentry = parent; in shrink_dentry_list()
1051 struct dentry *dentry = container_of(item, struct dentry, d_lru); in dentry_lru_isolate() local
1059 if (!spin_trylock(&dentry->d_lock)) in dentry_lru_isolate()
1067 if (dentry->d_lockref.count) { in dentry_lru_isolate()
1068 d_lru_isolate(lru, dentry); in dentry_lru_isolate()
1069 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1073 if (dentry->d_flags & DCACHE_REFERENCED) { in dentry_lru_isolate()
1074 dentry->d_flags &= ~DCACHE_REFERENCED; in dentry_lru_isolate()
1075 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1099 d_lru_shrink_move(lru, dentry, freeable); in dentry_lru_isolate()
1100 spin_unlock(&dentry->d_lock); in dentry_lru_isolate()
1132 struct dentry *dentry = container_of(item, struct dentry, d_lru); in dentry_lru_isolate_shrink() local
1139 if (!spin_trylock(&dentry->d_lock)) in dentry_lru_isolate_shrink()
1142 d_lru_shrink_move(lru, dentry, freeable); in dentry_lru_isolate_shrink()
1143 spin_unlock(&dentry->d_lock); in dentry_lru_isolate_shrink()
1192 static void d_walk(struct dentry *parent, void *data, in d_walk()
1193 enum d_walk_ret (*enter)(void *, struct dentry *), in d_walk() argument
1196 struct dentry *this_parent; in d_walk()
1223 struct dentry *dentry = list_entry(tmp, struct dentry, d_child); in d_walk() local
1226 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_walk()
1228 ret = enter(data, dentry); in d_walk()
1233 spin_unlock(&dentry->d_lock); in d_walk()
1239 spin_unlock(&dentry->d_lock); in d_walk()
1243 if (!list_empty(&dentry->d_subdirs)) { in d_walk()
1245 spin_release(&dentry->d_lock.dep_map, 1, _RET_IP_); in d_walk()
1246 this_parent = dentry; in d_walk()
1250 spin_unlock(&dentry->d_lock); in d_walk()
1258 struct dentry *child = this_parent; in d_walk()
1272 child = list_entry(next, struct dentry, d_child); in d_walk()
1304 static enum d_walk_ret check_mount(void *data, struct dentry *dentry) in check_mount() argument
1307 if (d_mountpoint(dentry)) { in check_mount()
1321 int have_submounts(struct dentry *parent) in have_submounts()
1339 int d_set_mounted(struct dentry *dentry) in d_set_mounted() argument
1341 struct dentry *p; in d_set_mounted()
1344 for (p = dentry->d_parent; !IS_ROOT(p); p = p->d_parent) { in d_set_mounted()
1353 spin_lock(&dentry->d_lock); in d_set_mounted()
1354 if (!d_unlinked(dentry)) { in d_set_mounted()
1356 if (!d_mountpoint(dentry)) { in d_set_mounted()
1357 dentry->d_flags |= DCACHE_MOUNTED; in d_set_mounted()
1361 spin_unlock(&dentry->d_lock); in d_set_mounted()
1383 struct dentry *start;
1388 static enum d_walk_ret select_collect(void *_data, struct dentry *dentry) in select_collect() argument
1393 if (data->start == dentry) in select_collect()
1396 if (dentry->d_flags & DCACHE_SHRINK_LIST) { in select_collect()
1399 if (dentry->d_flags & DCACHE_LRU_LIST) in select_collect()
1400 d_lru_del(dentry); in select_collect()
1401 if (!dentry->d_lockref.count) { in select_collect()
1402 d_shrink_add(dentry, &data->dispose); in select_collect()
1423 void shrink_dcache_parent(struct dentry *parent) in shrink_dcache_parent()
1442 static enum d_walk_ret umount_check(void *_data, struct dentry *dentry) in umount_check() argument
1445 if (!list_empty(&dentry->d_subdirs)) in umount_check()
1449 if (dentry == _data && dentry->d_lockref.count == 1) in umount_check()
1454 dentry, in umount_check()
1455 dentry->d_inode ? in umount_check()
1456 dentry->d_inode->i_ino : 0UL, in umount_check()
1457 dentry, in umount_check()
1458 dentry->d_lockref.count, in umount_check()
1459 dentry->d_sb->s_type->name, in umount_check()
1460 dentry->d_sb->s_id); in umount_check()
1465 static void do_one_tree(struct dentry *dentry) in do_one_tree() argument
1467 shrink_dcache_parent(dentry); in do_one_tree()
1468 d_walk(dentry, dentry, umount_check, NULL); in do_one_tree()
1469 d_drop(dentry); in do_one_tree()
1470 dput(dentry); in do_one_tree()
1478 struct dentry *dentry; in shrink_dcache_for_umount() local
1482 dentry = sb->s_root; in shrink_dcache_for_umount()
1484 do_one_tree(dentry); in shrink_dcache_for_umount()
1487 dentry = dget(hlist_bl_entry(hlist_bl_first(&sb->s_anon), struct dentry, d_hash)); in shrink_dcache_for_umount()
1488 do_one_tree(dentry); in shrink_dcache_for_umount()
1494 struct dentry *mountpoint;
1496 static enum d_walk_ret detach_and_collect(void *_data, struct dentry *dentry) in detach_and_collect() argument
1500 if (d_mountpoint(dentry)) { in detach_and_collect()
1501 __dget_dlock(dentry); in detach_and_collect()
1502 data->mountpoint = dentry; in detach_and_collect()
1506 return select_collect(&data->select, dentry); in detach_and_collect()
1527 void d_invalidate(struct dentry *dentry) in d_invalidate() argument
1532 spin_lock(&dentry->d_lock); in d_invalidate()
1533 if (d_unhashed(dentry)) { in d_invalidate()
1534 spin_unlock(&dentry->d_lock); in d_invalidate()
1537 spin_unlock(&dentry->d_lock); in d_invalidate()
1540 if (!dentry->d_inode) { in d_invalidate()
1541 d_drop(dentry); in d_invalidate()
1550 data.select.start = dentry; in d_invalidate()
1553 d_walk(dentry, &data, detach_and_collect, check_and_drop); in d_invalidate()
1579 struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) in __d_alloc()
1581 struct dentry *dentry; in __d_alloc() local
1584 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); in __d_alloc()
1585 if (!dentry) in __d_alloc()
1594 dentry->d_iname[DNAME_INLINE_LEN-1] = 0; in __d_alloc()
1599 kmem_cache_free(dentry_cache, dentry); in __d_alloc()
1608 dname = dentry->d_iname; in __d_alloc()
1611 dentry->d_name.len = name->len; in __d_alloc()
1612 dentry->d_name.hash = name->hash; in __d_alloc()
1618 dentry->d_name.name = dname; in __d_alloc()
1620 dentry->d_lockref.count = 1; in __d_alloc()
1621 dentry->d_flags = 0; in __d_alloc()
1622 spin_lock_init(&dentry->d_lock); in __d_alloc()
1623 seqcount_init(&dentry->d_seq); in __d_alloc()
1624 dentry->d_inode = NULL; in __d_alloc()
1625 dentry->d_parent = dentry; in __d_alloc()
1626 dentry->d_sb = sb; in __d_alloc()
1627 dentry->d_op = NULL; in __d_alloc()
1628 dentry->d_fsdata = NULL; in __d_alloc()
1629 INIT_HLIST_BL_NODE(&dentry->d_hash); in __d_alloc()
1630 INIT_LIST_HEAD(&dentry->d_lru); in __d_alloc()
1631 INIT_LIST_HEAD(&dentry->d_subdirs); in __d_alloc()
1632 INIT_HLIST_NODE(&dentry->d_u.d_alias); in __d_alloc()
1633 INIT_LIST_HEAD(&dentry->d_child); in __d_alloc()
1634 d_set_d_op(dentry, dentry->d_sb->s_d_op); in __d_alloc()
1638 return dentry; in __d_alloc()
1650 struct dentry *d_alloc(struct dentry * parent, const struct qstr *name) in d_alloc()
1652 struct dentry *dentry = __d_alloc(parent->d_sb, name); in d_alloc() local
1653 if (!dentry) in d_alloc()
1655 dentry->d_flags |= DCACHE_RCUACCESS; in d_alloc()
1662 dentry->d_parent = parent; in d_alloc()
1663 list_add(&dentry->d_child, &parent->d_subdirs); in d_alloc()
1666 return dentry; in d_alloc()
1678 struct dentry *d_alloc_pseudo(struct super_block *sb, const struct qstr *name) in d_alloc_pseudo()
1684 struct dentry *d_alloc_name(struct dentry *parent, const char *name) in d_alloc_name()
1695 void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op) in d_set_d_op() argument
1697 WARN_ON_ONCE(dentry->d_op); in d_set_d_op()
1698 WARN_ON_ONCE(dentry->d_flags & (DCACHE_OP_HASH | in d_set_d_op()
1705 dentry->d_op = op; in d_set_d_op()
1709 dentry->d_flags |= DCACHE_OP_HASH; in d_set_d_op()
1711 dentry->d_flags |= DCACHE_OP_COMPARE; in d_set_d_op()
1713 dentry->d_flags |= DCACHE_OP_REVALIDATE; in d_set_d_op()
1715 dentry->d_flags |= DCACHE_OP_WEAK_REVALIDATE; in d_set_d_op()
1717 dentry->d_flags |= DCACHE_OP_DELETE; in d_set_d_op()
1719 dentry->d_flags |= DCACHE_OP_PRUNE; in d_set_d_op()
1721 dentry->d_flags |= DCACHE_OP_SELECT_INODE; in d_set_d_op()
1723 dentry->d_flags |= DCACHE_OP_REAL; in d_set_d_op()
1736 void d_set_fallthru(struct dentry *dentry) in d_set_fallthru() argument
1738 spin_lock(&dentry->d_lock); in d_set_fallthru()
1739 dentry->d_flags |= DCACHE_FALLTHRU; in d_set_fallthru()
1740 spin_unlock(&dentry->d_lock); in d_set_fallthru()
1779 static void __d_instantiate(struct dentry *dentry, struct inode *inode) in __d_instantiate() argument
1783 spin_lock(&dentry->d_lock); in __d_instantiate()
1785 hlist_add_head(&dentry->d_u.d_alias, &inode->i_dentry); in __d_instantiate()
1786 raw_write_seqcount_begin(&dentry->d_seq); in __d_instantiate()
1787 __d_set_inode_and_type(dentry, inode, add_flags); in __d_instantiate()
1788 raw_write_seqcount_end(&dentry->d_seq); in __d_instantiate()
1789 spin_unlock(&dentry->d_lock); in __d_instantiate()
1790 fsnotify_d_instantiate(dentry, inode); in __d_instantiate()
1808 void d_instantiate(struct dentry *entry, struct inode * inode) in d_instantiate()
1836 static struct dentry *__d_instantiate_unique(struct dentry *entry, in __d_instantiate_unique()
1839 struct dentry *alias; in __d_instantiate_unique()
1871 struct dentry *d_instantiate_unique(struct dentry *entry, struct inode *inode) in d_instantiate_unique()
1873 struct dentry *result; in d_instantiate_unique()
1901 void d_instantiate_new(struct dentry *entry, struct inode *inode) in d_instantiate_new()
1926 int d_instantiate_no_diralias(struct dentry *entry, struct inode *inode) in d_instantiate_no_diralias()
1944 struct dentry *d_make_root(struct inode *root_inode) in d_make_root()
1946 struct dentry *res = NULL; in d_make_root()
1963 static struct dentry * __d_find_any_alias(struct inode *inode) in __d_find_any_alias()
1965 struct dentry *alias; in __d_find_any_alias()
1969 alias = hlist_entry(inode->i_dentry.first, struct dentry, d_u.d_alias); in __d_find_any_alias()
1981 struct dentry *d_find_any_alias(struct inode *inode) in d_find_any_alias()
1983 struct dentry *de; in d_find_any_alias()
1992 static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) in __d_obtain_alias()
1995 struct dentry *tmp; in __d_obtain_alias()
1996 struct dentry *res; in __d_obtain_alias()
2065 struct dentry *d_obtain_alias(struct inode *inode) in d_obtain_alias()
2086 struct dentry *d_obtain_root(struct inode *inode) in d_obtain_root()
2108 struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, in d_add_ci() argument
2111 struct dentry *found; in d_add_ci()
2112 struct dentry *new; in d_add_ci()
2118 found = d_hash_and_lookup(dentry->d_parent, name); in d_add_ci()
2120 new = d_alloc(dentry->d_parent, name); in d_add_ci()
2158 const struct dentry *parent, in slow_dentry_cmp()
2159 struct dentry *dentry, in slow_dentry_cmp() argument
2163 int tlen = dentry->d_name.len; in slow_dentry_cmp()
2164 const char *tname = dentry->d_name.name; in slow_dentry_cmp()
2166 if (read_seqcount_retry(&dentry->d_seq, seq)) { in slow_dentry_cmp()
2170 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name)) in slow_dentry_cmp()
2204 struct dentry *__d_lookup_rcu(const struct dentry *parent, in __d_lookup_rcu()
2212 struct dentry *dentry; in __d_lookup_rcu() local
2234 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup_rcu()
2252 seq = raw_seqcount_begin(&dentry->d_seq); in __d_lookup_rcu()
2253 if (dentry->d_parent != parent) in __d_lookup_rcu()
2255 if (d_unhashed(dentry)) in __d_lookup_rcu()
2259 if (dentry->d_name.hash != hashlen_hash(hashlen)) in __d_lookup_rcu()
2262 switch (slow_dentry_cmp(parent, dentry, seq, name)) { in __d_lookup_rcu()
2264 return dentry; in __d_lookup_rcu()
2272 if (dentry->d_name.hash_len != hashlen) in __d_lookup_rcu()
2275 if (!dentry_cmp(dentry, str, hashlen_len(hashlen))) in __d_lookup_rcu()
2276 return dentry; in __d_lookup_rcu()
2292 struct dentry *d_lookup(const struct dentry *parent, const struct qstr *name) in d_lookup()
2294 struct dentry *dentry; in d_lookup() local
2299 dentry = __d_lookup(parent, name); in d_lookup()
2300 if (dentry) in d_lookup()
2303 return dentry; in d_lookup()
2322 struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name) in __d_lookup()
2329 struct dentry *found = NULL; in __d_lookup()
2330 struct dentry *dentry; in __d_lookup() local
2354 hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) { in __d_lookup()
2356 if (dentry->d_name.hash != hash) in __d_lookup()
2359 spin_lock(&dentry->d_lock); in __d_lookup()
2360 if (dentry->d_parent != parent) in __d_lookup()
2362 if (d_unhashed(dentry)) in __d_lookup()
2370 int tlen = dentry->d_name.len; in __d_lookup()
2371 const char *tname = dentry->d_name.name; in __d_lookup()
2372 if (parent->d_op->d_compare(parent, dentry, tlen, tname, name)) in __d_lookup()
2375 if (dentry->d_name.len != len) in __d_lookup()
2377 if (dentry_cmp(dentry, str, len)) in __d_lookup()
2381 dentry->d_lockref.count++; in __d_lookup()
2382 found = dentry; in __d_lookup()
2383 spin_unlock(&dentry->d_lock); in __d_lookup()
2386 spin_unlock(&dentry->d_lock); in __d_lookup()
2400 struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name) in d_hash_and_lookup()
2438 void d_delete(struct dentry * dentry) in d_delete() argument
2446 spin_lock(&dentry->d_lock); in d_delete()
2447 inode = dentry->d_inode; in d_delete()
2449 if (dentry->d_lockref.count == 1) { in d_delete()
2451 spin_unlock(&dentry->d_lock); in d_delete()
2455 dentry->d_flags &= ~DCACHE_CANT_MOUNT; in d_delete()
2456 dentry_unlink_inode(dentry); in d_delete()
2457 fsnotify_nameremove(dentry, isdir); in d_delete()
2461 if (!d_unhashed(dentry)) in d_delete()
2462 __d_drop(dentry); in d_delete()
2464 spin_unlock(&dentry->d_lock); in d_delete()
2466 fsnotify_nameremove(dentry, isdir); in d_delete()
2470 static void __d_rehash(struct dentry * entry, struct hlist_bl_head *b) in __d_rehash()
2478 static void _d_rehash(struct dentry * entry) in _d_rehash()
2490 void d_rehash(struct dentry * entry) in d_rehash()
2512 void dentry_update_name_case(struct dentry *dentry, struct qstr *name) in dentry_update_name_case() argument
2514 BUG_ON(!mutex_is_locked(&dentry->d_parent->d_inode->i_mutex)); in dentry_update_name_case()
2515 BUG_ON(dentry->d_name.len != name->len); /* d_lookup gives this */ in dentry_update_name_case()
2517 spin_lock(&dentry->d_lock); in dentry_update_name_case()
2518 write_seqcount_begin(&dentry->d_seq); in dentry_update_name_case()
2519 memcpy((unsigned char *)dentry->d_name.name, name->name, name->len); in dentry_update_name_case()
2520 write_seqcount_end(&dentry->d_seq); in dentry_update_name_case()
2521 spin_unlock(&dentry->d_lock); in dentry_update_name_case()
2525 static void swap_names(struct dentry *dentry, struct dentry *target) in swap_names() argument
2528 if (unlikely(dname_external(dentry))) { in swap_names()
2532 swap(target->d_name.name, dentry->d_name.name); in swap_names()
2538 memcpy(target->d_iname, dentry->d_name.name, in swap_names()
2539 dentry->d_name.len + 1); in swap_names()
2540 dentry->d_name.name = target->d_name.name; in swap_names()
2544 if (unlikely(dname_external(dentry))) { in swap_names()
2549 memcpy(dentry->d_iname, target->d_name.name, in swap_names()
2551 target->d_name.name = dentry->d_name.name; in swap_names()
2552 dentry->d_name.name = dentry->d_iname; in swap_names()
2559 kmemcheck_mark_initialized(dentry->d_iname, DNAME_INLINE_LEN); in swap_names()
2562 swap(((long *) &dentry->d_iname)[i], in swap_names()
2567 swap(dentry->d_name.hash_len, target->d_name.hash_len); in swap_names()
2570 static void copy_name(struct dentry *dentry, struct dentry *target) in copy_name() argument
2573 if (unlikely(dname_external(dentry))) in copy_name()
2574 old_name = external_name(dentry); in copy_name()
2577 dentry->d_name = target->d_name; in copy_name()
2579 memcpy(dentry->d_iname, target->d_name.name, in copy_name()
2581 dentry->d_name.name = dentry->d_iname; in copy_name()
2582 dentry->d_name.hash_len = target->d_name.hash_len; in copy_name()
2588 static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) in dentry_lock_for_move() argument
2593 if (IS_ROOT(dentry) || dentry->d_parent == target->d_parent) in dentry_lock_for_move()
2596 if (d_ancestor(dentry->d_parent, target->d_parent)) { in dentry_lock_for_move()
2597 spin_lock(&dentry->d_parent->d_lock); in dentry_lock_for_move()
2602 spin_lock_nested(&dentry->d_parent->d_lock, in dentry_lock_for_move()
2606 if (target < dentry) { in dentry_lock_for_move()
2608 spin_lock_nested(&dentry->d_lock, 3); in dentry_lock_for_move()
2610 spin_lock_nested(&dentry->d_lock, 2); in dentry_lock_for_move()
2615 static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target) in dentry_unlock_for_move() argument
2617 if (target->d_parent != dentry->d_parent) in dentry_unlock_for_move()
2618 spin_unlock(&dentry->d_parent->d_lock); in dentry_unlock_for_move()
2622 spin_unlock(&dentry->d_lock); in dentry_unlock_for_move()
2650 static void __d_move(struct dentry *dentry, struct dentry *target, in __d_move() argument
2653 if (!dentry->d_inode) in __d_move()
2656 BUG_ON(d_ancestor(dentry, target)); in __d_move()
2657 BUG_ON(d_ancestor(target, dentry)); in __d_move()
2659 dentry_lock_for_move(dentry, target); in __d_move()
2661 write_seqcount_begin(&dentry->d_seq); in __d_move()
2670 __d_drop(dentry); in __d_move()
2671 __d_rehash(dentry, d_hash(target->d_parent, target->d_name.hash)); in __d_move()
2680 d_hash(dentry->d_parent, dentry->d_name.hash)); in __d_move()
2685 swap_names(dentry, target); in __d_move()
2687 copy_name(dentry, target); in __d_move()
2690 if (IS_ROOT(dentry)) { in __d_move()
2692 dentry->d_flags |= DCACHE_RCUACCESS; in __d_move()
2693 dentry->d_parent = target->d_parent; in __d_move()
2696 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); in __d_move()
2699 swap(dentry->d_parent, target->d_parent); in __d_move()
2701 list_move(&dentry->d_child, &dentry->d_parent->d_subdirs); in __d_move()
2704 fsnotify_d_move(dentry); in __d_move()
2708 write_seqcount_end(&dentry->d_seq); in __d_move()
2710 dentry_unlock_for_move(dentry, target); in __d_move()
2722 void d_move(struct dentry *dentry, struct dentry *target) in d_move() argument
2725 __d_move(dentry, target, false); in d_move()
2735 void d_exchange(struct dentry *dentry1, struct dentry *dentry2) in d_exchange()
2757 struct dentry *d_ancestor(struct dentry *p1, struct dentry *p2) in d_ancestor()
2759 struct dentry *p; in d_ancestor()
2778 struct dentry *dentry, struct dentry *alias) in __d_unalias() argument
2784 if (alias->d_parent == dentry->d_parent) in __d_unalias()
2788 if (!mutex_trylock(&dentry->d_sb->s_vfs_rename_mutex)) in __d_unalias()
2790 m1 = &dentry->d_sb->s_vfs_rename_mutex; in __d_unalias()
2795 __d_move(alias, dentry, false); in __d_unalias()
2828 struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) in d_splice_alias() argument
2833 BUG_ON(!d_unhashed(dentry)); in d_splice_alias()
2836 __d_instantiate(dentry, NULL); in d_splice_alias()
2841 struct dentry *new = __d_find_any_alias(inode); in d_splice_alias()
2846 if (unlikely(d_ancestor(new, dentry))) { in d_splice_alias()
2853 dentry->d_name.name, in d_splice_alias()
2857 int err = __d_unalias(inode, dentry, new); in d_splice_alias()
2864 __d_move(new, dentry, false); in d_splice_alias()
2873 __d_instantiate(dentry, inode); in d_splice_alias()
2876 security_d_instantiate(dentry, inode); in d_splice_alias()
2877 d_rehash(dentry); in d_splice_alias()
2953 struct dentry *dentry; in prepend_path() local
2970 dentry = path->dentry; in prepend_path()
2974 while (dentry != root->dentry || vfsmnt != root->mnt) { in prepend_path()
2975 struct dentry * parent; in prepend_path()
2977 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { in prepend_path()
2980 if (dentry != vfsmnt->mnt_root) { in prepend_path()
2988 dentry = ACCESS_ONCE(mnt->mnt_mountpoint); in prepend_path()
2997 parent = dentry->d_parent; in prepend_path()
2999 error = prepend_name(&bptr, &blen, &dentry->d_name); in prepend_path()
3003 dentry = parent; in prepend_path()
3091 if (d_unlinked(path->dentry)) { in path_with_deleted()
3148 if (path->dentry->d_op && path->dentry->d_op->d_dname && in d_path()
3149 (!IS_ROOT(path->dentry) || path->dentry != path->mnt->mnt_root)) in d_path()
3150 return path->dentry->d_op->d_dname(path->dentry, buf, buflen); in d_path()
3166 char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen, in dynamic_dname() argument
3184 char *simple_dname(struct dentry *dentry, char *buffer, int buflen) in simple_dname() argument
3189 prepend(&end, &buflen, dentry->d_name.name, dentry->d_name.len) || in simple_dname()
3199 static char *__dentry_path(struct dentry *d, char *buf, int buflen) in __dentry_path()
3201 struct dentry *dentry; in __dentry_path() local
3211 dentry = d; in __dentry_path()
3219 while (!IS_ROOT(dentry)) { in __dentry_path()
3220 struct dentry *parent = dentry->d_parent; in __dentry_path()
3223 error = prepend_name(&end, &len, &dentry->d_name); in __dentry_path()
3228 dentry = parent; in __dentry_path()
3244 char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen) in dentry_path_raw() argument
3246 return __dentry_path(dentry, buf, buflen); in dentry_path_raw()
3250 char *dentry_path(struct dentry *dentry, char *buf, int buflen) in dentry_path() argument
3255 if (d_unlinked(dentry)) { in dentry_path()
3261 retval = __dentry_path(dentry, buf, buflen); in dentry_path()
3312 if (!d_unlinked(pwd.dentry)) { in SYSCALL_DEFINE2()
3363 int is_subdir(struct dentry *new_dentry, struct dentry *old_dentry) in is_subdir()
3389 static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry) in d_genocide_kill() argument
3391 struct dentry *root = data; in d_genocide_kill()
3392 if (dentry != root) { in d_genocide_kill()
3393 if (d_unhashed(dentry) || !dentry->d_inode) in d_genocide_kill()
3396 if (!(dentry->d_flags & DCACHE_GENOCIDE)) { in d_genocide_kill()
3397 dentry->d_flags |= DCACHE_GENOCIDE; in d_genocide_kill()
3398 dentry->d_lockref.count--; in d_genocide_kill()
3404 void d_genocide(struct dentry *parent) in d_genocide()
3409 void d_tmpfile(struct dentry *dentry, struct inode *inode) in d_tmpfile() argument
3412 BUG_ON(dentry->d_name.name != dentry->d_iname || in d_tmpfile()
3413 !hlist_unhashed(&dentry->d_u.d_alias) || in d_tmpfile()
3414 !d_unlinked(dentry)); in d_tmpfile()
3415 spin_lock(&dentry->d_parent->d_lock); in d_tmpfile()
3416 spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); in d_tmpfile()
3417 dentry->d_name.len = sprintf(dentry->d_iname, "#%llu", in d_tmpfile()
3419 spin_unlock(&dentry->d_lock); in d_tmpfile()
3420 spin_unlock(&dentry->d_parent->d_lock); in d_tmpfile()
3421 d_instantiate(dentry, inode); in d_tmpfile()
3469 dentry_cache = KMEM_CACHE(dentry, in dcache_init()