Skip to content

Commit 46ea89e

Browse files
author
Dominik Brodowski
committed
fs: add do_linkat() helper and ksys_link() wrapper; remove in-kernel calls to syscall
Using the fs-internal do_linkat() helper allows us to get rid of fs-internal calls to the sys_linkat() syscall. Introducing the ksys_link() wrapper allows us to avoid the in-kernel calls to sys_link() 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_link(). In the near future, the only fs-external user of ksys_link() should be converted to use vfs_link() instead. 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 87c4e19 commit 46ea89e

4 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎fs/internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ long do_rmdir(int dfd, const char __user *pathname);
6262
long do_unlinkat(int dfd, struct filename *name);
6363
long do_symlinkat(const char __user *oldname, int newdfd,
6464
const char __user *newname);
65+
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
66+
const char __user *newname, int flags);
6567

6668
/*
6769
* namespace.c

‎fs/namei.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,8 +4250,8 @@ EXPORT_SYMBOL(vfs_link);
42504250
* with linux 2.0, and to avoid hard-linking to directories
42514251
* and other special files. --ADM
42524252
*/
4253-
SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
4254-
int, newdfd, const char __user *, newname, int, flags)
4253+
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
4254+
const char __user *newname, int flags)
42554255
{
42564256
struct dentry *new_dentry;
42574257
struct path old_path, new_path;
@@ -4315,9 +4315,15 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
43154315
return error;
43164316
}
43174317

4318+
SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
4319+
int, newdfd, const char __user *, newname, int, flags)
4320+
{
4321+
return do_linkat(olddfd, oldname, newdfd, newname, flags);
4322+
}
4323+
43184324
SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname)
43194325
{
4320-
return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
4326+
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
43214327
}
43224328

43234329
/**

‎include/linux/syscalls.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,13 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode,
997997
return do_mknodat(AT_FDCWD, filename, mode, dev);
998998
}
999999

1000+
extern int do_linkat(int olddfd, const char __user *oldname, int newdfd,
1001+
const char __user *newname, int flags);
1002+
1003+
static inline long ksys_link(const char __user *oldname,
1004+
const char __user *newname)
1005+
{
1006+
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
1007+
}
1008+
10001009
#endif

‎init/initramfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static int __init maybe_link(void)
306306
if (nlink >= 2) {
307307
char *old = find_link(major, minor, ino, mode, collected);
308308
if (old)
309-
return (sys_link(old, collected) < 0) ? -1 : 1;
309+
return (ksys_link(old, collected) < 0) ? -1 : 1;
310310
}
311311
return 0;
312312
}

0 commit comments

Comments
 (0)