1#ifndef __LINUX_DCACHE_H
2#define __LINUX_DCACHE_H
3
4#include <linux/atomic.h>
5#include <linux/list.h>
6#include <linux/rculist.h>
7#include <linux/rculist_bl.h>
8#include <linux/spinlock.h>
9#include <linux/seqlock.h>
10#include <linux/cache.h>
11#include <linux/rcupdate.h>
12#include <linux/lockref.h>
13#include <linux/stringhash.h>
14
15struct path;
16struct vfsmount;
17
18
19
20
21
22
23
24
25
26
27#define IS_ROOT(x) ((x) == (x)->d_parent)
28
29
30#ifdef __LITTLE_ENDIAN
31 #define HASH_LEN_DECLARE u32 hash; u32 len
32 #define bytemask_from_count(cnt) (~(~0ul << (cnt)*8))
33#else
34 #define HASH_LEN_DECLARE u32 len; u32 hash
35 #define bytemask_from_count(cnt) (~(~0ul >> (cnt)*8))
36#endif
37
38
39
40
41
42
43
44
45struct qstr {
46 union {
47 struct {
48 HASH_LEN_DECLARE;
49 };
50 u64 hash_len;
51 };
52 const unsigned char *name;
53};
54
55#define QSTR_INIT(n,l) { { { .len = l } }, .name = n }
56
57struct dentry_stat_t {
58 long nr_dentry;
59 long nr_unused;
60 long age_limit;
61 long want_pages;
62 long dummy[2];
63};
64extern struct dentry_stat_t dentry_stat;
65
66
67
68
69
70
71#ifdef CONFIG_64BIT
72# define DNAME_INLINE_LEN 32
73#else
74# ifdef CONFIG_SMP
75# define DNAME_INLINE_LEN 36
76# else
77# define DNAME_INLINE_LEN 40
78# endif
79#endif
80
81#define d_lock d_lockref.lock
82
83struct dentry {
84
85 unsigned int d_flags;
86 seqcount_t d_seq;
87 struct hlist_bl_node d_hash;
88 struct dentry *d_parent;
89 struct qstr d_name;
90 struct inode *d_inode;
91
92 unsigned char d_iname[DNAME_INLINE_LEN];
93
94
95 struct lockref d_lockref;
96 const struct dentry_operations *d_op;
97 struct super_block *d_sb;
98 unsigned long d_time;
99 void *d_fsdata;
100
101 union {
102 struct list_head d_lru;
103 wait_queue_head_t *d_wait;
104 };
105 struct list_head d_child;
106 struct list_head d_subdirs;
107
108
109
110 union {
111 struct hlist_node d_alias;
112 struct hlist_bl_node d_in_lookup_hash;
113 struct rcu_head d_rcu;
114 } d_u;
115};
116
117
118
119
120
121
122
123enum dentry_d_lock_class
124{
125 DENTRY_D_LOCK_NORMAL,
126 DENTRY_D_LOCK_NESTED
127};
128
129struct dentry_operations {
130 int (*d_revalidate)(struct dentry *, unsigned int);
131 int (*d_weak_revalidate)(struct dentry *, unsigned int);
132 int (*d_hash)(const struct dentry *, struct qstr *);
133 int (*d_compare)(const struct dentry *,
134 unsigned int, const char *, const struct qstr *);
135 int (*d_delete)(const struct dentry *);
136 int (*d_init)(struct dentry *);
137 void (*d_release)(struct dentry *);
138 void (*d_prune)(struct dentry *);
139 void (*d_iput)(struct dentry *, struct inode *);
140 char *(*d_dname)(struct dentry *, char *, int);
141 struct vfsmount *(*d_automount)(struct path *);
142 int (*d_manage)(struct dentry *, bool);
143 struct dentry *(*d_real)(struct dentry *, const struct inode *,
144 unsigned int);
145} ____cacheline_aligned;
146
147
148
149
150
151
152
153
154
155
156#define DCACHE_OP_HASH 0x00000001
157#define DCACHE_OP_COMPARE 0x00000002
158#define DCACHE_OP_REVALIDATE 0x00000004
159#define DCACHE_OP_DELETE 0x00000008
160#define DCACHE_OP_PRUNE 0x00000010
161
162#define DCACHE_DISCONNECTED 0x00000020
163
164
165
166
167
168
169
170
171
172
173#define DCACHE_REFERENCED 0x00000040
174#define DCACHE_RCUACCESS 0x00000080
175
176#define DCACHE_CANT_MOUNT 0x00000100
177#define DCACHE_GENOCIDE 0x00000200
178#define DCACHE_SHRINK_LIST 0x00000400
179
180#define DCACHE_OP_WEAK_REVALIDATE 0x00000800
181
182#define DCACHE_NFSFS_RENAMED 0x00001000
183
184
185#define DCACHE_COOKIE 0x00002000
186#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x00004000
187
188
189#define DCACHE_DENTRY_KILLED 0x00008000
190
191#define DCACHE_MOUNTED 0x00010000
192#define DCACHE_NEED_AUTOMOUNT 0x00020000
193#define DCACHE_MANAGE_TRANSIT 0x00040000
194#define DCACHE_MANAGED_DENTRY \
195 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
196
197#define DCACHE_LRU_LIST 0x00080000
198
199#define DCACHE_ENTRY_TYPE 0x00700000
200#define DCACHE_MISS_TYPE 0x00000000
201#define DCACHE_WHITEOUT_TYPE 0x00100000
202#define DCACHE_DIRECTORY_TYPE 0x00200000
203#define DCACHE_AUTODIR_TYPE 0x00300000
204#define DCACHE_REGULAR_TYPE 0x00400000
205#define DCACHE_SPECIAL_TYPE 0x00500000
206#define DCACHE_SYMLINK_TYPE 0x00600000
207
208#define DCACHE_MAY_FREE 0x00800000
209#define DCACHE_FALLTHRU 0x01000000
210#define DCACHE_ENCRYPTED_WITH_KEY 0x02000000
211#define DCACHE_OP_REAL 0x04000000
212
213#define DCACHE_PAR_LOOKUP 0x10000000
214#define DCACHE_DENTRY_CURSOR 0x20000000
215
216extern seqlock_t rename_lock;
217
218
219
220
221extern void d_instantiate(struct dentry *, struct inode *);
222extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
223extern int d_instantiate_no_diralias(struct dentry *, struct inode *);
224extern void __d_drop(struct dentry *dentry);
225extern void d_drop(struct dentry *dentry);
226extern void d_delete(struct dentry *);
227extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op);
228
229
230extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
231extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
232extern struct dentry * d_alloc_parallel(struct dentry *, const struct qstr *,
233 wait_queue_head_t *);
234extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
235extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
236extern struct dentry * d_exact_alias(struct dentry *, struct inode *);
237extern struct dentry *d_find_any_alias(struct inode *inode);
238extern struct dentry * d_obtain_alias(struct inode *);
239extern struct dentry * d_obtain_root(struct inode *);
240extern void shrink_dcache_sb(struct super_block *);
241extern void shrink_dcache_parent(struct dentry *);
242extern void shrink_dcache_for_umount(struct super_block *);
243extern void d_invalidate(struct dentry *);
244
245
246extern struct dentry * d_make_root(struct inode *);
247
248
249extern void d_genocide(struct dentry *);
250
251extern void d_tmpfile(struct dentry *, struct inode *);
252
253extern struct dentry *d_find_alias(struct inode *);
254extern void d_prune_aliases(struct inode *);
255
256
257extern int have_submounts(struct dentry *);
258
259
260
261
262extern void d_rehash(struct dentry *);
263
264extern void d_add(struct dentry *, struct inode *);
265
266extern void dentry_update_name_case(struct dentry *, const struct qstr *);
267
268
269extern void d_move(struct dentry *, struct dentry *);
270extern void d_exchange(struct dentry *, struct dentry *);
271extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
272
273
274extern struct dentry *d_lookup(const struct dentry *, const struct qstr *);
275extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
276extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *);
277extern struct dentry *__d_lookup_rcu(const struct dentry *parent,
278 const struct qstr *name, unsigned *seq);
279
280static inline unsigned d_count(const struct dentry *dentry)
281{
282 return dentry->d_lockref.count;
283}
284
285
286
287
288extern __printf(4, 5)
289char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
290extern char *simple_dname(struct dentry *, char *, int);
291
292extern char *__d_path(const struct path *, const struct path *, char *, int);
293extern char *d_absolute_path(const struct path *, char *, int);
294extern char *d_path(const struct path *, char *, int);
295extern char *dentry_path_raw(struct dentry *, char *, int);
296extern char *dentry_path(struct dentry *, char *, int);
297
298
299
300
301
302
303
304
305
306
307
308static inline struct dentry *dget_dlock(struct dentry *dentry)
309{
310 if (dentry)
311 dentry->d_lockref.count++;
312 return dentry;
313}
314
315static inline struct dentry *dget(struct dentry *dentry)
316{
317 if (dentry)
318 lockref_get(&dentry->d_lockref);
319 return dentry;
320}
321
322extern struct dentry *dget_parent(struct dentry *dentry);
323
324
325
326
327
328
329
330
331static inline int d_unhashed(const struct dentry *dentry)
332{
333 return hlist_bl_unhashed(&dentry->d_hash);
334}
335
336static inline int d_unlinked(const struct dentry *dentry)
337{
338 return d_unhashed(dentry) && !IS_ROOT(dentry);
339}
340
341static inline int cant_mount(const struct dentry *dentry)
342{
343 return (dentry->d_flags & DCACHE_CANT_MOUNT);
344}
345
346static inline void dont_mount(struct dentry *dentry)
347{
348 spin_lock(&dentry->d_lock);
349 dentry->d_flags |= DCACHE_CANT_MOUNT;
350 spin_unlock(&dentry->d_lock);
351}
352
353extern void __d_lookup_done(struct dentry *);
354
355static inline int d_in_lookup(struct dentry *dentry)
356{
357 return dentry->d_flags & DCACHE_PAR_LOOKUP;
358}
359
360static inline void d_lookup_done(struct dentry *dentry)
361{
362 if (unlikely(d_in_lookup(dentry))) {
363 spin_lock(&dentry->d_lock);
364 __d_lookup_done(dentry);
365 spin_unlock(&dentry->d_lock);
366 }
367}
368
369extern void dput(struct dentry *);
370
371static inline bool d_managed(const struct dentry *dentry)
372{
373 return dentry->d_flags & DCACHE_MANAGED_DENTRY;
374}
375
376static inline bool d_mountpoint(const struct dentry *dentry)
377{
378 return dentry->d_flags & DCACHE_MOUNTED;
379}
380
381
382
383
384static inline unsigned __d_entry_type(const struct dentry *dentry)
385{
386 return dentry->d_flags & DCACHE_ENTRY_TYPE;
387}
388
389static inline bool d_is_miss(const struct dentry *dentry)
390{
391 return __d_entry_type(dentry) == DCACHE_MISS_TYPE;
392}
393
394static inline bool d_is_whiteout(const struct dentry *dentry)
395{
396 return __d_entry_type(dentry) == DCACHE_WHITEOUT_TYPE;
397}
398
399static inline bool d_can_lookup(const struct dentry *dentry)
400{
401 return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE;
402}
403
404static inline bool d_is_autodir(const struct dentry *dentry)
405{
406 return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE;
407}
408
409static inline bool d_is_dir(const struct dentry *dentry)
410{
411 return d_can_lookup(dentry) || d_is_autodir(dentry);
412}
413
414static inline bool d_is_symlink(const struct dentry *dentry)
415{
416 return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;
417}
418
419static inline bool d_is_reg(const struct dentry *dentry)
420{
421 return __d_entry_type(dentry) == DCACHE_REGULAR_TYPE;
422}
423
424static inline bool d_is_special(const struct dentry *dentry)
425{
426 return __d_entry_type(dentry) == DCACHE_SPECIAL_TYPE;
427}
428
429static inline bool d_is_file(const struct dentry *dentry)
430{
431 return d_is_reg(dentry) || d_is_special(dentry);
432}
433
434static inline bool d_is_negative(const struct dentry *dentry)
435{
436
437 return d_is_miss(dentry);
438}
439
440static inline bool d_is_positive(const struct dentry *dentry)
441{
442 return !d_is_negative(dentry);
443}
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460static inline bool d_really_is_negative(const struct dentry *dentry)
461{
462 return dentry->d_inode == NULL;
463}
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478static inline bool d_really_is_positive(const struct dentry *dentry)
479{
480 return dentry->d_inode != NULL;
481}
482
483static inline int simple_positive(struct dentry *dentry)
484{
485 return d_really_is_positive(dentry) && !d_unhashed(dentry);
486}
487
488extern void d_set_fallthru(struct dentry *dentry);
489
490static inline bool d_is_fallthru(const struct dentry *dentry)
491{
492 return dentry->d_flags & DCACHE_FALLTHRU;
493}
494
495
496extern int sysctl_vfs_cache_pressure;
497
498static inline unsigned long vfs_pressure_ratio(unsigned long val)
499{
500 return mult_frac(val, sysctl_vfs_cache_pressure, 100);
501}
502
503
504
505
506
507
508
509
510static inline struct inode *d_inode(const struct dentry *dentry)
511{
512 return dentry->d_inode;
513}
514
515
516
517
518
519
520
521
522static inline struct inode *d_inode_rcu(const struct dentry *dentry)
523{
524 return ACCESS_ONCE(dentry->d_inode);
525}
526
527
528
529
530
531
532
533
534
535
536
537static inline struct inode *d_backing_inode(const struct dentry *upper)
538{
539 struct inode *inode = upper->d_inode;
540
541 return inode;
542}
543
544
545
546
547
548
549
550
551
552
553
554static inline struct dentry *d_backing_dentry(struct dentry *upper)
555{
556 return upper;
557}
558
559
560
561
562
563
564
565
566
567
568
569
570static inline struct dentry *d_real(struct dentry *dentry,
571 const struct inode *inode,
572 unsigned int flags)
573{
574 if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
575 return dentry->d_op->d_real(dentry, inode, flags);
576 else
577 return dentry;
578}
579
580
581
582
583
584
585
586
587static inline struct inode *d_real_inode(const struct dentry *dentry)
588{
589
590 return d_backing_inode(d_real((struct dentry *) dentry, NULL, 0));
591}
592
593
594#endif
595