blob: 38d10326246afbbec371b5cddc2beaff37f1dd48 [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
Pavel Emelyanov20fad132008-07-25 01:48:43 -070017struct bsd_acct_struct;
18
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080019struct pid_namespace {
Cedric Le Goater9a575a92006-12-08 02:37:59 -080020 struct kref kref;
21 struct pidmap pidmap[PIDMAP_ENTRIES];
22 int last_pid;
Sukadev Bhattiprolu84d73782006-12-08 02:38:01 -080023 struct task_struct *child_reaper;
Pavel Emelianovbaf8f0f2007-10-18 23:39:48 -070024 struct kmem_cache *pid_cachep;
Pavel Emelyanovcaafa432008-04-30 00:54:31 -070025 unsigned int level;
Pavel Emelyanovfaacbfd2007-10-18 23:40:04 -070026 struct pid_namespace *parent;
Pavel Emelyanov07543f52007-10-18 23:40:08 -070027#ifdef CONFIG_PROC_FS
28 struct vfsmount *proc_mnt;
29#endif
Pavel Emelyanov20fad132008-07-25 01:48:43 -070030#ifdef CONFIG_BSD_PROCESS_ACCT
31 struct bsd_acct_struct *bacct;
32#endif
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070033};
34
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080035extern struct pid_namespace init_pid_ns;
Sukadev Bhattiprolu3fbc9642006-10-02 02:17:24 -070036
Eric W. Biederman57d5f662007-11-14 17:00:13 -080037#ifdef CONFIG_PID_NS
Pavel Emelianova05f7b12007-10-18 23:39:47 -070038static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
Cedric Le Goater9a575a92006-12-08 02:37:59 -080039{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070040 if (ns != &init_pid_ns)
41 kref_get(&ns->kref);
Pavel Emelianova05f7b12007-10-18 23:39:47 -070042 return ns;
Cedric Le Goater9a575a92006-12-08 02:37:59 -080043}
44
Eric W. Biederman213dd262007-07-15 23:41:15 -070045extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080046extern void free_pid_ns(struct kref *kref);
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080047extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080048
49static inline void put_pid_ns(struct pid_namespace *ns)
50{
Pavel Emelyanovb461cc02007-10-18 23:40:09 -070051 if (ns != &init_pid_ns)
52 kref_put(&ns->kref, free_pid_ns);
Cedric Le Goater9a575a92006-12-08 02:37:59 -080053}
54
Eric W. Biederman57d5f662007-11-14 17:00:13 -080055#else /* !CONFIG_PID_NS */
56#include <linux/err.h>
57
58static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
59{
60 return ns;
61}
62
63static inline struct pid_namespace *
64copy_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
71static inline void put_pid_ns(struct pid_namespace *ns)
72{
73}
74
Pavel Emelyanov74bd59b2008-02-08 04:18:24 -080075
76static inline void zap_pid_ns_processes(struct pid_namespace *ns)
77{
78 BUG();
79}
Eric W. Biederman57d5f662007-11-14 17:00:13 -080080#endif /* CONFIG_PID_NS */
81
Eric W. Biederman61bce0f2009-01-07 18:08:49 -080082extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
Adrian Bunk3ae4eed2008-07-25 01:48:34 -070083void pidhash_init(void);
84void pidmap_init(void);
85
Sukadev Bhattiprolu61a58c62006-12-08 02:37:58 -080086#endif /* _LINUX_PID_NS_H */