]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
fs: add ksys_ftruncate() wrapper; remove in-kernel calls to sys_ftruncate()
authorDominik Brodowski <linux@dominikbrodowski.net>
Sun, 11 Mar 2018 10:34:54 +0000 (11:34 +0100)
committerDominik Brodowski <linux@dominikbrodowski.net>
Mon, 2 Apr 2018 18:16:00 +0000 (20:16 +0200)
Using the ksys_ftruncate() wrapper allows us to get rid of in-kernel
calls to the sys_ftruncate() 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_ftruncate().

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>
arch/mips/kernel/linux32.c
arch/parisc/kernel/sys_parisc.c
arch/powerpc/kernel/sys_ppc32.c
arch/s390/kernel/compat_linux.c
arch/sparc/kernel/sys_sparc32.c
arch/x86/ia32/sys_ia32.c
fs/internal.h
fs/open.c
include/linux/syscalls.h
init/initramfs.c

index b332f6fc1e726f048d2db25c365e5148bae81158..3c90449742a0b485d6e342ea6199f9f8e73b6007 100644 (file)
@@ -88,7 +88,7 @@ SYSCALL_DEFINE4(32_truncate64, const char __user *, path,
 SYSCALL_DEFINE4(32_ftruncate64, unsigned long, fd, unsigned long, __dummy,
        unsigned long, a2, unsigned long, a3)
 {
-       return sys_ftruncate(fd, merge_64(a2, a3));
+       return ksys_ftruncate(fd, merge_64(a2, a3));
 }
 
 SYSCALL_DEFINE5(32_llseek, unsigned int, fd, unsigned int, offset_high,
index 378a754ca1867fb17d48625150a707dd95675b87..6d2a64859c22bda036060d4cf4013abe00865af3 100644 (file)
@@ -298,7 +298,7 @@ asmlinkage long parisc_truncate64(const char __user * path,
 asmlinkage long parisc_ftruncate64(unsigned int fd,
                                        unsigned int high, unsigned int low)
 {
-       return sys_ftruncate(fd, (long)high << 32 | low);
+       return ksys_ftruncate(fd, (long)high << 32 | low);
 }
 
 /* stubs for the benefit of the syscall_table since truncate64 and truncate 
@@ -309,7 +309,7 @@ asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
 }
 asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
 {
-       return sys_ftruncate(fd, length);
+       return ksys_ftruncate(fd, length);
 }
 asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
 {
index 15f216d022e220252982302029f42f84b68ab3ba..e0c9b7f1bf380c63f27c45234efbd6ab42deeb21 100644 (file)
@@ -107,7 +107,7 @@ asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
 asmlinkage int compat_sys_ftruncate64(unsigned int fd, u32 reg4, unsigned long high,
                                 unsigned long low)
 {
-       return sys_ftruncate(fd, (high << 32) | low);
+       return ksys_ftruncate(fd, (high << 32) | low);
 }
 
 long ppc32_fadvise64(int fd, u32 unused, u32 offset_high, u32 offset_low,
index 9a9bb395359c2eed848351d31fe8682717a3404e..9c5e975f71a6375f74b431906e41f3d55f89e8a8 100644 (file)
@@ -307,7 +307,7 @@ COMPAT_SYSCALL_DEFINE3(s390_truncate64, const char __user *, path, u32, high, u3
 
 COMPAT_SYSCALL_DEFINE3(s390_ftruncate64, unsigned int, fd, u32, high, u32, low)
 {
-       return sys_ftruncate(fd, (unsigned long)high << 32 | low);
+       return ksys_ftruncate(fd, (unsigned long)high << 32 | low);
 }
 
 COMPAT_SYSCALL_DEFINE5(s390_pread64, unsigned int, fd, char __user *, ubuf,
index 6d964bdefbaa96ca74e9c2ea84cb4caba0708fdb..d64b425fff931cd2e46a87a3daabeb79a5218458 100644 (file)
@@ -65,7 +65,7 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned
        if ((int)high < 0)
                return -EINVAL;
        else
-               return sys_ftruncate(fd, (high << 32) | low);
+               return ksys_ftruncate(fd, (high << 32) | low);
 }
 
 static int cp_compat_stat64(struct kstat *stat,
index 23a5260eae677be4787f94059b290b6ca6b50844..1979e5b4ad9a1271d49f251b556bc3feb4a4d99f 100644 (file)
@@ -61,7 +61,7 @@ COMPAT_SYSCALL_DEFINE3(x86_truncate64, const char __user *, filename,
 COMPAT_SYSCALL_DEFINE3(x86_ftruncate64, unsigned int, fd,
                       unsigned long, offset_low, unsigned long, offset_high)
 {
-       return sys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
+       return ksys_ftruncate(fd, ((loff_t) offset_high << 32) | offset_low);
 }
 
 /*
index c797480cbd6f3d6f924ddb4357f405247f7dbf5f..980d005b21b4111084ab7a56b17fda7e5b1320f5 100644 (file)
@@ -119,6 +119,7 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname,
 extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
                const char *, const struct open_flags *);
 
+long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
 long do_faccessat(int dfd, const char __user *filename, int mode);
 int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
 int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
index 7b2eccb541f2cbb1006ca1e5206fbbc1c5872ee7..b3f3b2cd9f1993c25e8ea24ae026936f74e74524 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -162,7 +162,7 @@ COMPAT_SYSCALL_DEFINE2(truncate, const char __user *, path, compat_off_t, length
 }
 #endif
 
-static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
+long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
 {
        struct inode *inode;
        struct dentry *dentry;
index df0d1e818a6e22066a0b119f48a7b97068b83741..41023177c8ecf30c45b02475ed54f3a267cefbcf 100644 (file)
@@ -1038,4 +1038,11 @@ static inline long ksys_lchown(const char __user *filename, uid_t user,
                             AT_SYMLINK_NOFOLLOW);
 }
 
+extern long do_sys_ftruncate(unsigned int fd, loff_t length, int small);
+
+static inline long ksys_ftruncate(unsigned int fd, unsigned long length)
+{
+       return do_sys_ftruncate(fd, length, 1);
+}
+
 #endif
index 35173bef7c00d59329d443e5602b09f3a801548b..0d3b001b0dc534a9345e0af490845818ab5c4af1 100644 (file)
@@ -346,7 +346,7 @@ static int __init do_name(void)
                                ksys_fchown(wfd, uid, gid);
                                ksys_fchmod(wfd, mode);
                                if (body_len)
-                                       sys_ftruncate(wfd, body_len);
+                                       ksys_ftruncate(wfd, body_len);
                                vcollected = kstrdup(collected, GFP_KERNEL);
                                state = CopyFile;
                        }