Chinaunix首页 | 论坛 | 博客
  • 博客访问: 420526
  • 博文数量: 99
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 1012
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 16:30
个人简介

linux kernel 工程师

文章分类

全部博文(99)

文章存档

2018年(5)

2017年(12)

2016年(27)

2015年(10)

2014年(43)

2012年(2)

我的朋友

分类: LINUX

2016-12-22 18:22:36






对于attach_mnt函数,参数mnt是child_mnt, path是mount_point代表的路径节点。
比如图1中,child_mnt是/dev/sdc1层次中的vfsmount结构。mount_point是/mnt/tmp1,也就是说path包含的是是/mnt/tmp1 的dentry 和vfsmount结构。

首先调用mnt_set_mountpoint,使得child_mnt与mount_point建立联系。
/dev/sdc1层次中的vfsmount结构中的这两个指针指向/mnt/tmp1层次中vfsmount和dentry。
/mnt/tmp1层次中的dentry把d_mounted++。


如图2所示,所有的vfsmount结构都通过mnt_hash这个list成员链入mount_hashtable这哈希表上,
ash值根据mount_point的dentry, vfsmount两个成员算出。

另外child_mnt这个vfsmount结构还要通过mnt_child这个成员链入mount_point的path->mnt->mnt_mounts里。


点击(此处)折叠或打开
  1. void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
  2.             struct vfsmount *child_mnt)
  3. {
  4.     child_mnt->mnt_parent = mntget(mnt);
  5.     child_mnt->mnt_mountpoint = dget(dentry);
  6.     dentry->d_mounted++;
  7. }

  8. static void attach_mnt(struct vfsmount *mnt, struct path *path)
  9. {
  10.     mnt_set_mountpoint(path->mnt, path->dentry, mnt);
  11.     list_add_tail(&mnt->mnt_hash, mount_hashtable +
  12.             hash(path->mnt, path->dentry));
  13.     list_add_tail(&mnt->mnt_child, &path->mnt->mnt_mounts);
  14. }

知道了attach_mnt的原理之后,再来看__lookup_mnt函数。
__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry, int dir)
函数中形参mnt和dentry代表的是mount_point路径的vfs_mount和dentry结构。要查找其child_mnt, 需要首先根据mount_point路径的vfs_mount和dentry算出hash值,
并在mount_hashtable表中找到链表头,遍历这个链表,如果某个节点的vfs结构满足
p->mnt_parent == mnt && p->mnt_mountpoint == dentry

就找到了child_mount.



点击(此处)折叠或打开

  1. /*
  2.  * find the first or last mount at @dentry on vfsmount @mnt depending on
  3.  * @dir. If @dir is set return the first mount else return the last mount.
  4.  */
  5. struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry,
  6.              int dir)
  7. {
  8.     struct list_head *head = mount_hashtable + hash(mnt, dentry);
  9.     struct list_head *tmp = head;
  10.     struct vfsmount *p, *found = NULL;

  11.     for (;;) {
  12.         tmp = dir ? tmp->next : tmp->prev;
  13.         p = NULL;
  14.         if (tmp == head)
  15.             break;
  16.         p = list_entry(tmp, struct vfsmount, mnt_hash);
  17.         if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) {
  18.             found = p;
  19.             break;
  20.         }
  21.     }
  22.     return found;


阅读(518) | 评论(0) | 转发(0) |
0

上一篇:dentry与vfsmount

下一篇:do_path_lookup

给主人留下些什么吧!~~