对于
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里。
点击(
此处)折叠或打开
-
void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
-
struct vfsmount *child_mnt)
-
{
-
child_mnt->mnt_parent = mntget(mnt);
-
child_mnt->mnt_mountpoint = dget(dentry);
-
dentry->d_mounted++;
-
}
-
-
static void attach_mnt(struct vfsmount *mnt, struct path *path)
-
{
-
mnt_set_mountpoint(path->mnt, path->dentry, mnt);
-
list_add_tail(&mnt->mnt_hash, mount_hashtable +
-
hash(path->mnt, path->dentry));
-
list_add_tail(&mnt->mnt_child, &path->mnt->mnt_mounts);
-
}
知道了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.
-
/*
-
* find the first or last mount at @dentry on vfsmount @mnt depending on
-
* @dir. If @dir is set return the first mount else return the last mount.
-
*/
-
struct vfsmount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry,
-
int dir)
-
{
-
struct list_head *head = mount_hashtable + hash(mnt, dentry);
-
struct list_head *tmp = head;
-
struct vfsmount *p, *found = NULL;
-
-
for (;;) {
-
tmp = dir ? tmp->next : tmp->prev;
-
p = NULL;
-
if (tmp == head)
-
break;
-
p = list_entry(tmp, struct vfsmount, mnt_hash);
-
if (p->mnt_parent == mnt && p->mnt_mountpoint == dentry) {
-
found = p;
-
break;
-
}
-
}
-
return found;
阅读(548) | 评论(0) | 转发(0) |