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

 原文: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的过程。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值