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); |
| 42 | |
| 43 | static inline void put_pid_ns(struct pid_namespace *ns) |
| 44 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 45 | if (ns != &init_pid_ns) |
| 46 | kref_put(&ns->kref, free_pid_ns); |
Cedric Le Goater | 9a575a9 | 2006-12-08 02:37:59 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Eric W. Biederman | 57d5f66 | 2007-11-14 17:00:13 -0800 | [diff] [blame] | 49 | #else /* !CONFIG_PID_NS */ |
| 50 | #include <linux/err.h> |
| 51 | |
| 52 | static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) |
| 53 | { |
| 54 | return ns; |
| 55 | } |
| 56 | |
| 57 | static inline struct pid_namespace * |
| 58 | copy_pid_ns(unsigned long flags, struct pid_namespace *ns) |
| 59 | { |
| 60 | if (flags & CLONE_NEWPID) |
| 61 | ns = ERR_PTR(-EINVAL); |
| 62 | return ns; |
| 63 | } |
| 64 | |
| 65 | static inline void put_pid_ns(struct pid_namespace *ns) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | #endif /* CONFIG_PID_NS */ |
| 70 | |
Sukadev Bhattiprolu | 2894d650 | 2007-10-18 23:39:49 -0700 | [diff] [blame] | 71 | static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk) |
| 72 | { |
| 73 | return tsk->nsproxy->pid_ns; |
| 74 | } |
| 75 | |
Sukadev Bhattiprolu | 88f21d8 | 2007-10-18 23:39:50 -0700 | [diff] [blame] | 76 | static inline struct task_struct *task_child_reaper(struct task_struct *tsk) |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 77 | { |
Pavel Emelyanov | b461cc0 | 2007-10-18 23:40:09 -0700 | [diff] [blame] | 78 | BUG_ON(tsk != current); |
| 79 | return tsk->nsproxy->pid_ns->child_reaper; |
Sukadev Bhattiprolu | 84d7378 | 2006-12-08 02:38:01 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Sukadev Bhattiprolu | 61a58c6 | 2006-12-08 02:37:58 -0800 | [diff] [blame] | 82 | #endif /* _LINUX_PID_NS_H */ |