nscommon: simplify initialization
There's a lot of information that namespace implementers don't need to know about at all. Encapsulate this all in the initialization helper. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
@@ -27,7 +27,7 @@ static struct cgroup_namespace *alloc_cgroup_ns(void)
|
||||
new_ns = kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT);
|
||||
if (!new_ns)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
ret = ns_common_init(&new_ns->ns, &cgroupns_operations, true);
|
||||
ret = ns_common_init(new_ns, &cgroupns_operations);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
ns_tree_add(new_ns);
|
||||
|
||||
+8
-9
@@ -1,21 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <linux/ns_common.h>
|
||||
#include <linux/proc_ns.h>
|
||||
|
||||
int ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops,
|
||||
bool alloc_inum)
|
||||
int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum)
|
||||
{
|
||||
if (alloc_inum && !ns->inum) {
|
||||
int ret;
|
||||
ret = proc_alloc_inum(&ns->inum);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
refcount_set(&ns->count, 1);
|
||||
ns->stashed = NULL;
|
||||
ns->ops = ops;
|
||||
ns->ns_id = 0;
|
||||
RB_CLEAR_NODE(&ns->ns_tree_node);
|
||||
INIT_LIST_HEAD(&ns->ns_list_node);
|
||||
return 0;
|
||||
|
||||
if (inum) {
|
||||
ns->inum = inum;
|
||||
return 0;
|
||||
}
|
||||
return proc_alloc_inum(&ns->inum);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
|
||||
if (ns->pid_cachep == NULL)
|
||||
goto out_free_idr;
|
||||
|
||||
err = ns_common_init(&ns->ns, &pidns_operations, true);
|
||||
err = ns_common_init(ns, &pidns_operations);
|
||||
if (err)
|
||||
goto out_free_idr;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ static struct time_namespace *clone_time_ns(struct user_namespace *user_ns,
|
||||
if (!ns->vvar_page)
|
||||
goto fail_free;
|
||||
|
||||
err = ns_common_init(&ns->ns, &timens_operations, true);
|
||||
err = ns_common_init(ns, &timens_operations);
|
||||
if (err)
|
||||
goto fail_free_page;
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ int create_user_ns(struct cred *new)
|
||||
|
||||
ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP);
|
||||
|
||||
ret = ns_common_init(&ns->ns, &userns_operations, true);
|
||||
ret = ns_common_init(ns, &userns_operations);
|
||||
if (ret)
|
||||
goto fail_free;
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
|
||||
if (!ns)
|
||||
goto fail_dec;
|
||||
|
||||
err = ns_common_init(&ns->ns, &utsns_operations, true);
|
||||
err = ns_common_init(ns, &utsns_operations);
|
||||
if (err)
|
||||
goto fail_free;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user