forked from Minki/linux
fs: refactor ksys_umount
Factor out a path_umount helper that takes a struct path * instead of the actual file name. This will allow to convert the init and devtmpfs code to properly mount based on a kernel pointer instead of relying on the implicit set_fs(KERNEL_DS) during early init. Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
a1e6aaa374
commit
41525f56e2
@ -1706,36 +1706,19 @@ static inline bool may_mandlock(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
static int path_umount(struct path *path, int flags)
|
||||||
* Now umount can handle mount points as well as block devices.
|
|
||||||
* This is important for filesystems which use unnamed block devices.
|
|
||||||
*
|
|
||||||
* We now support a flag for forced unmount like the other 'big iron'
|
|
||||||
* unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
|
|
||||||
*/
|
|
||||||
|
|
||||||
int ksys_umount(char __user *name, int flags)
|
|
||||||
{
|
{
|
||||||
struct path path;
|
|
||||||
struct mount *mnt;
|
struct mount *mnt;
|
||||||
int retval;
|
int retval;
|
||||||
int lookup_flags = LOOKUP_MOUNTPOINT;
|
|
||||||
|
|
||||||
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
|
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!may_mount())
|
if (!may_mount())
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
if (!(flags & UMOUNT_NOFOLLOW))
|
mnt = real_mount(path->mnt);
|
||||||
lookup_flags |= LOOKUP_FOLLOW;
|
|
||||||
|
|
||||||
retval = user_path_at(AT_FDCWD, name, lookup_flags, &path);
|
|
||||||
if (retval)
|
|
||||||
goto out;
|
|
||||||
mnt = real_mount(path.mnt);
|
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
if (path.dentry != path.mnt->mnt_root)
|
if (path->dentry != path->mnt->mnt_root)
|
||||||
goto dput_and_out;
|
goto dput_and_out;
|
||||||
if (!check_mnt(mnt))
|
if (!check_mnt(mnt))
|
||||||
goto dput_and_out;
|
goto dput_and_out;
|
||||||
@ -1748,12 +1731,25 @@ int ksys_umount(char __user *name, int flags)
|
|||||||
retval = do_umount(mnt, flags);
|
retval = do_umount(mnt, flags);
|
||||||
dput_and_out:
|
dput_and_out:
|
||||||
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
|
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
|
||||||
dput(path.dentry);
|
dput(path->dentry);
|
||||||
mntput_no_expire(mnt);
|
mntput_no_expire(mnt);
|
||||||
out:
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ksys_umount(char __user *name, int flags)
|
||||||
|
{
|
||||||
|
int lookup_flags = LOOKUP_MOUNTPOINT;
|
||||||
|
struct path path;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!(flags & UMOUNT_NOFOLLOW))
|
||||||
|
lookup_flags |= LOOKUP_FOLLOW;
|
||||||
|
ret = user_path_at(AT_FDCWD, name, lookup_flags, &path);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
return path_umount(&path, flags);
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
|
SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
|
||||||
{
|
{
|
||||||
return ksys_umount(name, flags);
|
return ksys_umount(name, flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user