Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
C
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653/* SPDX-License-Identifier: GPL-2.0 */#ifndef __LINUX_DCACHE_H#define __LINUX_DCACHE_H
#include <linux/atomic.h>#include <linux/list.h>#include <linux/math.h>#include <linux/rculist.h>#include <linux/rculist_bl.h>#include <linux/spinlock.h>#include <linux/seqlock.h>#include <linux/cache.h>#include <linux/rcupdate.h>#include <linux/lockref.h>#include <linux/stringhash.h>#include <linux/wait.h>
struct path;struct file;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)
/* The hash is always the low bits of hash_len */#ifdef __LITTLE_ENDIAN #define HASH_LEN_DECLARE u32 hash; u32 len #define bytemask_from_count(cnt) (~(~0ul << (cnt)*8))#else #define HASH_LEN_DECLARE u32 len; u32 hash #define bytemask_from_count(cnt) (~(~0ul >> (cnt)*8))#endif
/* * "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 { union { struct { HASH_LEN_DECLARE; }; u64 hash_len; }; const unsigned char *name;};
#define QSTR_INIT(n,l) { { { .len = l } }, .name = n }#define QSTR_LEN(n,l) (struct qstr)QSTR_INIT(n,l)#define QSTR(n) QSTR_LEN(n, strlen(n))
extern const struct qstr empty_name;extern const struct qstr slash_name;extern const struct qstr dotdot_name;
/* * 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# define DNAME_INLINE_WORDS 5 /* 192 bytes */#else# ifdef CONFIG_SMP# define DNAME_INLINE_WORDS 9 /* 128 bytes */# else# define DNAME_INLINE_WORDS 11 /* 128 bytes */# endif#endif
#define DNAME_INLINE_LEN (DNAME_INLINE_WORDS*sizeof(unsigned long))
union shortname_store { unsigned char string[DNAME_INLINE_LEN]; unsigned long words[DNAME_INLINE_WORDS];};
#define d_lock d_lockref.lock#define d_iname d_shortname.stringstruct completion_list;
struct dentry { /* RCU lookup touched fields */ unsigned int d_flags; /* protected by d_lock */ seqcount_spinlock_t d_seq; /* per dentry seqlock */ struct hlist_bl_node d_hash; /* lookup hash list */ struct dentry *d_parent; /* parent directory */ union { struct qstr __d_name; /* for use ONLY in fs/dcache.c */ const struct qstr d_name; }; struct inode *d_inode; /* Where the name belongs to - NULL is * negative */ union shortname_store d_shortname; /* --- cacheline 1 boundary (64 bytes) was 32 bytes ago --- */
/* Ref lookup also touches following */ 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 */ /* --- cacheline 2 boundary (128 bytes) --- */ struct lockref d_lockref; /* per-dentry lock and refcount * keep separate from RCU lookup area if * possible! */
struct list_head d_lru; /* LRU list */ struct hlist_node d_sib; /* child of parent list */ struct hlist_head d_children; /* our children */ /* * the following members can share memory - their uses are * mutually exclusive. */ union { /* positives: inode alias list */ struct hlist_node d_alias; /* in-lookup ones (all negative, live): hash chain */ struct hlist_bl_node d_in_lookup_hash; /* killed ones: (already negative) used to schedule freeing */ struct rcu_head d_rcu; /* * live non-in-lookup negatives: used if shrink_dcache_tree() * races with eviction by another thread and needs to wait for * this dentry to get killed . Remains NULL for almost all * negative dentries. */ struct completion_list *waiters; };};
/* * 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};
enum d_real_type { D_REAL_DATA, D_REAL_METADATA,};
struct dentry_operations { int (*d_revalidate)(struct inode *, const struct qstr *, struct dentry *, unsigned int); int (*d_weak_revalidate)(struct dentry *, unsigned int); int (*d_hash)(const struct dentry *, struct qstr *); int (*d_compare)(const struct dentry *, unsigned int, const char *, const struct qstr *); int (*d_delete)(const struct dentry *); int (*d_init)(struct dentry *); void (*d_release)(struct dentry *); void (*d_prune)(struct dentry *); void (*d_iput)(struct dentry *, struct inode *); char *(*d_dname)(struct dentry *, char *, int); struct vfsmount *(*d_automount)(struct path *); int (*d_manage)(const struct path *, bool); struct dentry *(*d_real)(struct dentry *, enum d_real_type type); bool (*d_unalias_trylock)(const struct dentry *); void (*d_unalias_unlock)(const struct dentry *);} ____cacheline_aligned;
/* * Locking rules for dentry_operations callbacks are to be found in * Documentation/filesystems/locking.rst. Keep it updated! * * FUrther descriptions are found in Documentation/filesystems/vfs.rst. * Keep it updated too! */
/* d_flags entries */enum dentry_flags { DCACHE_OP_HASH = BIT(0), DCACHE_OP_COMPARE = BIT(1), DCACHE_OP_REVALIDATE = BIT(2), DCACHE_OP_DELETE = BIT(3), DCACHE_OP_PRUNE = BIT(4), /* * 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. */ DCACHE_DISCONNECTED = BIT(5), DCACHE_REFERENCED = BIT(6), /* Recently used, don't discard. */ DCACHE_DONTCACHE = BIT(7), /* Purge from memory on final dput() */ DCACHE_CANT_MOUNT = BIT(8), DCACHE_LOOKUP_WAITERS = BIT(9), /* A thread is waiting for * PAR_LOOKUP to clear */ DCACHE_SHRINK_LIST = BIT(10), DCACHE_OP_WEAK_REVALIDATE = BIT(11), /* * this dentry has been "silly renamed" and has to be deleted on the * last dput() */ DCACHE_NFSFS_RENAMED = BIT(12), DCACHE_FSNOTIFY_PARENT_WATCHED = BIT(13), /* Parent inode is watched by some fsnotify listener */ DCACHE_DENTRY_KILLED = BIT(14), DCACHE_MOUNTED = BIT(15), /* is a mountpoint */ DCACHE_NEED_AUTOMOUNT = BIT(16), /* handle automount on this dir */ DCACHE_MANAGE_TRANSIT = BIT(17), /* manage transit from this dirent */ DCACHE_LRU_LIST = BIT(18), DCACHE_ENTRY_TYPE = (7 << 19), /* bits 19..21 are for storing type: */ DCACHE_MISS_TYPE = (0 << 19), /* Negative dentry */ DCACHE_WHITEOUT_TYPE = (1 << 19), /* Whiteout dentry (stop pathwalk) */ DCACHE_DIRECTORY_TYPE = (2 << 19), /* Normal directory */ DCACHE_AUTODIR_TYPE = (3 << 19), /* Lookupless directory (presumed automount) */ DCACHE_REGULAR_TYPE = (4 << 19), /* Regular file type */ DCACHE_SPECIAL_TYPE = (5 << 19), /* Other file type */ DCACHE_SYMLINK_TYPE = (6 << 19), /* Symlink */ DCACHE_NOKEY_NAME = BIT(22), /* Encrypted name encoded without key */ DCACHE_OP_REAL = BIT(23), DCACHE_PAR_LOOKUP = BIT(24), /* being looked up (with parent locked shared) */ DCACHE_DENTRY_CURSOR = BIT(25), DCACHE_NORCU = BIT(26), /* No RCU delay for freeing */ DCACHE_PERSISTENT = BIT(27)};
#define DCACHE_MANAGED_DENTRY \ (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT)
extern seqlock_t rename_lock;
/* * These are the low-level FS interfaces to the dcache.. */extern void d_instantiate(struct dentry *, struct inode *);extern void d_instantiate_new(struct dentry *, struct inode *);extern void __d_drop(struct dentry *dentry);extern void d_drop(struct dentry *dentry);extern void d_delete(struct dentry *);
/* allocate/de-allocate */extern struct dentry * d_alloc(struct dentry *, const struct qstr *);extern struct dentry * d_alloc_anon(struct super_block *);extern struct dentry * d_alloc_parallel(struct dentry *, const struct qstr *);extern struct dentry * d_splice_alias(struct inode *, struct dentry *);/* weird procfs mess; *NOT* exported */extern struct dentry * d_splice_alias_ops(struct inode *, struct dentry *, const struct dentry_operations *);extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *);extern bool d_same_name(const struct dentry *dentry, const struct dentry *parent, const struct qstr *name);extern struct dentry *d_find_any_alias(struct inode *inode);extern struct dentry * d_obtain_alias(struct inode *);extern struct dentry * d_obtain_root(struct inode *);extern void shrink_dcache_sb(struct super_block *);extern void shrink_dcache_parent(struct dentry *);extern void d_invalidate(struct dentry *);
/* only used at mount-time */extern struct dentry * d_make_root(struct inode *);
extern void d_mark_tmpfile(struct file *, struct inode *);int d_mark_tmpfile_name(struct file *file, const struct qstr *name);extern void d_tmpfile(struct file *, struct inode *);
extern struct dentry *d_find_alias(struct inode *);extern void d_prune_aliases(struct inode *);extern bool __move_to_shrink_list(struct dentry *, struct list_head *);extern void shrink_dentry_list(struct list_head *);
extern struct dentry *d_find_alias_rcu(struct inode *);
/* test whether we have any submounts in a subdir tree */extern int path_has_submounts(const struct path *);
/* * This adds the entry to the hash queues. */extern void d_rehash(struct dentry *); extern void d_add(struct dentry *, struct inode *);
/* used for rename() and baskets */extern void d_move(struct dentry *, struct dentry *);extern void d_exchange(struct dentry *, struct dentry *);extern struct dentry *d_ancestor(struct dentry *, struct dentry *);
extern struct dentry *d_lookup(const struct dentry *, const struct qstr *);
static inline unsigned d_count(const struct dentry *dentry){ return dentry->d_lockref.count;}
ino_t d_parent_ino(struct dentry *dentry);
/* * helper function for dentry_operations.d_dname() members */extern __printf(3, 4)char *dynamic_dname(char *, int, const char *, ...);
extern char *__d_path(const struct path *, const struct path *, char *, int);extern char *d_absolute_path(const struct path *, char *, int);extern char *d_path(const struct path *, char *, int);extern char *dentry_path_raw(const struct dentry *, char *, int);extern char *dentry_path(const struct dentry *, char *, int);
/* Allocation counts.. */
/** * dget_dlock - get a reference to a dentry * @dentry: dentry to get a reference to * * Given a live dentry, increment the reference count and return the dentry. * Caller must hold @dentry->d_lock. Making sure that dentry is alive is * caller's resonsibility. There are many conditions sufficient to guarantee * that; e.g. anything with non-negative refcount is alive, so's anything * hashed, anything positive, anyone's parent, etc. */static inline struct dentry *dget_dlock(struct dentry *dentry){ dentry->d_lockref.count++; return dentry;}
/** * dget - get a reference to a dentry * @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 * destroyed when it has references. Conversely, a dentry with * no references can disappear for any number of reasons, starting * with memory pressure. In other words, that primitive is * used to clone an existing reference; using it on something with * zero refcount is a bug. * * NOTE: it will spin if @dentry->d_lock is held. From the deadlock * avoidance point of view it is equivalent to spin_lock()/increment * refcount/spin_unlock(), so calling it under @dentry->d_lock is * always a bug; so's calling it under ->d_lock on any of its descendents. * */static inline struct dentry *dget(struct dentry *dentry){ if (dentry) lockref_get(&dentry->d_lockref); return dentry;}
/* dentry->d_inode->i_lock must be held by caller */static inline bool dget_alias_ilocked(struct dentry *dentry){ if (likely(!(READ_ONCE(dentry->d_flags) & DCACHE_NORCU))) { lockref_get(&dentry->d_lockref); return true; } // NORCU dentries with zero refcount MUST NOT be grabbed spin_lock(&dentry->d_lock); if (dentry->d_lockref.count > 0) { dget_dlock(dentry); spin_unlock(&dentry->d_lock); return true; } spin_unlock(&dentry->d_lock); return false;}
extern struct dentry *dget_parent(struct dentry *dentry);
/** * d_unhashed - is dentry hashed * @dentry: entry to check * * Returns true if the dentry passed is not currently hashed. */static inline int d_unhashed(const struct dentry *dentry){ return hlist_bl_unhashed(&dentry->d_hash);}
static inline int d_unlinked(const struct dentry *dentry){ return d_unhashed(dentry) && !IS_ROOT(dentry);}
static inline int cant_mount(const struct dentry *dentry){ 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);}
extern void __d_lookup_unhash_wake(struct dentry *dentry);
static inline int d_in_lookup(const 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))) __d_lookup_unhash_wake(dentry);}
extern void dput(struct dentry *);
static inline bool d_managed(const struct dentry *dentry){ return dentry->d_flags & DCACHE_MANAGED_DENTRY;}
static inline bool d_mountpoint(const struct dentry *dentry){ return dentry->d_flags & DCACHE_MOUNTED;}
/* * Directory cache entry type accessor functions. */static inline unsigned __d_entry_type(const struct dentry *dentry){ return dentry->d_flags & DCACHE_ENTRY_TYPE;}
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;}
static inline bool d_can_lookup(const struct dentry *dentry){ 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;}
static inline bool d_is_dir(const struct dentry *dentry){ return d_can_lookup(dentry) || d_is_autodir(dentry);}
static inline bool d_is_symlink(const struct dentry *dentry){ return __d_entry_type(dentry) == DCACHE_SYMLINK_TYPE;}
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;}
static inline bool d_is_file(const struct dentry *dentry){ return d_is_reg(dentry) || d_is_special(dentry);}
static inline bool d_is_negative(const struct dentry *dentry){ // TODO: check d_is_whiteout(dentry) also. return d_is_miss(dentry);}
static inline bool d_flags_negative(unsigned flags){ return (flags & DCACHE_ENTRY_TYPE) == DCACHE_MISS_TYPE;}
static inline bool d_is_positive(const struct dentry *dentry){ return !d_is_negative(dentry);}
/** * 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;}
static inline int simple_positive(const struct dentry *dentry){ return d_really_is_positive(dentry) && !d_unhashed(dentry);}
unsigned long vfs_pressure_ratio(unsigned long val);
/** * 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 READ_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 READ_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_real - Return the real dentry * @dentry: the dentry to query * @type: the type of real dentry (data or metadata) * * If dentry is on a union/overlay, then return the underlying, real dentry. * Otherwise return the dentry itself. * * See also: Documentation/filesystems/vfs.rst */static inline struct dentry *d_real(struct dentry *dentry, enum d_real_type type){ if (unlikely(dentry->d_flags & DCACHE_OP_REAL)) return dentry->d_op->d_real(dentry, type); else return dentry;}
/** * d_real_inode - Return the real inode hosting the data * @dentry: The dentry to query * * If dentry is on a union/overlay, then return the underlying, real inode. * Otherwise return d_inode(). */static inline struct inode *d_real_inode(const struct dentry *dentry){ /* This usage of d_real() results in const dentry */ return d_inode(d_real((struct dentry *) dentry, D_REAL_DATA));}
struct name_snapshot { struct qstr name; union shortname_store inline_name;};void take_dentry_name_snapshot(struct name_snapshot *, struct dentry *);void release_dentry_name_snapshot(struct name_snapshot *);
static inline struct dentry *d_first_child(const struct dentry *dentry){ return hlist_entry_safe(dentry->d_children.first, struct dentry, d_sib);}
static inline struct dentry *d_next_sibling(const struct dentry *dentry){ return hlist_entry_safe(dentry->d_sib.next, struct dentry, d_sib);}
void set_default_d_op(struct super_block *, const struct dentry_operations *);struct dentry *d_make_persistent(struct dentry *, struct inode *);void d_make_discardable(struct dentry *dentry);
/* inode->i_lock must be held over that */#define for_each_alias(dentry, inode) \ hlist_for_each_entry(dentry, &(inode)->i_dentry, d_alias)
#endif /* __LINUX_DCACHE_H */