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
13struct nameidata;
14struct path;
15struct vfsmount;
16
17
18
19
20
21
22
23
24
25
26#define IS_ROOT(x) ((x) == (x)->d_parent)
27
28
29
30
31
32
33
34
35struct qstr {
36 unsigned int hash;
37 unsigned int len;
38 const unsigned char *name;
39};
40
41struct dentry_stat_t {
42 int nr_dentry;
43 int nr_unused;
44 int age_limit;
45 int want_pages;
46 int dummy[2];
47};
48extern struct dentry_stat_t dentry_stat;
49
50
51
52
53
54static inline int dentry_cmp(const unsigned char *cs, size_t scount,
55 const unsigned char *ct, size_t tcount)
56{
57 int ret;
58 if (scount != tcount)
59 return 1;
60 do {
61 ret = (*cs != *ct);
62 if (ret)
63 break;
64 cs++;
65 ct++;
66 tcount--;
67 } while (tcount);
68 return ret;
69}
70
71
72
73#define init_name_hash() 0
74
75
76static inline unsigned long
77partial_name_hash(unsigned long c, unsigned long prevhash)
78{
79 return (prevhash + (c << 4) + (c >> 4)) * 11;
80}
81
82
83
84
85
86static inline unsigned long end_name_hash(unsigned long hash)
87{
88 return (unsigned int) hash;
89}
90
91
92static inline unsigned int
93full_name_hash(const unsigned char *name, unsigned int len)
94{
95 unsigned long hash = init_name_hash();
96 while (len--)
97 hash = partial_name_hash(*name++, hash);
98 return end_name_hash(hash);
99}
100
101
102
103
104
105
106#ifdef CONFIG_64BIT
107# define DNAME_INLINE_LEN 32
108#else
109# ifdef CONFIG_SMP
110# define DNAME_INLINE_LEN 36
111# else
112# define DNAME_INLINE_LEN 40
113# endif
114#endif
115
116struct dentry {
117
118 unsigned int d_flags;
119 seqcount_t d_seq;
120 struct hlist_bl_node d_hash;
121 struct dentry *d_parent;
122 struct qstr d_name;
123 struct inode *d_inode;
124
125 unsigned char d_iname[DNAME_INLINE_LEN];
126
127
128 unsigned int d_count;
129 spinlock_t d_lock;
130 const struct dentry_operations *d_op;
131 struct super_block *d_sb;
132 unsigned long d_time;
133 void *d_fsdata;
134
135 struct list_head d_lru;
136
137
138
139 union {
140 struct list_head d_child;
141 struct rcu_head d_rcu;
142 } d_u;
143 struct list_head d_subdirs;
144 struct list_head d_alias;
145};
146
147
148
149
150
151
152
153enum dentry_d_lock_class
154{
155 DENTRY_D_LOCK_NORMAL,
156 DENTRY_D_LOCK_NESTED
157};
158
159struct dentry_operations {
160 int (*d_revalidate)(struct dentry *, struct nameidata *);
161 int (*d_hash)(const struct dentry *, const struct inode *,
162 struct qstr *);
163 int (*d_compare)(const struct dentry *, const struct inode *,
164 const struct dentry *, const struct inode *,
165 unsigned int, const char *, const struct qstr *);
166 int (*d_delete)(const struct dentry *);
167 void (*d_release)(struct dentry *);
168 void (*d_iput)(struct dentry *, struct inode *);
169 char *(*d_dname)(struct dentry *, char *, int);
170 struct vfsmount *(*d_automount)(struct path *);
171 int (*d_manage)(struct dentry *, bool);
172} ____cacheline_aligned;
173
174
175
176
177
178
179
180
181
182
183#define DCACHE_OP_HASH 0x0001
184#define DCACHE_OP_COMPARE 0x0002
185#define DCACHE_OP_REVALIDATE 0x0004
186#define DCACHE_OP_DELETE 0x0008
187
188#define DCACHE_DISCONNECTED 0x0010
189
190
191
192
193
194
195
196
197
198
199#define DCACHE_REFERENCED 0x0020
200#define DCACHE_RCUACCESS 0x0040
201
202#define DCACHE_CANT_MOUNT 0x0100
203#define DCACHE_GENOCIDE 0x0200
204
205#define DCACHE_NFSFS_RENAMED 0x1000
206
207
208#define DCACHE_COOKIE 0x2000
209#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x4000
210
211
212#define DCACHE_MOUNTED 0x10000
213#define DCACHE_NEED_AUTOMOUNT 0x20000
214#define DCACHE_MANAGE_TRANSIT 0x40000
215#define DCACHE_NEED_LOOKUP 0x80000
216#define DCACHE_MANAGED_DENTRY \
217 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
218
219extern seqlock_t rename_lock;
220
221static inline int dname_external(struct dentry *dentry)
222{
223 return dentry->d_name.name != dentry->d_iname;
224}
225
226
227
228
229extern void d_instantiate(struct dentry *, struct inode *);
230extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
231extern struct dentry * d_materialise_unique(struct dentry *, struct inode *);
232extern void __d_drop(struct dentry *dentry);
233extern void d_drop(struct dentry *dentry);
234extern void d_delete(struct dentry *);
235extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op);
236
237
238extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
239extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
240extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
241extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
242extern struct dentry * d_obtain_alias(struct inode *);
243extern void shrink_dcache_sb(struct super_block *);
244extern void shrink_dcache_parent(struct dentry *);
245extern void shrink_dcache_for_umount(struct super_block *);
246extern int d_invalidate(struct dentry *);
247
248
249extern struct dentry * d_alloc_root(struct inode *);
250
251
252extern void d_genocide(struct dentry *);
253
254extern struct dentry *d_find_alias(struct inode *);
255extern void d_prune_aliases(struct inode *);
256
257
258extern int have_submounts(struct dentry *);
259
260
261
262
263extern void d_rehash(struct dentry *);
264
265
266
267
268
269
270
271
272
273
274static inline void d_add(struct dentry *entry, struct inode *inode)
275{
276 d_instantiate(entry, inode);
277 d_rehash(entry);
278}
279
280
281
282
283
284
285
286
287
288static inline struct dentry *d_add_unique(struct dentry *entry, struct inode *inode)
289{
290 struct dentry *res;
291
292 res = d_instantiate_unique(entry, inode);
293 d_rehash(res != NULL ? res : entry);
294 return res;
295}
296
297extern void dentry_update_name_case(struct dentry *, struct qstr *);
298
299
300extern void d_move(struct dentry *, struct dentry *);
301extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
302
303
304extern struct dentry *d_lookup(struct dentry *, struct qstr *);
305extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
306extern struct dentry *__d_lookup(struct dentry *, struct qstr *);
307extern struct dentry *__d_lookup_rcu(struct dentry *parent, struct qstr *name,
308 unsigned *seq, struct inode **inode);
309
310
311
312
313
314
315
316
317
318
319static inline int __d_rcu_to_refcount(struct dentry *dentry, unsigned seq)
320{
321 int ret = 0;
322
323 assert_spin_locked(&dentry->d_lock);
324 if (!read_seqcount_retry(&dentry->d_seq, seq)) {
325 ret = 1;
326 dentry->d_count++;
327 }
328
329 return ret;
330}
331
332
333extern int d_validate(struct dentry *, struct dentry *);
334
335
336
337
338extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
339
340extern char *__d_path(const struct path *path, struct path *root, char *, int);
341extern char *d_path(const struct path *, char *, int);
342extern char *d_path_with_unreachable(const struct path *, char *, int);
343extern char *dentry_path_raw(struct dentry *, char *, int);
344extern char *dentry_path(struct dentry *, char *, int);
345
346
347
348
349
350
351
352
353
354
355
356static inline struct dentry *dget_dlock(struct dentry *dentry)
357{
358 if (dentry)
359 dentry->d_count++;
360 return dentry;
361}
362
363static inline struct dentry *dget(struct dentry *dentry)
364{
365 if (dentry) {
366 spin_lock(&dentry->d_lock);
367 dget_dlock(dentry);
368 spin_unlock(&dentry->d_lock);
369 }
370 return dentry;
371}
372
373extern struct dentry *dget_parent(struct dentry *dentry);
374
375
376
377
378
379
380
381
382static inline int d_unhashed(struct dentry *dentry)
383{
384 return hlist_bl_unhashed(&dentry->d_hash);
385}
386
387static inline int d_unlinked(struct dentry *dentry)
388{
389 return d_unhashed(dentry) && !IS_ROOT(dentry);
390}
391
392static inline int cant_mount(struct dentry *dentry)
393{
394 return (dentry->d_flags & DCACHE_CANT_MOUNT);
395}
396
397static inline void dont_mount(struct dentry *dentry)
398{
399 spin_lock(&dentry->d_lock);
400 dentry->d_flags |= DCACHE_CANT_MOUNT;
401 spin_unlock(&dentry->d_lock);
402}
403
404extern void dput(struct dentry *);
405
406static inline bool d_managed(struct dentry *dentry)
407{
408 return dentry->d_flags & DCACHE_MANAGED_DENTRY;
409}
410
411static inline bool d_mountpoint(struct dentry *dentry)
412{
413 return dentry->d_flags & DCACHE_MOUNTED;
414}
415
416static inline bool d_need_lookup(struct dentry *dentry)
417{
418 return dentry->d_flags & DCACHE_NEED_LOOKUP;
419}
420
421extern void d_clear_need_lookup(struct dentry *dentry);
422
423extern int sysctl_vfs_cache_pressure;
424
425#endif
426