Commit 0101db7a authored by Dominik Brodowski's avatar Dominik Brodowski

fs: add do_mkdirat() helper and ksys_mkdir() wrapper; remove in-kernel calls to syscall

Using the fs-internal do_mkdirat() helper allows us to get rid of
fs-internal calls to the sys_mkdirat() syscall.

Introducing the ksys_mkdir() wrapper allows us to avoid the in-kernel calls
to the sys_mkdir() syscall. The ksys_ prefix denotes that this function is
meant as a drop-in replacement for the syscall. In particular, it uses the
same calling convention as sys_mkdir().

This patch is part of a series which removes in-kernel calls to syscalls.
On this basis, the syscall entry path can be streamlined. For details, see
http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net

Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent f459dffa
...@@ -55,6 +55,7 @@ extern void __init chrdev_init(void); ...@@ -55,6 +55,7 @@ extern void __init chrdev_init(void);
extern int user_path_mountpoint_at(int, const char __user *, unsigned int, struct path *); extern int user_path_mountpoint_at(int, const char __user *, unsigned int, struct path *);
extern int vfs_path_lookup(struct dentry *, struct vfsmount *, extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
const char *, unsigned int, struct path *); const char *, unsigned int, struct path *);
long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
long do_rmdir(int dfd, const char __user *pathname); long do_rmdir(int dfd, const char __user *pathname);
long do_unlinkat(int dfd, struct filename *name); long do_unlinkat(int dfd, struct filename *name);
......
...@@ -3803,7 +3803,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -3803,7 +3803,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
} }
EXPORT_SYMBOL(vfs_mkdir); EXPORT_SYMBOL(vfs_mkdir);
SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) long do_mkdirat(int dfd, const char __user *pathname, umode_t mode)
{ {
struct dentry *dentry; struct dentry *dentry;
struct path path; struct path path;
...@@ -3828,9 +3828,14 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode) ...@@ -3828,9 +3828,14 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
return error; return error;
} }
SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
{
return do_mkdirat(dfd, pathname, mode);
}
SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode) SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode)
{ {
return sys_mkdirat(AT_FDCWD, pathname, mode); return do_mkdirat(AT_FDCWD, pathname, mode);
} }
int vfs_rmdir(struct inode *dir, struct dentry *dentry) int vfs_rmdir(struct inode *dir, struct dentry *dentry)
......
...@@ -972,4 +972,11 @@ static inline long ksys_rmdir(const char __user *pathname) ...@@ -972,4 +972,11 @@ static inline long ksys_rmdir(const char __user *pathname)
return do_rmdir(AT_FDCWD, pathname); return do_rmdir(AT_FDCWD, pathname);
} }
extern long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
static inline long ksys_mkdir(const char __user *pathname, umode_t mode)
{
return do_mkdirat(AT_FDCWD, pathname, mode);
}
#endif #endif
...@@ -60,7 +60,7 @@ static void __init handle_initrd(void) ...@@ -60,7 +60,7 @@ static void __init handle_initrd(void)
create_dev("/dev/root.old", Root_RAM0); create_dev("/dev/root.old", Root_RAM0);
/* mount initrd on rootfs' /root */ /* mount initrd on rootfs' /root */
mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
sys_mkdir("/old", 0700); ksys_mkdir("/old", 0700);
ksys_chdir("/old"); ksys_chdir("/old");
/* try loading default modules from initrd */ /* try loading default modules from initrd */
......
...@@ -352,7 +352,7 @@ static int __init do_name(void) ...@@ -352,7 +352,7 @@ static int __init do_name(void)
} }
} }
} else if (S_ISDIR(mode)) { } else if (S_ISDIR(mode)) {
sys_mkdir(collected, mode); ksys_mkdir(collected, mode);
sys_chown(collected, uid, gid); sys_chown(collected, uid, gid);
sys_chmod(collected, mode); sys_chmod(collected, mode);
dir_add(collected, mtime); dir_add(collected, mtime);
......
...@@ -29,7 +29,7 @@ static int __init default_rootfs(void) ...@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
{ {
int err; int err;
err = sys_mkdir((const char __user __force *) "/dev", 0755); err = ksys_mkdir((const char __user __force *) "/dev", 0755);
if (err < 0) if (err < 0)
goto out; goto out;
...@@ -39,7 +39,7 @@ static int __init default_rootfs(void) ...@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
if (err < 0) if (err < 0)
goto out; goto out;
err = sys_mkdir((const char __user __force *) "/root", 0700); err = ksys_mkdir((const char __user __force *) "/root", 0700);
if (err < 0) if (err < 0)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment