diff options
Diffstat (limited to 'include/linux/pid.h')
-rw-r--r-- | include/linux/pid.h | 61 |
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 | ||
43 | struct 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 | |||
50 | struct 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 | |||
57 | struct 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 | ||
54 | extern struct pid init_struct_pid; | 67 | extern struct pid init_struct_pid; |
@@ -83,26 +96,60 @@ extern void FASTCALL(detach_pid(struct task_struct *task, enum pid_type)); | |||
83 | extern void FASTCALL(transfer_pid(struct task_struct *old, | 96 | extern 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 | ||
99 | struct pid_namespace; | ||
100 | extern 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 | */ |
90 | extern struct pid *FASTCALL(find_pid(int nr)); | 112 | extern struct pid *FASTCALL(find_pid_ns(int nr, struct pid_namespace *ns)); |
113 | extern struct pid *find_vpid(int nr); | ||
114 | extern 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 | */ |
95 | extern struct pid *find_get_pid(int nr); | 119 | extern struct pid *find_get_pid(int nr); |
96 | extern struct pid *find_ge_pid(int nr); | 120 | extern struct pid *find_ge_pid(int nr, struct pid_namespace *); |
97 | 121 | ||
98 | extern struct pid *alloc_pid(void); | 122 | extern struct pid *alloc_pid(struct pid_namespace *ns); |
99 | extern void FASTCALL(free_pid(struct pid *pid)); | 123 | extern void FASTCALL(free_pid(struct pid *pid)); |
124 | extern 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 | ||
101 | static inline pid_t pid_nr(struct pid *pid) | 138 | static 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 | |||
146 | pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns); | ||
147 | |||
148 | static 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 | ||