diff options
Diffstat (limited to 'include/linux/dcache.h')
-rw-r--r-- | include/linux/dcache.h | 243 |
1 files changed, 128 insertions, 115 deletions
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 6a4aea30aa09..59fcd24b1468 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -4,7 +4,9 @@ | |||
4 | #include <asm/atomic.h> | 4 | #include <asm/atomic.h> |
5 | #include <linux/list.h> | 5 | #include <linux/list.h> |
6 | #include <linux/rculist.h> | 6 | #include <linux/rculist.h> |
7 | #include <linux/rculist_bl.h> | ||
7 | #include <linux/spinlock.h> | 8 | #include <linux/spinlock.h> |
9 | #include <linux/seqlock.h> | ||
8 | #include <linux/cache.h> | 10 | #include <linux/cache.h> |
9 | #include <linux/rcupdate.h> | 11 | #include <linux/rcupdate.h> |
10 | 12 | ||
@@ -45,6 +47,27 @@ struct dentry_stat_t { | |||
45 | }; | 47 | }; |
46 | extern struct dentry_stat_t dentry_stat; | 48 | extern struct dentry_stat_t dentry_stat; |
47 | 49 | ||
50 | /* | ||
51 | * Compare 2 name strings, return 0 if they match, otherwise non-zero. | ||
52 | * The strings are both count bytes long, and count is non-zero. | ||
53 | */ | ||
54 | static 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 | |||
48 | /* Name hashing routines. Initial hash value */ | 71 | /* Name hashing routines. Initial hash value */ |
49 | /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */ | 72 | /* Hash courtesy of the R5 hash in reiserfs modulo sign bits */ |
50 | #define init_name_hash() 0 | 73 | #define init_name_hash() 0 |
@@ -81,25 +104,33 @@ full_name_hash(const unsigned char *name, unsigned int len) | |||
81 | * large memory footprint increase). | 104 | * large memory footprint increase). |
82 | */ | 105 | */ |
83 | #ifdef CONFIG_64BIT | 106 | #ifdef CONFIG_64BIT |
84 | #define DNAME_INLINE_LEN_MIN 32 /* 192 bytes */ | 107 | # define DNAME_INLINE_LEN 32 /* 192 bytes */ |
85 | #else | 108 | #else |
86 | #define DNAME_INLINE_LEN_MIN 40 /* 128 bytes */ | 109 | # ifdef CONFIG_SMP |
110 | # define DNAME_INLINE_LEN 36 /* 128 bytes */ | ||
111 | # else | ||
112 | # define DNAME_INLINE_LEN 40 /* 128 bytes */ | ||
113 | # endif | ||
87 | #endif | 114 | #endif |
88 | 115 | ||
89 | struct dentry { | 116 | struct dentry { |
90 | atomic_t d_count; | 117 | /* RCU lookup touched fields */ |
91 | unsigned int d_flags; /* protected by d_lock */ | 118 | unsigned int d_flags; /* protected by d_lock */ |
92 | spinlock_t d_lock; /* per dentry lock */ | 119 | seqcount_t d_seq; /* per dentry seqlock */ |
93 | int d_mounted; | 120 | struct hlist_bl_node d_hash; /* lookup hash list */ |
94 | struct inode *d_inode; /* Where the name belongs to - NULL is | ||
95 | * negative */ | ||
96 | /* | ||
97 | * The next three fields are touched by __d_lookup. Place them here | ||
98 | * so they all fit in a cache line. | ||
99 | */ | ||
100 | struct hlist_node d_hash; /* lookup hash list */ | ||
101 | struct dentry *d_parent; /* parent directory */ | 121 | struct dentry *d_parent; /* parent directory */ |
102 | struct qstr d_name; | 122 | struct qstr d_name; |
123 | struct inode *d_inode; /* Where the name belongs to - NULL is | ||
124 | * negative */ | ||
125 | unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */ | ||
126 | |||
127 | /* Ref lookup also touches following */ | ||
128 | unsigned int d_count; /* protected by d_lock */ | ||
129 | spinlock_t d_lock; /* per dentry lock */ | ||
130 | const struct dentry_operations *d_op; | ||
131 | struct super_block *d_sb; /* The root of the dentry tree */ | ||
132 | unsigned long d_time; /* used by d_revalidate */ | ||
133 | void *d_fsdata; /* fs-specific data */ | ||
103 | 134 | ||
104 | struct list_head d_lru; /* LRU list */ | 135 | struct list_head d_lru; /* LRU list */ |
105 | /* | 136 | /* |
@@ -111,12 +142,6 @@ struct dentry { | |||
111 | } d_u; | 142 | } d_u; |
112 | struct list_head d_subdirs; /* our children */ | 143 | struct list_head d_subdirs; /* our children */ |
113 | struct list_head d_alias; /* inode alias list */ | 144 | struct list_head d_alias; /* inode alias list */ |
114 | unsigned long d_time; /* used by d_revalidate */ | ||
115 | const struct dentry_operations *d_op; | ||
116 | struct super_block *d_sb; /* The root of the dentry tree */ | ||
117 | void *d_fsdata; /* fs-specific data */ | ||
118 | |||
119 | unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */ | ||
120 | }; | 145 | }; |
121 | 146 | ||
122 | /* | 147 | /* |
@@ -133,96 +158,61 @@ enum dentry_d_lock_class | |||
133 | 158 | ||
134 | struct dentry_operations { | 159 | struct dentry_operations { |
135 | int (*d_revalidate)(struct dentry *, struct nameidata *); | 160 | int (*d_revalidate)(struct dentry *, struct nameidata *); |
136 | int (*d_hash) (struct dentry *, struct qstr *); | 161 | int (*d_hash)(const struct dentry *, const struct inode *, |
137 | int (*d_compare) (struct dentry *, struct qstr *, struct qstr *); | 162 | struct qstr *); |
138 | int (*d_delete)(struct dentry *); | 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 *); | ||
139 | void (*d_release)(struct dentry *); | 167 | void (*d_release)(struct dentry *); |
140 | void (*d_iput)(struct dentry *, struct inode *); | 168 | void (*d_iput)(struct dentry *, struct inode *); |
141 | char *(*d_dname)(struct dentry *, char *, int); | 169 | char *(*d_dname)(struct dentry *, char *, int); |
142 | }; | 170 | } ____cacheline_aligned; |
143 | |||
144 | /* the dentry parameter passed to d_hash and d_compare is the parent | ||
145 | * directory of the entries to be compared. It is used in case these | ||
146 | * functions need any directory specific information for determining | ||
147 | * equivalency classes. Using the dentry itself might not work, as it | ||
148 | * might be a negative dentry which has no information associated with | ||
149 | * it */ | ||
150 | 171 | ||
151 | /* | 172 | /* |
152 | locking rules: | 173 | * Locking rules for dentry_operations callbacks are to be found in |
153 | big lock dcache_lock d_lock may block | 174 | * Documentation/filesystems/Locking. Keep it updated! |
154 | d_revalidate: no no no yes | 175 | * |
155 | d_hash no no no yes | 176 | * FUrther descriptions are found in Documentation/filesystems/vfs.txt. |
156 | d_compare: no yes yes no | 177 | * Keep it updated too! |
157 | d_delete: no yes no no | ||
158 | d_release: no no no yes | ||
159 | d_iput: no no no yes | ||
160 | */ | 178 | */ |
161 | 179 | ||
162 | /* d_flags entries */ | 180 | /* d_flags entries */ |
163 | #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */ | 181 | #define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */ |
164 | #define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly | 182 | #define DCACHE_NFSFS_RENAMED 0x0002 |
165 | * renamed" and has to be | 183 | /* this dentry has been "silly renamed" and has to be deleted on the last |
166 | * deleted on the last dput() | 184 | * dput() */ |
167 | */ | 185 | |
168 | #define DCACHE_DISCONNECTED 0x0004 | 186 | #define DCACHE_DISCONNECTED 0x0004 |
169 | /* This dentry is possibly not currently connected to the dcache tree, | 187 | /* This dentry is possibly not currently connected to the dcache tree, in |
170 | * in which case its parent will either be itself, or will have this | 188 | * which case its parent will either be itself, or will have this flag as |
171 | * flag as well. nfsd will not use a dentry with this bit set, but will | 189 | * well. nfsd will not use a dentry with this bit set, but will first |
172 | * first endeavour to clear the bit either by discovering that it is | 190 | * endeavour to clear the bit either by discovering that it is connected, |
173 | * connected, or by performing lookup operations. Any filesystem which | 191 | * or by performing lookup operations. Any filesystem which supports |
174 | * supports nfsd_operations MUST have a lookup function which, if it finds | 192 | * nfsd_operations MUST have a lookup function which, if it finds a |
175 | * a directory inode with a DCACHE_DISCONNECTED dentry, will d_move | 193 | * directory inode with a DCACHE_DISCONNECTED dentry, will d_move that |
176 | * that dentry into place and return that dentry rather than the passed one, | 194 | * dentry into place and return that dentry rather than the passed one, |
177 | * typically using d_splice_alias. | 195 | * typically using d_splice_alias. */ |
178 | */ | ||
179 | 196 | ||
180 | #define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */ | 197 | #define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */ |
181 | #define DCACHE_UNHASHED 0x0010 | 198 | #define DCACHE_UNHASHED 0x0010 |
182 | 199 | #define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 | |
183 | #define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched by inotify */ | 200 | /* Parent inode is watched by inotify */ |
184 | 201 | ||
185 | #define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */ | 202 | #define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */ |
186 | 203 | #define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 | |
187 | #define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */ | 204 | /* Parent inode is watched by some fsnotify listener */ |
188 | 205 | ||
189 | #define DCACHE_CANT_MOUNT 0x0100 | 206 | #define DCACHE_CANT_MOUNT 0x0100 |
207 | #define DCACHE_GENOCIDE 0x0200 | ||
208 | #define DCACHE_MOUNTED 0x0400 /* is a mountpoint */ | ||
190 | 209 | ||
191 | extern spinlock_t dcache_lock; | 210 | #define DCACHE_OP_HASH 0x1000 |
192 | extern seqlock_t rename_lock; | 211 | #define DCACHE_OP_COMPARE 0x2000 |
193 | 212 | #define DCACHE_OP_REVALIDATE 0x4000 | |
194 | /** | 213 | #define DCACHE_OP_DELETE 0x8000 |
195 | * d_drop - drop a dentry | ||
196 | * @dentry: dentry to drop | ||
197 | * | ||
198 | * d_drop() unhashes the entry from the parent dentry hashes, so that it won't | ||
199 | * be found through a VFS lookup any more. Note that this is different from | ||
200 | * deleting the dentry - d_delete will try to mark the dentry negative if | ||
201 | * possible, giving a successful _negative_ lookup, while d_drop will | ||
202 | * just make the cache lookup fail. | ||
203 | * | ||
204 | * d_drop() is used mainly for stuff that wants to invalidate a dentry for some | ||
205 | * reason (NFS timeouts or autofs deletes). | ||
206 | * | ||
207 | * __d_drop requires dentry->d_lock. | ||
208 | */ | ||
209 | |||
210 | static inline void __d_drop(struct dentry *dentry) | ||
211 | { | ||
212 | if (!(dentry->d_flags & DCACHE_UNHASHED)) { | ||
213 | dentry->d_flags |= DCACHE_UNHASHED; | ||
214 | hlist_del_rcu(&dentry->d_hash); | ||
215 | } | ||
216 | } | ||
217 | 214 | ||
218 | static inline void d_drop(struct dentry *dentry) | 215 | extern seqlock_t rename_lock; |
219 | { | ||
220 | spin_lock(&dcache_lock); | ||
221 | spin_lock(&dentry->d_lock); | ||
222 | __d_drop(dentry); | ||
223 | spin_unlock(&dentry->d_lock); | ||
224 | spin_unlock(&dcache_lock); | ||
225 | } | ||
226 | 216 | ||
227 | static inline int dname_external(struct dentry *dentry) | 217 | static inline int dname_external(struct dentry *dentry) |
228 | { | 218 | { |
@@ -235,10 +225,14 @@ static inline int dname_external(struct dentry *dentry) | |||
235 | extern void d_instantiate(struct dentry *, struct inode *); | 225 | extern void d_instantiate(struct dentry *, struct inode *); |
236 | extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *); | 226 | extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *); |
237 | extern struct dentry * d_materialise_unique(struct dentry *, struct inode *); | 227 | extern struct dentry * d_materialise_unique(struct dentry *, struct inode *); |
228 | extern void __d_drop(struct dentry *dentry); | ||
229 | extern void d_drop(struct dentry *dentry); | ||
238 | extern void d_delete(struct dentry *); | 230 | extern void d_delete(struct dentry *); |
231 | extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op); | ||
239 | 232 | ||
240 | /* allocate/de-allocate */ | 233 | /* allocate/de-allocate */ |
241 | extern struct dentry * d_alloc(struct dentry *, const struct qstr *); | 234 | extern struct dentry * d_alloc(struct dentry *, const struct qstr *); |
235 | extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *); | ||
242 | extern struct dentry * d_splice_alias(struct inode *, struct dentry *); | 236 | extern struct dentry * d_splice_alias(struct inode *, struct dentry *); |
243 | extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); | 237 | extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); |
244 | extern struct dentry * d_obtain_alias(struct inode *); | 238 | extern struct dentry * d_obtain_alias(struct inode *); |
@@ -296,14 +290,40 @@ static inline struct dentry *d_add_unique(struct dentry *entry, struct inode *in | |||
296 | return res; | 290 | return res; |
297 | } | 291 | } |
298 | 292 | ||
293 | extern void dentry_update_name_case(struct dentry *, struct qstr *); | ||
294 | |||
299 | /* used for rename() and baskets */ | 295 | /* used for rename() and baskets */ |
300 | extern void d_move(struct dentry *, struct dentry *); | 296 | extern void d_move(struct dentry *, struct dentry *); |
301 | extern struct dentry *d_ancestor(struct dentry *, struct dentry *); | 297 | extern struct dentry *d_ancestor(struct dentry *, struct dentry *); |
302 | 298 | ||
303 | /* appendix may either be NULL or be used for transname suffixes */ | 299 | /* appendix may either be NULL or be used for transname suffixes */ |
304 | extern struct dentry * d_lookup(struct dentry *, struct qstr *); | 300 | extern struct dentry *d_lookup(struct dentry *, struct qstr *); |
305 | extern struct dentry * __d_lookup(struct dentry *, struct qstr *); | 301 | extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *); |
306 | extern struct dentry * d_hash_and_lookup(struct dentry *, struct qstr *); | 302 | extern struct dentry *__d_lookup(struct dentry *, struct qstr *); |
303 | extern struct dentry *__d_lookup_rcu(struct dentry *parent, struct qstr *name, | ||
304 | unsigned *seq, struct inode **inode); | ||
305 | |||
306 | /** | ||
307 | * __d_rcu_to_refcount - take a refcount on dentry if sequence check is ok | ||
308 | * @dentry: dentry to take a ref on | ||
309 | * @seq: seqcount to verify against | ||
310 | * Returns: 0 on failure, else 1. | ||
311 | * | ||
312 | * __d_rcu_to_refcount operates on a dentry,seq pair that was returned | ||
313 | * by __d_lookup_rcu, to get a reference on an rcu-walk dentry. | ||
314 | */ | ||
315 | static inline int __d_rcu_to_refcount(struct dentry *dentry, unsigned seq) | ||
316 | { | ||
317 | int ret = 0; | ||
318 | |||
319 | assert_spin_locked(&dentry->d_lock); | ||
320 | if (!read_seqcount_retry(&dentry->d_seq, seq)) { | ||
321 | ret = 1; | ||
322 | dentry->d_count++; | ||
323 | } | ||
324 | |||
325 | return ret; | ||
326 | } | ||
307 | 327 | ||
308 | /* validate "insecure" dentry pointer */ | 328 | /* validate "insecure" dentry pointer */ |
309 | extern int d_validate(struct dentry *, struct dentry *); | 329 | extern int d_validate(struct dentry *, struct dentry *); |
@@ -316,34 +336,37 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...); | |||
316 | extern char *__d_path(const struct path *path, struct path *root, char *, int); | 336 | extern char *__d_path(const struct path *path, struct path *root, char *, int); |
317 | extern char *d_path(const struct path *, char *, int); | 337 | extern char *d_path(const struct path *, char *, int); |
318 | extern char *d_path_with_unreachable(const struct path *, char *, int); | 338 | extern char *d_path_with_unreachable(const struct path *, char *, int); |
319 | extern char *__dentry_path(struct dentry *, char *, int); | 339 | extern char *dentry_path_raw(struct dentry *, char *, int); |
320 | extern char *dentry_path(struct dentry *, char *, int); | 340 | extern char *dentry_path(struct dentry *, char *, int); |
321 | 341 | ||
322 | /* Allocation counts.. */ | 342 | /* Allocation counts.. */ |
323 | 343 | ||
324 | /** | 344 | /** |
325 | * dget, dget_locked - get a reference to a dentry | 345 | * dget, dget_dlock - get a reference to a dentry |
326 | * @dentry: dentry to get a reference to | 346 | * @dentry: dentry to get a reference to |
327 | * | 347 | * |
328 | * Given a dentry or %NULL pointer increment the reference count | 348 | * Given a dentry or %NULL pointer increment the reference count |
329 | * if appropriate and return the dentry. A dentry will not be | 349 | * if appropriate and return the dentry. A dentry will not be |
330 | * destroyed when it has references. dget() should never be | 350 | * destroyed when it has references. |
331 | * called for dentries with zero reference counter. For these cases | ||
332 | * (preferably none, functions in dcache.c are sufficient for normal | ||
333 | * needs and they take necessary precautions) you should hold dcache_lock | ||
334 | * and call dget_locked() instead of dget(). | ||
335 | */ | 351 | */ |
336 | 352 | static inline struct dentry *dget_dlock(struct dentry *dentry) | |
353 | { | ||
354 | if (dentry) | ||
355 | dentry->d_count++; | ||
356 | return dentry; | ||
357 | } | ||
358 | |||
337 | static inline struct dentry *dget(struct dentry *dentry) | 359 | static inline struct dentry *dget(struct dentry *dentry) |
338 | { | 360 | { |
339 | if (dentry) { | 361 | if (dentry) { |
340 | BUG_ON(!atomic_read(&dentry->d_count)); | 362 | spin_lock(&dentry->d_lock); |
341 | atomic_inc(&dentry->d_count); | 363 | dget_dlock(dentry); |
364 | spin_unlock(&dentry->d_lock); | ||
342 | } | 365 | } |
343 | return dentry; | 366 | return dentry; |
344 | } | 367 | } |
345 | 368 | ||
346 | extern struct dentry * dget_locked(struct dentry *); | 369 | extern struct dentry *dget_parent(struct dentry *dentry); |
347 | 370 | ||
348 | /** | 371 | /** |
349 | * d_unhashed - is dentry hashed | 372 | * d_unhashed - is dentry hashed |
@@ -374,21 +397,11 @@ static inline void dont_mount(struct dentry *dentry) | |||
374 | spin_unlock(&dentry->d_lock); | 397 | spin_unlock(&dentry->d_lock); |
375 | } | 398 | } |
376 | 399 | ||
377 | static inline struct dentry *dget_parent(struct dentry *dentry) | ||
378 | { | ||
379 | struct dentry *ret; | ||
380 | |||
381 | spin_lock(&dentry->d_lock); | ||
382 | ret = dget(dentry->d_parent); | ||
383 | spin_unlock(&dentry->d_lock); | ||
384 | return ret; | ||
385 | } | ||
386 | |||
387 | extern void dput(struct dentry *); | 400 | extern void dput(struct dentry *); |
388 | 401 | ||
389 | static inline int d_mountpoint(struct dentry *dentry) | 402 | static inline int d_mountpoint(struct dentry *dentry) |
390 | { | 403 | { |
391 | return dentry->d_mounted; | 404 | return dentry->d_flags & DCACHE_MOUNTED; |
392 | } | 405 | } |
393 | 406 | ||
394 | extern struct vfsmount *lookup_mnt(struct path *); | 407 | extern struct vfsmount *lookup_mnt(struct path *); |