Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
dcache.c File Reference
#include <linux/syscalls.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/fsnotify.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/hash.h>
#include <linux/cache.h>
#include <linux/export.h>
#include <linux/mount.h>
#include <linux/file.h>
#include <asm/uaccess.h>
#include <linux/security.h>
#include <linux/seqlock.h>
#include <linux/swap.h>
#include <linux/bootmem.h>
#include <linux/fs_struct.h>
#include <linux/hardirq.h>
#include <linux/bit_spinlock.h>
#include <linux/rculist_bl.h>
#include <linux/prefetch.h>
#include <linux/ratelimit.h>
#include "internal.h"
#include "mount.h"

Go to the source code of this file.

Macros

#define D_HASHBITS   d_hash_shift
 
#define D_HASHMASK   d_hash_mask
 

Functions

 EXPORT_SYMBOL_GPL (sysctl_vfs_cache_pressure)
 
__cacheline_aligned_in_smp DEFINE_SEQLOCK (rename_lock)
 
 EXPORT_SYMBOL (rename_lock)
 
void __d_drop (struct dentry *dentry)
 
 EXPORT_SYMBOL (__d_drop)
 
void d_drop (struct dentry *dentry)
 
 EXPORT_SYMBOL (d_drop)
 
void d_clear_need_lookup (struct dentry *dentry)
 
 EXPORT_SYMBOL (d_clear_need_lookup)
 
void dput (struct dentry *dentry)
 
 EXPORT_SYMBOL (dput)
 
int d_invalidate (struct dentry *dentry)
 
 EXPORT_SYMBOL (d_invalidate)
 
struct dentrydget_parent (struct dentry *dentry)
 
 EXPORT_SYMBOL (dget_parent)
 
struct dentryd_find_alias (struct inode *inode)
 
 EXPORT_SYMBOL (d_find_alias)
 
void d_prune_aliases (struct inode *inode)
 
 EXPORT_SYMBOL (d_prune_aliases)
 
void prune_dcache_sb (struct super_block *sb, int count)
 
void shrink_dcache_sb (struct super_block *sb)
 
 EXPORT_SYMBOL (shrink_dcache_sb)
 
void shrink_dcache_for_umount (struct super_block *sb)
 
int have_submounts (struct dentry *parent)
 
 EXPORT_SYMBOL (have_submounts)
 
void shrink_dcache_parent (struct dentry *parent)
 
 EXPORT_SYMBOL (shrink_dcache_parent)
 
: qstr of the name

d_alloc - allocate a dcache entry : parent of entry to allocate

Allocates a dentry. It returns NULL if there is insufficient memory available. On a success the dentry is returned. The name passed in is copied and the copy passed in may be reused after this call.

struct dentry__d_alloc (struct super_block *sb, const struct qstr *name)
 
struct dentryd_alloc (struct dentry *parent, const struct qstr *name)
 
 EXPORT_SYMBOL (d_alloc)
 
struct dentryd_alloc_pseudo (struct super_block *sb, const struct qstr *name)
 
 EXPORT_SYMBOL (d_alloc_pseudo)
 
struct dentryd_alloc_name (struct dentry *parent, const char *name)
 
 EXPORT_SYMBOL (d_alloc_name)
 
void d_set_d_op (struct dentry *dentry, const struct dentry_operations *op)
 
 EXPORT_SYMBOL (d_set_d_op)
 
void d_instantiate (struct dentry *entry, struct inode *inode)
 
 EXPORT_SYMBOL (d_instantiate)
 
struct dentryd_instantiate_unique (struct dentry *entry, struct inode *inode)
 
 EXPORT_SYMBOL (d_instantiate_unique)
 
struct dentryd_make_root (struct inode *root_inode)
 
 EXPORT_SYMBOL (d_make_root)
 
struct dentryd_find_any_alias (struct inode *inode)
 
 EXPORT_SYMBOL (d_find_any_alias)
 
struct dentryd_obtain_alias (struct inode *inode)
 
 EXPORT_SYMBOL (d_obtain_alias)
 
struct dentryd_splice_alias (struct inode *inode, struct dentry *dentry)
 
 EXPORT_SYMBOL (d_splice_alias)
 
: qstr of name we wish to find

On hash failure or on lookup failure NULL is returned.

struct dentry__d_lookup_rcu (const struct dentry *parent, const struct qstr *name, unsigned *seqp, struct inode *inode)
 
