stat cleanups (resend)
Hi Al,
a bunch of cleanups to untangle our mess of state related helpers.
Diffstat:
fs/stat.c | 70 +++++++++++++++++++++------------------------------ include/linux/fs.h | 22 +++------------- include/linux/stat.h | 2 - 3 files changed, 34 insertions(+), 60 deletions(-)
PATCH 1/5 fs: remove vfs_statx_fd
vfs_statx_fd is only used to implement vfs_fstat. Remove vfs_statx_fd and just implement vfs_fstat directly.
--- fs/stat.c | 22 +++++++--------------- include/linux/fs.h | 7 +------ 2 files changed, 8 insertions(+), 21 deletions(-)
fs/stat.c +7 -15
@@ -126,35 +126,27 @@ int vfs_getattr(const struct path *path, struct kstat *stat,EXPORT_SYMBOL (vfs_getattr);/** -* vfs_statx_fd - Get the enhanced basic attributes by file descriptor +* vfs_fstat - Get the basic attributes by file descriptor * @fd: The file descriptor referring to the file of interest * @stat: The result structure to fill in. -* @request_mask: STATX_xxx flags indicating what the caller wants -* @query_flags: Query mode (KSTAT_QUERY_FLAGS) * * This function is a wrapper around vfs_getattr(). The main difference is * that it uses a file descriptor to determine the file location. * * 0 will be returned on success, and a -ve error code if unsuccessful. */ -int vfs_statx_fd (unsigned int fd,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int vfs_fstat (int fd,struct kstat *stat) {struct fd f; -int error = -EBADF ; - -if (query_flags & ~KSTAT_QUERY_FLAGS ) -return -EINVAL ; +int error; f =fdget_raw (fd); -if (f.file) { - error =vfs_getattr (&f.file->f_path, stat, - request_mask, query_flags); -fdput (f); - } +if (!f.file) +return -EBADF ; + error =vfs_getattr (&f.file->f_path, stat,STATX_BASIC_STATS ,0 ); +fdput (f);return error; } -EXPORT_SYMBOL (vfs_statx_fd);static inline unsigned vfs_stat_set_lookup_flags (unsigned *lookup_flags,int flags)
include/linux/fs.h +1 -6
@@ -3166,7 +3166,7 @@ extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *);extern int vfs_statx (int ,const char __user *,int ,struct kstat *,u32 ); -extern int vfs_statx_fd (unsigned int ,struct kstat *,u32 ,unsigned int ); +int vfs_fstat (int fd,struct kstat *stat);static inline int vfs_stat (const char __user *filename,struct kstat *stat) {
@@ -3184,11 +3184,6 @@ static inline int vfs_fstatat(int dfd, const char __user *filename,return vfs_statx (dfd, filename, flags |AT_NO_AUTOMOUNT , stat,STATX_BASIC_STATS ); } -static inline int vfs_fstat (int fd,struct kstat *stat) -{ -return vfs_statx_fd (fd, stat,STATX_BASIC_STATS ,0 ); -} -extern const char *vfs_get_link (struct dentry *,struct delayed_call *);extern int vfs_readlink (struct dentry *,char __user *,int );
Signature · 1 line
2.28.0
PATCH 2/5 fs: implement vfs_stat and vfs_lstat in terms of vfs_fstatat
In reply to Christoph HellwigGo through vfs_fstatat instead of duplicating the *stat to statx mapping three times.
--- include/linux/fs.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
include/linux/fs.h +7 -9
@@ -3168,21 +3168,19 @@ extern int iterate_dir(struct file *, struct dir_context *);extern int vfs_statx (int ,const char __user *,int ,struct kstat *,u32 );int vfs_fstat (int fd,struct kstat *stat); -static inline int vfs_stat (const char __user *filename,struct kstat *stat) +static inline int vfs_fstatat (int dfd,const char __user *filename, +struct kstat *stat,int flags) { -return vfs_statx (AT_FDCWD , filename,AT_NO_AUTOMOUNT , +return vfs_statx (dfd, filename, flags |AT_NO_AUTOMOUNT , stat,STATX_BASIC_STATS ); } -static inline int vfs_lstat (const char __user *name,struct kstat *stat) +static inline int vfs_stat (const char __user *filename,struct kstat *stat) { -return vfs_statx (AT_FDCWD , name,AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT , - stat,STATX_BASIC_STATS ); +return vfs_fstatat (AT_FDCWD , filename, stat,0 ); } -static inline int vfs_fstatat (int dfd,const char __user *filename, -struct kstat *stat,int flags) +static inline int vfs_lstat (const char __user *name,struct kstat *stat) { -return vfs_statx (dfd, filename, flags |AT_NO_AUTOMOUNT , - stat,STATX_BASIC_STATS ); +return vfs_fstatat (AT_FDCWD , name, stat,AT_SYMLINK_NOFOLLOW ); }extern const char *vfs_get_link (struct dentry *,struct delayed_call *);
Signature · 1 line
2.28.0
PATCH 3/5 fs: move vfs_fstatat out of line
In reply to Christoph HellwigThis allows to keep vfs_statx static in fs/stat.c to prepare for the following changes.
--- fs/stat.c | 9 +++++++-- include/linux/fs.h | 9 ++------- 2 files changed, 9 insertions(+), 9 deletions(-)
fs/stat.c +7 -2
@@ -181,7 +181,7 @@ static inline unsigned vfs_stat_set_lookup_flags(unsigned *lookup_flags,* * 0 will be returned on success, and a -ve error code if unsuccessful. */ -int vfs_statx (int dfd,const char __user *filename,int flags, +static int vfs_statx (int dfd,const char __user *filename,int flags,struct kstat *stat,u32 request_mask) {struct path path;
@@ -209,8 +209,13 @@ int vfs_statx(int dfd, const char __user *filename, int flags, out:return error; } -EXPORT_SYMBOL (vfs_statx); +int vfs_fstatat (int dfd,const char __user *filename, +struct kstat *stat,int flags) +{ +return vfs_statx (dfd, filename, flags |AT_NO_AUTOMOUNT , + stat,STATX_BASIC_STATS ); +}#ifdef __ARCH_WANT_OLD_STAT
include/linux/fs.h +2 -7
@@ -3165,15 +3165,10 @@ extern const struct inode_operations simple_symlink_inode_operations;extern int iterate_dir (struct file *,struct dir_context *); -extern int vfs_statx (int ,const char __user *,int ,struct kstat *,u32 ); +int vfs_fstatat (int dfd,const char __user *filename,struct kstat *stat, +int flags);int vfs_fstat (int fd,struct kstat *stat); -static inline int vfs_fstatat (int dfd,const char __user *filename, -struct kstat *stat,int flags) -{ -return vfs_statx (dfd, filename, flags |AT_NO_AUTOMOUNT , - stat,STATX_BASIC_STATS ); -}static inline int vfs_stat (const char __user *filename,struct kstat *stat) {return vfs_fstatat (AT_FDCWD , filename, stat,0 );
Signature · 1 line
2.28.0
PATCH 4/5 fs: remove vfs_stat_set_lookup_flags
In reply to Christoph HellwigThe function really obsfucates checking for valid flags and setting the lookup flags. The fact that it returns -EINVAL through and unsigned return value, which is then used as boolean really doesn't help either.
--- fs/stat.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
fs/stat.c +12 -21
@@ -148,24 +148,6 @@ int vfs_fstat(int fd, struct kstat *stat)return error; } -static inline unsigned vfs_stat_set_lookup_flags (unsigned *lookup_flags, -int flags) -{ -if ((flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT | -AT_EMPTY_PATH |KSTAT_QUERY_FLAGS )) !=0 ) -return -EINVAL ; - - *lookup_flags =LOOKUP_FOLLOW |LOOKUP_AUTOMOUNT ; -if (flags &AT_SYMLINK_NOFOLLOW ) - *lookup_flags &= ~LOOKUP_FOLLOW ; -if (flags &AT_NO_AUTOMOUNT ) - *lookup_flags &= ~LOOKUP_AUTOMOUNT ; -if (flags &AT_EMPTY_PATH ) - *lookup_flags |=LOOKUP_EMPTY ; - -return 0 ; -} -/** * vfs_statx - Get basic and extra attributes by filename * @dfd: A file descriptor representing the base dir for a relative filename
@@ -185,11 +167,20 @@ static int vfs_statx(int dfd, const char __user *filename, int flags, struct kstat *stat, u32 request_mask) {struct path path; -int error = -EINVAL ; -unsigned lookup_flags; +unsigned lookup_flags =0 ; +int error; -if (vfs_stat_set_lookup_flags (&lookup_flags, flags)) +if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT |AT_EMPTY_PATH | +KSTAT_QUERY_FLAGS ))return -EINVAL ; + +if (!(flags &AT_SYMLINK_NOFOLLOW )) + lookup_flags |=LOOKUP_FOLLOW ; +if (!(flags &AT_NO_AUTOMOUNT )) + lookup_flags |=LOOKUP_AUTOMOUNT ; +if (flags &AT_EMPTY_PATH ) + lookup_flags |=LOOKUP_EMPTY ; + retry: error =user_path_at (dfd, filename, lookup_flags, &path);if (error)
Signature · 1 line
2.28.0
PATCH 5/5 fs: remove KSTAT_QUERY_FLAGS
In reply to Christoph HellwigKSTAT_QUERY_FLAGS expands to AT_STATX_SYNC_TYPE, which itself already is a mask. Remove the double name, especially given that the prefix is a little confusing vs the normal AT_* flags.
--- fs/stat.c | 8 ++++---- include/linux/stat.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-)
fs/stat.c +4 -4
@@ -56,7 +56,7 @@ EXPORT_SYMBOL(generic_fillattr);* @path: file to get attributes from * @stat: structure to return attributes in * @request_mask: STATX_xxx flags indicating what the caller wants -* @query_flags: Query mode (KSTAT_QUERY_FLAGS) +* @query_flags: Query mode (AT_STATX_SYNC_TYPE) * * Get attributes without calling security_inode_getattr. *
@@ -71,7 +71,7 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,memset (stat,0 ,sizeof (*stat)); stat->result_mask |=STATX_BASIC_STATS ; - query_flags &=KSTAT_QUERY_FLAGS ; + query_flags &=AT_STATX_SYNC_TYPE ;/* allow the fs to override these if it really wants to */ /* SB_NOATIME means filesystem supplies dummy atime value */
@@ -97,7 +97,7 @@ EXPORT_SYMBOL(vfs_getattr_nosec);* @path: The file of interest * @stat: Where to return the statistics * @request_mask: STATX_xxx flags indicating what the caller wants -* @query_flags: Query mode (KSTAT_QUERY_FLAGS) +* @query_flags: Query mode (AT_STATX_SYNC_TYPE) * * Ask the filesystem for a file's attributes. The caller must indicate in * request_mask and query_flags to indicate what they want.
@@ -171,7 +171,7 @@ static int vfs_statx(int dfd, const char __user *filename, int flags,int error;if (flags & ~(AT_SYMLINK_NOFOLLOW |AT_NO_AUTOMOUNT |AT_EMPTY_PATH | -KSTAT_QUERY_FLAGS )) +AT_STATX_SYNC_TYPE ))return -EINVAL ;if (!(flags &AT_SYMLINK_NOFOLLOW ))
include/linux/stat.h +0 -2
@@ -19,8 +19,6 @@#include <linux/time.h> #include <linux/uidgid.h> -#define KSTAT_QUERY_FLAGS (AT_STATX_SYNC_TYPE) -struct kstat {u32 result_mask;/* What fields the user got */ umode_t mode;
Signature · 1 line
2.28.0
Quoted 3 lines · Christoph Hellwig
Hi Al,
a bunch of cleanups to untangle our mess of state related helpers.
Applied to #work.misc, visible in #for-next