Skip to content

Commit 0f32ab8

Browse files
author
Dominik Brodowski
committed
fs: add ksys_unlink() wrapper; remove in-kernel calls to sys_unlink()
Using this wrapper allows us to avoid the in-kernel calls to the sys_unlink() syscall. The ksys_ prefix denotes that this function is meant s a drop-in replacement for the syscall. In particular, it uses the same calling convention as sys_unlink(). In the near future, all callers of ksys_unlink() should be converted to call do_unlinkat() directly or, at least, to operate on regular kernel pointers. 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: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent 447016e commit 0f32ab8

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎include/linux/syscalls.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,4 +954,15 @@ int ksys_chroot(const char __user *filename);
954954
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
955955
int ksys_chdir(const char __user *filename);
956956

957+
/*
958+
* The following kernel syscall equivalents are just wrappers to fs-internal
959+
* functions. Therefore, provide stubs to be inlined at the callsites.
960+
*/
961+
extern long do_unlinkat(int dfd, struct filename *name);
962+
963+
static inline long ksys_unlink(const char __user *pathname)
964+
{
965+
return do_unlinkat(AT_FDCWD, getname(pathname));
966+
}
967+
957968
#endif

‎init/do_mounts.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern int root_mountflags;
1616

1717
static inline int create_dev(char *name, dev_t dev)
1818
{
19-
sys_unlink(name);
19+
ksys_unlink(name);
2020
return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
2121
}
2222

‎init/do_mounts_initrd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ bool __init initrd_load(void)
128128
* mounted in the normal path.
129129
*/
130130
if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
131-
sys_unlink("/initrd.image");
131+
ksys_unlink("/initrd.image");
132132
handle_initrd();
133133
return true;
134134
}
135135
}
136-
sys_unlink("/initrd.image");
136+
ksys_unlink("/initrd.image");
137137
return false;
138138
}

‎init/do_mounts_rd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ int __init rd_load_image(char *from)
288288
sys_close(out_fd);
289289
out:
290290
kfree(buf);
291-
sys_unlink("/dev/ram");
291+
ksys_unlink("/dev/ram");
292292
return res;
293293
}
294294

‎init/initramfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static void __init clean_path(char *path, umode_t fmode)
319319
if (S_ISDIR(st.mode))
320320
sys_rmdir(path);
321321
else
322-
sys_unlink(path);
322+
ksys_unlink(path);
323323
}
324324
}
325325

@@ -591,7 +591,7 @@ static void __init clean_rootfs(void)
591591
if (S_ISDIR(st.mode))
592592
sys_rmdir(dirp->d_name);
593593
else
594-
sys_unlink(dirp->d_name);
594+
ksys_unlink(dirp->d_name);
595595
}
596596

597597
num -= dirp->d_reclen;

0 commit comments

Comments
 (0)