Blame view

include/linux/dcache.h 18.8 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  #ifndef __LINUX_DCACHE_H
  #define __LINUX_DCACHE_H
60063497a   Arun Sharma   atomic: use <linu...
4
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
  #include <linux/list.h>
82524746c   Franck Bui-Huu   rcu: split list.h...
6
  #include <linux/rculist.h>
ceb5bdc2d   Nick Piggin   fs: dcache per-bu...
7
  #include <linux/rculist_bl.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
  #include <linux/spinlock.h>
31e6b01f4   Nick Piggin   fs: rcu-walk for ...
9
  #include <linux/seqlock.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
  #include <linux/cache.h>
  #include <linux/rcupdate.h>
98474236f   Waiman Long   vfs: make the den...
12
  #include <linux/lockref.h>
f4bcbe792   George Spelvin   Pull out string h...
13
  #include <linux/stringhash.h>
f9411ebe3   Ingo Molnar   rcu: Separate the...
14
  #include <linux/wait.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15

cf28b4863   Jan Blunck   d_path: Make d_pa...
16
  struct path;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
21
22
23
24
25
26
27
28
  struct vfsmount;
  
  /*
   * linux/include/linux/dcache.h
   *
   * Dirent cache data structures
   *
   * (C) Copyright 1997 Thomas Schoebel-Theuer,
   * with heavy changes by Linus Torvalds
   */
  
  #define IS_ROOT(x) ((x) == (x)->d_parent)
26fe57502   Linus Torvalds   vfs: make it poss...
29
30
  /* The hash is always the low bits of hash_len */
  #ifdef __LITTLE_ENDIAN
2bd03e49d   Andrew Morton   include/linux/dca...
31
   #define HASH_LEN_DECLARE u32 hash; u32 len
a5c21dcef   Will Deacon   dcache: allow wor...
32
   #define bytemask_from_count(cnt)	(~(~0ul << (cnt)*8))
26fe57502   Linus Torvalds   vfs: make it poss...
33
  #else
2bd03e49d   Andrew Morton   include/linux/dca...
34
   #define HASH_LEN_DECLARE u32 len; u32 hash
a5c21dcef   Will Deacon   dcache: allow wor...
35
   #define bytemask_from_count(cnt)	(~(~0ul >> (cnt)*8))
26fe57502   Linus Torvalds   vfs: make it poss...
36
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
40
41
42
43
44
  /*
   * "quick string" -- eases parameter passing, but more importantly
   * saves "metadata" about the string (ie length and the hash).
   *
   * hash comes first so it snuggles against d_parent in the
   * dentry.
   */
  struct qstr {
26fe57502   Linus Torvalds   vfs: make it poss...
45
46
47
48
49
50
  	union {
  		struct {
  			HASH_LEN_DECLARE;
  		};
  		u64 hash_len;
  	};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
  	const unsigned char *name;
  };
26fe57502   Linus Torvalds   vfs: make it poss...
53
  #define QSTR_INIT(n,l) { { { .len = l } }, .name = n }
26fe57502   Linus Torvalds   vfs: make it poss...
54

cdf01226b   David Howells   VFS: Provide empt...
55
56
57
58
  extern const char empty_string[];
  extern const struct qstr empty_name;
  extern const char slash_string[];
  extern const struct qstr slash_name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  struct dentry_stat_t {
3942c07cc   Glauber Costa   fs: bump inode an...
60
61
62
63
64
  	long nr_dentry;
  	long nr_unused;
  	long age_limit;          /* age in seconds */
  	long want_pages;         /* pages requested by system */
  	long dummy[2];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
  };
  extern struct dentry_stat_t dentry_stat;
c2452f327   Nick Piggin   shrink struct dentry
67
68
69
70
71
72
  /*
   * Try to keep struct dentry aligned on 64 byte cachelines (this will
   * give reasonable cacheline footprint with larger lines without the
   * large memory footprint increase).
   */
  #ifdef CONFIG_64BIT
44a7d7a87   Nick Piggin   fs: cache optimis...
73
  # define DNAME_INLINE_LEN 32 /* 192 bytes */
c2452f327   Nick Piggin   shrink struct dentry
74
  #else
44a7d7a87   Nick Piggin   fs: cache optimis...
75
76
77
78
79
  # ifdef CONFIG_SMP
  #  define DNAME_INLINE_LEN 36 /* 128 bytes */
  # else
  #  define DNAME_INLINE_LEN 40 /* 128 bytes */
  # endif
