blob: 00474b047145ed1f54f3003fe597873a4665cc48 [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>
Paul Gortmaker187f1882011-11-23 20:12:59 -05005#include <linux/bug.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07006#include <linux/mm.h>
7#include <linux/threads.h>
Cedric Le Goater9a575a92006-12-08 02:37:59 -08008#include <linux/nsproxy.h>
9#include <linux/kref.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -070010
11struct pidmap {
12 atomic_t nr_free;
13 void *page;
14};
15
16#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
17
Pavel Emelyanov20fad132008-07-25 01:48:43 -070018struct bsd_acct_struct;
19
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080020struct pid_namespace {
Cedric Le Goater9a575a92006-12-08 02:37:59 -080021 struct kref kref;
22 struct pidmap pidmap[PIDMAP_ENTRIES];
23 int last_pid;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080024 struct task_struct *child_reaper;
Pavel Emelianovbaf8f0f2007-10-18 23:39:48 -070025 struct kmem_cache *pid_cachep;
Pavel Emelyanovcaafa432008-04-30 00:54:31 -070026 unsigned int level;
Pavel Emelyanovfaacbfd2007-10-18 23:40:04 -070027 struct pid_namespace *parent;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070028#ifdef CONFIG_PROC_FS
29 struct vfsmount *proc_mnt;
30#endif
Pavel Emelyanov20fad132008-07-25 01:48:43 -070031#ifdef CONFIG_BSD_PROCESS_ACCT
32 struct bsd_acct_struct *bacct;
33#endif
Eric W. Biedermandcb0f222012-02-09 08:48:21 -080034 kgid_t pid_gid;
Vasiliy Kulikov04996802012-01-10 15:11:31 -080035 int hide_pid;
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070036 int reboot; /* group exit code if this pidns was rebooted */
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070037};
38
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080039extern struct pid_namespace init_pid_ns;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070040
Eric W. Biederman57d5f662007-11-14 17:00:13 -080041#ifdef CONFIG_PID_NS
Pavel Emelianova05f7b12007-10-18 23:39:47 -070042static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
Cedric Le Goater9a575a92006-12-08 02:37:59 -080043{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070044 if (ns != &init_pid_ns)
45 kref_get(&ns->kref);
Pavel Emelianova05f7b12007-10-18 23:39:47 -070046 return ns;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080047}
48
Eric W. Biederman213dd262007-07-15 23:41:15 -070049extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080050extern void free_pid_ns(struct kref *kref);
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080051extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070052extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080053
54static inline void put_pid_ns(struct pid_namespace *ns)
55{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070056 if (ns != &init_pid_ns)
57 kref_put(&ns->kref, free_pid_ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080058}
59
Eric W. Biederman57d5f662007-11-14 17:00:13 -080060#else /* !CONFIG_PID_NS */
61#include <linux/err.h>
62
63static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
64{
65 return ns;
66}
67
68static inline struct pid_namespace *
69copy_pid_ns(unsigned long flags, struct pid_namespace *ns)
70{
71 if (flags & CLONE_NEWPID)
72 ns = ERR_PTR(-EINVAL);
73 return ns;
74}
75
76static inline void put_pid_ns(struct pid_namespace *ns)
77{
78}
79
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080080static inline void zap_pid_ns_processes(struct pid_namespace *ns)
81{
82 BUG();
83}
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070084
85static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
86{
87 return 0;
88}
Eric W. Biederman57d5f662007-11-14 17:00:13 -080089#endif /* CONFIG_PID_NS */
90
Eric W. Biederman61bce0f2009-01-07 18:08:49 -080091extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
Adrian Bunk3ae4eed2008-07-25 01:48:34 -070092void pidhash_init(void);
93void pidmap_init(void);
94
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080095#endif /* _LINUX_PID_NS_H */