Make set_fs_{root,pwd} take a struct path
In nearly all cases the set_fs_{root,pwd}() calls work on a struct path. Change the function to reflect this and use path_get() here. Signed-off-by: Jan Blunck <jblunck@suse.de> Signed-off-by: Andreas Gruenbacher <agruen@suse.de> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
6ac08c39a1
commit
ac748a09fc
3 changed files with 20 additions and 24 deletions
|
@ -1650,15 +1650,14 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
|
||||||
* Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
|
* Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
|
||||||
* It can block. Requires the big lock held.
|
* It can block. Requires the big lock held.
|
||||||
*/
|
*/
|
||||||
void set_fs_root(struct fs_struct *fs, struct vfsmount *mnt,
|
void set_fs_root(struct fs_struct *fs, struct path *path)
|
||||||
struct dentry *dentry)
|
|
||||||
{
|
{
|
||||||
struct path old_root;
|
struct path old_root;
|
||||||
|
|
||||||
write_lock(&fs->lock);
|
write_lock(&fs->lock);
|
||||||
old_root = fs->root;
|
old_root = fs->root;
|
||||||
fs->root.mnt = mntget(mnt);
|
fs->root = *path;
|
||||||
fs->root.dentry = dget(dentry);
|
path_get(path);
|
||||||
write_unlock(&fs->lock);
|
write_unlock(&fs->lock);
|
||||||
if (old_root.dentry)
|
if (old_root.dentry)
|
||||||
path_put(&old_root);
|
path_put(&old_root);
|
||||||
|
@ -1668,15 +1667,14 @@ void set_fs_root(struct fs_struct *fs, struct vfsmount *mnt,
|
||||||
* Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
|
* Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
|
||||||
* It can block. Requires the big lock held.
|
* It can block. Requires the big lock held.
|
||||||
*/
|
*/
|
||||||
void set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
|
void set_fs_pwd(struct fs_struct *fs, struct path *path)
|
||||||
struct dentry *dentry)
|
|
||||||
{
|
{
|
||||||
struct path old_pwd;
|
struct path old_pwd;
|
||||||
|
|
||||||
write_lock(&fs->lock);
|
write_lock(&fs->lock);
|
||||||
old_pwd = fs->pwd;
|
old_pwd = fs->pwd;
|
||||||
fs->pwd.mnt = mntget(mnt);
|
fs->pwd = *path;
|
||||||
fs->pwd.dentry = dget(dentry);
|
path_get(path);
|
||||||
write_unlock(&fs->lock);
|
write_unlock(&fs->lock);
|
||||||
|
|
||||||
if (old_pwd.dentry)
|
if (old_pwd.dentry)
|
||||||
|
@ -1697,12 +1695,10 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
|
||||||
task_unlock(p);
|
task_unlock(p);
|
||||||
if (fs->root.dentry == old_nd->path.dentry
|
if (fs->root.dentry == old_nd->path.dentry
|
||||||
&& fs->root.mnt == old_nd->path.mnt)
|
&& fs->root.mnt == old_nd->path.mnt)
|
||||||
set_fs_root(fs, new_nd->path.mnt,
|
set_fs_root(fs, &new_nd->path);
|
||||||
new_nd->path.dentry);
|
|
||||||
if (fs->pwd.dentry == old_nd->path.dentry
|
if (fs->pwd.dentry == old_nd->path.dentry
|
||||||
&& fs->pwd.mnt == old_nd->path.mnt)
|
&& fs->pwd.mnt == old_nd->path.mnt)
|
||||||
set_fs_pwd(fs, new_nd->path.mnt,
|
set_fs_pwd(fs, &new_nd->path);
|
||||||
new_nd->path.dentry);
|
|
||||||
put_fs_struct(fs);
|
put_fs_struct(fs);
|
||||||
} else
|
} else
|
||||||
task_unlock(p);
|
task_unlock(p);
|
||||||
|
@ -1845,6 +1841,7 @@ static void __init init_mount_tree(void)
|
||||||
{
|
{
|
||||||
struct vfsmount *mnt;
|
struct vfsmount *mnt;
|
||||||
struct mnt_namespace *ns;
|
struct mnt_namespace *ns;
|
||||||
|
struct path root;
|
||||||
|
|
||||||
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
|
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
|
||||||
if (IS_ERR(mnt))
|
if (IS_ERR(mnt))
|
||||||
|
@ -1863,8 +1860,11 @@ static void __init init_mount_tree(void)
|
||||||
init_task.nsproxy->mnt_ns = ns;
|
init_task.nsproxy->mnt_ns = ns;
|
||||||
get_mnt_ns(ns);
|
get_mnt_ns(ns);
|
||||||
|
|
||||||
set_fs_pwd(current->fs, ns->root, ns->root->mnt_root);
|
root.mnt = ns->root;
|
||||||
set_fs_root(current->fs, ns->root, ns->root->mnt_root);
|
root.dentry = ns->root->mnt_root;
|
||||||
|
|
||||||
|
set_fs_pwd(current->fs, &root);
|
||||||
|
set_fs_root(current->fs, &root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __init mnt_init(void)
|
void __init mnt_init(void)
|
||||||
|
|
12
fs/open.c
12
fs/open.c
|
@ -490,7 +490,7 @@ asmlinkage long sys_chdir(const char __user * filename)
|
||||||
if (error)
|
if (error)
|
||||||
goto dput_and_out;
|
goto dput_and_out;
|
||||||
|
|
||||||
set_fs_pwd(current->fs, nd.path.mnt, nd.path.dentry);
|
set_fs_pwd(current->fs, &nd.path);
|
||||||
|
|
||||||
dput_and_out:
|
dput_and_out:
|
||||||
path_put(&nd.path);
|
path_put(&nd.path);
|
||||||
|
@ -501,9 +501,7 @@ asmlinkage long sys_chdir(const char __user * filename)
|
||||||
asmlinkage long sys_fchdir(unsigned int fd)
|
asmlinkage long sys_fchdir(unsigned int fd)
|
||||||
{
|
{
|
||||||
struct file *file;
|
struct file *file;
|
||||||
struct dentry *dentry;
|
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
struct vfsmount *mnt;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
error = -EBADF;
|
error = -EBADF;
|
||||||
|
@ -511,9 +509,7 @@ asmlinkage long sys_fchdir(unsigned int fd)
|
||||||
if (!file)
|
if (!file)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
dentry = file->f_path.dentry;
|
inode = file->f_path.dentry->d_inode;
|
||||||
mnt = file->f_path.mnt;
|
|
||||||
inode = dentry->d_inode;
|
|
||||||
|
|
||||||
error = -ENOTDIR;
|
error = -ENOTDIR;
|
||||||
if (!S_ISDIR(inode->i_mode))
|
if (!S_ISDIR(inode->i_mode))
|
||||||
|
@ -521,7 +517,7 @@ asmlinkage long sys_fchdir(unsigned int fd)
|
||||||
|
|
||||||
error = file_permission(file, MAY_EXEC);
|
error = file_permission(file, MAY_EXEC);
|
||||||
if (!error)
|
if (!error)
|
||||||
set_fs_pwd(current->fs, mnt, dentry);
|
set_fs_pwd(current->fs, &file->f_path);
|
||||||
out_putf:
|
out_putf:
|
||||||
fput(file);
|
fput(file);
|
||||||
out:
|
out:
|
||||||
|
@ -545,7 +541,7 @@ asmlinkage long sys_chroot(const char __user * filename)
|
||||||
if (!capable(CAP_SYS_CHROOT))
|
if (!capable(CAP_SYS_CHROOT))
|
||||||
goto dput_and_out;
|
goto dput_and_out;
|
||||||
|
|
||||||
set_fs_root(current->fs, nd.path.mnt, nd.path.dentry);
|
set_fs_root(current->fs, &nd.path);
|
||||||
set_fs_altroot();
|
set_fs_altroot();
|
||||||
error = 0;
|
error = 0;
|
||||||
dput_and_out:
|
dput_and_out:
|
||||||
|
|
|
@ -20,8 +20,8 @@ extern struct kmem_cache *fs_cachep;
|
||||||
|
|
||||||
extern void exit_fs(struct task_struct *);
|
extern void exit_fs(struct task_struct *);
|
||||||
extern void set_fs_altroot(void);
|
extern void set_fs_altroot(void);
|
||||||
extern void set_fs_root(struct fs_struct *, struct vfsmount *, struct dentry *);
|
extern void set_fs_root(struct fs_struct *, struct path *);
|
||||||
extern void set_fs_pwd(struct fs_struct *, struct vfsmount *, struct dentry *);
|
extern void set_fs_pwd(struct fs_struct *, struct path *);
|
||||||
extern struct fs_struct *copy_fs_struct(struct fs_struct *);
|
extern struct fs_struct *copy_fs_struct(struct fs_struct *);
|
||||||
extern void put_fs_struct(struct fs_struct *);
|
extern void put_fs_struct(struct fs_struct *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue