]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - kernel/nsproxy.c
[PATCH] nsproxy: move init_nsproxy into kernel/nsproxy.c
[mirror_ubuntu-artful-kernel.git] / kernel / nsproxy.c
CommitLineData
ab516013
SH
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>
0437eb59
SH
15#include <linux/init_task.h>
16
17struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
ab516013
SH
18
19static inline void get_nsproxy(struct nsproxy *ns)
20{
21 atomic_inc(&ns->count);
22}
23
24void get_task_namespaces(struct task_struct *tsk)
25{
26 struct nsproxy *ns = tsk->nsproxy;
27 if (ns) {
28 get_nsproxy(ns);
29 }
30}
31
32/*
33 * creates a copy of "orig" with refcount 1.
34 * This does not grab references to the contained namespaces,
35 * so that needs to be done by dup_namespaces.
36 */
37static inline struct nsproxy *clone_namespaces(struct nsproxy *orig)
38{
39 struct nsproxy *ns;
40
41 ns = kmalloc(sizeof(struct nsproxy), GFP_KERNEL);
42 if (ns) {
43 memcpy(ns, orig, sizeof(struct nsproxy));
44 atomic_set(&ns->count, 1);
45 }
46 return ns;
47}
48
49/*
50 * copies the nsproxy, setting refcount to 1, and grabbing a
51 * reference to all contained namespaces. Called from
52 * sys_unshare()
53 */
54struct nsproxy *dup_namespaces(struct nsproxy *orig)
55{
56 struct nsproxy *ns = clone_namespaces(orig);
57
58 return ns;
59}
60
61/*
62 * called from clone. This now handles copy for nsproxy and all
63 * namespaces therein.
64 */
65int copy_namespaces(int flags, struct task_struct *tsk)
66{
67 struct nsproxy *old_ns = tsk->nsproxy;
68
69 if (!old_ns)
70 return 0;
71
72 get_nsproxy(old_ns);
73
74 return 0;
75}
76
77void free_nsproxy(struct nsproxy *ns)
78{
79 kfree(ns);
80}