IPC: make struct ipc_ids static in ipc_namespace
[safe/jmp/linux-2.6] / ipc / namespace.c
1 /*
2  * linux/ipc/namespace.c
3  * Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
4  */
5
6 #include <linux/ipc.h>
7 #include <linux/msg.h>
8 #include <linux/ipc_namespace.h>
9 #include <linux/rcupdate.h>
10 #include <linux/nsproxy.h>
11 #include <linux/slab.h>
12
13 #include "util.h"
14
15 static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
16 {
17         struct ipc_namespace *ns;
18
19         ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
20         if (ns == NULL)
21                 return ERR_PTR(-ENOMEM);
22
23         sem_init_ns(ns);
24         msg_init_ns(ns);
25         shm_init_ns(ns);
26
27         kref_init(&ns->kref);
28         return ns;
29 }
30
31 struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
32 {
33         struct ipc_namespace *new_ns;
34
35         BUG_ON(!ns);
36         get_ipc_ns(ns);
37
38         if (!(flags & CLONE_NEWIPC))
39                 return ns;
40
41         new_ns = clone_ipc_ns(ns);
42
43         put_ipc_ns(ns);
44         return new_ns;
45 }
46
47 void free_ipc_ns(struct kref *kref)
48 {
49         struct ipc_namespace *ns;
50
51         ns = container_of(kref, struct ipc_namespace, kref);
52         sem_exit_ns(ns);
53         msg_exit_ns(ns);
54         shm_exit_ns(ns);
55         kfree(ns);
56 }