vfs: path_ API
Subsystems (6)
cover vfs: path_ API
Al,
This is against vfs-2.6#merge-base + latest linus tree (for 93265d13ea5c3ec5f61a8009407fbe046ce6b7c0)
Thanks,
Miklos
--
PATCH 1/14 cgroup: dont call vfs_mkdir
From: Miklos Szeredi <[email protected]>
cgroup_clone() calls vfs_mkdir() to create a directory in the cgroup filesystem. Replace with explicit call to cgroup_mkdir() and fsnotify_mkdir().
This is equivalent, except that the following functions are not called before cgroup_mkdir():
- may_create()
- security_inode_mkdir()
- DQUOT_INIT()
Permission to clone the cgroup has already been checked in copy_namespaces() (requiring CAP_SYS_ADMIN). Additional file system related capability checks are inappropriate and confusing.
The quota check is unnecessary, as quotas don't make any sense for this filesystem.
--- kernel/cgroup.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/cgroup.c +4 -1
@@ -25,6 +25,7 @@#include <linux/cgroup.h> #include <linux/errno.h> #include <linux/fs.h> +#include <linux/fsnotify.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/mm.h>
@@ -2928,7 +2929,9 @@ int cgroup_clone(struct task_struct *tsk }/* Create the cgroup directory, which also creates the cgroup */ - ret =vfs_mkdir (inode, dentry,S_IFDIR |0755 ); + ret =cgroup_mkdir (inode, dentry,S_IFDIR ); +if (!ret) +fsnotify_mkdir (inode, dentry); child =__d_cgrp (dentry);dput (dentry);if (ret) {
--
PATCH 2/14 reiserfs: dont call vfs_rmdir
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
reiserfs_delete_xattrs() calls vfs_rmdir() to remove the private directory associated with the extended attributes for an inode. Replace with explicit call to reiserfs_rmdir().
The extended attribute files reside in a private directory, completely inaccessible from userspace. This means, that checking against mounts on the dentry is not necessary.
The calls to may_delete() and security_inode_rmdir(), as performed by vfs_rmdir() are also unecessary for this case.
Based on patch by Jeff Mahoney.
--- fs/reiserfs/namei.c | 2 +- fs/reiserfs/xattr.c | 22 +++++++++++++++++++++- include/linux/reiserfs_fs.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-)
fs/reiserfs/namei.c +1 -1
@@ -850,7 +850,7 @@ static inline int reiserfs_empty_dir(strreturn 1 ; } -static int reiserfs_rmdir (struct inode *dir,struct dentry *dentry) +int reiserfs_rmdir (struct inode *dir,struct dentry *dentry) {int retval, err;struct inode *inode;
fs/reiserfs/xattr.c +21 -1
@@ -35,6 +35,7 @@#include <linux/namei.h> #include <linux/errno.h> #include <linux/fs.h> +#include <linux/quotaops.h> #include <linux/file.h> #include <linux/pagemap.h> #include <linux/xattr.h>
@@ -712,6 +713,25 @@ reiserfs_delete_xattrs_filler(void *buf, } +static int xattr_rmdir (struct inode *dir,struct dentry *dentry) +{ +int error; + +DQUOT_INIT (dir); + +mutex_lock_nested (&dentry->d_inode->i_mutex,I_MUTEX_CHILD ); +dentry_unhash (dentry); + error =reiserfs_rmdir (dir, dentry); +if (!error) + dentry->d_inode->i_flags |=S_DEAD ; +mutex_unlock (&dentry->d_inode->i_mutex); +if (!error) +d_delete (dentry); +dput (dentry); + +return error; +} +/* This is called w/ inode->i_mutex downed */ int reiserfs_delete_xattrs (struct inode *inode) {
@@ -746,7 +766,7 @@ int reiserfs_delete_xattrs(struct inodeif (dir->d_inode->i_nlink <=2 ) { root =get_xa_root (inode->i_sb,XATTR_REPLACE );reiserfs_write_lock_xattrs (inode->i_sb); - err =vfs_rmdir (root->d_inode, dir); + err =xattr_rmdir (root->d_inode, dir);reiserfs_write_unlock_xattrs (inode->i_sb);dput (root); }else {
include/linux/reiserfs_fs.h +1 -0
@@ -1911,6 +1911,7 @@ static inline void reiserfs_update_sd(stvoid sd_attrs_to_i_attrs (__u16 sd_attrs,struct inode *inode);void i_attrs_to_sd_attrs (struct inode *inode,__u16 * sd_attrs);int reiserfs_setattr (struct dentry *dentry,struct iattr *attr); +int reiserfs_rmdir (struct inode *dir,struct dentry *dentry);/* namei.c */ void set_de_name_and_namelen (struct reiserfs_dir_entry *de);
--
PATCH 3/14 reiserfs: dont call notify_change
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Reiserfs calls notify_change() on it's private extended attribute files to resize and change ownership of these files. Replace with reiserfs_setattr().
This is equivalent, except that:
- i_alloc_sem locking is not performed around reiserfs_setattr() when the size is changed
- security_inode_setattr() is not called before reiserfs_setattr()
- fsnotify_change() is not called after reiserfs_setattr()
None of the above is necessary, since the files are private to reiserfs and inaccessible from userspace.
Also remove setting of ctime on the xattr files.
Based on patch by Jeff Mahoney.
--- fs/reiserfs/xattr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/reiserfs/xattr.c +5 -5
@@ -458,9 +458,9 @@ reiserfs_xattr_set(struct inode *inode,/* Resize it so we're ok to write there */ newattrs.ia_size = buffer_size; - newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; + newattrs.ia_valid =ATTR_SIZE ;mutex_lock_nested (&xinode->i_mutex,I_MUTEX_XATTR ); - err =notify_change (dentry, &newattrs); + err =reiserfs_setattr (dentry, &newattrs);if (err) goto out_filp;
@@ -810,7 +810,7 @@ reiserfs_chown_xattrs_filler(void *buf, }if (!S_ISDIR (xafile->d_inode->i_mode)) - err =notify_change (xafile, attrs); + err =reiserfs_setattr (xafile, attrs);dput (xafile);return err;
@@ -843,7 +843,7 @@ int reiserfs_chown_xattrs(struct inode *lock_kernel (); - attrs->ia_valid &= (ATTR_UID |ATTR_GID |ATTR_CTIME ); + attrs->ia_valid &= (ATTR_UID |ATTR_GID ); buf.xadir = dir; buf.attrs = attrs; buf.inode = inode;
@@ -854,7 +854,7 @@ int reiserfs_chown_xattrs(struct inode * goto out_dir; } - err =notify_change (dir, attrs); + err =reiserfs_setattr (dir, attrs);unlock_kernel (); out_dir:
--
PATCH 4/14 hpfs: dont call notify_change
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
hpfs_unlink() calls notify_change() to truncate the file before deleting. Replace with explicit call to hpfs_notify_change().
This is equivalent, except that:
- security_inode_setattr() is not called before hpfs_notify_change()
- fsnotify_change() is not called after hpfs_notify_change()
The truncation is just an implementation detail, so both the security check and the notification are unnecessary.
Possibly even the ctime modification is wrong?
--- fs/hpfs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/hpfs/namei.c +2 -1
@@ -426,7 +426,8 @@ again:/*printk("HPFS: truncating file before delete.\n");*/ newattrs.ia_size =0 ; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + newattrs.ia_ctime =current_fs_time (inode->i_sb); + err =hpfs_notify_change (dentry, &newattrs);put_write_access (inode);if (!err) goto again;
--
Mikulas Patocka
maintainerRe: [patch 04/14] hpfs: dont call notify_change
What about down_write on i_alloc_sem --- notify change takes that and your patch bypasses that.
Mikulas
Quoted 37 lines
From: Miklos Szeredi <[email protected]>
hpfs_unlink()callsnotify_change()to truncate the file before deleting. Replace with explicit call tohpfs_notify_change().This is equivalent, except that:
-security_inode_setattr()is not called beforehpfs_notify_change()
-fsnotify_change()is not called afterhpfs_notify_change()The truncation is just an implementation detail, so both the security check and the notification are unnecessary.
Possibly even the ctime modification is wrong?
Signed-off-by Miklos Szeredi <[email protected]>CC Mikulas Patocka <[email protected]>--- fs/hpfs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Index:
linux-2.6/fs/hpfs/namei.c
===================================================================fs/hpfs/namei.c +2
-2@@ -426,7 +426,8 @@ again:/*printk("HPFS: truncating file before delete.\n");*/ newattrs.ia_size =0 ; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + newattrs.ia_ctime =current_fs_time (inode->i_sb); + err =hpfs_notify_change (dentry, &newattrs);put_write_access (inode);if (!err) goto again; --
Re: [patch 04/14] hpfs: dont call notify_change
Quoted 2 lines · Mikulas Patocka
What about
down_writeoni_alloc_sem--- notify change takes that and your patch bypasses that.
i_alloc_sem is only relevant if filesystem uses blockdev_direct_IO() and friends. It is not used for anything else, so for hpfs there's no need to surround take that lock.
Thanks,
Miklos
Quoted 38 lines
Quoted 37 lines
From: Miklos Szeredi <[email protected]>
hpfs_unlink()callsnotify_change()to truncate the file before deleting. Replace with explicit call tohpfs_notify_change().This is equivalent, except that:
-security_inode_setattr()is not called beforehpfs_notify_change()
-fsnotify_change()is not called afterhpfs_notify_change()The truncation is just an implementation detail, so both the security check and the notification are unnecessary.
Possibly even the ctime modification is wrong?
Signed-off-by Miklos Szeredi <[email protected]>CC Mikulas Patocka <[email protected]>--- fs/hpfs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Index:
linux-2.6/fs/hpfs/namei.c
===================================================================fs/hpfs/namei.c +2
-2@@ -426,7 +426,8 @@ again:/*printk("HPFS: truncating file before delete.\n");*/ newattrs.ia_size =0 ; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + newattrs.ia_ctime =current_fs_time (inode->i_sb); + err =hpfs_notify_change (dentry, &newattrs);put_write_access (inode);if (!err) goto again; --
Mikulas Patocka
maintainerRe: [patch 04/14] hpfs: dont call notify_change
Quoted 42 lines · Miklos Szeredi
Quoted 35 lines · Mikulas Patocka
Quoted 35 lines
From: Miklos Szeredi <[email protected]>
hpfs_unlink()callsnotify_change()to truncate the file before deleting. Replace with explicit call tohpfs_notify_change().This is equivalent, except that:
-security_inode_setattr()is not called beforehpfs_notify_change()
-fsnotify_change()is not called afterhpfs_notify_change()The truncation is just an implementation detail, so both the security check and the notification are unnecessary.
Possibly even the ctime modification is wrong?
Signed-off-by Miklos Szeredi <[email protected]>CC Mikulas Patocka <[email protected]>--- fs/hpfs/namei.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Index:
linux-2.6/fs/hpfs/namei.c
===================================================================fs/hpfs/namei.c +2
-1@@ -426,7 +426,8 @@ again:/*printk("HPFS: truncating file before delete.\n");*/ newattrs.ia_size =0 ; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + newattrs.ia_ctime =current_fs_time (inode->i_sb); + err =hpfs_notify_change (dentry, &newattrs);put_write_access (inode);if (!err) goto again;Quoted 4 lines
Quoted 1 line
--
What about
down_writeoni_alloc_sem--- notify change takes that and your patch bypasses that.
Quoted 7 lines
i_alloc_semis only relevant if filesystem usesblockdev_direct_IO()and friends. It is not used for anything else, so for hpfs there's no need to surround take that lock.Thanks,
Miklos
I don't care much about this part anyway. This piece of code is not supposed to work reliably (what if the file has zero size or has fragments less then 2kb?), and if you change it to make it work more reliably under a circumstance when someone is deleting file he doesn't own, so what.
This is just design flaw of hpfs.
If you are certain about correctness of your patch, change it (but test it --- I placed a test partition at
http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/test-hpfs-partition.gz).
Or, the alternative is to remove the truncate code at all.
Mikulas
PATCH 5/14 vfs: add path_create() and path_mknod()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
R/O bind mounts require operations which modify the filesystem to be wrapped in mnt_want_write()/mnt_drop_write(). Create helpers which do this, so callers won't need to bother, and more importantly, cannot forget! Call these path_*, analogous to vfs_*. Since there are no callers of vfs_* left, make them static.
Overall this patchset is just 23 lines in the red, but at the same time it fixes several places in nfsd and the whole of ecryptfs, where the mnt_want_write/drop_write() calls were missing.
It will also help with merging certain security modules, which need to know the path within the namespace, and not just within the filesystem. These helpers will allow the security hooks to be in a common place, and need not be repeated in all callers.
Note, that the mnt_want_write/drop_write() bracketing provided by the path_* functions is not strictly necessary in all cases, since the caller may do it's own bracketing to span multiple VFS calls. However, this does not make the checks in path_* incorrect, just redundant.
The advantages of the path_* API are:
- it's consistent
- it provides some (not all) guarantees, i.e. it's easier to prove that all callers play by the rules
- for the syscall case it has zero cost
- for all the other cases it has either zero, or minimal cost
It does require the caller to have a vfsmount available, but it's hard to imagine that the caller does not have it:
- most userspace calls do have it, as they are either operating on a path or a file descriptor. There are some exceptions like sync(2) and ustat(2), the latter not being a very exemplary interface, and neither of them being relevant to this discussion.
- all kernel callers (nfs export, stacking) should have it, as they need it for open() anyway
And even if some theoretical caller didn't have the vfsmount, it still should be easy to allocate one, providing a clean way to do the r/o bracketing, and not requiring another mechanism to be exported that provides the same functionality on the superblock.
This patch:
Introduce path_create() and path_mknod(). Make vfs_create() and vfs_mknod() static.
--- fs/ecryptfs/inode.c | 33 ++++++++++------------ fs/namei.c | 75 +++++++++++++++++++++++++++------------------------- fs/nfsd/vfs.c | 19 +++++++++---- include/linux/fs.h | 4 +- ipc/mqueue.c | 6 +++- net/unix/af_unix.c | 6 ---- 6 files changed, 76 insertions(+), 67 deletions(-)
fs/ecryptfs/inode.c +15 -18
@@ -61,23 +61,19 @@ static void unlock_dir(struct dentry *di* Returns zero on success; non-zero on error condition */ static int -ecryptfs_create_underlying_file (struct inode *lower_dir_inode, +ecryptfs_create_underlying_file (struct dentry *lower_dir_dentry,struct dentry *dentry,int mode,struct nameidata *nd) {struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); -struct vfsmount *lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); -struct dentry *dentry_save; -struct vfsmount *vfsmount_save; +struct path save;int rc; - dentry_save = nd->path.dentry; - vfsmount_save = nd->path.mnt; - nd->path.dentry = lower_dentry; - nd->path.mnt = lower_mnt; - rc =vfs_create (lower_dir_inode, lower_dentry, mode, nd); - nd->path.dentry = dentry_save; - nd->path.mnt = vfsmount_save; + save = nd->path; + nd->path.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + nd->path.dentry = lower_dir_dentry; + rc =path_create (&nd->path, lower_dentry, mode, nd); + nd->path = save;return rc; }
@@ -111,7 +107,7 @@ ecryptfs_do_create(struct inode *directo rc =PTR_ERR (lower_dir_dentry); goto out; } - rc =ecryptfs_create_underlying_file (lower_dir_dentry->d_inode, + rc =ecryptfs_create_underlying_file (lower_dir_dentry, ecryptfs_dentry, mode, nd);if (rc) { printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
@@ -528,20 +524,21 @@ ecryptfs_mknod(struct inode *dir, struct {int rc;struct dentry *lower_dentry; -struct dentry *lower_dir_dentry; +struct path lower_dir; lower_dentry =ecryptfs_dentry_to_lower (dentry); - lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mknod (lower_dir_dentry->d_inode, lower_dentry, mode, dev); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_dir.dentry =lock_parent (lower_dentry); + rc =path_mknod (&lower_dir, lower_dentry, mode, dev);if (rc || !lower_dentry->d_inode) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb,0 );if (rc) goto out; -fsstack_copy_attr_times (dir, lower_dir_dentry->d_inode); -fsstack_copy_inode_size (dir, lower_dir_dentry->d_inode); +fsstack_copy_attr_times (dir, lower_dir.dentry->d_inode); +fsstack_copy_inode_size (dir, lower_dir.dentry->d_inode); out: -unlock_dir (lower_dir_dentry); +unlock_dir (lower_dir.dentry);if (!dentry->d_inode)d_drop (dentry);return rc;
fs/namei.c +40 -35
119 lines not on this page · raw message
fs/nfsd/vfs.c +13 -6
@@ -130,6 +130,12 @@ out:return err; } +static void fh_to_path (struct svc_fh *fhp,struct path *path) +{ + path->dentry = fhp->fh_dentry; + path->mnt = fhp->fh_export->ex_path.mnt; +} + __be32 nfsd_lookup_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp, const char *name, unsigned int len,
@@ -1186,6 +1192,7 @@ nfsd_create(struct svc_rqst *rqstp, stru char *fname, int flen, struct iattr *iap, int type, dev_t rdev, struct svc_fh *resfhp) { + struct path dir_path;struct dentry *dentry, *dchild =NULL ;struct inode *dirp;__be32 err;
@@ -1261,13 +1268,11 @@ nfsd_create(struct svc_rqst *rqstp, struif (host_err) goto out_nfserr; -/* -* Get the dir op function pointer. -*/ +fh_to_path (fhp, &dir_path); err =0 ;switch (type) {case S_IFREG : - host_err =vfs_create (dirp, dchild, iap->ia_mode,NULL ); + host_err =path_create (&dir_path, dchild, iap->ia_mode,NULL );break ;case S_IFDIR : host_err =vfs_mkdir (dirp, dchild, iap->ia_mode);
@@ -1276,7 +1281,7 @@ nfsd_create(struct svc_rqst *rqstp, strucase S_IFBLK :case S_IFIFO :case S_IFSOCK : - host_err =vfs_mknod (dirp, dchild, iap->ia_mode, rdev); + host_err =path_mknod (&dir_path, dchild, iap->ia_mode, rdev);break ; }if (host_err <0 ) {
@@ -1318,6 +1323,7 @@ nfsd_create_v3(struct svc_rqst *rqstp, s struct svc_fh *resfhp, int createmode, u32 *verifier, int *truncp, int *created) { + struct path dir_path;struct dentry *dentry, *dchild =NULL ;struct inode *dirp;__be32 err;
@@ -1408,7 +1414,8 @@ nfsd_create_v3(struct svc_rqst *rqstp, s goto out; } - host_err =vfs_create (dirp, dchild, iap->ia_mode,NULL ); +fh_to_path (fhp, &dir_path); + host_err =path_create (&dir_path, dchild, iap->ia_mode,NULL );if (host_err <0 ) {mnt_drop_write (fhp->fh_export->ex_path.mnt); goto out_nfserr;
include/linux/fs.h +2 -2
@@ -1126,9 +1126,9 @@ extern void unlock_super(struct super_bl* VFS helper functions.. */ extern int vfs_permission (struct nameidata *,int ); -extern int vfs_create (struct inode *,struct dentry *,int ,struct nameidata *); +extern int path_create (struct path *,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 path_mknod (struct path *,struct dentry *,int ,dev_t );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 *);
ipc/mqueue.c +5 -1
@@ -599,6 +599,7 @@ static struct file *do_create(struct den {struct mq_attr attr;struct file *result; +struct path dir_path;int ret;if (u_attr) {
@@ -616,7 +617,10 @@ static struct file *do_create(struct den ret =mnt_want_write (mqueue_mnt);if (ret) goto out; - ret =vfs_create (dir->d_inode, dentry, mode,NULL ); + + dir_path.mnt = mqueue_mnt; + dir_path.dentry = dir; + ret =path_create (&dir_path, dentry, mode,NULL ); dentry->d_fsdata =NULL ;if (ret) goto out_drop_write;
net/unix/af_unix.c +1 -5
@@ -824,11 +824,7 @@ static int unix_bind(struct socket *sock*/ mode =S_IFSOCK | (SOCK_INODE (sock)->i_mode & ~current->fs->umask); - err =mnt_want_write (nd.path.mnt); -if (err) - goto out_mknod_dput; - err =vfs_mknod (nd.path.dentry->d_inode, dentry, mode,0 ); -mnt_drop_write (nd.path.mnt); + err =path_mknod (&nd.path, dentry, mode,0 );if (err) goto out_mknod_dput;mutex_unlock (&nd.path.dentry->d_inode->i_mutex);
--
PATCH 6/14 vfs: add path_mkdir()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_mkdir(). Make vfs_mkdir() static.
--- fs/ecryptfs/inode.c | 15 ++++++++------- fs/namei.c | 23 +++++++++++++++-------- fs/nfsd/nfs4recover.c | 6 +----- fs/nfsd/vfs.c | 2 +- include/linux/fs.h | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-)
fs/ecryptfs/inode.c +8 -7
@@ -476,21 +476,22 @@ static int ecryptfs_mkdir(struct inode * {int rc;struct dentry *lower_dentry; -struct dentry *lower_dir_dentry; +struct path lower_dir; lower_dentry =ecryptfs_dentry_to_lower (dentry); - lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mkdir (lower_dir_dentry->d_inode, lower_dentry, mode); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_dir.dentry =lock_parent (lower_dentry); + rc =path_mkdir (&lower_dir, lower_dentry, mode);if (rc || !lower_dentry->d_inode) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb,0 );if (rc) goto out; -fsstack_copy_attr_times (dir, lower_dir_dentry->d_inode); -fsstack_copy_inode_size (dir, lower_dir_dentry->d_inode); - dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; +fsstack_copy_attr_times (dir, lower_dir.dentry->d_inode); +fsstack_copy_inode_size (dir, lower_dir.dentry->d_inode); + dir->i_nlink = lower_dir.dentry->d_inode->i_nlink; out: -unlock_dir (lower_dir_dentry); +unlock_dir (lower_dir.dentry);if (!dentry->d_inode)d_drop (dentry);return rc;
fs/namei.c +15 -8
@@ -2052,7 +2052,7 @@ asmlinkage long sys_mknod(const char __ureturn sys_mknodat (AT_FDCWD , filename, mode, dev); } -int vfs_mkdir (struct inode *dir,struct dentry *dentry,int mode) +static int vfs_mkdir (struct inode *dir,struct dentry *dentry,int mode) {int error =may_create (dir, dentry,NULL );
@@ -2074,6 +2074,19 @@ int vfs_mkdir(struct inode *dir, structreturn error; } +int path_mkdir (struct path *dir_path,struct dentry *dentry,int mode) +{ +int error =mnt_want_write (dir_path->mnt); + +if (!error) { + error =vfs_mkdir (dir_path->dentry->d_inode, dentry, mode); +mnt_drop_write (dir_path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_mkdir); +asmlinkage long sys_mkdirat (int dfd,const char __user *pathname,int mode) {int error =0 ;
@@ -2096,12 +2109,7 @@ asmlinkage long sys_mkdirat(int dfd, conif (!IS_POSIXACL (nd.path.dentry->d_inode)) mode &= ~current->fs->umask; - error =mnt_want_write (nd.path.mnt); -if (error) - goto out_dput; - error =vfs_mkdir (nd.path.dentry->d_inode, dentry, mode); -mnt_drop_write (nd.path.mnt); -out_dput: + error =path_mkdir (&nd.path, dentry, mode);dput (dentry); out_unlock:mutex_unlock (&nd.path.dentry->d_inode->i_mutex);
@@ -2906,7 +2914,6 @@ EXPORT_SYMBOL(file_permission);EXPORT_SYMBOL (unlock_rename);EXPORT_SYMBOL (vfs_follow_link);EXPORT_SYMBOL (vfs_link); -EXPORT_SYMBOL (vfs_mkdir);EXPORT_SYMBOL (generic_permission);EXPORT_SYMBOL (vfs_readlink);EXPORT_SYMBOL (vfs_rename);
fs/nfsd/nfs4recover.c +1 -5
@@ -155,11 +155,7 @@ nfsd4_create_clid_dir(struct nfs4_clientdprintk ("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n" ); goto out_put; } - status =mnt_want_write (rec_dir.path.mnt); -if (status) - goto out_put; - status =vfs_mkdir (rec_dir.path.dentry->d_inode, dentry,S_IRWXU ); -mnt_drop_write (rec_dir.path.mnt); + status =path_mkdir (&rec_dir.path, dentry,S_IRWXU ); out_put:dput (dentry); out_unlock:
fs/nfsd/vfs.c +1 -1
@@ -1275,7 +1275,7 @@ nfsd_create(struct svc_rqst *rqstp, stru host_err =path_create (&dir_path, dchild, iap->ia_mode,NULL );break ;case S_IFDIR : - host_err =vfs_mkdir (dirp, dchild, iap->ia_mode); + host_err =path_mkdir (&dir_path, dchild, iap->ia_mode);break ;case S_IFCHR :case S_IFBLK :
include/linux/fs.h +1 -1
@@ -1127,7 +1127,7 @@ extern void unlock_super(struct super_bl*/ extern int vfs_permission (struct nameidata *,int );extern int path_create (struct path *,struct dentry *,int ,struct nameidata *); -extern int vfs_mkdir (struct inode *,struct dentry *,int ); +extern int path_mkdir (struct path *,struct dentry *,int );extern int path_mknod (struct path *,struct dentry *,int ,dev_t );extern int vfs_symlink (struct inode *,struct dentry *,const char *);extern int vfs_link (struct dentry *,struct inode *,struct dentry *);
--
PATCH 7/14 vfs: add path_rmdir()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_rmdir(). Make vfs_rmdir() static.
--- fs/ecryptfs/inode.c | 13 +++++++------ fs/namei.c | 23 +++++++++++++++-------- fs/nfsd/nfs4recover.c | 3 ++- fs/nfsd/vfs.c | 4 +++- include/linux/fs.h | 2 +- 5 files changed, 28 insertions(+), 17 deletions(-)
fs/ecryptfs/inode.c +7 -6
@@ -500,20 +500,21 @@ out:static int ecryptfs_rmdir (struct inode *dir,struct dentry *dentry) {struct dentry *lower_dentry; -struct dentry *lower_dir_dentry; +struct path lower_dir;int rc; lower_dentry =ecryptfs_dentry_to_lower (dentry);dget (dentry); - lower_dir_dentry =lock_parent (lower_dentry); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_dir.dentry =lock_parent (lower_dentry);dget (lower_dentry); - rc =vfs_rmdir (lower_dir_dentry->d_inode, lower_dentry); + rc =path_rmdir (&lower_dir, lower_dentry);dput (lower_dentry);if (!rc)d_delete (lower_dentry); -fsstack_copy_attr_times (dir, lower_dir_dentry->d_inode); - dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; -unlock_dir (lower_dir_dentry); +fsstack_copy_attr_times (dir, lower_dir.dentry->d_inode); + dir->i_nlink = lower_dir.dentry->d_inode->i_nlink; +unlock_dir (lower_dir.dentry);if (!rc)d_drop (dentry);dput (dentry);
fs/namei.c +15 -8
@@ -2152,7 +2152,7 @@ void dentry_unhash(struct dentry *dentryspin_unlock (&dcache_lock); } -int vfs_rmdir (struct inode *dir,struct dentry *dentry) +static int vfs_rmdir (struct inode *dir,struct dentry *dentry) {int error =may_delete (dir, dentry,1 );
@@ -2185,6 +2185,19 @@ int vfs_rmdir(struct inode *dir, structreturn error; } +int path_rmdir (struct path *dir_path,struct dentry *dentry) +{ +int error =mnt_want_write (dir_path->mnt); + +if (!error) { + error =vfs_rmdir (dir_path->dentry->d_inode, dentry); +mnt_drop_write (dir_path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_rmdir); +static long do_rmdir (int dfd,const char __user *pathname) {int error =0 ;
@@ -2216,12 +2229,7 @@ static long do_rmdir(int dfd, const char error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2; - error =mnt_want_write (nd.path.mnt); -if (error) - goto exit3; - error =vfs_rmdir (nd.path.dentry->d_inode, dentry); -mnt_drop_write (nd.path.mnt); -exit3: + error =path_rmdir (&nd.path, dentry);dput (dentry); exit2:mutex_unlock (&nd.path.dentry->d_inode->i_mutex);
@@ -2917,7 +2925,6 @@ EXPORT_SYMBOL(vfs_link);EXPORT_SYMBOL (generic_permission);EXPORT_SYMBOL (vfs_readlink);EXPORT_SYMBOL (vfs_rename); -EXPORT_SYMBOL (vfs_rmdir);EXPORT_SYMBOL (vfs_symlink);EXPORT_SYMBOL (vfs_unlink);EXPORT_SYMBOL (dentry_unhash);
fs/nfsd/nfs4recover.c +2 -1
@@ -267,6 +267,7 @@ nfsd4_remove_clid_file(struct dentry *distatic int nfsd4_clear_clid_dir (struct dentry *dir,struct dentry *dentry) { +struct path dir_path = { .dentry = dir, .mnt = rec_dir.path.mnt };int status;/* For now this directory should already be empty, but we empty it of
@@ -274,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,* a kernel from the future.... */ nfsd4_list_rec_dir (dentry, nfsd4_remove_clid_file);mutex_lock_nested (&dir->d_inode->i_mutex,I_MUTEX_PARENT ); - status =vfs_rmdir (dir->d_inode, dentry); + status =path_rmdir (&dir_path, dentry);mutex_unlock (&dir->d_inode->i_mutex);return status; }
fs/nfsd/vfs.c +3 -1
@@ -1760,6 +1760,7 @@ __be32 nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, char *fname, int flen) { + struct path dir_path;struct dentry *dentry, *rdentry;struct inode *dirp;__be32 err;
@@ -1794,6 +1795,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struif (host_err) goto out_nfserr; +fh_to_path (fhp, &dir_path);if (type !=S_IFDIR ) {/* It's UNLINK */ #ifdef MSNFS if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
@@ -1803,7 +1805,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru#endif host_err =vfs_unlink (dirp, rdentry); }else {/* It's RMDIR */ - host_err =vfs_rmdir (dirp, rdentry); + host_err =path_rmdir (&dir_path, rdentry); }dput (rdentry);
include/linux/fs.h +1 -1
@@ -1131,7 +1131,7 @@ extern int path_mkdir(struct path *, strextern int path_mknod (struct path *,struct dentry *,int ,dev_t );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 path_rmdir (struct path *,struct dentry *);extern int vfs_unlink (struct inode *,struct dentry *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);
--
PATCH 8/14 vfs: add path_unlink()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_unlink(). Make vfs_unlink() static.
--- fs/ecryptfs/inode.c | 12 ++++++------ fs/namei.c | 22 +++++++++++++++------- fs/nfsd/nfs4recover.c | 3 ++- fs/nfsd/vfs.c | 12 ++---------- include/linux/fs.h | 2 +- ipc/mqueue.c | 10 +++++----- 6 files changed, 31 insertions(+), 30 deletions(-)
fs/ecryptfs/inode.c +6 -6
@@ -415,22 +415,22 @@ static int ecryptfs_unlink(struct inode {int rc =0 ;struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); -struct inode *lower_dir_inode =ecryptfs_inode_to_lower (dir); -struct dentry *lower_dir_dentry; +struct path lower_dir; - lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_unlink (lower_dir_inode, lower_dentry); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_dir.dentry =lock_parent (lower_dentry); + rc =path_unlink (&lower_dir, lower_dentry);if (rc) {printk (KERN_ERR "Error in vfs_unlink; rc = [%d]\n" , rc); goto out_unlock; } -fsstack_copy_attr_times (dir, lower_dir_inode); +fsstack_copy_attr_times (dir, lower_dir.dentry->d_inode); dentry->d_inode->i_nlink =ecryptfs_inode_to_lower (dentry->d_inode)->i_nlink; dentry->d_inode->i_ctime = dir->i_ctime;d_drop (dentry); out_unlock: -unlock_dir (lower_dir_dentry); +unlock_dir (lower_dir.dentry);return rc; }
fs/namei.c +15 -7
@@ -2245,7 +2245,7 @@ asmlinkage long sys_rmdir(const char __ureturn do_rmdir (AT_FDCWD , pathname); } -int vfs_unlink (struct inode *dir,struct dentry *dentry) +static int vfs_unlink (struct inode *dir,struct dentry *dentry) {int error =may_delete (dir, dentry,0 );
@@ -2276,6 +2276,19 @@ int vfs_unlink(struct inode *dir, structreturn error; } +int path_unlink (struct path *dir_path,struct dentry *dentry) +{ +int error =mnt_want_write (dir_path->mnt); + +if (!error) { + error =vfs_unlink (dir_path->dentry->d_inode, dentry); +mnt_drop_write (dir_path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_unlink); +/* * Make sure that the actual truncation of the file will occur outside its * directory's i_mutex. Truncate can take a long time if there is a lot of
@@ -2310,11 +2323,7 @@ static long do_unlinkat(int dfd, const c inode = dentry->d_inode;if (inode)atomic_inc (&inode->i_count); - error =mnt_want_write (nd.path.mnt); -if (error) - goto exit2; - error =vfs_unlink (nd.path.dentry->d_inode, dentry); -mnt_drop_write (nd.path.mnt); + error =path_unlink (&nd.path, dentry); exit2:dput (dentry); }
@@ -2926,6 +2935,5 @@ EXPORT_SYMBOL(generic_permission);EXPORT_SYMBOL (vfs_readlink);EXPORT_SYMBOL (vfs_rename);EXPORT_SYMBOL (vfs_symlink); -EXPORT_SYMBOL (vfs_unlink);EXPORT_SYMBOL (dentry_unhash);EXPORT_SYMBOL (generic_readlink);
fs/nfsd/nfs4recover.c +2 -1
@@ -252,6 +252,7 @@ out:static int nfsd4_remove_clid_file (struct dentry *dir,struct dentry *dentry) { +struct path dir_path = { .dentry = dir, .mnt = rec_dir.path.mnt };int status;if (!S_ISREG (dir->d_inode->i_mode)) {
@@ -259,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *direturn -EINVAL ; }mutex_lock_nested (&dir->d_inode->i_mutex,I_MUTEX_PARENT ); - status =vfs_unlink (dir->d_inode, dentry); + status =path_unlink (&dir_path, dentry);mutex_unlock (&dir->d_inode->i_mutex);return status; }
fs/nfsd/vfs.c +2 -10
@@ -1762,7 +1762,6 @@ nfsd_unlink(struct svc_rqst *rqstp, stru {struct path dir_path;struct dentry *dentry, *rdentry; -struct inode *dirp;__be32 err;int host_err;
@@ -1775,7 +1774,6 @@ nfsd_unlink(struct svc_rqst *rqstp, strufh_lock_nested (fhp,I_MUTEX_PARENT ); dentry = fhp->fh_dentry; - dirp = dentry->d_inode; rdentry =lookup_one_len (fname, dentry, flen); host_err =PTR_ERR (rdentry);
@@ -1791,10 +1789,6 @@ nfsd_unlink(struct svc_rqst *rqstp, struif (!type) type = rdentry->d_inode->i_mode &S_IFMT ; - host_err =mnt_want_write (fhp->fh_export->ex_path.mnt); -if (host_err) - goto out_nfserr; -fh_to_path (fhp, &dir_path);if (type !=S_IFDIR ) {/* It's UNLINK */ #ifdef MSNFS
@@ -1803,7 +1797,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru host_err = -EPERM; } else#endif - host_err =vfs_unlink (dirp, rdentry); + host_err =path_unlink (&dir_path, rdentry); }else {/* It's RMDIR */ host_err =path_rmdir (&dir_path, rdentry); }
@@ -1811,12 +1805,10 @@ nfsd_unlink(struct svc_rqst *rqstp, strudput (rdentry);if (host_err) - goto out_drop; + goto out_nfserr;if (EX_ISSYNC (fhp->fh_export)) host_err =nfsd_sync_dir (dentry); -out_drop: -mnt_drop_write (fhp->fh_export->ex_path.mnt); out_nfserr: err =nfserrno (host_err); out:
include/linux/fs.h +1 -1
@@ -1132,7 +1132,7 @@ extern int path_mknod(struct path *, strextern int vfs_symlink (struct inode *,struct dentry *,const char *);extern int vfs_link (struct dentry *,struct inode *,struct dentry *);extern int path_rmdir (struct path *,struct dentry *); -extern int vfs_unlink (struct inode *,struct dentry *); +extern int path_unlink (struct path *,struct dentry *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);/*
ipc/mqueue.c +5 -5
@@ -736,6 +736,7 @@ asmlinkage long sys_mq_unlink(const charchar *name;struct dentry *dentry;struct inode *inode =NULL ; +struct path dir_path; name =getname (u_name);if (IS_ERR (name))
@@ -757,11 +758,10 @@ asmlinkage long sys_mq_unlink(const char inode = dentry->d_inode;if (inode)atomic_inc (&inode->i_count); - err =mnt_want_write (mqueue_mnt); -if (err) - goto out_err; - err =vfs_unlink (dentry->d_parent->d_inode, dentry); -mnt_drop_write (mqueue_mnt); + + dir_path.mnt = mqueue_mnt; + dir_path.dentry = dentry->d_parent; + err =path_unlink (&dir_path, dentry); out_err:dput (dentry);
--
PATCH 9/14 vfs: add path_symlink()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_symlink(). Make vfs_symlink() static.
--- fs/ecryptfs/inode.c | 14 +++++++------- fs/namei.c | 26 ++++++++++++++++++-------- fs/nfsd/vfs.c | 12 ++++-------- include/linux/fs.h | 2 +- 4 files changed, 30 insertions(+), 24 deletions(-)
fs/ecryptfs/inode.c +7 -7
@@ -439,14 +439,15 @@ static int ecryptfs_symlink(struct inode {int rc;struct dentry *lower_dentry; -struct dentry *lower_dir_dentry; +struct path lower_dir;char *encoded_symname;int encoded_symlen;struct ecryptfs_crypt_stat *crypt_stat =NULL ; lower_dentry =ecryptfs_dentry_to_lower (dentry);dget (lower_dentry); - lower_dir_dentry =lock_parent (lower_dentry); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_dir.dentry =lock_parent (lower_dentry); encoded_symlen =ecryptfs_encode_filename (crypt_stat, symname,strlen (symname), &encoded_symname);
@@ -454,18 +455,17 @@ static int ecryptfs_symlink(struct inode rc = encoded_symlen; goto out_lock; } - rc =vfs_symlink (lower_dir_dentry->d_inode, lower_dentry, - encoded_symname); + rc =path_symlink (&lower_dir, lower_dentry, encoded_symname);kfree (encoded_symname);if (rc || !lower_dentry->d_inode) goto out_lock; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb,0 );if (rc) goto out_lock; -fsstack_copy_attr_times (dir, lower_dir_dentry->d_inode); -fsstack_copy_inode_size (dir, lower_dir_dentry->d_inode); +fsstack_copy_attr_times (dir, lower_dir.dentry->d_inode); +fsstack_copy_inode_size (dir, lower_dir.dentry->d_inode); out_lock: -unlock_dir (lower_dir_dentry); +unlock_dir (lower_dir.dentry);dput (lower_dentry);if (!dentry->d_inode)d_drop (dentry);
fs/namei.c +18 -8
@@ -2358,7 +2358,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) +static int vfs_symlink (struct inode *dir,struct dentry *dentry,const char *oldname) {int error =may_create (dir, dentry,NULL );
@@ -2379,6 +2379,22 @@ int vfs_symlink(struct inode *dir, strucreturn error; } +int path_symlink (struct path *dir_path,struct dentry *dentry, +const char *oldname) +{ +int error =mnt_want_write (dir_path->mnt); + +if (!error) { +struct inode *dir = dir_path->dentry->d_inode; + + error =vfs_symlink (dir, dentry, oldname); +mnt_drop_write (dir_path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_symlink); +asmlinkage long sys_symlinkat (const char __user *oldname,int newdfd,const char __user *newname) {
@@ -2404,12 +2420,7 @@ asmlinkage long sys_symlinkat(const charif (IS_ERR (dentry)) goto out_unlock; - error =mnt_want_write (nd.path.mnt); -if (error) - goto out_dput; - error =vfs_symlink (nd.path.dentry->d_inode, dentry, from); -mnt_drop_write (nd.path.mnt); -out_dput: + error =path_symlink (&nd.path, dentry, from);dput (dentry); out_unlock:mutex_unlock (&nd.path.dentry->d_inode->i_mutex);
@@ -2934,6 +2945,5 @@ EXPORT_SYMBOL(vfs_link);EXPORT_SYMBOL (generic_permission);EXPORT_SYMBOL (vfs_readlink);EXPORT_SYMBOL (vfs_rename); -EXPORT_SYMBOL (vfs_symlink);EXPORT_SYMBOL (dentry_unhash);EXPORT_SYMBOL (generic_readlink);
fs/nfsd/vfs.c +4 -8
@@ -1520,6 +1520,7 @@ nfsd_symlink(struct svc_rqst *rqstp, strstruct svc_fh *resfhp, struct iattr *iap) { + struct path dir_path;struct dentry *dentry, *dnew;__be32 err, cerr;int host_err;
@@ -1541,10 +1542,7 @@ nfsd_symlink(struct svc_rqst *rqstp, strif (IS_ERR (dnew)) goto out_nfserr; - host_err =mnt_want_write (fhp->fh_export->ex_path.mnt); -if (host_err) - goto out_nfserr; - +fh_to_path (fhp, &dir_path);if (unlikely (path[plen] !=0 )) {char *path_alloced =kmalloc (plen+1 ,GFP_KERNEL );if (path_alloced ==NULL )
@@ -1552,11 +1550,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); + host_err =path_symlink (&dir_path, dnew, path_alloced);kfree (path_alloced); } }else - host_err =vfs_symlink (dentry->d_inode, dnew, path); + host_err =path_symlink (&dir_path, dnew, path);if (!host_err) {if (EX_ISSYNC (fhp->fh_export))
@@ -1565,8 +1563,6 @@ nfsd_symlink(struct svc_rqst *rqstp, str err =nfserrno (host_err);fh_unlock (fhp); -mnt_drop_write (fhp->fh_export->ex_path.mnt); - cerr =fh_compose (resfhp, fhp->fh_export, dnew, fhp);dput (dnew);if (err==0 ) err = cerr;
include/linux/fs.h +1 -1
@@ -1129,7 +1129,7 @@ extern int vfs_permission(struct nameidaextern int path_create (struct path *,struct dentry *,int ,struct nameidata *);extern int path_mkdir (struct path *,struct dentry *,int );extern int path_mknod (struct path *,struct dentry *,int ,dev_t ); -extern int vfs_symlink (struct inode *,struct dentry *,const char *); +extern int path_symlink (struct path *,struct dentry *,const char *);extern int vfs_link (struct dentry *,struct inode *,struct dentry *);extern int path_rmdir (struct path *,struct dentry *);extern int path_unlink (struct path *,struct dentry *);
--
PATCH 10/14 vfs: add path_link()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_link(). Make vfs_link() static.
--- fs/ecryptfs/inode.c | 10 +++++----- fs/namei.c | 26 ++++++++++++++++++-------- fs/nfsd/vfs.c | 14 ++++---------- include/linux/fs.h | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-)
fs/ecryptfs/inode.c +5 -5
@@ -379,7 +379,7 @@ static int ecryptfs_link(struct dentry * {struct dentry *lower_old_dentry;struct dentry *lower_new_dentry; -struct dentry *lower_dir_dentry; +struct path lower_dir;u64 file_size_save;int rc;
@@ -388,9 +388,9 @@ static int ecryptfs_link(struct dentry * lower_new_dentry =ecryptfs_dentry_to_lower (new_dentry);dget (lower_old_dentry);dget (lower_new_dentry); - lower_dir_dentry =lock_parent (lower_new_dentry); - rc =vfs_link (lower_old_dentry, lower_dir_dentry->d_inode, - lower_new_dentry); + lower_dir.mnt =ecryptfs_dentry_to_lower_mnt (new_dentry); + lower_dir.dentry =lock_parent (lower_new_dentry); + rc =path_link (lower_old_dentry, &lower_dir, lower_new_dentry);if (rc || !lower_new_dentry->d_inode) goto out_lock; rc =ecryptfs_interpose (lower_new_dentry, new_dentry, dir->i_sb,0 );
@@ -402,7 +402,7 @@ static int ecryptfs_link(struct dentry *ecryptfs_inode_to_lower (old_dentry->d_inode)->i_nlink;i_size_write (new_dentry->d_inode, file_size_save); out_lock: -unlock_dir (lower_dir_dentry); +unlock_dir (lower_dir.dentry);dput (lower_new_dentry);dput (lower_old_dentry);d_drop (lower_old_dentry);
fs/namei.c +18 -8
@@ -2437,7 +2437,7 @@ asmlinkage long sys_symlink(const char _return sys_symlinkat (oldname,AT_FDCWD , newname); } -int vfs_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) +static int vfs_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) {struct inode *inode = old_dentry->d_inode;int error;
@@ -2475,6 +2475,22 @@ int vfs_link(struct dentry *old_dentry,return error; } +int path_link (struct dentry *old_dentry,struct path *dir_path, +struct dentry *new_dentry) +{ +int error =mnt_want_write (dir_path->mnt); + +if (!error) { +struct inode *dir = dir_path->dentry->d_inode; + + error =vfs_link (old_dentry, dir, new_dentry); +mnt_drop_write (dir_path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_link); +/* * Hardlinks are often used in delicate situations. We avoid * security-related surprises by not following symlinks on the
@@ -2516,12 +2532,7 @@ asmlinkage long sys_linkat(int olddfd, c error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto out_unlock; - error =mnt_want_write (nd.path.mnt); -if (error) - goto out_dput; - error =vfs_link (old_path.dentry, nd.path.dentry->d_inode, new_dentry); -mnt_drop_write (nd.path.mnt); -out_dput: + error =path_link (old_path.dentry, &nd.path, new_dentry);dput (new_dentry); out_unlock:mutex_unlock (&nd.path.dentry->d_inode->i_mutex);
@@ -2941,7 +2952,6 @@ EXPORT_SYMBOL(vfs_permission);EXPORT_SYMBOL (file_permission);EXPORT_SYMBOL (unlock_rename);EXPORT_SYMBOL (vfs_follow_link); -EXPORT_SYMBOL (vfs_link);EXPORT_SYMBOL (generic_permission);EXPORT_SYMBOL (vfs_readlink);EXPORT_SYMBOL (vfs_rename);
fs/nfsd/vfs.c +4 -10
@@ -1582,8 +1582,9 @@ __be32 nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *name, int len, struct svc_fh *tfhp) { + struct path dir_path;struct dentry *ddir, *dnew, *dold; -struct inode *dirp, *dest; +struct inode *dest;__be32 err;int host_err;
@@ -1603,7 +1604,6 @@ nfsd_link(struct svc_rqst *rqstp, structfh_lock_nested (ffhp,I_MUTEX_PARENT ); ddir = ffhp->fh_dentry; - dirp = ddir->d_inode; dnew =lookup_one_len (name, ddir, len); host_err =PTR_ERR (dnew);
@@ -1613,12 +1613,8 @@ nfsd_link(struct svc_rqst *rqstp, struct dold = tfhp->fh_dentry; dest = dold->d_inode; - host_err =mnt_want_write (tfhp->fh_export->ex_path.mnt); -if (host_err) { - err =nfserrno (host_err); - goto out_dput; - } - host_err =vfs_link (dold, dirp, dnew); +fh_to_path (ffhp, &dir_path); + host_err =path_link (dold, &dir_path, dnew);if (!host_err) {if (EX_ISSYNC (ffhp->fh_export)) { err =nfserrno (nfsd_sync_dir (ddir));
@@ -1631,8 +1627,6 @@ nfsd_link(struct svc_rqst *rqstp, structelse err =nfserrno (host_err); } -mnt_drop_write (tfhp->fh_export->ex_path.mnt); -out_dput:dput (dnew); out_unlock:fh_unlock (ffhp);
include/linux/fs.h +1 -1
@@ -1130,7 +1130,7 @@ extern int path_create(struct path *, stextern int path_mkdir (struct path *,struct dentry *,int );extern int path_mknod (struct path *,struct dentry *,int ,dev_t );extern int path_symlink (struct path *,struct dentry *,const char *); -extern int vfs_link (struct dentry *,struct inode *,struct dentry *); +extern int path_link (struct dentry *,struct path *,struct dentry *);extern int path_rmdir (struct path *,struct dentry *);extern int path_unlink (struct path *,struct dentry *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);
--
PATCH 11/14 vfs: add path_rename()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_rename(). Make vfs_rename() static.
--- fs/ecryptfs/inode.c | 22 ++++++++++++---------- fs/namei.c | 33 ++++++++++++++++++++++++--------- fs/nfsd/vfs.c | 19 +++++-------------- include/linux/fs.h | 3 ++- 4 files changed, 43 insertions(+), 34 deletions(-)
fs/ecryptfs/inode.c +12 -10
@@ -553,25 +553,27 @@ ecryptfs_rename(struct inode *old_dir, sint rc;struct dentry *lower_old_dentry;struct dentry *lower_new_dentry; -struct dentry *lower_old_dir_dentry; -struct dentry *lower_new_dir_dentry; +struct path lower_old_dir; +struct path lower_new_dir; lower_old_dentry =ecryptfs_dentry_to_lower (old_dentry); lower_new_dentry =ecryptfs_dentry_to_lower (new_dentry);dget (lower_old_dentry);dget (lower_new_dentry); - lower_old_dir_dentry =dget_parent (lower_old_dentry); - lower_new_dir_dentry =dget_parent (lower_new_dentry); -lock_rename (lower_old_dir_dentry, lower_new_dir_dentry); - rc =vfs_rename (lower_old_dir_dentry->d_inode, lower_old_dentry, - lower_new_dir_dentry->d_inode, lower_new_dentry); + lower_old_dir.mnt =ecryptfs_dentry_to_lower_mnt (old_dentry); + lower_old_dir.dentry =dget_parent (lower_old_dentry); + lower_new_dir.mnt =ecryptfs_dentry_to_lower_mnt (new_dentry); + lower_new_dir.dentry =dget_parent (lower_new_dentry); +lock_rename (lower_old_dir.dentry, lower_new_dir.dentry); + rc =path_rename (&lower_old_dir, lower_old_dentry, + &lower_new_dir, lower_new_dentry);if (rc) goto out_lock; -fsstack_copy_attr_all (new_dir, lower_new_dir_dentry->d_inode,NULL ); +fsstack_copy_attr_all (new_dir, lower_new_dir.dentry->d_inode,NULL );if (new_dir != old_dir) -fsstack_copy_attr_all (old_dir, lower_old_dir_dentry->d_inode,NULL ); +fsstack_copy_attr_all (old_dir, lower_old_dir.dentry->d_inode,NULL ); out_lock: -unlock_rename (lower_old_dir_dentry, lower_new_dir_dentry); +unlock_rename (lower_old_dir.dentry, lower_new_dir.dentry);dput (lower_new_dentry->d_parent);dput (lower_old_dentry->d_parent);dput (lower_new_dentry);
fs/namei.c +24 -9
@@ -2654,8 +2654,8 @@ static int vfs_rename_other(struct inodereturn error; } -int vfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry) +static int vfs_rename (struct inode *old_dir,struct dentry *old_dentry, +struct inode *new_dir,struct dentry *new_dentry) {int error;int is_dir =S_ISDIR (old_dentry->d_inode->i_mode);
@@ -2697,6 +2697,27 @@ int vfs_rename(struct inode *old_dir, streturn error; } +int path_rename (struct path *old_dir_path,struct dentry *old_dentry, +struct path *new_dir_path,struct dentry *new_dentry) +{ +int error; +struct vfsmount *mnt = old_dir_path->mnt; + +BUG_ON (mnt != new_dir_path->mnt); + + error =mnt_want_write (mnt); +if (!error) { +struct inode *old_dir = old_dir_path->dentry->d_inode; +struct inode *new_dir = new_dir_path->dentry->d_inode; + + error =vfs_rename (old_dir, old_dentry, new_dir, new_dentry); +mnt_drop_write (mnt); + } + +return error; +} +EXPORT_SYMBOL (path_rename); +static int do_rename (int olddfd,const char *oldname,int newdfd,const char *newname) {
@@ -2758,12 +2779,7 @@ static int do_rename(int olddfd, const cif (new_dentry == trap) goto exit5; - error =mnt_want_write (oldnd.path.mnt); -if (error) - goto exit5; - error =vfs_rename (old_dir->d_inode, old_dentry, - new_dir->d_inode, new_dentry); -mnt_drop_write (oldnd.path.mnt); + error =path_rename (&oldnd.path, old_dentry, &newnd.path, new_dentry); exit5:dput (new_dentry); exit4:
@@ -2954,6 +2970,5 @@ EXPORT_SYMBOL(unlock_rename);EXPORT_SYMBOL (vfs_follow_link);EXPORT_SYMBOL (generic_permission);EXPORT_SYMBOL (vfs_readlink); -EXPORT_SYMBOL (vfs_rename);EXPORT_SYMBOL (dentry_unhash);EXPORT_SYMBOL (generic_readlink);
fs/nfsd/vfs.c +5 -14
@@ -1646,8 +1646,9 @@ __be32 nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, struct svc_fh *tfhp, char *tname, int tlen) { + struct path old_dir_path; +struct path new_dir_path;struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap; -struct inode *fdir, *tdir;__be32 err;int host_err;
@@ -1659,10 +1660,7 @@ nfsd_rename(struct svc_rqst *rqstp, stru goto out; fdentry = ffhp->fh_dentry; - fdir = fdentry->d_inode; - tdentry = tfhp->fh_dentry; - tdir = tdentry->d_inode; err = (rqstp->rq_vers ==2 ) ? nfserr_acces : nfserr_xdev;if (ffhp->fh_export != tfhp->fh_export)
@@ -1706,22 +1704,15 @@ nfsd_rename(struct svc_rqst *rqstp, stru goto out_dput_new; } - host_err = -EXDEV ; -if (ffhp->fh_export->ex_path.mnt != tfhp->fh_export->ex_path.mnt) - goto out_dput_new; - host_err =mnt_want_write (ffhp->fh_export->ex_path.mnt); -if (host_err) - goto out_dput_new; - - host_err =vfs_rename (fdir, odentry, tdir, ndentry); +fh_to_path (ffhp, &old_dir_path); +fh_to_path (tfhp, &new_dir_path); + host_err =path_rename (&old_dir_path, odentry, &new_dir_path, ndentry);if (!host_err &&EX_ISSYNC (tfhp->fh_export)) { host_err =nfsd_sync_dir (tdentry);if (!host_err) host_err =nfsd_sync_dir (fdentry); } -mnt_drop_write (ffhp->fh_export->ex_path.mnt); - out_dput_new:dput (ndentry); out_dput_old:
include/linux/fs.h +2 -1
@@ -1133,7 +1133,8 @@ extern int path_symlink(struct path *, sextern int path_link (struct dentry *,struct path *,struct dentry *);extern int path_rmdir (struct path *,struct dentry *);extern int path_unlink (struct path *,struct dentry *); -extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *); +extern int path_rename (struct path *,struct dentry *, +struct path *,struct dentry *);/* * VFS dentry helper functions.
--
PATCH 12/14 vfs: add path_setattr()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_setattr(). Stop exporting notify_change() to modules.
--- fs/attr.c | 14 +++++++++++++- fs/ecryptfs/inode.c | 11 ++++++----- fs/nfsd/vfs.c | 17 +++++++++++------ fs/open.c | 52 ++++++++++------------------------------------------ include/linux/fs.h | 1 + 5 files changed, 41 insertions(+), 54 deletions(-)
fs/attr.c +13 -1
@@ -14,6 +14,7 @@#include <linux/fcntl.h> #include <linux/quotaops.h> #include <linux/security.h> +#include <linux/mount.h> /* Taken over from the old code... */
@@ -188,4 +189,15 @@ int notify_change(struct dentry * dentryreturn error; } -EXPORT_SYMBOL (notify_change); +int path_setattr (struct path *path,struct iattr *attr) +{ +int error =mnt_want_write (path->mnt); + +if (!error) { + error =notify_change (path->dentry, attr); +mnt_drop_write (path->mnt); + } + +return error; +} +EXPORT_SYMBOL (path_setattr);
fs/ecryptfs/inode.c +6 -5
@@ -828,7 +828,7 @@ ecryptfs_permission(struct inode *inode,static int ecryptfs_setattr (struct dentry *dentry,struct iattr *ia) {int rc =0 ; -struct dentry *lower_dentry; +struct path lower_path;struct inode *inode;struct inode *lower_inode;struct ecryptfs_crypt_stat *crypt_stat;
@@ -838,7 +838,8 @@ static int ecryptfs_setattr(struct dentrecryptfs_init_crypt_stat (crypt_stat); inode = dentry->d_inode; lower_inode =ecryptfs_inode_to_lower (inode); - lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_path.mnt =ecryptfs_dentry_to_lower_mnt (dentry); + lower_path.dentry =ecryptfs_dentry_to_lower (dentry);mutex_lock (&crypt_stat->cs_mutex);if (S_ISDIR (dentry->d_inode->i_mode)) crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED );
@@ -889,9 +890,9 @@ static int ecryptfs_setattr(struct dentrif (ia->ia_valid & (ATTR_KILL_SUID |ATTR_KILL_SGID )) ia->ia_valid &= ~ATTR_MODE ; -mutex_lock (&lower_dentry->d_inode->i_mutex); - rc =notify_change (lower_dentry, ia); -mutex_unlock (&lower_dentry->d_inode->i_mutex); +mutex_lock (&lower_path.dentry->d_inode->i_mutex); + rc =path_setattr (&lower_path, ia); +mutex_unlock (&lower_path.dentry->d_inode->i_mutex); out:fsstack_copy_attr_all (inode, lower_inode,NULL );return rc;
fs/nfsd/vfs.c +11 -6
@@ -393,8 +393,11 @@ nfsd_setattr(struct svc_rqst *rqstp, str err = nfserr_notsync;if (!check_guard || guardtime == inode->i_ctime.tv_sec) { +struct path path; +fh_lock (fhp); - host_err =notify_change (dentry, iap); +fh_to_path (fhp, &path); + host_err =path_setattr (&path, iap); err =nfserrno (host_err);fh_unlock (fhp); }
@@ -950,14 +953,16 @@ out:return err; } -static void kill_suid (struct dentry *dentry) +static void kill_suid (struct svc_fh *fhp) { +struct path path;struct iattr ia; ia.ia_valid =ATTR_KILL_SUID |ATTR_KILL_SGID |ATTR_KILL_PRIV ; -mutex_lock (&dentry->d_inode->i_mutex); -notify_change (dentry, &ia); -mutex_unlock (&dentry->d_inode->i_mutex); +mutex_lock (&path.dentry->d_inode->i_mutex); +fh_to_path (fhp, &path); +path_setattr (&path, &ia); +mutex_unlock (&path.dentry->d_inode->i_mutex); } static __be32
@@ -1015,7 +1020,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s/* clear setuid/setgid flag after write */ if (host_err >=0 && (inode->i_mode & (S_ISUID |S_ISGID ))) -kill_suid (dentry); +kill_suid (fhp);if (host_err >=0 && stable) {static ino_t last_ino;
fs/open.c +10 -42
118 lines not on this page · raw message
include/linux/fs.h +1 -0
@@ -1761,6 +1761,7 @@ extern int do_remount_sb(struct super_blextern sector_t bmap (struct inode *,sector_t );#endif extern int notify_change (struct dentry *,struct iattr *); +extern int path_setattr (struct path *,struct iattr *);extern int inode_permission (struct inode *,int );extern int generic_permission (struct inode *,int ,int (*check_acl)(struct inode *,int ));
--
PATCH 13/14 vfs: add path_setxattr()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_setxattr(). Make vfs_setxattr() static.
--- fs/nfsd/vfs.c | 18 ++++++++++-------- fs/xattr.c | 44 ++++++++++++++++++++++---------------------- include/linux/xattr.h | 3 ++- 3 files changed, 34 insertions(+), 31 deletions(-)
fs/nfsd/vfs.c +10 -8
@@ -435,7 +435,7 @@ static ssize_t nfsd_getxattr(struct dent#if defined(CONFIG_NFSD_V4 )static int -set_nfsv4_acl_one (struct dentry *dentry,struct posix_acl *pacl,char *key) +set_nfsv4_acl_one (struct path *path,struct posix_acl *pacl,char *key) {int len;size_t buflen;
@@ -454,7 +454,7 @@ set_nfsv4_acl_one(struct dentry *dentry, goto out; } - error =vfs_setxattr (dentry, key, buf, len,0 ); + error =path_setxattr (path, key, buf, len,0 ); out:kfree (buf);return error;
@@ -466,7 +466,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst {__be32 error;int host_error; -struct dentry *dentry; +struct path path;struct inode *inode;struct posix_acl *pacl =NULL , *dpacl =NULL ;unsigned int flags =0 ;
@@ -476,8 +476,8 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqstif (error)return error; - dentry = fhp->fh_dentry; - inode = dentry->d_inode; +fh_to_path (fhp, &path); + inode = path.dentry->d_inode;if (S_ISDIR (inode->i_mode)) flags =NFS4_ACL_DIR ;
@@ -487,12 +487,12 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst }else if (host_error <0 ) goto out_nfserr; - host_error =set_nfsv4_acl_one (dentry, pacl,POSIX_ACL_XATTR_ACCESS ); + host_error =set_nfsv4_acl_one (&path, pacl,POSIX_ACL_XATTR_ACCESS );if (host_error <0 ) goto out_release;if (S_ISDIR (inode->i_mode)) - host_error =set_nfsv4_acl_one (dentry, dpacl,POSIX_ACL_XATTR_DEFAULT ); + host_error =set_nfsv4_acl_one (&path, dpacl,POSIX_ACL_XATTR_DEFAULT ); out_release:posix_acl_release (pacl);
@@ -2035,6 +2035,7 @@ nfsd_get_posix_acl(struct svc_fh *fhp, iint nfsd_set_posix_acl (struct svc_fh *fhp,int type,struct posix_acl *acl) { +struct path path;struct inode *inode = fhp->fh_dentry->d_inode;char *name;void *value =NULL ;
@@ -2070,8 +2071,9 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i error =mnt_want_write (fhp->fh_export->ex_path.mnt);if (error) goto getout; +fh_to_path (fhp, &path);if (size) - error =vfs_setxattr (fhp->fh_dentry, name, value, size,0 ); + error =path_setxattr (&path, name, value, size,0 );else {if (!S_ISDIR (inode->i_mode) && type ==ACL_TYPE_DEFAULT ) error =0 ;
fs/xattr.c +22 -22
91 lines not on this page · raw message
include/linux/xattr.h +2 -1
@@ -35,6 +35,7 @@struct inode ;struct dentry ; +struct path ;struct xattr_handler {char *prefix;
@@ -49,7 +50,7 @@ struct xattr_handler {ssize_t xattr_getsecurity (struct inode *,const char *,void *,size_t );ssize_t vfs_getxattr (struct dentry *,const char *,void *,size_t );ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size); -int vfs_setxattr (struct dentry *,const char *,const void *,size_t ,int ); +int path_setxattr (struct path *,const char *,const void *,size_t ,int );int vfs_removexattr (struct dentry *,const char *);ssize_t generic_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size);
--
PATCH 14/14 vfs: add path_removexattr()
In reply to Miklos SzerediFrom: Miklos Szeredi <[email protected]>
Introduce path_removexattr(). Make vfs_removexattr() static.
--- fs/nfsd/vfs.c | 6 +----- fs/xattr.c | 41 +++++++++++++++++++---------------------- include/linux/xattr.h | 2 +- 3 files changed, 21 insertions(+), 28 deletions(-)
fs/nfsd/vfs.c +1 -5
@@ -2068,9 +2068,6 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i }else size =0 ; - error =mnt_want_write (fhp->fh_export->ex_path.mnt); -if (error) - goto getout;fh_to_path (fhp, &path);if (size) error =path_setxattr (&path, name, value, size,0 );
@@ -2078,12 +2075,11 @@ nfsd_set_posix_acl(struct svc_fh *fhp, iif (!S_ISDIR (inode->i_mode) && type ==ACL_TYPE_DEFAULT ) error =0 ;else { - error =vfs_removexattr (fhp->fh_dentry, name); + error =path_removexattr (&path, name);if (error == -ENODATA ) error =0 ; } } -mnt_drop_write (fhp->fh_export->ex_path.mnt); getout:kfree (value);
fs/xattr.c +19 -22
89 lines not on this page · raw message
include/linux/xattr.h +1 -1
@@ -51,7 +51,7 @@ ssize_t xattr_getsecurity(struct inode *ssize_t vfs_getxattr (struct dentry *,const char *,void *,size_t );ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size);int path_setxattr (struct path *,const char *,const void *,size_t ,int ); -int vfs_removexattr (struct dentry *,const char *); +int path_removexattr (struct path *,const char *);ssize_t generic_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size);ssize_t generic_listxattr (struct dentry *dentry,char *buffer,size_t buffer_size);
--