在sys_mount的调用过程中,会调用到vfs_kern_mount
调用关系如下:
sys_mount
->do_mount
->do_new_mount
->do_kern_mount
->vfs_kern_mount
在proc_fs中也会调用vfs_kern_mount
-
void __init proc_root_init(void)
-
{
-
...
-
proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
-
...
-
}
-
-
struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
-
{
-
return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
-
}
-
struct vfsmount *
-
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
-
{
-
struct file_system_type *type = get_fs_type(fstype);
-
struct vfsmount *mnt;
-
if (!type)
-
return ERR_PTR(-ENODEV);
-
mnt = vfs_kern_mount(type, flags, name, data);
-
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
-
!mnt->mnt_sb->s_subtype)
-
mnt = fs_set_subtype(mnt, fstype);
-
put_filesystem(type);
-
return mnt;
-
}
-
struct vfsmount *
-
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
-
{
-
struct vfsmount *mnt;
-
char *secdata = NULL;
-
int error;
-
-
if (!type)
-
return ERR_PTR(-ENODEV);
-
/* 分配一份vfsmount结构 */
-
error = -ENOMEM;
-
mnt = alloc_vfsmnt(name);
-
if (!mnt)
-
goto out;
-
-
if (flags & MS_KERNMOUNT)
-
mnt->mnt_flags = MNT_INTERNAL;
-
-
if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
-
secdata = alloc_secdata();
-
if (!secdata)
-
goto out_mnt;
-
-
error = security_sb_copy_data(data, secdata);
-
if (error)
-
goto out_free_secdata;
-
}
-
/* 读取超级块
-
procfs对应的函数是proc_get_sb
-
*/
-
error = type->get_sb(type, flags, name, data, mnt);
-
if (error < 0)
-
goto out_free_secdata;
-
BUG_ON(!mnt->mnt_sb);
-
WARN_ON(!mnt->mnt_sb->s_bdi);
-
WARN_ON(mnt->mnt_sb->s_bdi == &default_backing_dev_info);
-
mnt->mnt_sb->s_flags |= MS_BORN;
-
-
error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
-
if (error)
-
goto out_sb;
-
-
/*
-
* filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
-
* but s_maxbytes was an unsigned long long for many releases. Throw
-
* this warning for a little while to try and catch filesystems that
-
* violate this rule. This warning should be either removed or
-
* converted to a BUG() in 2.6.34.
-
*/
-
WARN((mnt->mnt_sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
-
"negative value (%lld)\n", type->name, mnt->mnt_sb->s_maxbytes);
-
-
mnt->mnt_mountpoint = mnt->mnt_root;
-
mnt->mnt_parent = mnt;
-
up_write(&mnt->mnt_sb->s_umount);
-
free_secdata(secdata);
-
return mnt;
-
out_sb:
-
dput(mnt->mnt_root);
-
deactivate_locked_super(mnt->mnt_sb);
-
out_free_secdata:
-
free_secdata(secdata);
-
out_mnt:
-
free_vfsmnt(mnt);
-
out:
-
return ERR_PTR(error);
-
}
阅读(1146) | 评论(0) | 转发(0) |