aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/nsproxy.c
diff options
context:
space:
mode:
authorSerge E. Hallyn <serue@us.ibm.com>2006-10-02 05:18:06 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 10:57:20 -0400
commitab516013ad9ca47f1d3a936fa81303bfbf734d52 (patch)
tree643ea9c4c3d28958cb42dd87b1856f74edd22b11 /kernel/nsproxy.c
parentb1ba4ddde0cf67991d89f039365eaaeda61aa027 (diff)
[PATCH] namespaces: add nsproxy
This patch adds a nsproxy structure to the task struct. Later patches will move the fs namespace pointer into this structure, and introduce a new utsname namespace into the nsproxy. The vserver and openvz functionality, then, would be implemented in large part by virtualizing/isolating more and more resources into namespaces, each contained in the nsproxy. [akpm@osdl.org: build fix] Signed-off-by: Serge Hallyn <serue@us.ibm.com> Cc: Kirill Korotaev <dev@openvz.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Herbert Poetzl <herbert@13thfloor.at> Cc: Andrey Savochkin <saw@sw.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/nsproxy.c')
-rw-r--r--kernel/nsproxy.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
new file mode 100644
index 000000000000..ad9508865473
--- /dev/null
+++ b/kernel/nsproxy.c
@@ -0,0 +1,77 @@
1/*
2 * Copyright (C) 2006 IBM Corporation
3 *
4 * Author: Serge Hallyn <serue@us.ibm.com>
5 *
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
9 * License.
10 */
11
12#include <linux/module.h>
13#include <linux/version.h>
14#include <linux/nsproxy.h>
15
16static inline void get_nsproxy(struct nsproxy *ns)
17{
18 atomic_inc(&ns->count);
19}
20
21void get_task_namespaces(struct task_struct *tsk)
22{
23 struct nsproxy *ns = tsk->nsproxy;
24 if (ns) {
25 get_nsproxy(ns);
26 }
27}
28
29/*
30 * creates a copy of "orig" with refcount 1.
31 * This does not grab references to the contained namespaces,
32 * so that needs to be done by dup_namespaces.
33 */
34static inline struct nsproxy *clone_namespaces(struct nsproxy *orig)
35{
36 struct nsproxy *ns;
37
38 ns = kmalloc(sizeof(struct nsproxy), GFP_KERNEL);
39 if (ns) {
40 memcpy(ns, orig, sizeof(struct nsproxy));
41 atomic_set(&ns->count, 1);
42 }
43 return ns;
44}
45
46/*
47 * copies the nsproxy, setting refcount to 1, and grabbing a
48 * reference to all contained namespaces. Called from
49 * sys_unshare()
50 */
51struct nsproxy *dup_namespaces(struct nsproxy *orig)
52{
53 struct nsproxy *ns = clone_namespaces(orig);
54
55 return ns;
56}
57
58/*
59 * called from clone. This now handles copy for nsproxy and all
60 * namespaces therein.
61 */
62int copy_namespaces(int flags, struct task_struct *tsk)
63{
64 struct nsproxy *old_ns = tsk->nsproxy;
65
66 if (!old_ns)
67 return 0;
68
69 get_nsproxy(old_ns);
70
71 return 0;
72}
73
74void free_nsproxy(struct nsproxy *ns)
75{
76 kfree(ns);
77}