linux vfs 解析 之 mount 文件系统 (中)

找到了要 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   |     
                                               +--------------+     
                                               |              |     
                                                                    


从这张图可以看

你可能感兴趣的:(linux vfs 解析 之 mount 文件系统 (中))