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