c2452f327   Nick Piggin   shrink struct dentry
80
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

98474236f   Waiman Long   vfs: make the den...
82
  #define d_lock	d_lockref.lock
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
  struct dentry {
44a7d7a87   Nick Piggin   fs: cache optimis...
84
  	/* RCU lookup touched fields */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  	unsigned int d_flags;		/* protected by d_lock */
31e6b01f4   Nick Piggin   fs: rcu-walk for ...
86
  	seqcount_t d_seq;		/* per dentry seqlock */
ceb5bdc2d   Nick Piggin   fs: dcache per-bu...
87
  	struct hlist_bl_node d_hash;	/* lookup hash list */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
  	struct dentry *d_parent;	/* parent directory */
  	struct qstr d_name;
44a7d7a87   Nick Piggin   fs: cache optimis...
90
91
92
93
94
  	struct inode *d_inode;		/* Where the name belongs to - NULL is
  					 * negative */
  	unsigned char d_iname[DNAME_INLINE_LEN];	/* small names */
  
  	/* Ref lookup also touches following */
98474236f   Waiman Long   vfs: make the den...
95
  	struct lockref d_lockref;	/* per-dentry lock and refcount */
44a7d7a87   Nick Piggin   fs: cache optimis...
96
97
98
99
  	const struct dentry_operations *d_op;
  	struct super_block *d_sb;	/* The root of the dentry tree */
  	unsigned long d_time;		/* used by d_revalidate */
  	void *d_fsdata;			/* fs-specific data */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100

d9171b934   Al Viro   parallel lookups ...
101
102
103
104
  	union {
  		struct list_head d_lru;		/* LRU list */
  		wait_queue_head_t *d_wait;	/* in-lookup ones only */
  	};
946e51f2b   Al Viro   move d_rcu from o...
105
106
  	struct list_head d_child;	/* child of parent list */
  	struct list_head d_subdirs;	/* our children */
5160ee6fc   Eric Dumazet   [PATCH] shrink de...
107
  	/*
946e51f2b   Al Viro   move d_rcu from o...
108
  	 * d_alias and d_rcu can share memory
5160ee6fc   Eric Dumazet   [PATCH] shrink de...
109
110
  	 */
  	union {
946e51f2b   Al Viro   move d_rcu from o...
111
  		struct hlist_node d_alias;	/* inode alias list */
94bdd655c   Al Viro   parallel lookups ...
112
  		struct hlist_bl_node d_in_lookup_hash;	/* only for in-lookup ones */
5160ee6fc   Eric Dumazet   [PATCH] shrink de...
113
114
  	 	struct rcu_head d_rcu;
  	} d_u;
3859a271a   Kees Cook   randstruct: Mark ...
115
  } __randomize_layout;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116