struct dentryd_lookup (struct dentry *parent, struct qstr *name)
 
 EXPORT_SYMBOL (d_lookup)
 
struct dentry__d_lookup (struct dentry *parent, struct qstr *name)
 
struct dentryd_hash_and_lookup (struct dentry *dir, struct qstr *name)
 
int d_validate (struct dentry *dentry, struct dentry *dparent)
 
 EXPORT_SYMBOL (d_validate)
 
void d_delete (struct dentry *dentry)
 
 EXPORT_SYMBOL (d_delete)
 
void d_rehash (struct dentry *entry)
 
 EXPORT_SYMBOL (d_rehash)
 
. Old and new

name lengths must match (ie. no d_compare which allows mismatched name lengths).

Parent inode i_mutex must be held over d_lookup and into this call (to keep renames and concurrent inserts, and readdir(2) away).

void dentry_update_name_case (struct dentry *dentry, struct qstr *name)
 
 EXPORT_SYMBOL (dentry_update_name_case)
 
void d_move (struct dentry *dentry, struct dentry *target)
 
 EXPORT_SYMBOL (d_move)
 
struct dentryd_ancestor (struct dentry *p1, struct dentry *p2)
 
struct dentryd_materialise_unique (struct dentry *dentry, struct inode *inode)
 
 EXPORT_SYMBOL_GPL (d_materialise_unique)
 
char__d_path (const struct path *path, const struct path *root, char *buf, int buflen)
 
chard_absolute_path (const struct path *path, char *buf, int buflen)
 
chard_path (const struct path *path, char *buf, int buflen)
 
 EXPORT_SYMBOL (d_path)
 
chard_path_with_unreachable (const struct path *path, char *buf, int buflen)
 
chardynamic_dname (struct dentry *dentry, char *buffer, int buflen, const char *fmt,...)
 
chardentry_path_raw (struct dentry *dentry, char *buf, int buflen)
 
 EXPORT_SYMBOL (dentry_path_raw)
 
chardentry_path (struct dentry *dentry, char *buf, int buflen)
 
 SYSCALL_DEFINE2 (getcwd, char __user *, buf, unsigned long, size)
 
int is_subdir (struct dentry *new_dentry, struct dentry *old_dentry)
 
void d_genocide (struct dentry *root)
 

Variables

struct dentry_stat_t dentry_stat
 

: the case-exact name to be associated with the returned dentry

d_add_ci - lookup or allocate new dentry with case-exact name : the inode case-insensitive lookup has found : the negative dentry that was passed to the parent's lookup func

This is to avoid filling the dcache with case-insensitive names to the same inode, only the actual correct case is stored in the dcache for case-insensitive filesystems.

For a case-insensitive lookup match and if the the case-exact dentry already exists in in the dcache, use it and return it.

If no entry exists with the exact case name, allocate new dentry with the exact case, and return the spliced entry.

enum  slow_d_compare { D_COMP_OK, D_COMP_NOMATCH, D_COMP_SEQRETRY }
 
struct dentryd_add_ci (struct dentry *dentry, struct inode *inode, struct qstr *name)
 
 EXPORT_SYMBOL (d_add_ci)
 

: Name to find.

Check whether a dentry already exists for the given name, and return the inode number if it has an inode. Otherwise 0 is returned.

This routine is used to post-process directory listings for filesystems using synthetic inode numbers, and is necessary to keep getcwd() working.

int sysctl_vfs_cache_pressure __read_mostly = 100
 
ino_t find_inode_number (struct dentry *dir, struct qstr *name)
 
 EXPORT_SYMBOL (find_inode_number)
 
 __setup ("dhash_entries=", set_dhash_entries)
 
 EXPORT_SYMBOL (names_cachep)
 
 EXPORT_SYMBOL (d_genocide)
 
void __init vfs_caches_init_early (void)
 
void __init vfs_caches_init (unsigned long mempages)
 

Macro Definition Documentation

#define D_HASHBITS   d_hash_shift

Definition at line 99 of file dcache.c.

#define D_HASHMASK   d_hash_mask

Definition at line 100 of file dcache.c.

Enumeration Type Documentation

Enumerator:
D_COMP_OK 
D_COMP_NOMATCH 
D_COMP_SEQRETRY 

Definition at line 1777 of file dcache.c.

Function Documentation

struct dentry* __d_alloc ( struct super_block sb,
const struct qstr name 
)
read

Definition at line 1274 of file dcache.c.

void __d_drop ( struct dentry dentry)

d_drop - drop a dentry : dentry to drop

