aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/pid.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/pid.h')
-rw-r--r--include/linux/pid.h61
1 files changed, 54 insertions, 7 deletions
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 1e0e4e3423a6..e29a900a8499 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -40,15 +40,28 @@ enum pid_type
40 * processes. 40 * processes.
41 */ 41 */
42 42
43struct pid 43
44{ 44/*
45 atomic_t count; 45 * struct upid is used to get the id of the struct pid, as it is
46 * seen in particular namespace. Later the struct pid is found with
47 * find_pid_ns() using the int nr and struct pid_namespace *ns.
48 */
49
50struct upid {
46 /* Try to keep pid_chain in the same cacheline as nr for find_pid */ 51 /* Try to keep pid_chain in the same cacheline as nr for find_pid */
47 int nr; 52 int nr;
53 struct pid_namespace *ns;
48 struct hlist_node pid_chain; 54 struct hlist_node pid_chain;
55};
56
57struct pid
58{
59 atomic_t count;
49 /* lists of tasks that use this pid */ 60 /* lists of tasks that use this pid */
50 struct hlist_head tasks[PIDTYPE_MAX]; 61 struct hlist_head tasks[PIDTYPE_MAX];
51 struct rcu_head rcu; 62 struct rcu_head rcu;
63 int level;
64 struct upid numbers[1];
52}; 65};
53 66
54extern struct pid init_struct_pid; 67extern struct pid init_struct_pid;
@@ -83,26 +96,60 @@ extern void FASTCALL(detach_pid(struct task_struct *task, enum pid_type));
83extern void FASTCALL(transfer_pid(struct task_struct *old, 96extern void FASTCALL(transfer_pid(struct task_struct *old,
84 struct task_struct *new, enum pid_type)); 97 struct task_struct *new, enum pid_type));
85 98
99struct pid_namespace;
100extern struct pid_namespace init_pid_ns;
101
86/* 102/*
87 * look up a PID in the hash table. Must be called with the tasklist_lock 103 * look up a PID in the hash table. Must be called with the tasklist_lock
88 * or rcu_read_lock() held. 104 * or rcu_read_lock() held.
105 *
106 * find_pid_ns() finds the pid in the namespace specified
107 * find_pid() find the pid by its global id, i.e. in the init namespace
108 * find_vpid() finr the pid by its virtual id, i.e. in the current namespace
109 *
110 * see also find_task_by_pid() set in include/linux/sched.h
89 */ 111 */
90extern struct pid *FASTCALL(find_pid(int nr)); 112extern struct pid *FASTCALL(find_pid_ns(int nr, struct pid_namespace *ns));
113extern struct pid *find_vpid(int nr);
114extern struct pid *find_pid(int nr);
91 115
92/* 116/*
93 * Lookup a PID in the hash table, and return with it's count elevated. 117 * Lookup a PID in the hash table, and return with it's count elevated.
94 */ 118 */
95extern struct pid *find_get_pid(int nr); 119extern struct pid *find_get_pid(int nr);
96extern struct pid *find_ge_pid(int nr); 120extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
97 121
98extern struct pid *alloc_pid(void); 122extern struct pid *alloc_pid(struct pid_namespace *ns);
99extern void FASTCALL(free_pid(struct pid *pid)); 123extern void FASTCALL(free_pid(struct pid *pid));
124extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
125
126/*
127 * the helpers to get the pid's id seen from different namespaces
128 *
129 * pid_nr() : global id, i.e. the id seen from the init namespace;
130 * pid_vnr() : virtual id, i.e. the id seen from the namespace this pid
131 * belongs to. this only makes sence when called in the
132 * context of the task that belongs to the same namespace;
133 * pid_nr_ns() : id seen from the ns specified.
134 *
135 * see also task_xid_nr() etc in include/linux/sched.h
136 */
100 137
101static inline pid_t pid_nr(struct pid *pid) 138static inline pid_t pid_nr(struct pid *pid)
102{ 139{
103 pid_t nr = 0; 140 pid_t nr = 0;
104 if (pid) 141 if (pid)
105 nr = pid->nr; 142 nr = pid->numbers[0].nr;
143 return nr;
144}
145
146pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
147
148static inline pid_t pid_vnr(struct pid *pid)
149{
150 pid_t nr = 0;
151 if (pid)
152 nr = pid->numbers[pid->level].nr;
106 return nr; 153 return nr;
107} 154}
108 155