blob: 7246ef3d4455880f682f5d648fb75079f6c6d61c [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>
Kent Overstreeta27bb332013-05-07 16:19:08 -07007#include <linux/workqueue.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -07008#include <linux/threads.h>
Cedric Le Goater9a575a92006-12-08 02:37:59 -08009#include <linux/nsproxy.h>
10#include <linux/kref.h>
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -070011
12struct pidmap {
13 atomic_t nr_free;
14 void *page;
15};
16
Raphael S.Carvalho5cc54452013-04-30 15:28:27 -070017#define BITS_PER_PAGE (PAGE_SIZE * 8)
18#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
19#define PIDMAP_ENTRIES ((PID_MAX_LIMIT+BITS_PER_PAGE-1)/BITS_PER_PAGE)
Sukadev Bhattiproluaa5a6662006-10-02 02:17:23 -070020
Pavel Emelyanov20fad132008-07-25 01:48:43 -070021struct bsd_acct_struct;
22
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080023struct pid_namespace {
Cedric Le Goater9a575a92006-12-08 02:37:59 -080024 struct kref kref;
25 struct pidmap pidmap[PIDMAP_ENTRIES];
Al Viro1adfcb02013-10-03 13:28:06 -040026 struct rcu_head rcu;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080027 int last_pid;
Eric W. Biedermanc876ad762012-12-21 20:27:12 -080028 unsigned int nr_hashed;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080029 struct task_struct *child_reaper;
Pavel Emelianovbaf8f0f2007-10-18 23:39:48 -070030 struct kmem_cache *pid_cachep;
Pavel Emelyanovcaafa432008-04-30 00:54:31 -070031 unsigned int level;
Pavel Emelyanovfaacbfd2007-10-18 23:40:04 -070032 struct pid_namespace *parent;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070033#ifdef CONFIG_PROC_FS
34 struct vfsmount *proc_mnt;
Al Viro021ada72013-03-29 19:27:05 -040035 struct dentry *proc_self;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070036#endif
Pavel Emelyanov20fad132008-07-25 01:48:43 -070037#ifdef CONFIG_BSD_PROCESS_ACCT
38 struct bsd_acct_struct *bacct;
39#endif
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070040 struct user_namespace *user_ns;
Eric W. Biederman0a01f2c2012-08-01 10:33:47 -070041 struct work_struct proc_work;
Eric W. Biedermandcb0f222012-02-09 08:48:21 -080042 kgid_t pid_gid;
Vasiliy Kulikov04996802012-01-10 15:11:31 -080043 int hide_pid;
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070044 int reboot; /* group exit code if this pidns was rebooted */
Eric W. Biederman98f842e2011-06-15 10:21:48 -070045 unsigned int proc_inum;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070046};
47
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080048extern struct pid_namespace init_pid_ns;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070049
Eric W. Biedermanc876ad762012-12-21 20:27:12 -080050#define PIDNS_HASH_ADDING (1U << 31)
51
Eric W. Biederman57d5f662007-11-14 17:00:13 -080052#ifdef CONFIG_PID_NS
Pavel Emelianova05f7b12007-10-18 23:39:47 -070053static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
Cedric Le Goater9a575a92006-12-08 02:37:59 -080054{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070055 if (ns != &init_pid_ns)
56 kref_get(&ns->kref);
Pavel Emelianova05f7b12007-10-18 23:39:47 -070057 return ns;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080058}
59
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070060extern struct pid_namespace *copy_pid_ns(unsigned long flags,
61 struct user_namespace *user_ns, struct pid_namespace *ns);
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080062extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070063extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
Cyrill Gorcunovbbc2e3e2012-10-19 13:56:53 -070064extern void put_pid_ns(struct pid_namespace *ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080065
Eric W. Biederman57d5f662007-11-14 17:00:13 -080066#else /* !CONFIG_PID_NS */
67#include <linux/err.h>
68
69static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
70{
71 return ns;
72}
73
Eric W. Biederman49f4d8b2012-08-02 04:25:10 -070074static inline struct pid_namespace *copy_pid_ns(unsigned long flags,
75 struct user_namespace *user_ns, struct pid_namespace *ns)
Eric W. Biederman57d5f662007-11-14 17:00:13 -080076{
77 if (flags & CLONE_NEWPID)
78 ns = ERR_PTR(-EINVAL);
79 return ns;
80}
81
82static inline void put_pid_ns(struct pid_namespace *ns)
83{
84}
85
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080086static inline void zap_pid_ns_processes(struct pid_namespace *ns)
87{
88 BUG();
89}
Daniel Lezcanocf3f8922012-03-28 14:42:51 -070090
91static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
92{
93 return 0;
94}
Eric W. Biederman57d5f662007-11-14 17:00:13 -080095#endif /* CONFIG_PID_NS */
96
Eric W. Biederman61bce0f2009-01-07 18:08:49 -080097extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
Adrian Bunk3ae4eed2008-07-25 01:48:34 -070098void pidhash_init(void);
99void pidmap_init(void);
100
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -0800101#endif /* _LINUX_PID_NS_H */