a90b9c05d   Ingo Molnar   [PATCH] lockdep: ...
117
118
119
120
121
122
123
124
125
126
127
  /*
   * dentry->d_lock spinlock nesting subclasses:
   *
   * 0: normal
   * 1: nested
   */
  enum dentry_d_lock_class
  {
  	DENTRY_D_LOCK_NORMAL, /* implicitly used by plain spin_lock() APIs. */
  	DENTRY_D_LOCK_NESTED
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
  struct dentry_operations {
0b728e191   Al Viro   stop passing name...
129
  	int (*d_revalidate)(struct dentry *, unsigned int);
ecf3d1f1a   Jeff Layton   vfs: kill FS_REVA...
130
  	int (*d_weak_revalidate)(struct dentry *, unsigned int);
da53be12b   Linus Torvalds   Don't pass inode ...
131
  	int (*d_hash)(const struct dentry *, struct qstr *);
6fa67e707   Al Viro   get rid of 'paren...
132
  	int (*d_compare)(const struct dentry *,
621e155a3   Nick Piggin   fs: change d_comp...
133
  			unsigned int, const char *, const struct qstr *);
fe15ce446   Nick Piggin   fs: change d_dele...
134
  	int (*d_delete)(const struct dentry *);
285b102d3   Miklos Szeredi   vfs: new d_init m...
135
  	int (*d_init)(struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
136
  	void (*d_release)(struct dentry *);
f0023bc61   Sage Weil   vfs: add d_prune ...
137
  	void (*d_prune)(struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
  	void (*d_iput)(struct dentry *, struct inode *);
c23fbb6bc   Eric Dumazet   VFS: delay the de...
139
  	char *(*d_dname)(struct dentry *, char *, int);
9875cf806   David Howells   Add a dentry op t...
140
  	struct vfsmount *(*d_automount)(struct path *);
fb5f51c74   Ian Kent   vfs: change d_man...
141
  	int (*d_manage)(const struct path *, bool);
e698b8a43   Miklos Szeredi   vfs: document ->d...
142
  	struct dentry *(*d_real)(struct dentry *, const struct inode *,
495e64293   Miklos Szeredi   vfs: add flags to...
143
  				 unsigned int, unsigned int);
44a7d7a87   Nick Piggin   fs: cache optimis...
144
  } ____cacheline_aligned;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145

5eef7fa90   Nick Piggin   fs: dcache docume...
146
147
148
149
  /*
   * Locking rules for dentry_operations callbacks are to be found in
   * Documentation/filesystems/Locking. Keep it updated!
   *
621e155a3   Nick Piggin   fs: change d_comp...
150
151
   * FUrther descriptions are found in Documentation/filesystems/vfs.txt.
   * Keep it updated too!
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
152
153
154
   */
  
  /* d_flags entries */
b18825a7c   David Howells   VFS: Put a small ...
155
156
157
158
159
  #define DCACHE_OP_HASH			0x00000001
  #define DCACHE_OP_COMPARE		0x00000002
  #define DCACHE_OP_REVALIDATE		0x00000004
  #define DCACHE_OP_DELETE		0x00000008
  #define DCACHE_OP_PRUNE			0x00000010
5f57cbcc0   Nick Piggin   fs: dcache remove...
160

b18825a7c   David Howells   VFS: Put a small ...
161
  #define	DCACHE_DISCONNECTED		0x00000020
5f57cbcc0   Nick Piggin   fs: dcache remove...
162
163
164
165
166
167
168
169
170
       /* This dentry is possibly not currently connected to the dcache tree, in
        * which case its parent will either be itself, or will have this flag as
        * well.  nfsd will not use a dentry with this bit set, but will first
        * endeavour to clear the bit either by discovering that it is connected,
        * or by performing lookup operations.   Any filesystem which supports
        * nfsd_operations MUST have a lookup function which, if it finds a
        * directory inode with a DCACHE_DISCONNECTED dentry, will d_move that
        * dentry into place and return that dentry rather than the passed one,
        * typically using d_splice_alias. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171

b18825a7c   David Howells   VFS: Put a small ...
172
173
  #define DCACHE_REFERENCED		0x00000040 /* Recently used, don't discard. */
  #define DCACHE_RCUACCESS		0x00000080 /* Entry has ever been RCU-visible */
c28f7e56e   Eric Paris   fsnotify: parent ...
174

b18825a7c   David Howells   VFS: Put a small ...
175
176
177
  #define DCACHE_CANT_MOUNT		0x00000100
  #define DCACHE_GENOCIDE			0x00000200
  #define DCACHE_SHRINK_LIST		0x00000400
5f57cbcc0   Nick Piggin   fs: dcache remove...
178

b18825a7c   David Howells   VFS: Put a small ...
179
  #define DCACHE_OP_WEAK_REVALIDATE	0x00000800
ecf3d1f1a   Jeff Layton   vfs: kill FS_REVA...
180

b18825a7c   David Howells   VFS: Put a small ...
181
  #define DCACHE_NFSFS_RENAMED		0x00001000
830c0f0ed   Linus Torvalds   vfs: renumber DCA...
182
183
       /* this dentry has been "silly renamed" and has to be deleted on the last
        * dput() */
b18825a7c   David Howells   VFS: Put a small ...
184
185
  #define DCACHE_COOKIE			0x00002000 /* For use by dcookie subsystem */
  #define DCACHE_FSNOTIFY_PARENT_WATCHED	0x00004000
830c0f0ed   Linus Torvalds   vfs: renumber DCA...
186
       /* Parent inode is watched by some fsnotify listener */
fb045adb9   Nick Piggin   fs: dcache reduce...
187

b18825a7c   David Howells   VFS: Put a small ...
188
189
190
191
192
  #define DCACHE_DENTRY_KILLED		0x00008000
  
  #define DCACHE_MOUNTED			0x00010000 /* is a mountpoint */
  #define DCACHE_NEED_AUTOMOUNT		0x00020000 /* handle automount on this dir */
  #define DCACHE_MANAGE_TRANSIT		0x00040000 /* manage transit from this dirent */
9875cf806   David Howells   Add a dentry op t...
193
  #define DCACHE_MANAGED_DENTRY \
cc53ce53c   David Howells   Add a dentry op t...
194
  	(DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
9875cf806   David Howells   Add a dentry op t...
195

b18825a7c   David Howells   VFS: Put a small ...
196
197
198
  #define DCACHE_LRU_LIST			0x00080000
  
  #define DCACHE_ENTRY_TYPE		0x00700000
e7f7d2253   David Howells   VFS: Add a whiteo...
199
200
201
202
  #define DCACHE_MISS_TYPE		0x00000000 /* Negative dentry (maybe fallthru to nowhere) */
  #define DCACHE_WHITEOUT_TYPE		0x00100000 /* Whiteout dentry (stop pathwalk) */
  #define DCACHE_DIRECTORY_TYPE		0x00200000 /* Normal directory */
  #define DCACHE_AUTODIR_TYPE		0x00300000 /* Lookupless directory (presumed automount) */
44bdb5e5f   David Howells   VFS: Split DCACHE...
203
204
205
  #define DCACHE_REGULAR_TYPE		0x00400000 /* Regular file type (or fallthru to such) */
  #define DCACHE_SPECIAL_TYPE		0x00500000 /* Other file type (or fallthru to such) */
  #define DCACHE_SYMLINK_TYPE		0x00600000 /* Symlink (or fallthru to such) */
b161dfa69   Miklos Szeredi   vfs: dcache: use ...
206

41edf278f   Al Viro   dentry_kill(): do...
207
  #define DCACHE_MAY_FREE			0x00800000
df1a085af   David Howells   VFS: Add a fallth...
208
  #define DCACHE_FALLTHRU			0x01000000 /* Fall through to lower layer */
2d902671c   Miklos Szeredi   vfs: merge .d_sel...
209
210
  #define DCACHE_ENCRYPTED_WITH_KEY	0x02000000 /* dir is encrypted with a valid key */
  #define DCACHE_OP_REAL			0x04000000
0b81d0779   Jaegeuk Kim   fs crypto: move p...
211

85c7f8104   Al Viro   beginning of tran...
212
  #define DCACHE_PAR_LOOKUP		0x10000000 /* being looked up (with parent locked shared) */
ba65dc5ef   Al Viro   much milder d_wal...
213
  #define DCACHE_DENTRY_CURSOR		0x20000000
85c7f8104   Al Viro   beginning of tran...
214

74c3cbe33   Al Viro   [PATCH] audit: wa...
215
  extern seqlock_t rename_lock;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
219
220
  /*
   * These are the low-level FS interfaces to the dcache..
   */
  extern void d_instantiate(struct dentry *, struct inode *);
f440ea85d   Al Viro   do d_instantiate/...
221
  extern void d_instantiate_new(struct dentry *, struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
  extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
b70a80e7a   Miklos Szeredi   vfs: introduce d_...
223
  extern int d_instantiate_no_diralias(struct dentry *, struct inode *);
789680d1e   Nick Piggin   fs: dcache scale ...
224
225
  extern void __d_drop(struct dentry *dentry);
  extern void d_drop(struct dentry *dentry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
226
  extern void d_delete(struct dentry *);
fb045adb9   Nick Piggin   fs: dcache reduce...
227
  extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
229
230
  
  /* allocate/de-allocate */
  extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
4b936885a   Nick Piggin   fs: improve scala...
231
  extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
d9171b934   Al Viro   parallel lookups ...
232
233
  extern struct dentry * d_alloc_parallel(struct dentry *, const struct qstr *,
  					wait_queue_head_t *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
  extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
e45b590b9   Christoph Hellwig   [PATCH] change d_...
235
  extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
668d0cd56   Al Viro   replace d_add_uni...
236
  extern struct dentry * d_exact_alias(struct dentry *, struct inode *);
46f72b349   Sage Weil   vfs: export symbo...
237
  extern struct dentry *d_find_any_alias(struct inode *inode);
4ea3ada29   Christoph Hellwig   [PATCH] new helpe...
238
  extern struct dentry * d_obtain_alias(struct inode *);
1a0a397e4   J. Bruce Fields   dcache: d_obtain_...
239
  extern struct dentry * d_obtain_root(struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240
241
  extern void shrink_dcache_sb(struct super_block *);
  extern void shrink_dcache_parent(struct dentry *);
c636ebdb1   David Howells   [PATCH] VFS: Dest...
242
  extern void shrink_dcache_for_umount(struct super_block *);
5542aa2fa   Eric W. Biederman   vfs: Make d_inval...
243
  extern void d_invalidate(struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
  
  /* only used at mount-time */
adc0e91ab   Al Viro   vfs: new helper -...
246
  extern struct dentry * d_make_root(struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
  
  /* <clickety>-<click> the ramfs-type tree */
  extern void d_genocide(struct dentry *);
60545d0d4   Al Viro   [O_TMPFILE] it's ...
250
  extern void d_tmpfile(struct dentry *, struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251
252
253
254
  extern struct dentry *d_find_alias(struct inode *);
  extern void d_prune_aliases(struct inode *);
  
  /* test whether we have any submounts in a subdir tree */
01619491a   Ian Kent   vfs: add path_has...
255
  extern int path_has_submounts(const struct path *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
258
259
260
  
  /*
   * This adds the entry to the hash queues.
   */
  extern void d_rehash(struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
   
34d0d19dc   Al Viro   uninline d_add()
262
  extern void d_add(struct dentry *, struct inode *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
263

9aba36dea   Al Viro   qstr constify ins...
264
  extern void dentry_update_name_case(struct dentry *, const struct qstr *);
fb2d5b86a   Nick Piggin   fs: name case upd...
265

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
266
267
  /* used for rename() and baskets */
  extern void d_move(struct dentry *, struct dentry *);
da1ce0670   Miklos Szeredi   vfs: add cross-re...
268
  extern void d_exchange(struct dentry *, struct dentry *);
e2761a116   OGAWA Hirofumi   [PATCH vfs-2.6 2/...
269
  extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
270
271
  
  /* appendix may either be NULL or be used for transname suffixes */
da2d8455e   Al Viro   constify d_lookup...
272
  extern struct dentry *d_lookup(const struct dentry *, const struct qstr *);
31e6b01f4   Nick Piggin   fs: rcu-walk for ...
273
  extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
a713ca2ab   Al Viro   constify __d_look...
274
  extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *);
8966be903   Linus Torvalds   vfs: trivial __d_...
275
  extern struct dentry *__d_lookup_rcu(const struct dentry *parent,
da53be12b   Linus Torvalds   Don't pass inode ...
276
  				const struct qstr *name, unsigned *seq);
31e6b01f4   Nick Piggin   fs: rcu-walk for ...
277

24924a20d   Peng Tao   vfs: constify den...
278
  static inline unsigned d_count(const struct dentry *dentry)
84d08fa88   Al Viro   helper for readin...
279
  {
98474236f   Waiman Long   vfs: make the den...
280
  	return dentry->d_lockref.count;
84d08fa88   Al Viro   helper for readin...
281
  }
c23fbb6bc   Eric Dumazet   VFS: delay the de...
282
283
284
  /*
   * helper function for dentry_operations.d_dname() members
   */
8db148606   Nicolas Iooss   include, lib: add...
285
286
  extern __printf(4, 5)
  char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
118b23022   Al Viro   cope with potenti...
287
  extern char *simple_dname(struct dentry *, char *, int);
c23fbb6bc   Eric Dumazet   VFS: delay the de...
288

02125a826   Al Viro   fix apparmor dere...
289
290
  extern char *__d_path(const struct path *, const struct path *, char *, int);
  extern char *d_absolute_path(const struct path *, char *, int);
20d4fdc1a   Jan Engelhardt   [patch 2/4] fs: m...
291
  extern char *d_path(const struct path *, char *, int);
ec2447c27   Nick Piggin   hostfs: simplify ...
292
  extern char *dentry_path_raw(struct dentry *, char *, int);
6092d0481   Ram Pai   [patch 1/7] vfs: ...
293
  extern char *dentry_path(struct dentry *, char *, int);
cf28b4863   Jan Blunck   d_path: Make d_pa...
294

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
296
297
  /* Allocation counts.. */
  
  /**
dc0474be3   Nick Piggin   fs: dcache ration...
298
   *	dget, dget_dlock -	get a reference to a dentry
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
300
301
302
   *	@dentry: dentry to get a reference to
   *
   *	Given a dentry or %NULL pointer increment the reference count
   *	if appropriate and return the dentry. A dentry will not be 
dc0474be3   Nick Piggin   fs: dcache ration...
303
   *	destroyed when it has references.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
   */
b7ab39f63   Nick Piggin   fs: dcache scale ...
305
306
  static inline struct dentry *dget_dlock(struct dentry *dentry)
  {
dc0474be3   Nick Piggin   fs: dcache ration...
307
  	if (dentry)
98474236f   Waiman Long   vfs: make the den...
308
  		dentry->d_lockref.count++;
b7ab39f63   Nick Piggin   fs: dcache scale ...
309
310
  	return dentry;
  }
2fd6b7f50   Nick Piggin   fs: dcache scale ...
311

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312
313
  static inline struct dentry *dget(struct dentry *dentry)
  {
98474236f   Waiman Long   vfs: make the den...
314
315
  	if (dentry)
  		lockref_get(&dentry->d_lockref);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
317
  	return dentry;
  }
b7ab39f63   Nick Piggin   fs: dcache scale ...
318
  extern struct dentry *dget_parent(struct dentry *dentry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
321
322
323
324
325
326
  
  /**
   *	d_unhashed -	is dentry hashed
   *	@dentry: entry to check
   *
   *	Returns true if the dentry passed is not currently hashed.
   */
   
f0d3b3ded   Al Viro   constify dcache.c...
327
  static inline int d_unhashed(const struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
  {
dea3667bc   Linus Torvalds   vfs: get rid of i...
329
  	return hlist_bl_unhashed(&dentry->d_hash);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
  }
f0d3b3ded   Al Viro   constify dcache.c...
331
  static inline int d_unlinked(const struct dentry *dentry)
f3da392e9   Alexey Dobriyan   dcache: extrace a...
332
333
334
  {
  	return d_unhashed(dentry) && !IS_ROOT(dentry);
  }
f0d3b3ded   Al Viro   constify dcache.c...
335
  static inline int cant_mount(const struct dentry *dentry)
d83c49f3e   Al Viro   Fix the regressio...
336
337
338
339
340
341
342
343
344
345
  {
  	return (dentry->d_flags & DCACHE_CANT_MOUNT);
  }
  
  static inline void dont_mount(struct dentry *dentry)
  {
  	spin_lock(&dentry->d_lock);
  	dentry->d_flags |= DCACHE_CANT_MOUNT;
  	spin_unlock(&dentry->d_lock);
  }
85c7f8104   Al Viro   beginning of tran...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  extern void __d_lookup_done(struct dentry *);
  
  static inline int d_in_lookup(struct dentry *dentry)
  {
  	return dentry->d_flags & DCACHE_PAR_LOOKUP;
  }
  
  static inline void d_lookup_done(struct dentry *dentry)
  {
  	if (unlikely(d_in_lookup(dentry))) {
  		spin_lock(&dentry->d_lock);
  		__d_lookup_done(dentry);
  		spin_unlock(&dentry->d_lock);
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
361
  extern void dput(struct dentry *);
f0d3b3ded   Al Viro   constify dcache.c...
362
  static inline bool d_managed(const struct dentry *dentry)
cc53ce53c   David Howells   Add a dentry op t...
363
364
365
  {
  	return dentry->d_flags & DCACHE_MANAGED_DENTRY;
  }
f0d3b3ded   Al Viro   constify dcache.c...
366
  static inline bool d_mountpoint(const struct dentry *dentry)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367
  {
5f57cbcc0   Nick Piggin   fs: dcache remove...
368
  	return dentry->d_flags & DCACHE_MOUNTED;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
  }
b18825a7c   David Howells   VFS: Put a small ...
370
371
372
  /*
   * Directory cache entry type accessor functions.
   */
b18825a7c   David Howells   VFS: Put a small ...
373
374
  static inline unsigned __d_entry_type(const struct dentry *dentry)
  {
a528aca7f   Al Viro   use ->d_seq to ge...
375
  	return dentry->d_flags & DCACHE_ENTRY_TYPE;
b18825a7c   David Howells   VFS: Put a small ...
376
  }
e7f7d2253   David Howells   VFS: Add a whiteo...
377
378
379
380
381
382
383
384
385
  static inline bool d_is_miss(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_MISS_TYPE;
  }
  
  static inline bool d_is_whiteout(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_WHITEOUT_TYPE;
  }
44b1d5304   Miklos Szeredi   vfs: add d_is_dir()
386
  static inline bool d_can_lookup(const struct dentry *dentry)
b18825a7c   David Howells   VFS: Put a small ...
387
388
389
390
391
392
393
394
  {
  	return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE;
  }
  
  static inline bool d_is_autodir(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE;
  }
44b1d5304   Miklos Szeredi   vfs: add d_is_dir()
395
396
397
398
  static inline bool d_is_dir(const struct dentry *dentry)
  {
  	return d_can_lookup(dentry) || d_is_autodir(dentry);
  }
b18825a7c   David Howells   VFS: Put a small ...
399
400
401
402
  static inline bool d_is_symlink(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;
  }
44bdb5e5f   David Howells   VFS: Split DCACHE...
403
404
405
406
407
408
409
410
411
  static inline bool d_is_reg(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_REGULAR_TYPE;
  }
  
  static inline bool d_is_special(const struct dentry *dentry)
  {
  	return __d_entry_type(dentry) == DCACHE_SPECIAL_TYPE;
  }
b18825a7c   David Howells   VFS: Put a small ...
412
413
  static inline bool d_is_file(const struct dentry *dentry)
  {
44bdb5e5f   David Howells   VFS: Split DCACHE...
414
  	return d_is_reg(dentry) || d_is_special(dentry);
b18825a7c   David Howells   VFS: Put a small ...
415
416
417
418
  }
  
  static inline bool d_is_negative(const struct dentry *dentry)
  {
e7f7d2253   David Howells   VFS: Add a whiteo...
419
420
  	// TODO: check d_is_whiteout(dentry) also.
  	return d_is_miss(dentry);
b18825a7c   David Howells   VFS: Put a small ...
421
422
423
424
425
426
  }
  
  static inline bool d_is_positive(const struct dentry *dentry)
  {
  	return !d_is_negative(dentry);
  }
525d27b23   David Howells   VFS: Add owner-fi...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  /**
   * d_really_is_negative - Determine if a dentry is really negative (ignoring fallthroughs)
   * @dentry: The dentry in question
   *
   * Returns true if the dentry represents either an absent name or a name that
   * doesn't map to an inode (ie. ->d_inode is NULL).  The dentry could represent
   * a true miss, a whiteout that isn't represented by a 0,0 chardev or a
   * fallthrough marker in an opaque directory.
   *
   * Note!  (1) This should be used *only* by a filesystem to examine its own
   * dentries.  It should not be used to look at some other filesystem's
   * dentries.  (2) It should also be used in combination with d_inode() to get
   * the inode.  (3) The dentry may have something attached to ->d_lower and the
   * type field of the flags may be set to something other than miss or whiteout.
   */
  static inline bool d_really_is_negative(const struct dentry *dentry)
  {
  	return dentry->d_inode == NULL;
  }
  
  /**
   * d_really_is_positive - Determine if a dentry is really positive (ignoring fallthroughs)
   * @dentry: The dentry in question
   *
   * Returns true if the dentry represents a name that maps to an inode
   * (ie. ->d_inode is not NULL).  The dentry might still represent a whiteout if
   * that is represented on medium as a 0,0 chardev.
   *
   * Note!  (1) This should be used *only* by a filesystem to examine its own
   * dentries.  It should not be used to look at some other filesystem's
   * dentries.  (2) It should also be used in combination with d_inode() to get
   * the inode.
   */
  static inline bool d_really_is_positive(const struct dentry *dentry)
  {
  	return dentry->d_inode != NULL;
  }
dc3f4198e   Al Viro   make simple_posit...
464
465
466
467
  static inline int simple_positive(struct dentry *dentry)
  {
  	return d_really_is_positive(dentry) && !d_unhashed(dentry);
  }
df1a085af   David Howells   VFS: Add a fallth...
468
469
470
471
472
473
  extern void d_set_fallthru(struct dentry *dentry);
  
  static inline bool d_is_fallthru(const struct dentry *dentry)
  {
  	return dentry->d_flags & DCACHE_FALLTHRU;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
474
  extern int sysctl_vfs_cache_pressure;
55f841ce9   Glauber Costa   super: fix calcul...
475
476
477
478
  static inline unsigned long vfs_pressure_ratio(unsigned long val)
  {
  	return mult_frac(val, sysctl_vfs_cache_pressure, 100);
  }
155e35d4d   David Howells   VFS: Introduce in...
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
  
  /**
   * d_inode - Get the actual inode of this dentry
   * @dentry: The dentry to query
   *
   * This is the helper normal filesystems should use to get at their own inodes
   * in their own dentries and ignore the layering superimposed upon them.
   */
  static inline struct inode *d_inode(const struct dentry *dentry)
  {
  	return dentry->d_inode;
  }
  
  /**
   * d_inode_rcu - Get the actual inode of this dentry with ACCESS_ONCE()
   * @dentry: The dentry to query
   *
   * This is the helper normal filesystems should use to get at their own inodes
   * in their own dentries and ignore the layering superimposed upon them.
   */
  static inline struct inode *d_inode_rcu(const struct dentry *dentry)
  {
  	return ACCESS_ONCE(dentry->d_inode);
  }
  
  /**
   * d_backing_inode - Get upper or lower inode we should be using
   * @upper: The upper layer
   *
   * This is the helper that should be used to get at the inode that will be used
   * if this dentry were to be opened as a file.  The inode may be on the upper
   * dentry or it may be on a lower dentry pinned by the upper.
   *
   * Normal filesystems should not use this to access their own inodes.
   */
  static inline struct inode *d_backing_inode(const struct dentry *upper)
  {
  	struct inode *inode = upper->d_inode;
  
  	return inode;
  }
  
  /**
   * d_backing_dentry - Get upper or lower dentry we should be using
   * @upper: The upper layer
   *
   * This is the helper that should be used to get the dentry of the inode that
   * will be used if this dentry were opened as a file.  It may be the upper
   * dentry or it may be a lower dentry pinned by the upper.
   *
   * Normal filesystems should not use this to access their own dentries.
   */
  static inline struct dentry *d_backing_dentry(struct dentry *upper)
  {
  	return upper;
  }
cd91304e7   Miklos Szeredi   ovl: fix relatime...
535
536
  /* d_real() flags */
  #define D_REAL_UPPER	0x2	/* return upper dentry or NULL if non-upper */
e698b8a43   Miklos Szeredi   vfs: document ->d...
537
538
539
540
  /**
   * d_real - Return the real dentry
   * @dentry: the dentry to query
   * @inode: inode to select the dentry from multiple layers (can be NULL)
495e64293   Miklos Szeredi   vfs: add flags to...
541
542
   * @open_flags: open flags to control copy-up behavior
   * @flags: flags to control what is returned by this function
e698b8a43   Miklos Szeredi   vfs: document ->d...
543
   *
03440c4e5   Masahiro Yamada   scripts/spelling....
544
   * If dentry is on a union/overlay, then return the underlying, real dentry.
e698b8a43   Miklos Szeredi   vfs: document ->d...
545
546
547
548
   * Otherwise return the dentry itself.
   *
   * See also: Documentation/filesystems/vfs.txt
   */
2d902671c   Miklos Szeredi   vfs: merge .d_sel...
549
550
  static inline struct dentry *d_real(struct dentry *dentry,
  				    const struct inode *inode,
495e64293   Miklos Szeredi   vfs: add flags to...
551
  				    unsigned int open_flags, unsigned int flags)
d101a1259   Miklos Szeredi   fs: add file_dent...
552
553
  {
  	if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
495e64293   Miklos Szeredi   vfs: add flags to...
554
  		return dentry->d_op->d_real(dentry, inode, open_flags, flags);
d101a1259   Miklos Szeredi   fs: add file_dent...
555
556
557
  	else
  		return dentry;
  }
a11808443   Miklos Szeredi   vfs: add d_real_i...
558
559
560
561
  /**
   * d_real_inode - Return the real inode
   * @dentry: The dentry to query
   *
03440c4e5   Masahiro Yamada   scripts/spelling....
562
   * If dentry is on a union/overlay, then return the underlying, real inode.
a11808443   Miklos Szeredi   vfs: add d_real_i...
563
564
   * Otherwise return d_inode().
   */
7b1742eb0   Miklos Szeredi   vfs: make argumen...
565
  static inline struct inode *d_real_inode(const struct dentry *dentry)
a11808443   Miklos Szeredi   vfs: add d_real_i...
566
  {
7b1742eb0   Miklos Szeredi   vfs: make argumen...
567
  	/* This usage of d_real() results in const dentry */
495e64293   Miklos Szeredi   vfs: add flags to...
568
  	return d_backing_inode(d_real((struct dentry *) dentry, NULL, 0, 0));
a11808443   Miklos Szeredi   vfs: add d_real_i...
569
  }
49d31c2f3   Al Viro   dentry name snaps...
570
  struct name_snapshot {
0a2c13d9c   Stephen Rothwell   include/linux/dca...
571
572
  	const unsigned char *name;
  	unsigned char inline_name[DNAME_INLINE_LEN];
49d31c2f3   Al Viro   dentry name snaps...
573
574
575
  };
  void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *);
  void release_dentry_name_snapshot(struct name_snapshot *);
54d5ca871   Miklos Szeredi   vfs: add vfs_sele...
576

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
577
  #endif	/* __LINUX_DCACHE_H */