d_drop() unhashes the entry from the parent dentry hashes, so that it won't be found through a VFS lookup any more. Note that this is different from deleting the dentry - d_delete will try to mark the dentry negative if possible, giving a successful negative lookup, while d_drop will just make the cache lookup fail.

d_drop() is used mainly for stuff that wants to invalidate a dentry for some reason (NFS timeouts or autofs deletes).

__d_drop requires dentry->d_lock.

Definition at line 440 of file dcache.c.

struct dentry* __d_lookup ( struct dentry parent,
struct qstr name 
)
read

Definition at line 1953 of file dcache.c.

struct dentry* __d_lookup_rcu ( const struct dentry parent,
const struct qstr name,
unsigned *  seqp,
struct inode inode 
)
read

Definition at line 1835 of file dcache.c.

char* __d_path ( const struct path path,
const struct path root,
char buf,
int  buflen 
)

__d_path - return the path of a dentry : the dentry/vfsmount to report : root vfsmnt/dentry : buffer to return value in : buffer length

Convert a dentry into an ASCII path name.

Returns a pointer into the buffer or an error code if the path was too long.

"buflen" should be positive.

If the path is not reachable from the supplied root, return NULL.

Definition at line 2653 of file dcache.c.

__setup ( )
char* d_absolute_path ( const struct path path,
char buf,
int  buflen 
)

Definition at line 2672 of file dcache.c.

struct dentry* d_add_ci ( struct dentry dentry,
struct inode inode,
struct qstr name 
)
read

Definition at line 1696 of file dcache.c.

struct dentry* d_alloc ( struct dentry parent,
const struct qstr name 
)
read

Definition at line 1339 of file dcache.c.

struct dentry* d_alloc_name ( struct dentry parent,
const char name 
)
read

Definition at line 1368 of file dcache.c.

struct dentry* d_alloc_pseudo ( struct super_block sb,
const struct qstr name 
)
read

Definition at line 1359 of file dcache.c.

struct dentry* d_ancestor ( struct dentry p1,
struct dentry p2 
)
read

d_ancestor - search for an ancestor : ancestor dentry : child dentry

Returns the ancestor dentry of p2 which is a child of p1, if p1 is an ancestor of p2, else NULL.

Definition at line 2370 of file dcache.c.

void d_clear_need_lookup ( struct dentry dentry)

Definition at line 466 of file dcache.c.

void d_delete ( struct dentry dentry)

d_delete - delete a dentry : The dentry to delete

Turn the dentry into a negative dentry if possible, otherwise remove it from the hash queues so it can be deleted later

Definition at line 2104 of file dcache.c.

void d_drop ( struct dentry dentry)

Definition at line 449 of file dcache.c.

struct dentry* d_find_alias ( struct inode inode)
read

Definition at line 737 of file dcache.c.

struct dentry* d_find_any_alias ( struct inode inode)
read

d_find_any_alias - find any alias for a given inode : inode to find an alias for

If any aliases exist for the given inode, take and return a reference for one of them. If no aliases exist, return NULL.

Definition at line 1555 of file dcache.c.

void d_genocide ( struct dentry root)

Definition at line 2985 of file dcache.c.

struct dentry* d_hash_and_lookup ( struct dentry dir,
struct qstr name 
)
read

Definition at line 2033 of file dcache.c.

void d_instantiate ( struct dentry entry,
struct inode inode 
)

d_instantiate - fill in inode information for a dentry : dentry to complete : inode to attach to this dentry

Fill in inode information in the entry.

This turns negative dentries into productive full members of society.

NOTE! This assumes that the inode count has been incremented (or otherwise set) by the caller to indicate that it is now in use by the dcache.

Definition at line 1432 of file dcache.c.

struct dentry* d_instantiate_unique ( struct dentry entry,
struct inode inode 
)
read

Definition at line 1496 of file dcache.c.

int d_invalidate ( struct dentry dentry)

d_invalidate - invalidate a dentry : dentry to invalidate

Try to invalidate the dentry if it turns out to be possible. If there are other dentries that can be reached through this one we can't delete it and we return -EBUSY. On success we return 0.

no dcache lock.

Definition at line 600 of file dcache.c.

struct dentry* d_lookup ( struct dentry parent,
struct qstr name 
)
read

Definition at line 1923 of file dcache.c.

struct dentry* d_make_root ( struct inode root_inode)
read

Definition at line 1520 of file dcache.c.

