Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_PID_NS_H |
| 2 | #define _LINUX_PID_NS_H |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 3 | |
| 4 | #include <linux/sched.h> |
| 5 | #include <linux/mm.h> |
| 6 | #include <linux/threads.h> |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 7 | #include <linux/nsproxy.h> |
| 8 | #include <linux/kref.h> |
Sukadev Bhattiprolu | aa5a666 | 2006-10-02 02:17:23 -0700 | [diff] [blame] | 9 | |
| 10 | struct pidmap { |
| 11 | atomic_t nr_free; |
| 12 | void *page; |
| 13 | }; |
| 14 | |
| 15 | #define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8) |
| 16 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 17 | struct pid_namespace { |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 18 | struct kref kref; |
| 19 | struct pidmap pidmap[PIDMAP_ENTRIES]; |
| 20 | int last_pid; |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 21 | struct task_struct *child_reaper; |
Pavel Emelianov | baf8f0f | 2007-10-18 23:39:48 -0700 | [diff] [blame] | 22 | struct kmem_cache *pid_cachep; |
Pavel Emelyanov | faacbfd | 2007-10-18 23:40:04 -0700 | [diff] [blame] | 23 | int level; |
| 24 | struct pid_namespace *parent; |
Pavel Emelyanov | 07543f5 | 2007-10-18 23:40:08 -0700 | [diff] [blame] | 25 | #ifdef CONFIG_PROC_FS |
| 26 | struct vfsmount *proc_mnt; |
| 27 | #endif |
Sukadev Bhattiprolu | 3fbc964 | 2006-10-02 02:17:24 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 30 | extern struct pid_namespace init_pid_ns; |
Sukadev Bhattiprolu | 3fbc964 | 2006-10-02 02:17:24 -0700 | [diff] [blame] | 31 | |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 32 | #ifdef CONFIG_PID_NS |
Pavel Emelianov | a05f7b1 | 2007-10-18 23:39:47 -0700 | [diff] [blame] | 33 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 34 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 35 | if (ns != &init_pid_ns) |
| 36 | kref_get(&ns->kref); |
Pavel Emelianov | a05f7b1 | 2007-10-18 23:39:47 -0700 | [diff] [blame] | 37 | return ns; |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Eric W. Biederman | 213dd26 | 2007-07-15 23:41:15 -0700 | [diff] [blame] | 40 | extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns); |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 41 | extern void free_pid_ns(struct kref *kref); |
Pavel Emelyanov | 74bd59b | 2008-02-08 04:18:24 -0800 | [diff] [blame] | 42 | extern void zap_pid_ns_processes(struct pid_namespace *pid_ns); |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 43 | |
| 44 | static inline void put_pid_ns(struct pid_namespace *ns) |
| 45 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 46 | if (ns != &init_pid_ns) |
| 47 | kref_put(&ns->kref, free_pid_ns); |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 50 | #else /* !CONFIG_PID_NS */ |
| 51 | #include <linux/err.h> |
| 52 | |
| 53 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
| 54 | { |
| 55 | return ns; |
| 56 | } |
| 57 | |
| 58 | static inline struct pid_namespace * |
| 59 | copy_pid_ns(unsigned long flags, struct pid_namespace *ns) |
| 60 | { |
| 61 | if (flags & CLONE_NEWPID) |
| 62 | ns = ERR_PTR(-EINVAL); |
| 63 | return ns; |
| 64 | } |
| 65 | |
| 66 | static inline void put_pid_ns(struct pid_namespace *ns) |
| 67 | { |
| 68 | } |
| 69 | |
Pavel Emelyanov | 74bd59b | 2008-02-08 04:18:24 -0800 | [diff] [blame] | 70 | |
| 71 | static inline void zap_pid_ns_processes(struct pid_namespace *ns) |
| 72 | { |
| 73 | BUG(); |
| 74 | } |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 75 | #endif /* CONFIG_PID_NS */ |
| 76 | |
Sukadev Bhattiprolu | 2894d650 | 2007-10-18 23:39:49 -0700 | [diff] [blame] | 77 | static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk) |
| 78 | { |
| 79 | return tsk->nsproxy->pid_ns; |
| 80 | } |
| 81 | |
Sukadev Bhattiprolu | 88f21d8 | 2007-10-18 23:39:50 -0700 | [diff] [blame] | 82 | static inline struct task_struct *task_child_reaper(struct task_struct *tsk) |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 83 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 84 | BUG_ON(tsk != current); |
| 85 | return tsk->nsproxy->pid_ns->child_reaper; |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 88 | #endif /* _LINUX_PID_NS_H */ |