0001
0002 #ifndef __LINUX_DCACHE_H
0003 #define __LINUX_DCACHE_H
0004
0005 #include <linux/atomic.h>
0006 #include <linux/list.h>
0007 #include <linux/math.h>
0008 #include <linux/rculist.h>
0009 #include <linux/rculist_bl.h>
0010 #include <linux/spinlock.h>
0011 #include <linux/seqlock.h>
0012 #include <linux/cache.h>
0013 #include <linux/rcupdate.h>
0014 #include <linux/lockref.h>
0015 #include <linux/stringhash.h>
0016 #include <linux/wait.h>
0017
0018 struct path;
0019 struct vfsmount;
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #define IS_ROOT(x) ((x) == (x)->d_parent)
0031
0032
0033 #ifdef __LITTLE_ENDIAN
0034 #define HASH_LEN_DECLARE u32 hash; u32 len
0035 #define bytemask_from_count(cnt) (~(~0ul << (cnt)*8))
0036 #else
0037 #define HASH_LEN_DECLARE u32 len; u32 hash
0038 #define bytemask_from_count(cnt) (~(~0ul >> (cnt)*8))
0039 #endif
0040
0041
0042
0043
0044
0045
0046
0047
0048 struct qstr {
0049 union {
0050 struct {
0051 HASH_LEN_DECLARE;
0052 };
0053 u64 hash_len;
0054 };
0055 const unsigned char *name;
0056 };
0057
0058 #define QSTR_INIT(n,l) { { { .len = l } }, .name = n }
0059
0060 extern const struct qstr empty_name;
0061 extern const struct qstr slash_name;
0062 extern const struct qstr dotdot_name;
0063
0064
0065
0066
0067
0068
0069 #ifdef CONFIG_64BIT
0070 # define DNAME_INLINE_LEN 32
0071 #else
0072 # ifdef CONFIG_SMP
0073 # define DNAME_INLINE_LEN 36
0074 # else
0075 # define DNAME_INLINE_LEN 40
0076 # endif
0077 #endif
0078
0079 #define d_lock d_lockref.lock
0080
0081 struct dentry {
0082
0083 unsigned int d_flags;
0084 seqcount_spinlock_t d_seq;
0085 struct hlist_bl_node d_hash;
0086 struct dentry *d_parent;
0087 struct qstr d_name;
0088 struct inode *d_inode;
0089
0090 unsigned char d_iname[DNAME_INLINE_LEN];
0091
0092
0093 struct lockref d_lockref;
0094 const struct dentry_operations *d_op;
0095 struct super_block *d_sb;
0096 unsigned long d_time;
0097 void *d_fsdata;
0098
0099 union {
0100 struct list_head d_lru;
0101 wait_queue_head_t *d_wait;
0102 };
0103 struct list_head d_child;
0104 struct list_head d_subdirs;
0105
0106
0107
0108 union {
0109 struct hlist_node d_alias;
0110 struct hlist_bl_node d_in_lookup_hash;
0111 struct rcu_head d_rcu;
0112 } d_u;
0113 } __randomize_layout;
0114
0115
0116
0117
0118
0119
0120
0121 enum dentry_d_lock_class
0122 {
0123 DENTRY_D_LOCK_NORMAL,
0124 DENTRY_D_LOCK_NESTED
0125 };
0126
0127 struct dentry_operations {
0128 int (*d_revalidate)(struct dentry *, unsigned int);
0129 int (*d_weak_revalidate)(struct dentry *, unsigned int);
0130 int (*d_hash)(const struct dentry *, struct qstr *);
0131 int (*d_compare)(const struct dentry *,
0132 unsigned int, const char *, const struct qstr *);
0133 int (*d_delete)(const struct dentry *);
0134 int (*d_init)(struct dentry *);
0135 void (*d_release)(struct dentry *);
0136 void (*d_prune)(struct dentry *);
0137 void (*d_iput)(struct dentry *, struct inode *);
0138 char *(*d_dname)(struct dentry *, char *, int);
0139 struct vfsmount *(*d_automount)(struct path *);
0140 int (*d_manage)(const struct path *, bool);
0141 struct dentry *(*d_real)(struct dentry *, const struct inode *);
0142 } ____cacheline_aligned;
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 #define DCACHE_OP_HASH 0x00000001
0154 #define DCACHE_OP_COMPARE 0x00000002
0155 #define DCACHE_OP_REVALIDATE 0x00000004
0156 #define DCACHE_OP_DELETE 0x00000008
0157 #define DCACHE_OP_PRUNE 0x00000010
0158
0159 #define DCACHE_DISCONNECTED 0x00000020
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 #define DCACHE_REFERENCED 0x00000040
0171
0172 #define DCACHE_DONTCACHE 0x00000080
0173
0174 #define DCACHE_CANT_MOUNT 0x00000100
0175 #define DCACHE_GENOCIDE 0x00000200
0176 #define DCACHE_SHRINK_LIST 0x00000400
0177
0178 #define DCACHE_OP_WEAK_REVALIDATE 0x00000800
0179
0180 #define DCACHE_NFSFS_RENAMED 0x00001000
0181
0182
0183 #define DCACHE_COOKIE 0x00002000
0184 #define DCACHE_FSNOTIFY_PARENT_WATCHED 0x00004000
0185
0186
0187 #define DCACHE_DENTRY_KILLED 0x00008000
0188
0189 #define DCACHE_MOUNTED 0x00010000
0190 #define DCACHE_NEED_AUTOMOUNT 0x00020000
0191 #define DCACHE_MANAGE_TRANSIT 0x00040000
0192 #define DCACHE_MANAGED_DENTRY \
0193 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
0194
0195 #define DCACHE_LRU_LIST 0x00080000
0196
0197 #define DCACHE_ENTRY_TYPE 0x00700000
0198 #define DCACHE_MISS_TYPE 0x00000000
0199 #define DCACHE_WHITEOUT_TYPE 0x00100000
0200 #define DCACHE_DIRECTORY_TYPE 0x00200000
0201 #define DCACHE_AUTODIR_TYPE 0x00300000
0202 #define DCACHE_REGULAR_TYPE 0x00400000
0203 #define DCACHE_SPECIAL_TYPE 0x00500000
0204 #define DCACHE_SYMLINK_TYPE 0x00600000
0205
0206 #define DCACHE_MAY_FREE 0x00800000
0207 #define DCACHE_FALLTHRU 0x01000000
0208 #define DCACHE_NOKEY_NAME 0x02000000
0209 #define DCACHE_OP_REAL 0x04000000
0210
0211 #define DCACHE_PAR_LOOKUP 0x10000000
0212 #define DCACHE_DENTRY_CURSOR 0x20000000
0213 #define DCACHE_NORCU 0x40000000
0214
0215 extern seqlock_t rename_lock;
0216
0217
0218
0219
0220 extern void d_instantiate(struct dentry *, struct inode *);
0221 extern void d_instantiate_new(struct dentry *, struct inode *);
0222 extern struct dentry * d_instantiate_unique(struct dentry *, struct inode *);
0223 extern struct dentry * d_instantiate_anon(struct dentry *, struct inode *);
0224 extern void __d_drop(struct dentry *dentry);
0225 extern void d_drop(struct dentry *dentry);
0226 extern void d_delete(struct dentry *);
0227 extern void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op);
0228
0229
0230 extern struct dentry * d_alloc(struct dentry *, const struct qstr *);
0231 extern struct dentry * d_alloc_anon(struct super_block *);
0232 extern struct dentry * d_alloc_parallel(struct dentry *, const struct qstr *,
0233 wait_queue_head_t *);
0234 extern struct dentry * d_splice_alias(struct inode *, struct dentry *);
0235 extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);
0236 extern bool d_same_name(const struct dentry *dentry, const struct dentry *parent,
0237 const struct qstr *name);
0238 extern struct dentry * d_exact_alias(struct dentry *, struct inode *);
0239 extern struct dentry *d_find_any_alias(struct inode *inode);
0240 extern struct dentry * d_obtain_alias(struct inode *);
0241 extern struct dentry * d_obtain_root(struct inode *);
0242 extern void shrink_dcache_sb(struct super_block *);
0243 extern void shrink_dcache_parent(struct dentry *);
0244 extern void shrink_dcache_for_umount(struct super_block *);
0245 extern void d_invalidate(struct dentry *);
0246
0247
0248 extern struct dentry * d_make_root(struct inode *);
0249
0250
0251 extern void d_genocide(struct dentry *);
0252
0253 extern void d_tmpfile(struct dentry *, struct inode *);
0254
0255 extern struct dentry *d_find_alias(struct inode *);
0256 extern void d_prune_aliases(struct inode *);
0257
0258 extern struct dentry *d_find_alias_rcu(struct inode *);
0259
0260
0261 extern int path_has_submounts(const struct path *);
0262
0263
0264
0265
0266 extern void d_rehash(struct dentry *);
0267
0268 extern void d_add(struct dentry *, struct inode *);
0269
0270
0271 extern void d_move(struct dentry *, struct dentry *);
0272 extern void d_exchange(struct dentry *, struct dentry *);
0273 extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
0274
0275
0276 extern struct dentry *d_lookup(const struct dentry *, const struct qstr *);
0277 extern struct dentry *d_hash_and_lookup(struct dentry *, struct qstr *);
0278 extern struct dentry *__d_lookup(const struct dentry *, const struct qstr *);
0279 extern struct dentry *__d_lookup_rcu(const struct dentry *parent,
0280 const struct qstr *name, unsigned *seq);
0281
0282 static inline unsigned d_count(const struct dentry *dentry)
0283 {
0284 return dentry->d_lockref.count;
0285 }
0286
0287
0288
0289
0290 extern __printf(4, 5)
0291 char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
0292
0293 extern char *__d_path(const struct path *, const struct path *, char *, int);
0294 extern char *d_absolute_path(const struct path *, char *, int);
0295 extern char *d_path(const struct path *, char *, int);
0296 extern char *dentry_path_raw(const struct dentry *, char *, int);
0297 extern char *dentry_path(const struct dentry *, char *, int);
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309 static inline struct dentry *dget_dlock(struct dentry *dentry)
0310 {
0311 if (dentry)
0312 dentry->d_lockref.count++;
0313 return dentry;
0314 }
0315
0316 static inline struct dentry *dget(struct dentry *dentry)
0317 {
0318 if (dentry)
0319 lockref_get(&dentry->d_lockref);
0320 return dentry;
0321 }
0322
0323 extern struct dentry *dget_parent(struct dentry *dentry);
0324
0325
0326
0327
0328
0329
0330
0331
0332 static inline int d_unhashed(const struct dentry *dentry)
0333 {
0334 return hlist_bl_unhashed(&dentry->d_hash);
0335 }
0336
0337 static inline int d_unlinked(const struct dentry *dentry)
0338 {
0339 return d_unhashed(dentry) && !IS_ROOT(dentry);
0340 }
0341
0342 static inline int cant_mount(const struct dentry *dentry)
0343 {
0344 return (dentry->d_flags & DCACHE_CANT_MOUNT);
0345 }
0346
0347 static inline void dont_mount(struct dentry *dentry)
0348 {
0349 spin_lock(&dentry->d_lock);
0350 dentry->d_flags |= DCACHE_CANT_MOUNT;
0351 spin_unlock(&dentry->d_lock);
0352 }
0353
0354 extern void __d_lookup_unhash_wake(struct dentry *dentry);
0355
0356 static inline int d_in_lookup(const struct dentry *dentry)
0357 {
0358 return dentry->d_flags & DCACHE_PAR_LOOKUP;
0359 }
0360
0361 static inline void d_lookup_done(struct dentry *dentry)
0362 {
0363 if (unlikely(d_in_lookup(dentry)))
0364 __d_lookup_unhash_wake(dentry);
0365 }
0366
0367 extern void dput(struct dentry *);
0368
0369 static inline bool d_managed(const struct dentry *dentry)
0370 {
0371 return dentry->d_flags & DCACHE_MANAGED_DENTRY;
0372 }
0373
0374 static inline bool d_mountpoint(const struct dentry *dentry)
0375 {
0376 return dentry->d_flags & DCACHE_MOUNTED;
0377 }
0378
0379
0380
0381
0382 static inline unsigned __d_entry_type(const struct dentry *dentry)
0383 {
0384 return dentry->d_flags & DCACHE_ENTRY_TYPE;
0385 }
0386
0387 static inline bool d_is_miss(const struct dentry *dentry)
0388 {
0389 return __d_entry_type(dentry) == DCACHE_MISS_TYPE;
0390 }
0391
0392 static inline bool d_is_whiteout(const struct dentry *dentry)
0393 {
0394 return __d_entry_type(dentry) == DCACHE_WHITEOUT_TYPE;
0395 }
0396
0397 static inline bool d_can_lookup(const struct dentry *dentry)
0398 {
0399 return __d_entry_type(dentry) == DCACHE_DIRECTORY_TYPE;
0400 }
0401
0402 static inline bool d_is_autodir(const struct dentry *dentry)
0403 {
0404 return __d_entry_type(dentry) == DCACHE_AUTODIR_TYPE;
0405 }
0406
0407 static inline bool d_is_dir(const struct dentry *dentry)
0408 {
0409 return d_can_lookup(dentry) || d_is_autodir(dentry);
0410 }
0411
0412 static inline bool d_is_symlink(const struct dentry *dentry)
0413 {
0414 return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;
0415 }
0416
0417 static inline bool d_is_reg(const struct dentry *dentry)
0418 {
0419 return __d_entry_type(dentry) == DCACHE_REGULAR_TYPE;
0420 }
0421
0422 static inline bool d_is_special(const struct dentry *dentry)
0423 {
0424 return __d_entry_type(dentry) == DCACHE_SPECIAL_TYPE;
0425 }
0426
0427 static inline bool d_is_file(const struct dentry *dentry)
0428 {
0429 return d_is_reg(dentry) || d_is_special(dentry);
0430 }
0431
0432 static inline bool d_is_negative(const struct dentry *dentry)
0433 {
0434
0435 return d_is_miss(dentry);
0436 }
0437
0438 static inline bool d_flags_negative(unsigned flags)
0439 {
0440 return (flags & DCACHE_ENTRY_TYPE) == DCACHE_MISS_TYPE;
0441 }
0442
0443 static inline bool d_is_positive(const struct dentry *dentry)
0444 {
0445 return !d_is_negative(dentry);
0446 }
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 static inline bool d_really_is_negative(const struct dentry *dentry)
0464 {
0465 return dentry->d_inode == NULL;
0466 }
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481 static inline bool d_really_is_positive(const struct dentry *dentry)
0482 {
0483 return dentry->d_inode != NULL;
0484 }
0485
0486 static inline int simple_positive(const struct dentry *dentry)
0487 {
0488 return d_really_is_positive(dentry) && !d_unhashed(dentry);
0489 }
0490
0491 extern void d_set_fallthru(struct dentry *dentry);
0492
0493 static inline bool d_is_fallthru(const struct dentry *dentry)
0494 {
0495 return dentry->d_flags & DCACHE_FALLTHRU;
0496 }
0497
0498
0499 extern int sysctl_vfs_cache_pressure;
0500
0501 static inline unsigned long vfs_pressure_ratio(unsigned long val)
0502 {
0503 return mult_frac(val, sysctl_vfs_cache_pressure, 100);
0504 }
0505
0506
0507
0508
0509
0510
0511
0512
0513 static inline struct inode *d_inode(const struct dentry *dentry)
0514 {
0515 return dentry->d_inode;
0516 }
0517
0518
0519
0520
0521
0522
0523
0524
0525 static inline struct inode *d_inode_rcu(const struct dentry *dentry)
0526 {
0527 return READ_ONCE(dentry->d_inode);
0528 }
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540 static inline struct inode *d_backing_inode(const struct dentry *upper)
0541 {
0542 struct inode *inode = upper->d_inode;
0543
0544 return inode;
0545 }
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557 static inline struct dentry *d_backing_dentry(struct dentry *upper)
0558 {
0559 return upper;
0560 }
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572 static inline struct dentry *d_real(struct dentry *dentry,
0573 const struct inode *inode)
0574 {
0575 if (unlikely(dentry->d_flags & DCACHE_OP_REAL))
0576 return dentry->d_op->d_real(dentry, inode);
0577 else
0578 return dentry;
0579 }
0580
0581
0582
0583
0584
0585
0586
0587
0588 static inline struct inode *d_real_inode(const struct dentry *dentry)
0589 {
0590
0591 return d_backing_inode(d_real((struct dentry *) dentry, NULL));
0592 }
0593
0594 struct name_snapshot {
0595 struct qstr name;
0596 unsigned char inline_name[DNAME_INLINE_LEN];
0597 };
0598 void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *);
0599 void release_dentry_name_snapshot(struct name_snapshot *);
0600
0601 #endif