Vfs dcache Function

Source: Internet
Author: User

In kernel 2.6.32, The dcache. c file of VFS exports a series of functions with export_symbol for kernel and file system programs.

1. export_symbol (d_alloc );

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

Construct the dentry of a sub-file or directory based on the dentry of the parent directory and the qstr structure of the file. This function is mainly used in the lookup process.

2. export_symbol (d_alloc_root );

Struct dentry * d_alloc_root (struct inode * root_inode)

It is used to allocate dentry to the file system root, where inode is the inode of the file system root.

3. export_symbol (d_delete );

Void d_delete (struct dentry * dentry)

/*
* When a file is deleted, we have two options:
*-Turn this dentry into a negative dentry
*-Unhash this dentry and free it.
*
* Usually, we want to just turn this
* A negative dentry, but if anybody else is
* Currently using the dentry or the inode
* We can't do that and we fall back on removing
* It from the hash queues and waiting
* It to be deleted later when it has no users
*/

The annotation of this function is described as above. After a file is deleted, dentry can be operated in two ways. One is to set dentry to a negative state (that is, the d_inode item in dentry is set to NULL), and the other is to remove dentry from the hash linked list and release space. Usually, after deleting a file, it will convert its dentry to a negative state, but when someone is still operating the file (inode's I _count is not 0 ), that is, if the inode of the file cannot be set to NULL, you need to remove the dentry from the hash linked list. After the last user releases the file, the dentry is released.

4. EXPORT_SYMBOL (d_find_alias );

Struct dentry * d_find_alias (struct inode * inode)

It is used to find the inode's alias dentry. The so-called alias dentry can be understood as the dentry used by the hard connection corresponding to the inode. When I read the vfs code, I noticed that different hard connections of vfs to the same inode will generate different dentry during lookup, these dentry columns are worn through the I _dentry linked list under the inode struct. In the dentry struct, different dentry columns corresponding to the same inode are stringed through the d_alias linked list.

5. EXPORT_SYMBOL (d_instantiate );

Void d_instantiate (struct dentry * entry, struct inode * inode)

Instantiate a dentry using inode

6. EXPORT_SYMBOL (d_invalidate );

Int d_invalidate (struct dentry * dentry)

Set a dentry to invalid.

7. EXPORT_SYMBOL (d_lookup );

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

Perform the lookup operation on the file based on the name and the dentry of the parent node to obtain the dentry of the subdirectory or sub-file.

8. EXPORT_SYMBOL (d_move)

Void d_move (struct dentry * dentry, struct dentry * target)

Move dentry to target, called by vfs_rename_other and vfs_rename_dir

9. EXPORT_SYMBOL_GPL (d_materialise_unique );

10. EXPORT_SYMBOL (d_path );

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

The path struct obtains the full path and stores it in the cached buf. The path struct is stored in the file pointer.

11. EXPORT_SYMBOL (d_prune_aliases );

Void d_prune_aliases (struct inode * inode)

Release all dentry corresponding to the current inode. Repeat the relationship between dentry and inode. An inode may correspond to multiple paths (aliases and hard links ), after a path is accessed, A dentry is generated, which are all linked together through the I _dentry linked list under inode.

Slave

Each dentry corresponds to a name in the namespace. each name points to an inode. when multiple dentry points to the same inode, it indicates that this inode has multiple names, forming a hardlink. these names are connected by inode-> I _dentry linked list header in inode. multiple dentries pointing to the same inode are connected through dentry-> d_alias.

12. EXPORT_SYMBOL (d_rehash );

Void d_rehash (struct dentry * entry)

Add a dentry to the hash linked list. The hash value is calculated by the dentry file name and the dentry pointer in the parent directory. For details, see the d_hash function.

13. EXPORT_SYMBOL (d_splice_alias );

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

This function is generally called in lookup,

Bind an inode to a negative dentry. inside this function, you must first determine whether the inode is a directory. If it is a directory, call the _ d_find_alias function to search for an alias dentry (note that the directory does not have a hard link, but a lot of content in it can also be used), call d_rehash to update the hash value, and call d_move to move the content of this alias dentry to the desired dentry. If no result is found for _ d_find_alias, The inode does not have the corresponding alias dentry. You need to call _ d_instantiate and d_rehash to bind the inode to the dentry. If inode is a file, use d_add to bind inode to dentry.

14. export_symbol (d_put)

Void dput (struct dentry * dentry)

To release the resources occupied by dentry, you must first determine the reference count of dentry, subtract one from it, and then determine whether the reference count is 0, if d_delete at the file system level is dentry-> d_op-> d_delete, dentry-> d_op-> d_delete is called to delete dentry, run d_drop to delete dentry from global dentry_hashtable, and call d_kill to clear memory resources occupied by dentry. If the d_delete file system does not exist, check whether the dentry-> d_lru linked list is empty. If not, add it to dentry-> d_sb-> s_dentry_lru. The s_dentry_lru here is supper.
A lru queue dentry_unused of the block, which is mainly used to place dentry that are not currently used and will be re-allocated later.

15. export_symbol (d_add_ci)

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

Note:

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

This function is used in a file system (such as ntfs) that is not sensitive to the size. It adds a file name that is not case sensitive to dentry.

16. EXPORT_SYMBOL (find_inode_number)

Ino_t find_inode_number (struct dentry * dir, struct qstr * name)

Locate the ino Number of the file based on the file name, and provide the dentry pointer of the parent directory of the file.

17. EXPORT_SYMBOL (have_submounts)

Int have_submounts (struct dentry * parent)

Check whether a mount point exists in the directory of the parent. If 0 is returned, it indicates that there is no mount point in the subdirectory of the parent. If 1 is returned, it indicates that there may be a mount point under it.

18. EXPORT_SYMBOL (shrink_dcache_parent)

Void shrink_dcache_parent (struct dentry * parent)

Remove the dentry of the parent, its subdirectories, and its sub-files from the cache.

19. EXPORT_SYMBOL (shrink_dcache_sb)

Void shrink_dcache_sb (struct super_block * sb)

The entire file system's dentry is kicked out of the cache, usually called before umount

20. EXPORT_SYMBOL (d_validate );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.