blob: 6db5522eef5122859d1b39cbacc839b3ab9740b8 [file] [log] [blame]
Pavel Emelyanovae5e1b22008-02-08 04:18:22 -08001#ifndef __IPC_NAMESPACE_H__
2#define __IPC_NAMESPACE_H__
3
4#include <linux/err.h>
Pierre Peiffered2ddbf2008-02-08 04:18:57 -08005#include <linux/idr.h>
6#include <linux/rwsem.h>
Pavel Emelyanovae5e1b22008-02-08 04:18:22 -08007
Pierre Peiffered2ddbf2008-02-08 04:18:57 -08008struct ipc_ids {
9 int in_use;
10 unsigned short seq;
11 unsigned short seq_max;
12 struct rw_semaphore rw_mutex;
13 struct idr ipcs_idr;
14};
15
Pavel Emelyanovae5e1b22008-02-08 04:18:22 -080016struct ipc_namespace {
17 struct kref kref;
Pierre Peiffered2ddbf2008-02-08 04:18:57 -080018 struct ipc_ids ids[3];
Pavel Emelyanovae5e1b22008-02-08 04:18:22 -080019
20 int sem_ctls[4];
21 int used_sems;
22
23 int msg_ctlmax;
24 int msg_ctlmnb;
25 int msg_ctlmni;
26 atomic_t msg_bytes;
27 atomic_t msg_hdrs;
28
29 size_t shm_ctlmax;
30 size_t shm_ctlall;
31 int shm_ctlmni;
32 int shm_tot;
33};
34
35extern struct ipc_namespace init_ipc_ns;
36
37#ifdef CONFIG_SYSVIPC
38#define INIT_IPC_NS(ns) .ns = &init_ipc_ns,
39#else
40#define INIT_IPC_NS(ns)
41#endif
42
43#if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
44extern void free_ipc_ns(struct kref *kref);
45extern struct ipc_namespace *copy_ipcs(unsigned long flags,
46 struct ipc_namespace *ns);
47
48static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
49{
50 if (ns)
51 kref_get(&ns->kref);
52 return ns;
53}
54
55static inline void put_ipc_ns(struct ipc_namespace *ns)
56{
57 kref_put(&ns->kref, free_ipc_ns);
58}
59#else
60static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
61 struct ipc_namespace *ns)
62{
63 if (flags & CLONE_NEWIPC)
64 return ERR_PTR(-EINVAL);
65
66 return ns;
67}
68
69static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
70{
71 return ns;
72}
73
74static inline void put_ipc_ns(struct ipc_namespace *ns)
75{
76}
77#endif
78#endif