Skip to content

Commit 57a7b5b

Browse files
author
Al Viro
committed
open_detached_copy(): separate creation of namespace into helper
... and convert the helper to use of a guard(namespace_excl) Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 71cf10c commit 57a7b5b

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

fs/namespace.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,18 +3047,17 @@ static int do_loopback(const struct path *path, const char *old_name,
30473047
return err;
30483048
}
30493049

3050-
static struct file *open_detached_copy(struct path *path, bool recursive)
3050+
static struct mnt_namespace *get_detached_copy(const struct path *path, bool recursive)
30513051
{
30523052
struct mnt_namespace *ns, *mnt_ns = current->nsproxy->mnt_ns, *src_mnt_ns;
30533053
struct user_namespace *user_ns = mnt_ns->user_ns;
30543054
struct mount *mnt, *p;
3055-
struct file *file;
30563055

30573056
ns = alloc_mnt_ns(user_ns, true);
30583057
if (IS_ERR(ns))
3059-
return ERR_CAST(ns);
3058+
return ns;
30603059

3061-
namespace_lock();
3060+
guard(namespace_excl)();
30623061

30633062
/*
30643063
* Record the sequence number of the source mount namespace.
@@ -3075,8 +3074,7 @@ static struct file *open_detached_copy(struct path *path, bool recursive)
30753074

30763075
mnt = __do_loopback(path, recursive);
30773076
if (IS_ERR(mnt)) {
3078-
namespace_unlock();
3079-
free_mnt_ns(ns);
3077+
emptied_ns = ns;
30803078
return ERR_CAST(mnt);
30813079
}
30823080

@@ -3085,11 +3083,19 @@ static struct file *open_detached_copy(struct path *path, bool recursive)
30853083
ns->nr_mounts++;
30863084
}
30873085
ns->root = mnt;
3088-
mntget(&mnt->mnt);
3089-
namespace_unlock();
3086+
return ns;
3087+
}
3088+
3089+
static struct file *open_detached_copy(struct path *path, bool recursive)
3090+
{
3091+
struct mnt_namespace *ns = get_detached_copy(path, recursive);
3092+
struct file *file;
3093+
3094+
if (IS_ERR(ns))
3095+
return ERR_CAST(ns);
30903096

30913097
mntput(path->mnt);
3092-
path->mnt = &mnt->mnt;
3098+
path->mnt = mntget(&ns->root->mnt);
30933099
file = dentry_open(path, O_PATH, current_cred());
30943100
if (IS_ERR(file))
30953101
dissolve_on_fput(path->mnt);

0 commit comments

Comments
 (0)