blob: 1689e28483e49d2c2f043a55531280e783fb48d5 [file] [log] [blame]
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -08001#ifndef _LINUX_PID_NS_H
2#define _LINUX_PID_NS_H
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07003
4#include <linux/sched.h>
5#include <linux/mm.h>
6#include <linux/threads.h>
Cedric Le Goater9a575a92006-12-08 02:37:59 -08007#include <linux/nsproxy.h>
8#include <linux/kref.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07009
10struct 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 Bhattiprolu61a58c62006-12-08 02:37:58 -080017struct pid_namespace {
Cedric Le Goater9a575a92006-12-08 02:37:59 -080018 struct kref kref;
19 struct pidmap pidmap[PIDMAP_ENTRIES];
20 int last_pid;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080021 struct task_struct *child_reaper;
Pavel Emelianovbaf8f0f2007-10-18 23:39:48 -070022 struct kmem_cache *pid_cachep;
Pavel Emelyanovfaacbfd2007-10-18 23:40:04 -070023 int level;
24 struct pid_namespace *parent;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070025#ifdef CONFIG_PROC_FS
26 struct vfsmount *proc_mnt;
27#endif
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070028};
29
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080030extern struct pid_namespace init_pid_ns;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070031
Eric W. Biederman57d5f662007-11-14 17:00:13 -080032#ifdef CONFIG_PID_NS
Pavel Emelianova05f7b12007-10-18 23:39:47 -070033static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
Cedric Le Goater9a575a92006-12-08 02:37:59 -080034{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070035 if (ns != &init_pid_ns)
36 kref_get(&ns->kref);
Pavel Emelianova05f7b12007-10-18 23:39:47 -070037 return ns;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080038}
39
Eric W. Biederman213dd262007-07-15 23:41:15 -070040extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080041extern void free_pid_ns(struct kref *kref);
42
43static inline void put_pid_ns(struct pid_namespace *ns)
44{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070045 if (ns != &init_pid_ns)
46 kref_put(&ns->kref, free_pid_ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080047}
48
Eric W. Biederman57d5f662007-11-14 17:00:13 -080049#else /* !CONFIG_PID_NS */
50#include <linux/err.h>
51
52static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
53{
54 return ns;
55}
56
57static inline struct pid_namespace *
58copy_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
65static inline void put_pid_ns(struct pid_namespace *ns)
66{
67}
68
69#endif /* CONFIG_PID_NS */
70
Sukadev Bhattiprolu2894d6502007-10-18 23:39:49 -070071static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
72{
73 return tsk->nsproxy->pid_ns;
74}
75
Sukadev Bhattiprolu88f21d82007-10-18 23:39:50 -070076static inline struct task_struct *task_child_reaper(struct task_struct *tsk)
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080077{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070078 BUG_ON(tsk != current);
79 return tsk->nsproxy->pid_ns->child_reaper;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080080}
81
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080082#endif /* _LINUX_PID_NS_H */