aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2011-11-16 21:43:59 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2011-11-16 22:00:34 -0500
commitea441d1104cf1efb471fa81bc91e9fd1e6ae29fd (patch)
tree32b7c4f7c78af47936a604e3f4e13e8e61f834a0 /fs/btrfs
parentc13344958780b4046305ee6235d686c846535529 (diff)
new helper: mount_subtree()
takes vfsmount and relative path, does lookup within that vfsmount (possibly triggering automounts) and returns the result as root of subtree suitable for return by ->mount() (i.e. a reference to dentry and an active reference to its superblock grabbed, superblock locked exclusive). btrfs and nfs switched to it instead of open-coding the sucker. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/super.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index cfbedd7755b..17ee7fc5e64 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -825,13 +825,9 @@ static char *setup_root_args(char *args)
825static struct dentry *mount_subvol(const char *subvol_name, int flags, 825static struct dentry *mount_subvol(const char *subvol_name, int flags,
826 const char *device_name, char *data) 826 const char *device_name, char *data)
827{ 827{
828 struct super_block *s;
829 struct dentry *root; 828 struct dentry *root;
830 struct vfsmount *mnt; 829 struct vfsmount *mnt;
831 struct mnt_namespace *ns_private;
832 char *newargs; 830 char *newargs;
833 struct path path;
834 int error;
835 831
836 newargs = setup_root_args(data); 832 newargs = setup_root_args(data);
837 if (!newargs) 833 if (!newargs)
@@ -842,36 +838,17 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
842 if (IS_ERR(mnt)) 838 if (IS_ERR(mnt))
843 return ERR_CAST(mnt); 839 return ERR_CAST(mnt);
844 840
845 ns_private = create_mnt_ns(mnt); 841 root = mount_subtree(mnt, subvol_name);
846 if (IS_ERR(ns_private))
847 return ERR_CAST(ns_private);
848
849 /*
850 * This will trigger the automount of the subvol so we can just
851 * drop the mnt we have here and return the dentry that we
852 * found.
853 */
854 error = vfs_path_lookup(mnt->mnt_root, mnt, subvol_name,
855 LOOKUP_FOLLOW, &path);
856 put_mnt_ns(ns_private);
857 if (error)
858 return ERR_PTR(error);
859 842
860 if (!is_subvolume_inode(path.dentry->d_inode)) { 843 if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) {
861 path_put(&path); 844 struct super_block *s = root->d_sb;
862 error = -EINVAL; 845 dput(root);
846 root = ERR_PTR(-EINVAL);
847 deactivate_locked_super(s);
863 printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n", 848 printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n",
864 subvol_name); 849 subvol_name);
865 return ERR_PTR(-EINVAL);
866 } 850 }
867 851
868 /* Get a ref to the sb and the dentry we found and return it */
869 s = path.mnt->mnt_sb;
870 atomic_inc(&s->s_active);
871 root = dget(path.dentry);
872 path_put(&path);
873 down_write(&s->s_umount);
874
875 return root; 852 return root;
876} 853}
877 854