* [PATCH] Separate out common fstatat code into vfs_fstatat
@ 2009-04-08 16:05 Oleg Drokin
2009-04-08 20:32 ` Christoph Hellwig
2009-04-08 20:34 ` [PATCH] kill vfs_stat_fd / vfs_lstat_fd Christoph Hellwig
0 siblings, 2 replies; 3+ messages in thread
From: Oleg Drokin @ 2009-04-08 16:05 UTC (permalink / raw)
To: linux-fsdevel; +Cc: linux-kernel
This is a version incorporating Christoph's suggestion.
Separate out common *fstatat functionality into a single function
instead of duplicating it all over the code.
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
arch/arm/kernel/sys_oabi-compat.c | 19 +++---------
arch/s390/kernel/compat_linux.c | 18 +++---------
arch/sparc/kernel/sys_sparc32.c | 19 +++---------
arch/x86/ia32/sys_ia32.c | 19 +++---------
fs/compat.c | 19 +++---------
fs/stat.c | 56 +++++++++++++++++++-------------------
include/linux/fs.h | 1
7 files changed, 54 insertions(+), 97 deletions(-)
Index: linux-2.6.29/arch/arm/kernel/sys_oabi-compat.c
===================================================================
--- linux-2.6.29.orig/arch/arm/kernel/sys_oabi-compat.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/arch/arm/kernel/sys_oabi-compat.c 2009-04-08 11:44:30.000000000 -0400
@@ -176,21 +176,12 @@
int flag)
{
struct kstat stat;
- int error = -EINVAL;
+ int error;
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_oldabi_stat64(&stat, statbuf);
-
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_oldabi_stat64(&stat, statbuf);
}
struct oabi_flock64 {
Index: linux-2.6.29/arch/s390/kernel/compat_linux.c
===================================================================
--- linux-2.6.29.orig/arch/s390/kernel/compat_linux.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/arch/s390/kernel/compat_linux.c 2009-04-08 11:44:38.000000000 -0400
@@ -702,20 +702,12 @@
struct stat64_emu31 __user* statbuf, int flag)
{
struct kstat stat;
- int error = -EINVAL;
+ int error;
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_stat64(statbuf, &stat);
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_stat64(statbuf, &stat);
}
/*
Index: linux-2.6.29/arch/sparc/kernel/sys_sparc32.c
===================================================================
--- linux-2.6.29.orig/arch/sparc/kernel/sys_sparc32.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/arch/sparc/kernel/sys_sparc32.c 2009-04-08 11:44:47.000000000 -0400
@@ -206,21 +206,12 @@
struct compat_stat64 __user * statbuf, int flag)
{
struct kstat stat;
- int error = -EINVAL;
-
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_compat_stat64(&stat, statbuf);
+ int error;
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_compat_stat64(&stat, statbuf);
}
asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
Index: linux-2.6.29/arch/x86/ia32/sys_ia32.c
===================================================================
--- linux-2.6.29.orig/arch/x86/ia32/sys_ia32.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/arch/x86/ia32/sys_ia32.c 2009-04-08 11:44:54.000000000 -0400
@@ -129,21 +129,12 @@
struct stat64 __user *statbuf, int flag)
{
struct kstat stat;
- int error = -EINVAL;
+ int error;
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_stat64(statbuf, &stat);
-
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_stat64(statbuf, &stat);
}
/*
Index: linux-2.6.29/fs/compat.c
===================================================================
--- linux-2.6.29.orig/fs/compat.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/fs/compat.c 2009-04-08 11:44:17.000000000 -0400
@@ -203,21 +203,12 @@
struct compat_stat __user *statbuf, int flag)
{
struct kstat stat;
- int error = -EINVAL;
-
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_compat_stat(&stat, statbuf);
+ int error;
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_compat_stat(&stat, statbuf);
}
#endif
Index: linux-2.6.29/fs/stat.c
===================================================================
--- linux-2.6.29.orig/fs/stat.c 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/fs/stat.c 2009-04-08 11:47:19.000000000 -0400
@@ -109,6 +109,24 @@
EXPORT_SYMBOL(vfs_fstat);
+int vfs_fstatat(int dfd, char __user *filename, struct kstat *stat, int flag)
+{
+ int error = -EINVAL;
+
+ if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
+ goto out;
+
+ if (flag & AT_SYMLINK_NOFOLLOW)
+ error = vfs_lstat_fd(dfd, filename, stat);
+ else
+ error = vfs_stat_fd(dfd, filename, stat);
+out:
+ return error;
+}
+
+EXPORT_SYMBOL(vfs_fstatat);
+
+
#ifdef __ARCH_WANT_OLD_STAT
/*
@@ -264,21 +282,12 @@
struct stat __user *, statbuf, int, flag)
{
struct kstat stat;
- int error = -EINVAL;
-
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_new_stat(&stat, statbuf);
+ int error;
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_new_stat(&stat, statbuf);
}
#endif
@@ -404,21 +413,12 @@
struct stat64 __user *, statbuf, int, flag)
{
struct kstat stat;
- int error = -EINVAL;
-
- if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
- goto out;
-
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, &stat);
- else
- error = vfs_stat_fd(dfd, filename, &stat);
-
- if (!error)
- error = cp_new_stat64(&stat, statbuf);
+ int error;
-out:
- return error;
+ error = vfs_fstatat(dfd, filename, &stat, flag);
+ if (error)
+ return error;
+ return cp_new_stat64(&stat, statbuf);
}
#endif /* __ARCH_WANT_STAT64 */
Index: linux-2.6.29/include/linux/fs.h
===================================================================
--- linux-2.6.29.orig/include/linux/fs.h 2009-04-08 01:47:52.000000000 -0400
+++ linux-2.6.29/include/linux/fs.h 2009-04-08 11:47:38.000000000 -0400
@@ -2075,6 +2075,7 @@
extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
extern int vfs_fstat(unsigned int, struct kstat *);
+extern int vfs_fstatat(int , char __user *, struct kstat *, int);
extern int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
unsigned long arg);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Separate out common fstatat code into vfs_fstatat
2009-04-08 16:05 [PATCH] Separate out common fstatat code into vfs_fstatat Oleg Drokin
@ 2009-04-08 20:32 ` Christoph Hellwig
2009-04-08 20:34 ` [PATCH] kill vfs_stat_fd / vfs_lstat_fd Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2009-04-08 20:32 UTC (permalink / raw)
To: Oleg Drokin; +Cc: linux-fsdevel, linux-kernel
On Wed, Apr 08, 2009 at 08:05:42PM +0400, Oleg Drokin wrote:
> This is a version incorporating Christoph's suggestion.
>
> Separate out common *fstatat functionality into a single function
> instead of duplicating it all over the code.
Looks good to me.
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] kill vfs_stat_fd / vfs_lstat_fd
2009-04-08 16:05 [PATCH] Separate out common fstatat code into vfs_fstatat Oleg Drokin
2009-04-08 20:32 ` Christoph Hellwig
@ 2009-04-08 20:34 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2009-04-08 20:34 UTC (permalink / raw)
To: Oleg Drokin; +Cc: linux-fsdevel, linux-kernel
There's really no reason to keep vfs_stat_fd and vfs_lstat_fd with
Oleg's vfs_fstatat. Use vfs_fstatat for the few cases having the
directory fd, and switch all others to vfs_stat / vfs_lstat.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Index: xfs/fs/compat.c
===================================================================
--- xfs.orig/fs/compat.c 2009-04-08 22:20:41.262444943 +0200
+++ xfs/fs/compat.c 2009-04-08 22:20:47.526445520 +0200
@@ -180,22 +180,24 @@ asmlinkage long compat_sys_newstat(char
struct compat_stat __user *statbuf)
{
struct kstat stat;
- int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
+ int error;
- if (!error)
- error = cp_compat_stat(&stat, statbuf);
- return error;
+ error = = vfs_stat(filename, &stat);
+ if (error)
+ return error;
+ return cp_compat_stat(&stat, statbuf);
}
asmlinkage long compat_sys_newlstat(char __user * filename,
struct compat_stat __user *statbuf)
{
struct kstat stat;
- int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
+ int error;
- if (!error)
- error = cp_compat_stat(&stat, statbuf);
- return error;
+ error = vfs_lstat(filename, &stat);
+ if (error)
+ return error;
+ return cp_compat_stat(&stat, statbuf);
}
#ifndef __ARCH_WANT_STAT64
Index: xfs/fs/stat.c
===================================================================
--- xfs.orig/fs/stat.c 2009-04-08 22:20:41.264445547 +0200
+++ xfs/fs/stat.c 2009-04-08 22:28:24.329448312 +0200
@@ -55,46 +55,6 @@ int vfs_getattr(struct vfsmount *mnt, st
EXPORT_SYMBOL(vfs_getattr);
-int vfs_stat_fd(int dfd, char __user *name, struct kstat *stat)
-{
- struct path path;
- int error;
-
- error = user_path_at(dfd, name, LOOKUP_FOLLOW, &path);
- if (!error) {
- error = vfs_getattr(path.mnt, path.dentry, stat);
- path_put(&path);
- }
- return error;
-}
-
-int vfs_stat(char __user *name, struct kstat *stat)
-{
- return vfs_stat_fd(AT_FDCWD, name, stat);
-}
-
-EXPORT_SYMBOL(vfs_stat);
-
-int vfs_lstat_fd(int dfd, char __user *name, struct kstat *stat)
-{
- struct path path;
- int error;
-
- error = user_path_at(dfd, name, 0, &path);
- if (!error) {
- error = vfs_getattr(path.mnt, path.dentry, stat);
- path_put(&path);
- }
- return error;
-}
-
-int vfs_lstat(char __user *name, struct kstat *stat)
-{
- return vfs_lstat_fd(AT_FDCWD, name, stat);
-}
-
-EXPORT_SYMBOL(vfs_lstat);
-
int vfs_fstat(unsigned int fd, struct kstat *stat)
{
struct file *f = fget(fd);
@@ -106,26 +66,43 @@ int vfs_fstat(unsigned int fd, struct ks
}
return error;
}
-
EXPORT_SYMBOL(vfs_fstat);
int vfs_fstatat(int dfd, char __user *filename, struct kstat *stat, int flag)
{
+ struct path path;
int error = -EINVAL;
+ int lookup_flags = 0;
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0)
goto out;
- if (flag & AT_SYMLINK_NOFOLLOW)
- error = vfs_lstat_fd(dfd, filename, stat);
- else
- error = vfs_stat_fd(dfd, filename, stat);
+ if (!(flag & AT_SYMLINK_NOFOLLOW))
+ lookup_flags |= LOOKUP_FOLLOW;
+
+ error = user_path_at(dfd, filename, lookup_flags, &path);
+ if (error)
+ goto out;
+
+ error = vfs_getattr(path.mnt, path.dentry, stat);
+ path_put(&path);
out:
return error;
}
-
EXPORT_SYMBOL(vfs_fstatat);
+int vfs_stat(char __user *name, struct kstat *stat)
+{
+ return vfs_fstatat(AT_FDCWD, name, stat, 0);
+}
+EXPORT_SYMBOL(vfs_stat);
+
+int vfs_lstat(char __user *name, struct kstat *stat)
+{
+ return vfs_fstatat(AT_FDCWD, name, stat, AT_SYMLINK_NOFOLLOW);
+}
+EXPORT_SYMBOL(vfs_lstat);
+
#ifdef __ARCH_WANT_OLD_STAT
@@ -173,23 +150,25 @@ static int cp_old_stat(struct kstat *sta
SYSCALL_DEFINE2(stat, char __user *, filename, struct __old_kernel_stat __user *, statbuf)
{
struct kstat stat;
- int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
+ int error;
- if (!error)
- error = cp_old_stat(&stat, statbuf);
+ error = vfs_stat(filename, &stat);
+ if (error)
+ return error;
- return error;
+ return cp_old_stat(&stat, statbuf);
}
SYSCALL_DEFINE2(lstat, char __user *, filename, struct __old_kernel_stat __user *, statbuf)
{
struct kstat stat;
- int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
+ int error;
- if (!error)
- error = cp_old_stat(&stat, statbuf);
+ error = vfs_lstat(filename, &stat);
+ if (error)
+ return error;
- return error;
+ return cp_old_stat(&stat, statbuf);
}
SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, statbuf)
@@ -258,23 +237,23 @@ static int cp_new_stat(struct kstat *sta
SYSCALL_DEFINE2(newstat, char __user *, filename, struct stat __user *, statbuf)
{
struct kstat stat;
- int error = vfs_stat_fd(AT_FDCWD, filename, &stat);
-
- if (!error)
- error = cp_new_stat(&stat, statbuf);
+ int error = vfs_stat(filename, &stat);
- return error;
+ if (error)
+ return error;
+ return cp_new_stat(&stat, statbuf);
}
SYSCALL_DEFINE2(newlstat, char __user *, filename, struct stat __user *, statbuf)
{
struct kstat stat;
- int error = vfs_lstat_fd(AT_FDCWD, filename, &stat);
+ int error;
- if (!error)
- error = cp_new_stat(&stat, statbuf);
+ error = vfs_lstat(filename, &stat);
+ if (error)
+ return error;
- return error;
+ return cp_new_stat(&stat, statbuf);
}
#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
Index: xfs/include/linux/fs.h
===================================================================
--- xfs.orig/include/linux/fs.h 2009-04-08 22:20:41.267529390 +0200
+++ xfs/include/linux/fs.h 2009-04-08 22:20:47.529528804 +0200
@@ -2223,8 +2223,6 @@ extern int vfs_readdir(struct file *, fi
extern int vfs_stat(char __user *, struct kstat *);
extern int vfs_lstat(char __user *, struct kstat *);
-extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
-extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
extern int vfs_fstat(unsigned int, struct kstat *);
extern int vfs_fstatat(int , char __user *, struct kstat *, int);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-04-08 20:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-08 16:05 [PATCH] Separate out common fstatat code into vfs_fstatat Oleg Drokin
2009-04-08 20:32 ` Christoph Hellwig
2009-04-08 20:34 ` [PATCH] kill vfs_stat_fd / vfs_lstat_fd Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).