Analysis of EXT3 Mount process

Source: Internet
Author: User
Tags data structures file system hash root directory linux

EXT3 Mount Principle

In essence, the process of EXT3 mount is actually the process by which the inode is substituted. For example, the/DEV/SDB block device is mount to the/mnt/alan directory. The problem with the mount process is to screen out the inode that the/mnt/alan dentry directory entry points to, and then relocate to the Inode index node that/DEV/SDB represents. In the absence of an analysis of the Linux VFS Mount code, my idea is to modify the Inode index node that dentry points to to enable access to the Mount file system. After analysis, in the actual VFS mount implementation process, or my original idea slightly different, but the basic goal is the same.

The basics of the mount process for the Linux VFS are as shown in the following illustration:

When the user enters the "mount/dev/sdb/mnt/alan" command, Linux resolves the/mnt/alan string, obtains the associated Dentry directory entry from the Dentry hash table, and then identifies the directory entry as dcache_mounted. Once the dentry is identified as a dcache_mounted, it means masking it on the access path.

When a ext3 file system is mount/dev/sdb on a device, the kernel creates a Superblock object for that filesystem and reads all superblock information from the/DEV/SDB device to initialize the memory object. The Linux kernel maintains a global Superblock object list. S_root is the Dentry directory entry that is maintained by the Superblock object, which is the root directory of the file system. That is, the file system content of the new mount needs to be accessed through the root directory. During the mount, the VFS creates a very important Vfsmount object that maintains all the information about the file system mount. The Vfsmount object is maintained through a hash table, and the hash value is computed through the path address, where the hash value Vfsmount is computed by the "/mnt/alan" path string. The mnt_root in Vfsmount points to the S_root root entry of the Superblock object. Therefore, the Vfsmount Hash table can be retrieved by the/mnt/alan address to get the Vfsmount object that is mount, and then the Mnt_root root entry is obtained.

For example, after/dev/sdb is mount, the user wants to access a file AB.C on the device, assuming the address of the file is:/MNT/ALAN/AB.C. When you open the file, you first need to do a path resolution. When parsing to/mnt/alan, the/mnt/alan dentry directory entry is obtained and the directory entry has been identified as dcache_mounted. After that, it uses/mnt/alan to compute the hash value to retrieve the Vfsmount hash Table, get the corresponding Vfsmount object, then use Vfsmount point mnt_root directory entry to replace/mnt/alan original Dentry, Thus the redirection of Dentry and Inode is realized. On the basis of the new dentry, the parser continues to execute and finally gets the Inode object that represents the Ab.c file.

Key Data Structure Description

The key data structures involved in the Linux VFS mount are analyzed below.

VFSMOUNT Data structure

The

Vfsmount data structure is one of the most important structures of the VFS mount, maintaining all the information of a mount point. The data structure is described as follows:

struct Vfsmount {struct list_head mnt_hash;    /* Connect to Vfsmount Hash Table * * * struct vfsmount *mnt_parent;  * * point to the parent node in the Mount tree/struct dentry *mnt_mountpoint;    /* The directory entry to the mount point * * struct dentry *mnt_root; /* The file system root item is mount/* struct super_block *MNT_SB;  
    * * Pointing to the file system being Mount Superblock/#ifdef config_smp struct MNT_PCP __percpu *MNT_PCP;      atomic_t Mnt_longterm;  
    /* How many of the refs are longterm */#else int mnt_count;  
int mnt_writers;    #endif struct List_head mnt_mounts; /* Subordinate (Child) Vfsmount object list/struct List_head mnt_child;  
    /* Link to the superior Vfsmount object of the chain-point/int mnt_flags;  
    /* 4 bytes hole on 64bits arches without fsnotify/#ifdef config_fsnotify __u32;  
struct Hlist_head mnt_fsnotify_marks;    #endif const char *mnt_devname;  
    * * The name of the device where the file system is located, such as/dev/sdb * * struct list_head mnt_list;    struct List_head mnt_expire; /* link in fs-specific expiry list */struct list_head mNt_share; /* Circular list of shared mounts/struct list_head mnt_slave_list;/* list of slave mounts/struct list_head m Nt_slave;    /* Slave list entry * * struct vfsmount *mnt_master;   /* Slave is on master->mnt_slave_list */struct mnt_namespace *mnt_ns;         /* containing namespace */int mnt_id;       * Mount identifier */int mnt_group_id;        /* Peer Group identifier */int mnt_expiry_mark;  
    /* True if marked for expiry */int mnt_pinned;  
int mnt_ghosts; };

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.