Skip to content

Commit 8f11538

Browse files
author
Al Viro
committed
do_add_mount(): lift lock_mount/unlock_mount into callers
preparation to finish_automount() fix (next commit) Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent bb6d3fb commit 8f11538

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

fs/namespace.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,45 +2697,32 @@ static int do_move_mount_old(struct path *path, const char *old_name)
26972697
/*
26982698
* add a mount into a namespace's mount tree
26992699
*/
2700-
static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags)
2700+
static int do_add_mount(struct mount *newmnt, struct mountpoint *mp,
2701+
struct path *path, int mnt_flags)
27012702
{
2702-
struct mountpoint *mp;
2703-
struct mount *parent;
2704-
int err;
2703+
struct mount *parent = real_mount(path->mnt);
27052704

27062705
mnt_flags &= ~MNT_INTERNAL_FLAGS;
27072706

2708-
mp = lock_mount(path);
2709-
if (IS_ERR(mp))
2710-
return PTR_ERR(mp);
2711-
2712-
parent = real_mount(path->mnt);
2713-
err = -EINVAL;
27142707
if (unlikely(!check_mnt(parent))) {
27152708
/* that's acceptable only for automounts done in private ns */
27162709
if (!(mnt_flags & MNT_SHRINKABLE))
2717-
goto unlock;
2710+
return -EINVAL;
27182711
/* ... and for those we'd better have mountpoint still alive */
27192712
if (!parent->mnt_ns)
2720-
goto unlock;
2713+
return -EINVAL;
27212714
}
27222715

27232716
/* Refuse the same filesystem on the same mount point */
2724-
err = -EBUSY;
27252717
if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb &&
27262718
path->mnt->mnt_root == path->dentry)
2727-
goto unlock;
2719+
return -EBUSY;
27282720

2729-
err = -EINVAL;
27302721
if (d_is_symlink(newmnt->mnt.mnt_root))
2731-
goto unlock;
2722+
return -EINVAL;
27322723

27332724
newmnt->mnt.mnt_flags = mnt_flags;
2734-
err = graft_tree(newmnt, parent, mp);
2735-
2736-
unlock:
2737-
unlock_mount(mp);
2738-
return err;
2725+
return graft_tree(newmnt, parent, mp);
27392726
}
27402727

27412728
static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags);
@@ -2748,6 +2735,7 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint,
27482735
unsigned int mnt_flags)
27492736
{
27502737
struct vfsmount *mnt;
2738+
struct mountpoint *mp;
27512739
struct super_block *sb = fc->root->d_sb;
27522740
int error;
27532741

@@ -2768,7 +2756,13 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint,
27682756

27692757
mnt_warn_timestamp_expiry(mountpoint, mnt);
27702758

2771-
error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags);
2759+
mp = lock_mount(mountpoint);
2760+
if (IS_ERR(mp)) {
2761+
mntput(mnt);
2762+
return PTR_ERR(mp);
2763+
}
2764+
error = do_add_mount(real_mount(mnt), mp, mountpoint, mnt_flags);
2765+
unlock_mount(mp);
27722766
if (error < 0)
27732767
mntput(mnt);
27742768
return error;
@@ -2830,6 +2824,7 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags,
28302824
int finish_automount(struct vfsmount *m, struct path *path)
28312825
{
28322826
struct mount *mnt = real_mount(m);
2827+
struct mountpoint *mp;
28332828
int err;
28342829
/* The new mount record should have at least 2 refs to prevent it being
28352830
* expired before we get a chance to add it
@@ -2842,7 +2837,13 @@ int finish_automount(struct vfsmount *m, struct path *path)
28422837
goto fail;
28432838
}
28442839

2845-
err = do_add_mount(mnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE);
2840+
mp = lock_mount(path);
2841+
if (IS_ERR(mp)) {
2842+
err = PTR_ERR(mp);
2843+
goto fail;
2844+
}
2845+
err = do_add_mount(mnt, mp, path, path->mnt->mnt_flags | MNT_SHRINKABLE);
2846+
unlock_mount(mp);
28462847
if (!err)
28472848
return 0;
28482849
fail:

0 commit comments

Comments
 (0)