Skip to content

Commit a1e6aaa

Browse files
author
Christoph Hellwig
committed
fs: refactor do_mount
Factor out a path_mount 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 38b0822 commit a1e6aaa

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

fs/namespace.c

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,12 +3115,11 @@ char *copy_mount_string(const void __user *data)
31153115
* Therefore, if this magic number is present, it carries no information
31163116
* and must be discarded.
31173117
*/
3118-
long do_mount(const char *dev_name, const char __user *dir_name,
3118+
static int path_mount(const char *dev_name, struct path *path,
31193119
const char *type_page, unsigned long flags, void *data_page)
31203120
{
3121-
struct path path;
31223121
unsigned int mnt_flags = 0, sb_flags;
3123-
int retval = 0;
3122+
int ret;
31243123

31253124
/* Discard magic */
31263125
if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
@@ -3133,19 +3132,13 @@ long do_mount(const char *dev_name, const char __user *dir_name,
31333132
if (flags & MS_NOUSER)
31343133
return -EINVAL;
31353134

3136-
/* ... and get the mountpoint */
3137-
retval = user_path_at(AT_FDCWD, dir_name, LOOKUP_FOLLOW, &path);
3138-
if (retval)
3139-
return retval;
3140-
3141-
retval = security_sb_mount(dev_name, &path,
3142-
type_page, flags, data_page);
3143-
if (!retval && !may_mount())
3144-
retval = -EPERM;
3145-
if (!retval && (flags & SB_MANDLOCK) && !may_mandlock())
3146-
retval = -EPERM;
3147-
if (retval)
3148-
goto dput_out;
3135+
ret = security_sb_mount(dev_name, path, type_page, flags, data_page);
3136+
if (ret)
3137+
return ret;
3138+
if (!may_mount())
3139+
return -EPERM;
3140+
if ((flags & SB_MANDLOCK) && !may_mandlock())
3141+
return -EPERM;
31493142

31503143
/* Default to relatime unless overriden */
31513144
if (!(flags & MS_NOATIME))
@@ -3172,7 +3165,7 @@ long do_mount(const char *dev_name, const char __user *dir_name,
31723165
((flags & (MS_NOATIME | MS_NODIRATIME | MS_RELATIME |
31733166
MS_STRICTATIME)) == 0)) {
31743167
mnt_flags &= ~MNT_ATIME_MASK;
3175-
mnt_flags |= path.mnt->mnt_flags & MNT_ATIME_MASK;
3168+
mnt_flags |= path->mnt->mnt_flags & MNT_ATIME_MASK;
31763169
}
31773170

31783171
sb_flags = flags & (SB_RDONLY |
@@ -3185,22 +3178,32 @@ long do_mount(const char *dev_name, const char __user *dir_name,
31853178
SB_I_VERSION);
31863179

31873180
if ((flags & (MS_REMOUNT | MS_BIND)) == (MS_REMOUNT | MS_BIND))
3188-
retval = do_reconfigure_mnt(&path, mnt_flags);
3189-
else if (flags & MS_REMOUNT)
3190-
retval = do_remount(&path, flags, sb_flags, mnt_flags,
3191-
data_page);
3192-
else if (flags & MS_BIND)
3193-
retval = do_loopback(&path, dev_name, flags & MS_REC);
3194-
else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
3195-
retval = do_change_type(&path, flags);
3196-
else if (flags & MS_MOVE)
3197-
retval = do_move_mount_old(&path, dev_name);
3198-
else
3199-
retval = do_new_mount(&path, type_page, sb_flags, mnt_flags,
3200-
dev_name, data_page);
3201-
dput_out:
3181+
return do_reconfigure_mnt(path, mnt_flags);
3182+
if (flags & MS_REMOUNT)
3183+
return do_remount(path, flags, sb_flags, mnt_flags, data_page);
3184+
if (flags & MS_BIND)
3185+
return do_loopback(path, dev_name, flags & MS_REC);
3186+
if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
3187+
return do_change_type(path, flags);
3188+
if (flags & MS_MOVE)
3189+
return do_move_mount_old(path, dev_name);
3190+
3191+
return do_new_mount(path, type_page, sb_flags, mnt_flags, dev_name,
3192+
data_page);
3193+
}
3194+
3195+
long do_mount(const char *dev_name, const char __user *dir_name,
3196+
const char *type_page, unsigned long flags, void *data_page)
3197+
{
3198+
struct path path;
3199+
int ret;
3200+
3201+
ret = user_path_at(AT_FDCWD, dir_name, LOOKUP_FOLLOW, &path);
3202+
if (ret)
3203+
return ret;
3204+
ret = path_mount(dev_name, &path, type_page, flags, data_page);
32023205
path_put(&path);
3203-
return retval;
3206+
return ret;
32043207
}
32053208

32063209
static struct ucounts *inc_mnt_namespaces(struct user_namespace *ns)

0 commit comments

Comments
 (0)