struct dentry* d_materialise_unique ( struct dentry dentry,
struct inode inode 
)
read

d_materialise_unique - introduce an inode into the tree : candidate dentry : inode to bind to the dentry, to which aliases may be attached

Introduces an dentry into the tree, substituting an extant disconnected root directory alias in its place if there is one. Caller must hold the i_mutex of the parent directory.

Definition at line 2474 of file dcache.c.

void d_move ( struct dentry dentry,
struct dentry target 
)

Definition at line 2354 of file dcache.c.

struct dentry* d_obtain_alias ( struct inode inode)
read

d_obtain_alias - find or allocate a dentry for a given inode : inode to allocate the dentry for

Obtain a dentry for an inode resulting from NFS filehandle conversion or similar open by handle operations. The returned dentry may be anonymous, or may have a full name (if the inode was already in the cache).

When called on a directory inode, we must ensure that the inode only ever has one dentry. If a dentry is found, that is returned instead of allocating a new one.

On successful return, the reference to the inode has been transferred to the dentry. In case of an error the reference on the inode is released. To make it easier to use in export operations a NULL or IS_ERR inode may be passed in and will be the error will be propagate to the return value, with a NULL replaced by ERR_PTR(-ESTALE).

Definition at line 1584 of file dcache.c.

char* d_path ( const struct path path,
char buf,
int  buflen 
)

d_path - return the path of a dentry : path to report : buffer to return value in : buffer length

Convert a dentry into an ASCII path name. If the entry has been deleted the string " (deleted)" is appended. Note that this is ambiguous.

Returns a pointer into the buffer or an error code if the path was too long. Note: Callers should use the returned pointer, not the passed in buffer, to use the name! The implementation often starts at an offset into the buffer, and may leave 0 bytes at the start.

"buflen" should be positive.

Definition at line 2729 of file dcache.c.

char* d_path_with_unreachable ( const struct path path,
char buf,
int  buflen 
)

d_path_with_unreachable - return the path of a dentry : path to report : buffer to return value in : buffer length

The difference from d_path() is that this prepends "(unreachable)" to paths which are unreachable from the current process' root.

Definition at line 2765 of file dcache.c.

void d_prune_aliases ( struct inode inode)

Definition at line 754 of file dcache.c.

void d_rehash ( struct dentry entry)

d_rehash - add an entry back to the hash : dentry to add to the hash

Adds a dentry to the hash according to its name.

Definition at line 2157 of file dcache.c.

void d_set_d_op ( struct dentry dentry,
const struct dentry_operations op 
)

Definition at line 1379 of file dcache.c.

struct dentry* d_splice_alias ( struct inode inode,
struct dentry dentry 
)
read

d_splice_alias - splice a disconnected dentry into the tree if one exists : the inode which may have a disconnected dentry : a negative dentry which we want to point to the inode.

If inode is a directory and has a 'disconnected' dentry (i.e. IS_ROOT and DCACHE_DISCONNECTED), then d_move that in place of the given dentry and return it, else simply d_add the inode to the dentry and return NULL.

This is needed in the lookup routine of any filesystem that is exportable (via knfsd) so that we can build dcache paths to directories effectively.

If a dentry was found and moved, then it is returned. Otherwise NULL is returned. This matches the expected return value of ->lookup.

Definition at line 1651 of file dcache.c.

int d_validate ( struct dentry dentry,
struct dentry dparent 
)

d_validate - verify dentry provided from insecure source (deprecated) : The dentry alleged to be valid child of : The parent dentry (known to be valid)

An insecure source has sent us a dentry, here we verify it and dget() it. This is used by ncpfs in its readdir implementation. Zero is returned in the dentry is invalid.

This function is slow for big directories, and deprecated, do not use it.

Definition at line 2063 of file dcache.c.

char* dentry_path ( struct dentry dentry,
char buf,
int  buflen 
)

Definition at line 2854 of file dcache.c.

char* dentry_path_raw ( struct dentry dentry,
char buf,
int  buflen 
)

Definition at line 2842 of file dcache.c.

void dentry_update_name_case ( struct dentry dentry,
struct qstr name 
)

Definition at line 2179 of file dcache.c.

struct dentry* dget_parent ( struct dentry dentry)
read

Definition at line 658 of file dcache.c.

void dput ( struct dentry dentry)

Definition at line 543 of file dcache.c.

char* dynamic_dname ( struct dentry dentry,
char buffer,
int  buflen,
const char fmt,
  ... 
)

