Skip to content

Commit 41525f5

Browse files
author
Christoph Hellwig
committed
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 <[email protected]>
1 parent a1e6aaa commit 41525f5

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

fs/namespace.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,36 +1706,19 @@ static inline bool may_mandlock(void)
17061706
}
17071707
#endif
17081708

1709-
/*
1710-
* Now umount can handle mount points as well as block devices.
1711-
* This is important for filesystems which use unnamed block devices.
1712-
*
1713-
* We now support a flag for forced unmount like the other 'big iron'
1714-
* unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
1715-
*/
1716-
1717-
int ksys_umount(char __user *name, int flags)
1709+
static int path_umount(struct path *path, int flags)
17181710
{
1719-
struct path path;
17201711
struct mount *mnt;
17211712
int retval;
1722-
int lookup_flags = LOOKUP_MOUNTPOINT;
17231713

17241714
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
17251715
return -EINVAL;
1726-
17271716
if (!may_mount())
17281717
return -EPERM;
17291718

1730-
if (!(flags & UMOUNT_NOFOLLOW))
1731-
lookup_flags |= LOOKUP_FOLLOW;
1732-
1733-
retval = user_path_at(AT_FDCWD, name, lookup_flags, &path);
1734-
if (retval)
1735-
goto out;
1736-
mnt = real_mount(path.mnt);
1719+
mnt = real_mount(path->mnt);
17371720
retval = -EINVAL;
1738-
if (path.dentry != path.mnt->mnt_root)
1721+
if (path->dentry != path->mnt->mnt_root)
17391722
goto dput_and_out;
17401723
if (!check_mnt(mnt))
17411724
goto dput_and_out;
@@ -1748,12 +1731,25 @@ int ksys_umount(char __user *name, int flags)
17481731
retval = do_umount(mnt, flags);
17491732
dput_and_out:
17501733
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
1751-
dput(path.dentry);
1734+
dput(path->dentry);
17521735
mntput_no_expire(mnt);
1753-
out:
17541736
return retval;
17551737
}
17561738

1739+
int ksys_umount(char __user *name, int flags)
1740+
{
1741+
int lookup_flags = LOOKUP_MOUNTPOINT;
1742+
struct path path;
1743+
int ret;
1744+
1745+
if (!(flags & UMOUNT_NOFOLLOW))
1746+
lookup_flags |= LOOKUP_FOLLOW;
1747+
ret = user_path_at(AT_FDCWD, name, lookup_flags, &path);
1748+
if (ret)
1749+
return ret;
1750+
return path_umount(&path, flags);
1751+
}
1752+
17571753
SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
17581754
{
17591755
return ksys_umount(name, flags);

0 commit comments

Comments
 (0)