Skip to content

Commit

Permalink
fs: add do_mkdirat() helper and ksys_mkdir() wrapper; remove in-kerne…
Browse files Browse the repository at this point in the history
…l 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/[email protected]

Cc: Al Viro <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Dominik Brodowski <[email protected]>
  • Loading branch information
Dominik Brodowski committed Apr 2, 2018
1 parent f459dff commit 0101db7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions fs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 vfs_path_lookup(struct dentry *, struct vfsmount *,
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_unlinkat(int dfd, struct filename *name);

Expand Down
9 changes: 7 additions & 2 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3803,7 +3803,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
}
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 path path;
Expand All @@ -3828,9 +3828,14 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
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)
{
return sys_mkdirat(AT_FDCWD, pathname, mode);
return do_mkdirat(AT_FDCWD, pathname, mode);
}

int vfs_rmdir(struct inode *dir, struct dentry *dentry)
Expand Down
7 changes: 7 additions & 0 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -972,4 +972,11 @@ static inline long ksys_rmdir(const char __user *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
2 changes: 1 addition & 1 deletion init/do_mounts_initrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void __init handle_initrd(void)
create_dev("/dev/root.old", Root_RAM0);
/* mount initrd on rootfs' /root */
mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
sys_mkdir("/old", 0700);
ksys_mkdir("/old", 0700);
ksys_chdir("/old");

/* try loading default modules from initrd */
Expand Down
2 changes: 1 addition & 1 deletion init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ static int __init do_name(void)
}
}
} else if (S_ISDIR(mode)) {
sys_mkdir(collected, mode);
ksys_mkdir(collected, mode);
sys_chown(collected, uid, gid);
sys_chmod(collected, mode);
dir_add(collected, mtime);
Expand Down
4 changes: 2 additions & 2 deletions init/noinitramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int __init default_rootfs(void)
{
int err;

err = sys_mkdir((const char __user __force *) "/dev", 0755);
err = ksys_mkdir((const char __user __force *) "/dev", 0755);
if (err < 0)
goto out;

Expand All @@ -39,7 +39,7 @@ static int __init default_rootfs(void)
if (err < 0)
goto out;

err = sys_mkdir((const char __user __force *) "/root", 0700);
err = ksys_mkdir((const char __user __force *) "/root", 0700);
if (err < 0)
goto out;

Expand Down

0 comments on commit 0101db7

Please sign in to comment.