Definition at line 2790 of file dcache.c.

EXPORT_SYMBOL ( rename_lock  )
EXPORT_SYMBOL ( __d_drop  )
EXPORT_SYMBOL ( d_drop  )
EXPORT_SYMBOL ( d_clear_need_lookup  )
EXPORT_SYMBOL ( dput  )
EXPORT_SYMBOL ( d_invalidate  )
EXPORT_SYMBOL ( dget_parent  )
EXPORT_SYMBOL ( d_find_alias  )
EXPORT_SYMBOL ( d_prune_aliases  )
EXPORT_SYMBOL ( shrink_dcache_sb  )
EXPORT_SYMBOL ( have_submounts  )
EXPORT_SYMBOL ( shrink_dcache_parent  )
EXPORT_SYMBOL ( d_alloc  )
EXPORT_SYMBOL ( d_alloc_pseudo  )
EXPORT_SYMBOL ( d_alloc_name  )
EXPORT_SYMBOL ( d_set_d_op  )
EXPORT_SYMBOL ( d_instantiate  )
EXPORT_SYMBOL ( d_instantiate_unique  )
EXPORT_SYMBOL ( d_make_root  )
EXPORT_SYMBOL ( d_find_any_alias  )
EXPORT_SYMBOL ( d_obtain_alias  )
EXPORT_SYMBOL ( d_splice_alias  )
EXPORT_SYMBOL ( d_add_ci  )
EXPORT_SYMBOL ( d_lookup  )
EXPORT_SYMBOL ( d_validate  )
EXPORT_SYMBOL ( d_delete  )
EXPORT_SYMBOL ( d_rehash  )
EXPORT_SYMBOL ( dentry_update_name_case  )
EXPORT_SYMBOL ( d_move  )
EXPORT_SYMBOL ( d_path  )
EXPORT_SYMBOL ( dentry_path_raw  )
EXPORT_SYMBOL ( find_inode_number  )
EXPORT_SYMBOL ( names_cachep  )
EXPORT_SYMBOL ( d_genocide  )
EXPORT_SYMBOL_GPL ( sysctl_vfs_cache_pressure  )
EXPORT_SYMBOL_GPL ( d_materialise_unique  )
ino_t find_inode_number ( struct dentry dir,
struct qstr name 
)

Definition at line 3063 of file dcache.c.

int have_submounts ( struct dentry parent)

have_submounts - check for mounts over a dentry : dentry to check.

Return true if the parent or its subdirectories contain a mount point

Definition at line 1074 of file dcache.c.

int is_subdir ( struct dentry new_dentry,
struct dentry old_dentry 
)

is_subdir - is new dentry a subdirectory of old_dentry : new dentry : old dentry

Returns 1 if new_dentry is a subdirectory of the parent (at any depth). Returns 0 otherwise. Caller must ensure that "new_dentry" is pinned before calling is_subdir()

Definition at line 2959 of file dcache.c.

void prune_dcache_sb ( struct super_block sb,
int  count 
)

prune_dcache_sb - shrink the dcache : superblock : number of entries to try to free

Attempt to shrink the superblock dcache LRU by entries. This is done when we need more memory an called from the superblock shrinker function.

This function may fail to free any resources if all the dentries are in use.

Definition at line 864 of file dcache.c.

void shrink_dcache_for_umount ( struct super_block sb)

Definition at line 1014 of file dcache.c.

void shrink_dcache_parent ( struct dentry parent)

shrink_dcache_parent - prune dcache : parent of entries to prune

Prune the dcache to remove unused children of the parent dentry.

Definition at line 1254 of file dcache.c.

void shrink_dcache_sb ( struct super_block sb)

shrink_dcache_sb - shrink dcache for a superblock : superblock

Shrink the dcache for the specified super block. This is used to free the dcache before unmounting a file system.

Definition at line 910 of file dcache.c.

SYSCALL_DEFINE2 ( getcwd  ,
char __user ,
buf  ,
unsigned  long,
size   
)

Definition at line 2893 of file dcache.c.

void __init vfs_caches_init ( unsigned long  mempages)

Definition at line 3156 of file dcache.c.

void __init vfs_caches_init_early ( void  )

Definition at line 3150 of file dcache.c.

Variable Documentation

struct kmem_cache* names_cachep __read_mostly = 100

Definition at line 81 of file dcache.c.

struct dentry_stat_t dentry_stat
Initial value:
= {
.age_limit = 45,
}

Definition at line 116 of file dcache.c.