vfs: cleanups
Subsystems (9)
Miklos Szeredi
maintainercover vfs: cleanups
Al,
Could you please take these VFS cleanups for 2.6.27?
Thanks,
Miklos
--
Miklos Szeredi
maintainerPATCH 1/5 vfs: truncate: dont check immutable twice
From: Miklos Szeredi <[email protected]>
vfs_permission(MAY_WRITE) already checked for the inode being immutable, so no need to repeat it.
--- fs/open.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/open.c +1 -1
@@ -254,7 +254,7 @@ static long do_sys_truncate(const char _ goto mnt_drop_write_and_out; error = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_APPEND (inode)) goto mnt_drop_write_and_out; error =get_write_access (inode);
--
Miklos Szeredi
maintainerPATCH 2/5 vfs: create file_truncate() helper
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Clean up do_truncate() API:
- create a new function file_truncate()
--- fs/exec.c | 2 +- fs/open.c | 24 ++++++++++++++++++++---- include/linux/fs.h | 2 ++ mm/tiny-shmem.c | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-)
fs/exec.c +1 -1
@@ -1772,7 +1772,7 @@ int do_coredump(long signr, int exit_cod goto close_fail;if (!file->f_op->write) goto close_fail; -if (!ispipe &&do_truncate (file->f_path.dentry,0 ,0 , file) !=0 ) +if (!ispipe &&file_truncate (file,0 ,0 ) !=0 ) goto close_fail; retval = binfmt->core_dump (signr, regs, file, core_limit);
fs/open.c +20 -4
@@ -195,6 +195,13 @@ out:return error; } +/* +* do_truncate - truncate (or extend) an inode +* @dentry: the dentry to truncate +* @length: the new length +* @time_attrs: file times to be updated (e.g. ATTR_MTIME|ATTR_CTIME) +* @filp: an open file or NULL (see file_truncate() as well) +*/ int do_truncate (struct dentry *dentry,loff_t length,unsigned int time_attrs,struct file *filp) {
@@ -221,6 +228,17 @@ int do_truncate(struct dentry *dentry, lreturn err; } +/* +* file_truncate - truncate (or extend) an open file +* @filp: the open file +* @length: the new length +* @time_attrs: file times to be updated (e.g. ATTR_MTIME|ATTR_CTIME) +*/ +int file_truncate (struct file *filp,loff_t length,unsigned int time_attrs) +{ +return do_truncate (filp->f_path.dentry, length, time_attrs, filp); +} +static long do_sys_truncate (const char __user * path,loff_t length) {struct nameidata nd;
@@ -294,7 +312,6 @@ asmlinkage long sys_truncate(const charstatic long do_sys_ftruncate (unsigned int fd,loff_t length,int small) {struct inode * inode; -struct dentry *dentry;struct file * file;int error;
@@ -310,8 +327,7 @@ static long do_sys_ftruncate(unsigned inif (file->f_flags &O_LARGEFILE ) small =0 ; - dentry = file->f_path.dentry; - inode = dentry->d_inode; + inode = file->f_path.dentry->d_inode; error = -EINVAL ;if (!S_ISREG (inode->i_mode) || !(file->f_mode &FMODE_WRITE )) goto out_putf;
@@ -327,7 +343,7 @@ static long do_sys_ftruncate(unsigned in error =locks_verify_truncate (inode, file, length);if (!error) - error =do_truncate (dentry, length,ATTR_MTIME |ATTR_CTIME , file); + error =file_truncate (file, length,ATTR_MTIME |ATTR_CTIME ); out_putf:fput (file); out:
include/linux/fs.h +2 -0
@@ -1598,6 +1598,8 @@ static inline int break_lease(struct inoextern int do_truncate (struct dentry *,loff_t start,unsigned int time_attrs,struct file *filp); +extern int file_truncate (struct file *filp,loff_t start, +unsigned int time_attrs);extern long do_sys_open (int dfd,const char __user *filename,int flags,int mode);extern struct file *filp_open (const char *,int ,int );
mm/tiny-shmem.c +1 -1
@@ -80,7 +80,7 @@ struct file *shmem_file_setup(char *name inode->i_nlink =0 ;/* It is unlinked */ /* notify everyone as to the change of file size */ - error =do_truncate (dentry, size,0 , file); + error =file_truncate (file, size,0 );if (error <0 ) goto close_file;
--
Miklos Szeredi
maintainerPATCH 3/5 vfs: change remove_suid() to file_remove_suid()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
All calls to remove_suid() are made with a file pointer, because (similarly to file_update_time) it is called when the file is written.
Clean up callers by passing in a file instead of a dentry.
--- fs/fuse/file.c | 2 +- fs/ntfs/file.c | 2 +- fs/splice.c | 4 ++-- fs/xfs/linux-2.6/xfs_lrw.c | 2 +- include/linux/fs.h | 2 +- mm/filemap.c | 7 ++++--- mm/filemap_xip.c | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-)
fs/fuse/file.c +1 -1
@@ -893,7 +893,7 @@ static ssize_t fuse_file_aio_write(strucif (count ==0 ) goto out; - err =remove_suid (file->f_path.dentry); + err =file_remove_suid (file);if (err) goto out;
fs/ntfs/file.c +1 -1
@@ -2118,7 +2118,7 @@ static ssize_t ntfs_file_aio_write_noloc goto out;if (!count) goto out; - err =remove_suid (file->f_path.dentry); + err =file_remove_suid (file);if (err) goto out;file_update_time (file);
fs/splice.c +2 -2
@@ -763,7 +763,7 @@ generic_file_splice_write_nolock(structssize_t ret;int err; - err =remove_suid (out->f_path.dentry); + err =file_remove_suid (out);if (unlikely (err))return err;
@@ -821,7 +821,7 @@ generic_file_splice_write(struct pipe_inssize_t ret;inode_double_lock (inode, pipe->inode); - ret =remove_suid (out->f_path.dentry); + ret =file_remove_suid (out);if (likely (!ret)) ret =__splice_from_pipe (pipe, &sd, pipe_to_file);inode_double_unlock (inode, pipe->inode);
fs/xfs/linux-2.6/xfs_lrw.c +1 -1
@@ -711,7 +711,7 @@ start: !capable(CAP_FSETID)) { error =xfs_write_clear_setuid (xip);if (likely (!error)) - error = -remove_suid (file->f_path.dentry); + error = -file_remove_suid (file);if (unlikely (error)) { goto out_unlock_internal; }
include/linux/fs.h +1 -1
@@ -1817,7 +1817,7 @@ extern void clear_inode(struct inode *);extern void destroy_inode (struct inode *);extern struct inode *new_inode (struct super_block *);extern int should_remove_suid (struct dentry *); -extern int remove_suid (struct dentry *); +extern int file_remove_suid (struct file *);extern void __insert_inode_hash (struct inode *,unsigned long hashval);extern void remove_inode_hash (struct inode *);
mm/filemap.c +4 -3
@@ -1668,8 +1668,9 @@ static int __remove_suid(struct dentry *return notify_change (dentry, &newattrs); } -int remove_suid (struct dentry *dentry) +int file_remove_suid (struct file *file) { +struct dentry *dentry = file->f_path.dentry;int killsuid =should_remove_suid (dentry);int killpriv =security_inode_need_killpriv (dentry);int error =0 ;
@@ -1683,7 +1684,7 @@ int remove_suid(struct dentry *dentry)return error; } -EXPORT_SYMBOL (remove_suid); +EXPORT_SYMBOL (file_remove_suid);static size_t __iovec_copy_from_user_inatomic (char *vaddr,const struct iovec *iov,size_t base,size_t bytes)
@@ -2394,7 +2395,7 @@ __generic_file_aio_write_nolock(struct kif (count ==0 ) goto out; - err =remove_suid (file->f_path.dentry); + err =file_remove_suid (file);if (err) goto out;
mm/filemap_xip.c +1 -1
@@ -380,7 +380,7 @@ xip_file_write(struct file *filp, constif (count ==0 ) goto out_backing; - ret =remove_suid (filp->f_path.dentry); + ret =file_remove_suid (filp);if (ret) goto out_backing;
--
Miklos Szeredi
maintainerPATCH 4/5 vfs: reuse local variable in vfs_link()
In reply to Miklos SzerediFrom: Tetsuo Handa <[email protected]>
Why not reuse "inode" which is assigned as
struct inode *inode = old_dentry->d_inode;
in the beginning of vfs_link() ?
--- fs/namei.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/namei.c +4 -4
@@ -2498,19 +2498,19 @@ int vfs_link(struct dentry *old_dentry,return -EPERM ;if (!dir->i_op || !dir->i_op->link)return -EPERM ; -if (S_ISDIR (old_dentry->d_inode->i_mode)) +if (S_ISDIR (inode->i_mode))return -EPERM ; error =security_inode_link (old_dentry, dir, new_dentry);if (error)return error; -mutex_lock (&old_dentry->d_inode->i_mutex); +mutex_lock (&inode->i_mutex);DQUOT_INIT (dir); error = dir->i_op->link (old_dentry, dir, new_dentry); -mutex_unlock (&old_dentry->d_inode->i_mutex); +mutex_unlock (&inode->i_mutex);if (!error) -fsnotify_link (dir, old_dentry->d_inode, new_dentry); +fsnotify_link (dir, inode, new_dentry);return error; }
--
Miklos Szeredi
maintainerPATCH 5/5 vfs: remove mode parameter from vfs_symlink()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Remove the unused mode parameter from vfs_symlink and callers.
Thanks to Tetsuo Handa for noticing.
--- fs/ecryptfs/inode.c | 4 +--- fs/namei.c | 4 ++-- fs/nfsd/vfs.c | 10 ++-------- include/linux/fs.h | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-)
fs/ecryptfs/inode.c +1 -3
@@ -444,7 +444,6 @@ static int ecryptfs_symlink(struct inodeint rc;struct dentry *lower_dentry;struct dentry *lower_dir_dentry; -umode_t mode;char *encoded_symname;int encoded_symlen;struct ecryptfs_crypt_stat *crypt_stat =NULL ;
@@ -452,7 +451,6 @@ static int ecryptfs_symlink(struct inode lower_dentry =ecryptfs_dentry_to_lower (dentry);dget (lower_dentry); lower_dir_dentry =lock_parent (lower_dentry); - mode =S_IALLUGO ; encoded_symlen =ecryptfs_encode_filename (crypt_stat, symname,strlen (symname), &encoded_symname);
@@ -461,7 +459,7 @@ static int ecryptfs_symlink(struct inode goto out_lock; } rc =vfs_symlink (lower_dir_dentry->d_inode, lower_dentry, - encoded_symname, mode); + encoded_symname);kfree (encoded_symname);if (rc || !lower_dentry->d_inode) goto out_lock;
fs/namei.c +2 -2
@@ -2408,7 +2408,7 @@ asmlinkage long sys_unlink(const char __return do_unlinkat (AT_FDCWD , pathname); } -int vfs_symlink (struct inode *dir,struct dentry *dentry,const char *oldname,int mode) +int vfs_symlink (struct inode *dir,struct dentry *dentry,const char *oldname) {int error =may_create (dir, dentry,NULL );
@@ -2457,7 +2457,7 @@ asmlinkage long sys_symlinkat(const char error =mnt_want_write (nd.path.mnt);if (error) goto out_dput; - error =vfs_symlink (nd.path.dentry->d_inode, dentry, from,S_IALLUGO ); + error =vfs_symlink (nd.path.dentry->d_inode, dentry, from);mnt_drop_write (nd.path.mnt); out_dput:dput (dentry);
fs/nfsd/vfs.c +2 -8
@@ -1517,7 +1517,6 @@ nfsd_symlink(struct svc_rqst *rqstp, strstruct dentry *dentry, *dnew;__be32 err, cerr;int host_err; -umode_t mode; err = nfserr_noent;if (!flen || !plen)
@@ -1536,11 +1535,6 @@ nfsd_symlink(struct svc_rqst *rqstp, strif (IS_ERR (dnew)) goto out_nfserr; - mode =S_IALLUGO ; -/* Only the MODE ATTRibute is even vaguely meaningful */ -if (iap && (iap->ia_valid &ATTR_MODE )) - mode = iap->ia_mode &S_IALLUGO ; - host_err =mnt_want_write (fhp->fh_export->ex_path.mnt);if (host_err) goto out_nfserr;
@@ -1552,11 +1546,11 @@ nfsd_symlink(struct svc_rqst *rqstp, strelse {strncpy (path_alloced, path, plen); path_alloced[plen] =0 ; - host_err =vfs_symlink (dentry->d_inode, dnew, path_alloced, mode); + host_err =vfs_symlink (dentry->d_inode, dnew, path_alloced);kfree (path_alloced); } }else - host_err =vfs_symlink (dentry->d_inode, dnew, path, mode); + host_err =vfs_symlink (dentry->d_inode, dnew, path);if (!host_err) {if (EX_ISSYNC (fhp->fh_export))
include/linux/fs.h +1 -1
@@ -1125,7 +1125,7 @@ extern int vfs_permission(struct nameidaextern int vfs_create (struct inode *,struct dentry *,int ,struct nameidata *);extern int vfs_mkdir (struct inode *,struct dentry *,int );extern int vfs_mknod (struct inode *,struct dentry *,int ,dev_t ); -extern int vfs_symlink (struct inode *,struct dentry *,const char *,int ); +extern int vfs_symlink (struct inode *,struct dentry *,const char *);extern int vfs_link (struct dentry *,struct inode *,struct dentry *);extern int vfs_rmdir (struct inode *,struct dentry *);extern int vfs_unlink (struct inode *,struct dentry *);
--