Commit 208f6f60 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  new helper: mount_subtree()
  switch create_mnt_ns() to saner calling conventions, fix double mntput() in nfs
  btrfs: fix double mntput() in mount_subvol()
parents ab5c5f63 ea441d11
...@@ -825,13 +825,9 @@ static char *setup_root_args(char *args) ...@@ -825,13 +825,9 @@ static char *setup_root_args(char *args)
static struct dentry *mount_subvol(const char *subvol_name, int flags, static struct dentry *mount_subvol(const char *subvol_name, int flags,
const char *device_name, char *data) const char *device_name, char *data)
{ {
struct super_block *s;
struct dentry *root; struct dentry *root;
struct vfsmount *mnt; struct vfsmount *mnt;
struct mnt_namespace *ns_private;
char *newargs; char *newargs;
struct path path;
int error;
newargs = setup_root_args(data); newargs = setup_root_args(data);
if (!newargs) if (!newargs)
...@@ -842,39 +838,17 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags, ...@@ -842,39 +838,17 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
if (IS_ERR(mnt)) if (IS_ERR(mnt))
return ERR_CAST(mnt); return ERR_CAST(mnt);
ns_private = create_mnt_ns(mnt); root = mount_subtree(mnt, subvol_name);
if (IS_ERR(ns_private)) {
mntput(mnt);
return ERR_CAST(ns_private);
}
/* if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) {
* This will trigger the automount of the subvol so we can just struct super_block *s = root->d_sb;
* drop the mnt we have here and return the dentry that we dput(root);
* found. root = ERR_PTR(-EINVAL);
*/ deactivate_locked_super(s);
error = vfs_path_lookup(mnt->mnt_root, mnt, subvol_name,
LOOKUP_FOLLOW, &path);
put_mnt_ns(ns_private);
if (error)
return ERR_PTR(error);
if (!is_subvolume_inode(path.dentry->d_inode)) {
path_put(&path);
mntput(mnt);
error = -EINVAL;
printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n", printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n",
subvol_name); subvol_name);
return ERR_PTR(-EINVAL);
} }
/* Get a ref to the sb and the dentry we found and return it */
s = path.mnt->mnt_sb;
atomic_inc(&s->s_active);
root = dget(path.dentry);
path_put(&path);
down_write(&s->s_umount);
return root; return root;
} }
......
...@@ -2483,11 +2483,41 @@ struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) ...@@ -2483,11 +2483,41 @@ struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt)
__mnt_make_longterm(mnt); __mnt_make_longterm(mnt);
new_ns->root = mnt; new_ns->root = mnt;
list_add(&new_ns->list, &new_ns->root->mnt_list); list_add(&new_ns->list, &new_ns->root->mnt_list);
} else {
mntput(mnt);
} }
return new_ns; return new_ns;
} }
EXPORT_SYMBOL(create_mnt_ns); EXPORT_SYMBOL(create_mnt_ns);
struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
{
struct mnt_namespace *ns;
struct path path;
int err;
ns = create_mnt_ns(mnt);
if (IS_ERR(ns))
return ERR_CAST(ns);
err = vfs_path_lookup(mnt->mnt_root, mnt,
name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path);
put_mnt_ns(ns);
if (err)
return ERR_PTR(err);
/* trade a vfsmount reference for active sb one */
atomic_inc(&path.mnt->mnt_sb->s_active);
mntput(path.mnt);
/* lock the sucker */
down_write(&path.mnt->mnt_sb->s_umount);
/* ... and return the root of (sub)tree on it */
return path.dentry;
}
EXPORT_SYMBOL(mount_subtree);
SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
char __user *, type, unsigned long, flags, void __user *, data) char __user *, type, unsigned long, flags, void __user *, data)
{ {
......
...@@ -2787,43 +2787,18 @@ static void nfs_referral_loop_unprotect(void) ...@@ -2787,43 +2787,18 @@ static void nfs_referral_loop_unprotect(void)
static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt, static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt,
const char *export_path) const char *export_path)
{ {
struct mnt_namespace *ns_private;
struct super_block *s;
struct dentry *dentry; struct dentry *dentry;
struct path path; int ret = nfs_referral_loop_protect();
int ret;
ns_private = create_mnt_ns(root_mnt);
ret = PTR_ERR(ns_private);
if (IS_ERR(ns_private))
goto out_mntput;
ret = nfs_referral_loop_protect(); if (ret) {
if (ret != 0) mntput(root_mnt);
goto out_put_mnt_ns; return ERR_PTR(ret);
}
ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
export_path, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path);
dentry = mount_subtree(root_mnt, export_path);
nfs_referral_loop_unprotect(); nfs_referral_loop_unprotect();
put_mnt_ns(ns_private);
if (ret != 0)
goto out_err;
s = path.mnt->mnt_sb;
atomic_inc(&s->s_active);
dentry = dget(path.dentry);
path_put(&path);
down_write(&s->s_umount);
return dentry; return dentry;
out_put_mnt_ns:
put_mnt_ns(ns_private);
out_mntput:
mntput(root_mnt);
out_err:
return ERR_PTR(ret);
} }
static struct dentry *nfs4_try_mount(int flags, const char *dev_name, static struct dentry *nfs4_try_mount(int flags, const char *dev_name,
......
...@@ -1886,6 +1886,7 @@ extern struct dentry *mount_single(struct file_system_type *fs_type, ...@@ -1886,6 +1886,7 @@ extern struct dentry *mount_single(struct file_system_type *fs_type,
extern struct dentry *mount_nodev(struct file_system_type *fs_type, extern struct dentry *mount_nodev(struct file_system_type *fs_type,
int flags, void *data, int flags, void *data,
int (*fill_super)(struct super_block *, void *, int)); int (*fill_super)(struct super_block *, void *, int));
extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path);
void generic_shutdown_super(struct super_block *sb); void generic_shutdown_super(struct super_block *sb);
void kill_block_super(struct super_block *sb); void kill_block_super(struct super_block *sb);
void kill_anon_super(struct super_block *sb); void kill_anon_super(struct super_block *sb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment