原文:http://blog.sina.com.cn/s/blog_5219094a0100caly.html
找到了要 mount 的目录,下面就开始实际的mount过程
mount的过程就是把设备的文件系统加入到 vfs 框架中
1. 首先,要mount一个新的设备,需要创建一个新的 super block。
这通过要mount的文件系统的 file_system_type, 调用其 get_sb 方法来创建一个新的 super block
2. 对于任何一个 mount 的文件系统,都要有一个 vfsmount, 创建这个vfsmount, 并设置好其属性(就是 vfsmount 中的各个成员)
3. 将创建好的 vfsmount 加入到系统中。
整个过程如下所示:
/---------> /---> dentry ("/") <-----------\
| | +--------------+ |
| \----| d_parent | |
| +--------------+ |
| | d_child | |
| +--------------+ |
| /-------->| d_subdirs |<-----------|-------\
| | +--------------+ | |
| | | d_mounted | | |
| | +--------------+ | |
| | | | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | dentry ("home") <-\ | |
| | +--------------+ | | |
| | | d_parent |----|-------/ |
| | +--------------+ | |
| \-------->| d_child |<---|- ...... ------/
| +--------------+ |
| /------>| d_subdirs |<---|-------------\
| | +--------------+ | |
| | | d_mounted | | |
| | +--------------+ | |
| | | | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | dentry ("xpl") <--------------------------------------\
| | +--------------+ | | |
| | | d_parent |----/ | |
| | +--------------+ | |
| \------>| d_child |<---- ...... ----/ |
| +--------------+ |
| | d_subdirs | |
| +--------------+ |
| | d_mounted | |
| +--------------+ |
| | | |
| |
| |
| |
| task_struct |
| +-------------+ |
| | | |
| +-------------+ |
| | name_space |---------\ |
| +-------------+ | |
| fs_struct <-----| fs | | |
| +----------+ +-------------+ | |
+----<----| root | | | | |
| +----------+ | |
| | pwd | | |
| +----------+ | |
| /------| rootmnt | | |
| | +----------+ | |
| | | pwdmnt | namespace <---/ |
| | +----------+ +---------+ |
| | | | | count | |
| | +---------+ |
| | | root | |
| | +---------+ |
| | /--------------------------->| list |<-------------------\ |
| | | +---------+ | |
| | | | sem | | |
| | | +---------+ | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| \----------> vfsmount <----\ vfsmount(new) | |
| | +---------------+ | +---------------+ | |
| \------| mnt_list |<-----|------>| mnt_list |<----/ |
| +---------------+ | +---------------+ |
| | mnt_parent | \-------| mnt_parent | |
| +---------------+ +---------------+ |
| | mnt_mountpoint| | mnt_mountpoint|----------/
| +---------------+ +---------------+
\-----<--------| mnt_root | | mnt_root |------------\
+---------------+ +---------------+ |
/--------| mnt_mounts |<----\ | mnt_mounts | |
| +---------------+ | +---------------+ |
| | mnt_sb | | | mnt_sb |--------\ |
| +---------------+ | +---------------+ | |
| | mnt_child | \------->| mnt_child |<---\ | |
| +---------------+ +---------------+ | | |
| | | | | | | |
| | | | | | | |
| | | |
| | | |
| | | |
\------------------------------------------------------------/ | |
| |
| |
| |
| |
| |
| |
| |
| |
| |
super_block ---------------------------------/ |
+-----------+ |
| s_list | |
+-----------+ |
| s_inodes | |
+-----------+ |
| s_files | |
+-------------+ +-----------+ |
| "/dev/hdb1" |<------| s_id | |
+-------------+ +-----------+ |
| s_op | |
+-----------+ |
| s_root |-----> dentry ("/" of hdb1) <--------/
+-----------+ +--------------+
| | | d_parent |
+--------------+
| d_child |
+--------------+
| d_subdirs |
+--------------+
| d_mounted |
+--------------+
| |
从这张图可以看到,三个目录: "/", "home" 和 "xpl" 的dentry
我们新mount的设备为/dev/hdb1, 新创建了一个super_block 和 一个 vfsmount (new)
新的super_block 在创建的时候已经加入到整个 vfs 的架构中(可参看前面的 super block 一节)
对于新的vfsmount:
其mountpoint为 目录 "xpl" 的dentry,
其mnt_root 是设备hdb1上的根目录的 dentry
其父 vfsmount 就是原文件系统中的那个 vfsmount
同时,我们将新的这个vfsmount加入到了进程的namespace中。
至此,我们已经完成了整个mount的过程。