aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/dcache.h
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2011-03-19 02:38:50 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-03-19 02:38:50 -0400
commit97eb3f24352ec6632c2127b35d8087d2a809a9b9 (patch)
tree722948059bbd325bbca232269490124231df80d4 /include/linux/dcache.h
parent439581ec07fa9cf3f519dd461a2cf41cfd3adcb4 (diff)
parentdef179c271ac9b5020deca798470521f14d11edd (diff)
Merge branch 'next' into for-linus
Diffstat (limited to 'include/linux/dcache.h')
-rw-r--r--include/linux/dcache.h253
1 files changed, 139 insertions, 114 deletions
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 6a4aea30aa09..f958c19e3ca5 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};
46extern struct dentry_stat_t dentry_stat; 48extern 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 */
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
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
89struct dentry { 116struct 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,68 @@ enum dentry_d_lock_class
133 158
134struct dentry_operations { 159struct 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 struct vfsmount *(*d_automount)(struct path *);
143 171 int (*d_manage)(struct dentry *, bool, bool);
144/* the dentry parameter passed to d_hash and d_compare is the parent 172} ____cacheline_aligned;
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 173
151/* 174/*
152locking rules: 175 * Locking rules for dentry_operations callbacks are to be found in
153 big lock dcache_lock d_lock may block 176 * Documentation/filesystems/Locking. Keep it updated!
154d_revalidate: no no no yes 177 *
155d_hash no no no yes 178 * FUrther descriptions are found in Documentation/filesystems/vfs.txt.
156d_compare: no yes yes no 179 * Keep it updated too!
157d_delete: no yes no no
158d_release: no no no yes
159d_iput: no no no yes
160 */ 180 */
161 181
162/* d_flags entries */ 182/* d_flags entries */
163#define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */ 183#define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
164#define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly 184#define DCACHE_NFSFS_RENAMED 0x0002
165 * renamed" and has to be 185 /* this dentry has been "silly renamed" and has to be deleted on the last
166 * deleted on the last dput() 186 * dput() */
167 */ 187
168#define DCACHE_DISCONNECTED 0x0004 188#define DCACHE_DISCONNECTED 0x0004
169 /* This dentry is possibly not currently connected to the dcache tree, 189 /* 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 190 * 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 191 * 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 192 * endeavour to clear the bit either by discovering that it is connected,
173 * connected, or by performing lookup operations. Any filesystem which 193 * or by performing lookup operations. Any filesystem which supports
174 * supports nfsd_operations MUST have a lookup function which, if it finds 194 * nfsd_operations MUST have a lookup function which, if it finds a
175 * a directory inode with a DCACHE_DISCONNECTED dentry, will d_move 195 * 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, 196 * dentry into place and return that dentry rather than the passed one,
177 * typically using d_splice_alias. 197 * typically using d_splice_alias. */
178 */
179 198
180#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */ 199#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
181#define DCACHE_UNHASHED 0x0010 200#define DCACHE_UNHASHED 0x0010
182 201#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020
183#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched by inotify */ 202 /* Parent inode is watched by inotify */
184 203
185#define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */ 204#define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */
186 205#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080
187#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */ 206 /* Parent inode is watched by some fsnotify listener */
188 207
189#define DCACHE_CANT_MOUNT 0x0100 208#define DCACHE_CANT_MOUNT 0x0100
209#define DCACHE_GENOCIDE 0x0200
190 210
191extern spinlock_t dcache_lock; 211#define DCACHE_OP_HASH 0x1000
192extern seqlock_t rename_lock; 212#define DCACHE_OP_COMPARE 0x2000
193 213#define DCACHE_OP_REVALIDATE 0x4000
194/** 214#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 215
210static inline void __d_drop(struct dentry *dentry) 216#define DCACHE_MOUNTED 0x10000 /* is a mountpoint */
211{ 217#define DCACHE_NEED_AUTOMOUNT 0x20000 /* handle automount on this dir */
212 if (!(dentry->d_flags & DCACHE_UNHASHED)) { 218#define DCACHE_MANAGE_TRANSIT 0x40000 /* manage transit from this dirent */
213 dentry->d_flags |= DCACHE_UNHASHED; 219#define DCACHE_MANAGED_DENTRY \
214 hlist_del_rcu(&dentry->d_hash); 220 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
215 }
216}
217 221
218static inline void d_drop(struct dentry *dentry) 222extern 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 223
227static inline int dname_external(struct dentry *dentry) 224static inline int dname_external(struct dentry *dentry)
228{ 225{
@@ -235,10 +232,14 @@ static inline int dname_external(struct dentry *dentry)
235extern void d_instantiate(struct dentry *, struct inode *); 232extern void d_instantiate(struct dentry *, struct inode *);
236extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *); 233extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
237extern struct dentry * d_materialise_unique(struct dentry *, struct inode *); 234extern struct dentry * d_materialise_unique(struct dentry *, struct inode *);
235extern void __d_drop(struct dentry *dentry);
236extern void d_drop(struct dentry *dentry);
238extern void d_delete(struct dentry *); 237extern void d_delete(struct dentry *);
238extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op);
239 239
240/* allocate/de-allocate */ 240/* allocate/de-allocate */
241extern struct dentry * d_alloc(struct dentry *, const struct qstr *); 241extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
242extern struct dentry * d_alloc_pseudo(struct super_block *, const struct qstr *);
242extern struct dentry * d_splice_alias(struct inode *, struct dentry *); 243extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
243extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); 244extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
244extern struct dentry * d_obtain_alias(struct inode *); 245extern struct dentry * d_obtain_alias(struct inode *);
@@ -296,14 +297,40 @@ static inline struct dentry *d_add_unique(struct dentry *entry, struct inode *in
296 return res; 297 return res;
297} 298}
298 299
300extern void dentry_update_name_case(struct dentry *, struct qstr *);
301
299/* used for rename() and baskets */ 302/* used for rename() and baskets */
300extern void d_move(struct dentry *, struct dentry *); 303extern void d_move(struct dentry *, struct dentry *);
301extern struct dentry *d_ancestor(struct dentry *, struct dentry *); 304extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
302 305
303/* appendix may either be NULL or be used for transname suffixes */ 306/* appendix may either be NULL or be used for transname suffixes */
304extern struct dentry * d_lookup(struct dentry *, struct qstr *); 307extern struct dentry *d_lookup(struct dentry *, struct qstr *);
305extern struct dentry * __d_lookup(struct dentry *, struct qstr *); 308extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
306extern struct dentry * d_hash_and_lookup(struct dentry *, struct qstr *); 309extern struct dentry *__d_lookup(struct dentry *, struct qstr *);
310extern struct dentry *__d_lookup_rcu(struct dentry *parent, struct qstr *name,
311 unsigned *seq, struct inode **inode);
312
313/**
314 * __d_rcu_to_refcount - take a refcount on dentry if sequence check is ok
315 * @dentry: dentry to take a ref on
316 * @seq: seqcount to verify against
317 * Returns: 0 on failure, else 1.
318 *
319 * __d_rcu_to_refcount operates on a dentry,seq pair that was returned
320 * by __d_lookup_rcu, to get a reference on an rcu-walk dentry.
321 */
322static inline int __d_rcu_to_refcount(struct dentry *dentry, unsigned seq)
323{
324 int ret = 0;
325
326 assert_spin_locked(&dentry->d_lock);
327 if (!read_seqcount_retry(&dentry->d_seq, seq)) {
328 ret = 1;
329 dentry->d_count++;
330 }
331
332 return ret;
333}
307 334
308/* validate "insecure" dentry pointer */ 335/* validate "insecure" dentry pointer */
309extern int d_validate(struct dentry *, struct dentry *); 336extern int d_validate(struct dentry *, struct dentry *);
@@ -316,34 +343,37 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
316extern char *__d_path(const struct path *path, struct path *root, char *, int); 343extern char *__d_path(const struct path *path, struct path *root, char *, int);
317extern char *d_path(const struct path *, char *, int); 344extern char *d_path(const struct path *, char *, int);
318extern char *d_path_with_unreachable(const struct path *, char *, int); 345extern char *d_path_with_unreachable(const struct path *, char *, int);
319extern char *__dentry_path(struct dentry *, char *, int); 346extern char *dentry_path_raw(struct dentry *, char *, int);
320extern char *dentry_path(struct dentry *, char *, int); 347extern char *dentry_path(struct dentry *, char *, int);
321 348
322/* Allocation counts.. */ 349/* Allocation counts.. */
323 350
324/** 351/**
325 * dget, dget_locked - get a reference to a dentry 352 * dget, dget_dlock - get a reference to a dentry
326 * @dentry: dentry to get a reference to 353 * @dentry: dentry to get a reference to
327 * 354 *
328 * Given a dentry or %NULL pointer increment the reference count 355 * Given a dentry or %NULL pointer increment the reference count
329 * if appropriate and return the dentry. A dentry will not be 356 * if appropriate and return the dentry. A dentry will not be
330 * destroyed when it has references. dget() should never be 357 * 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 */ 358 */
336 359static inline struct dentry *dget_dlock(struct dentry *dentry)
360{
361 if (dentry)
362 dentry->d_count++;
363 return dentry;
364}
365
337static inline struct dentry *dget(struct dentry *dentry) 366static inline struct dentry *dget(struct dentry *dentry)
338{ 367{
339 if (dentry) { 368 if (dentry) {
340 BUG_ON(!atomic_read(&dentry->d_count)); 369 spin_lock(&dentry->d_lock);
341 atomic_inc(&dentry->d_count); 370 dget_dlock(dentry);
371 spin_unlock(&dentry->d_lock);
342 } 372 }
343 return dentry; 373 return dentry;
344} 374}
345 375
346extern struct dentry * dget_locked(struct dentry *); 376extern struct dentry *dget_parent(struct dentry *dentry);
347 377
348/** 378/**
349 * d_unhashed - is dentry hashed 379 * d_unhashed - is dentry hashed
@@ -374,21 +404,16 @@ static inline void dont_mount(struct dentry *dentry)
374 spin_unlock(&dentry->d_lock); 404 spin_unlock(&dentry->d_lock);
375} 405}
376 406
377static inline struct dentry *dget_parent(struct dentry *dentry) 407extern void dput(struct dentry *);
378{
379 struct dentry *ret;
380 408
381 spin_lock(&dentry->d_lock); 409static inline bool d_managed(struct dentry *dentry)
382 ret = dget(dentry->d_parent); 410{
383 spin_unlock(&dentry->d_lock); 411 return dentry->d_flags & DCACHE_MANAGED_DENTRY;
384 return ret;
385} 412}
386 413
387extern void dput(struct dentry *); 414static inline bool d_mountpoint(struct dentry *dentry)
388
389static inline int d_mountpoint(struct dentry *dentry)
390{ 415{
391 return dentry->d_mounted; 416 return dentry->d_flags & DCACHE_MOUNTED;
392} 417}
393 418
394extern struct vfsmount *lookup_mnt(struct path *); 419extern struct vfsmount *lookup_mnt(struct path *);