diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-19 06:06:39 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-11-19 06:06:39 -0500 |
commit | 208f6f6068836e10d526e87fef6ca4364f4ec068 (patch) | |
tree | b9558820a176572b529ca6c1473b7c5ddb4b08ec /fs | |
parent | ab5c5f639bba89d1103deae447836edf41e37659 (diff) | |
parent | ea441d1104cf1efb471fa81bc91e9fd1e6ae29fd (diff) |
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()
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/super.c | 38 | ||||
-rw-r--r-- | fs/namespace.c | 30 | ||||
-rw-r--r-- | fs/nfs/super.c | 37 |
3 files changed, 42 insertions, 63 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 8bd9d6d0e07a..17ee7fc5e64e 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c | |||
@@ -825,13 +825,9 @@ static char *setup_root_args(char *args) | |||
825 | static struct dentry *mount_subvol(const char *subvol_name, int flags, | 825 | static 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,39 +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 | mntput(mnt); | ||
848 | return ERR_CAST(ns_private); | ||
849 | } | ||
850 | 842 | ||
851 | /* | 843 | if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) { |
852 | * This will trigger the automount of the subvol so we can just | 844 | struct super_block *s = root->d_sb; |
853 | * drop the mnt we have here and return the dentry that we | 845 | dput(root); |
854 | * found. | 846 | root = ERR_PTR(-EINVAL); |
855 | */ | 847 | deactivate_locked_super(s); |
856 | error = vfs_path_lookup(mnt->mnt_root, mnt, subvol_name, | ||
857 | LOOKUP_FOLLOW, &path); | ||
858 | put_mnt_ns(ns_private); | ||
859 | if (error) | ||
860 | return ERR_PTR(error); | ||
861 | |||
862 | if (!is_subvolume_inode(path.dentry->d_inode)) { | ||
863 | path_put(&path); | ||
864 | mntput(mnt); | ||
865 | error = -EINVAL; | ||
866 | printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n", | 848 | printk(KERN_ERR "btrfs: '%s' is not a valid subvolume\n", |
867 | subvol_name); | 849 | subvol_name); |
868 | return ERR_PTR(-EINVAL); | ||
869 | } | 850 | } |
870 | 851 | ||
871 | /* Get a ref to the sb and the dentry we found and return it */ | ||
872 | s = path.mnt->mnt_sb; | ||
873 | atomic_inc(&s->s_active); | ||
874 | root = dget(path.dentry); | ||
875 | path_put(&path); | ||
876 | down_write(&s->s_umount); | ||
877 | |||
878 | return root; | 852 | return root; |
879 | } | 853 | } |
880 | 854 | ||
diff --git a/fs/namespace.c b/fs/namespace.c index e5e1c7d1839b..50ee30345b4f 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -2483,11 +2483,41 @@ struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) | |||
2483 | __mnt_make_longterm(mnt); | 2483 | __mnt_make_longterm(mnt); |
2484 | new_ns->root = mnt; | 2484 | new_ns->root = mnt; |
2485 | list_add(&new_ns->list, &new_ns->root->mnt_list); | 2485 | list_add(&new_ns->list, &new_ns->root->mnt_list); |
2486 | } else { | ||
2487 | mntput(mnt); | ||
2486 | } | 2488 | } |
2487 | return new_ns; | 2489 | return new_ns; |
2488 | } | 2490 | } |
2489 | EXPORT_SYMBOL(create_mnt_ns); | 2491 | EXPORT_SYMBOL(create_mnt_ns); |
2490 | 2492 | ||
2493 | struct dentry *mount_subtree(struct vfsmount *mnt, const char *name) | ||
2494 | { | ||
2495 | struct mnt_namespace *ns; | ||
2496 | struct path path; | ||
2497 | int err; | ||
2498 | |||
2499 | ns = create_mnt_ns(mnt); | ||
2500 | if (IS_ERR(ns)) | ||
2501 | return ERR_CAST(ns); | ||
2502 | |||
2503 | err = vfs_path_lookup(mnt->mnt_root, mnt, | ||
2504 | name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path); | ||
2505 | |||
2506 | put_mnt_ns(ns); | ||
2507 | |||
2508 | if (err) | ||
2509 | return ERR_PTR(err); | ||
2510 | |||
2511 | /* trade a vfsmount reference for active sb one */ | ||
2512 | atomic_inc(&path.mnt->mnt_sb->s_active); | ||
2513 | mntput(path.mnt); | ||
2514 | /* lock the sucker */ | ||
2515 | down_write(&path.mnt->mnt_sb->s_umount); | ||
2516 | /* ... and return the root of (sub)tree on it */ | ||
2517 | return path.dentry; | ||
2518 | } | ||
2519 | EXPORT_SYMBOL(mount_subtree); | ||
2520 | |||
2491 | SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, | 2521 | SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, |
2492 | char __user *, type, unsigned long, flags, void __user *, data) | 2522 | char __user *, type, unsigned long, flags, void __user *, data) |
2493 | { | 2523 | { |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 480b3b6bf71e..134777406ee3 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -2787,43 +2787,18 @@ static void nfs_referral_loop_unprotect(void) | |||
2787 | static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt, | 2787 | static struct dentry *nfs_follow_remote_path(struct vfsmount *root_mnt, |
2788 | const char *export_path) | 2788 | const char *export_path) |
2789 | { | 2789 | { |
2790 | struct mnt_namespace *ns_private; | ||
2791 | struct super_block *s; | ||
2792 | struct dentry *dentry; | 2790 | struct dentry *dentry; |
2793 | struct path path; | 2791 | int ret = nfs_referral_loop_protect(); |
2794 | int ret; | ||
2795 | |||
2796 | ns_private = create_mnt_ns(root_mnt); | ||
2797 | ret = PTR_ERR(ns_private); | ||
2798 | if (IS_ERR(ns_private)) | ||
2799 | goto out_mntput; | ||
2800 | |||
2801 | ret = nfs_referral_loop_protect(); | ||
2802 | if (ret != 0) | ||
2803 | goto out_put_mnt_ns; | ||
2804 | 2792 | ||
2805 | ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, | 2793 | if (ret) { |
2806 | export_path, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path); | 2794 | mntput(root_mnt); |
2795 | return ERR_PTR(ret); | ||
2796 | } | ||
2807 | 2797 | ||
2798 | dentry = mount_subtree(root_mnt, export_path); | ||
2808 | nfs_referral_loop_unprotect(); | 2799 | nfs_referral_loop_unprotect(); |
2809 | put_mnt_ns(ns_private); | ||
2810 | |||
2811 | if (ret != 0) | ||
2812 | goto out_err; | ||
2813 | |||
2814 | s = path.mnt->mnt_sb; | ||
2815 | atomic_inc(&s->s_active); | ||
2816 | dentry = dget(path.dentry); | ||
2817 | 2800 | ||
2818 | path_put(&path); | ||
2819 | down_write(&s->s_umount); | ||
2820 | return dentry; | 2801 | return dentry; |
2821 | out_put_mnt_ns: | ||
2822 | put_mnt_ns(ns_private); | ||
2823 | out_mntput: | ||
2824 | mntput(root_mnt); | ||
2825 | out_err: | ||
2826 | return ERR_PTR(ret); | ||
2827 | } | 2802 | } |
2828 | 2803 | ||
2829 | static struct dentry *nfs4_try_mount(int flags, const char *dev_name, | 2804 | static struct dentry *nfs4_try_mount(int flags, const char *dev_name, |