Commit bae217ea authored by Dominik Brodowski's avatar Dominik Brodowski

fs: add ksys_open() wrapper; remove in-kernel calls to sys_open()

Using this wrapper allows us to avoid the in-kernel calls to the
sys_open() 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_open().

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 2ca2a09d
...@@ -1151,7 +1151,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla ...@@ -1151,7 +1151,7 @@ COMPAT_SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, fla
*/ */
SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode) SYSCALL_DEFINE2(creat, const char __user *, pathname, umode_t, mode)
{ {
return sys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode); return ksys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
} }
#endif #endif
......
...@@ -1057,4 +1057,15 @@ static inline int ksys_close(unsigned int fd) ...@@ -1057,4 +1057,15 @@ static inline int ksys_close(unsigned int fd)
return __close_fd(current->files, fd); return __close_fd(current->files, fd);
} }
extern long do_sys_open(int dfd, const char __user *filename, int flags,
umode_t mode);
static inline long ksys_open(const char __user *filename, int flags,
umode_t mode)
{
if (force_o_largefile())
flags |= O_LARGEFILE;
return do_sys_open(AT_FDCWD, filename, flags, mode);
}
#endif #endif
...@@ -489,13 +489,13 @@ void __init change_floppy(char *fmt, ...) ...@@ -489,13 +489,13 @@ void __init change_floppy(char *fmt, ...)
va_start(args, fmt); va_start(args, fmt);
vsprintf(buf, fmt, args); vsprintf(buf, fmt, args);
va_end(args); va_end(args);
fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0);
if (fd >= 0) { if (fd >= 0) {
sys_ioctl(fd, FDEJECT, 0); sys_ioctl(fd, FDEJECT, 0);
ksys_close(fd); ksys_close(fd);
} }
printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
fd = sys_open("/dev/console", O_RDWR, 0); fd = ksys_open("/dev/console", O_RDWR, 0);
if (fd >= 0) { if (fd >= 0) {
sys_ioctl(fd, TCGETS, (long)&termios); sys_ioctl(fd, TCGETS, (long)&termios);
termios.c_lflag &= ~ICANON; termios.c_lflag &= ~ICANON;
......
...@@ -38,7 +38,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new) ...@@ -38,7 +38,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
{ {
sys_unshare(CLONE_FS | CLONE_FILES); sys_unshare(CLONE_FS | CLONE_FILES);
/* stdin/stdout/stderr for /linuxrc */ /* stdin/stdout/stderr for /linuxrc */
sys_open("/dev/console", O_RDWR, 0); ksys_open("/dev/console", O_RDWR, 0);
ksys_dup(0); ksys_dup(0);
ksys_dup(0); ksys_dup(0);
/* move initrd over / and chdir/chroot in initrd root */ /* move initrd over / and chdir/chroot in initrd root */
...@@ -99,7 +99,7 @@ static void __init handle_initrd(void) ...@@ -99,7 +99,7 @@ static void __init handle_initrd(void)
if (!error) if (!error)
printk("okay\n"); printk("okay\n");
else { else {
int fd = sys_open("/dev/root.old", O_RDWR, 0); int fd = ksys_open("/dev/root.old", O_RDWR, 0);
if (error == -ENOENT) if (error == -ENOENT)
printk("/initrd does not exist. Ignored.\n"); printk("/initrd does not exist. Ignored.\n");
else else
......
...@@ -181,7 +181,7 @@ static void __init md_setup_drive(void) ...@@ -181,7 +181,7 @@ static void __init md_setup_drive(void)
partitioned ? "_d" : "", minor, partitioned ? "_d" : "", minor,
md_setup_args[ent].device_names); md_setup_args[ent].device_names);
fd = sys_open(name, 0, 0); fd = ksys_open(name, 0, 0);
if (fd < 0) { if (fd < 0) {
printk(KERN_ERR "md: open failed - cannot start " printk(KERN_ERR "md: open failed - cannot start "
"array %s\n", name); "array %s\n", name);
...@@ -244,7 +244,7 @@ static void __init md_setup_drive(void) ...@@ -244,7 +244,7 @@ static void __init md_setup_drive(void)
* array without it * array without it
*/ */
ksys_close(fd); ksys_close(fd);
fd = sys_open(name, 0, 0); fd = ksys_open(name, 0, 0);
sys_ioctl(fd, BLKRRPART, 0); sys_ioctl(fd, BLKRRPART, 0);
} }
ksys_close(fd); ksys_close(fd);
...@@ -294,7 +294,7 @@ static void __init autodetect_raid(void) ...@@ -294,7 +294,7 @@ static void __init autodetect_raid(void)
wait_for_device_probe(); wait_for_device_probe();
fd = sys_open("/dev/md0", 0, 0); fd = ksys_open("/dev/md0", 0, 0);
if (fd >= 0) { if (fd >= 0) {
sys_ioctl(fd, RAID_AUTORUN, raid_autopart); sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
ksys_close(fd); ksys_close(fd);
......
...@@ -196,11 +196,11 @@ int __init rd_load_image(char *from) ...@@ -196,11 +196,11 @@ int __init rd_load_image(char *from)
char rotator[4] = { '|' , '/' , '-' , '\\' }; char rotator[4] = { '|' , '/' , '-' , '\\' };
#endif #endif
out_fd = sys_open("/dev/ram", O_RDWR, 0); out_fd = ksys_open("/dev/ram", O_RDWR, 0);
if (out_fd < 0) if (out_fd < 0)
goto out; goto out;
in_fd = sys_open(from, O_RDONLY, 0); in_fd = ksys_open(from, O_RDONLY, 0);
if (in_fd < 0) if (in_fd < 0)
goto noclose_input; goto noclose_input;
...@@ -262,7 +262,7 @@ int __init rd_load_image(char *from) ...@@ -262,7 +262,7 @@ int __init rd_load_image(char *from)
goto noclose_input; goto noclose_input;
} }
change_floppy("disk #%d", disk); change_floppy("disk #%d", disk);
in_fd = sys_open(from, O_RDONLY, 0); in_fd = ksys_open(from, O_RDONLY, 0);
if (in_fd < 0) { if (in_fd < 0) {
printk("Error opening disk.\n"); printk("Error opening disk.\n");
goto noclose_input; goto noclose_input;
......
...@@ -340,7 +340,7 @@ static int __init do_name(void) ...@@ -340,7 +340,7 @@ static int __init do_name(void)
int openflags = O_WRONLY|O_CREAT; int openflags = O_WRONLY|O_CREAT;
if (ml != 1) if (ml != 1)
openflags |= O_TRUNC; openflags |= O_TRUNC;
wfd = sys_open(collected, openflags, mode); wfd = ksys_open(collected, openflags, mode);
if (wfd >= 0) { if (wfd >= 0) {
ksys_fchown(wfd, uid, gid); ksys_fchown(wfd, uid, gid);
...@@ -567,7 +567,7 @@ static void __init clean_rootfs(void) ...@@ -567,7 +567,7 @@ static void __init clean_rootfs(void)
struct linux_dirent64 *dirp; struct linux_dirent64 *dirp;
int num; int num;
fd = sys_open("/", O_RDONLY, 0); fd = ksys_open("/", O_RDONLY, 0);
WARN_ON(fd < 0); WARN_ON(fd < 0);
if (fd < 0) if (fd < 0)
return; return;
...@@ -629,7 +629,7 @@ static int __init populate_rootfs(void) ...@@ -629,7 +629,7 @@ static int __init populate_rootfs(void)
} }
printk(KERN_INFO "rootfs image is not initramfs (%s)" printk(KERN_INFO "rootfs image is not initramfs (%s)"
"; looks like an initrd\n", err); "; looks like an initrd\n", err);
fd = sys_open("/initrd.image", fd = ksys_open("/initrd.image",
O_WRONLY|O_CREAT, 0700); O_WRONLY|O_CREAT, 0700);
if (fd >= 0) { if (fd >= 0) {
ssize_t written = xwrite(fd, (char *)initrd_start, ssize_t written = xwrite(fd, (char *)initrd_start,
......
...@@ -1074,7 +1074,7 @@ static noinline void __init kernel_init_freeable(void) ...@@ -1074,7 +1074,7 @@ static noinline void __init kernel_init_freeable(void)
do_basic_setup(); do_basic_setup();
/* Open the /dev/console on the rootfs, this should never fail */ /* Open the /dev/console on the rootfs, this should never fail */
if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
pr_err("Warning: unable to open an initial console.\n"); pr_err("Warning: unable to open an initial console.\n");
(void) ksys_dup(0); (void) ksys_dup(0);
......
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