2 * Copyright (C) 2006 IBM Corporation
4 * Author: Serge Hallyn <serue@us.ibm.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
12 #include <linux/module.h>
13 #include <linux/version.h>
14 #include <linux/nsproxy.h>
15 #include <linux/init_task.h>
16 #include <linux/namespace.h>
18 struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
20 static inline void get_nsproxy(struct nsproxy *ns)
22 atomic_inc(&ns->count);
25 void get_task_namespaces(struct task_struct *tsk)
27 struct nsproxy *ns = tsk->nsproxy;
34 * creates a copy of "orig" with refcount 1.
35 * This does not grab references to the contained namespaces,
36 * so that needs to be done by dup_namespaces.
38 static inline struct nsproxy *clone_namespaces(struct nsproxy *orig)
42 ns = kmalloc(sizeof(struct nsproxy), GFP_KERNEL);
44 memcpy(ns, orig, sizeof(struct nsproxy));
45 atomic_set(&ns->count, 1);
51 * copies the nsproxy, setting refcount to 1, and grabbing a
52 * reference to all contained namespaces. Called from
55 struct nsproxy *dup_namespaces(struct nsproxy *orig)
57 struct nsproxy *ns = clone_namespaces(orig);
61 get_namespace(ns->namespace);
68 * called from clone. This now handles copy for nsproxy and all
71 int copy_namespaces(int flags, struct task_struct *tsk)
73 struct nsproxy *old_ns = tsk->nsproxy;
74 struct nsproxy *new_ns;
82 if (!(flags & CLONE_NEWNS))
85 new_ns = clone_namespaces(old_ns);
91 tsk->nsproxy = new_ns;
93 err = copy_namespace(flags, tsk);
95 tsk->nsproxy = old_ns;
105 void free_nsproxy(struct nsproxy *ns)
108 put_namespace(ns->namespace);