Helpers to obtain pid numbers
PATCH 8/20 Helpers to obtain pid numbers
When showing pid to user or getting the pid numerical id for in-kernel use the value of this id may differ depending on the namespace.
This set of helpers is used to get the global pid nr, the virtual (i.e. seen by task in its namespace) nr and the nr as it is seen from the specified namespace.
Signed-off-by Pavel Emelyanov <[email protected]>
Cc Oleg Nesterov <[email protected]>
---
include/linux/pid.h | 24 ++++++++++- include/linux/sched.h | 108 +++++++++++++++++++++++++++++++++++++++++++++----- kernel/pid.c | 13 ++++++ 3 files changed, 134 insertions(+), 11 deletions(-)
include/linux/pid.h renamed from include/linux/pid.h.ve9 +23 -1
@@ -104,11 +104,33 @@ extern struct pid *find_ge_pid(int nr);extern struct pid *alloc_pid (struct pid_namespace *ns);extern void FASTCALL (free_pid (struct pid *pid)); +/* +* the helpers to get the pid's id seen from different namespaces +* +* pid_nr() : global id, i.e. the id seen from the init namespace; +* pid_vnr() : virtual id, i.e. the id seen from the namespace this pid +* belongs to. this only makes sence when called in the +* context of the task that belongs to the same namespace; +* pid_nr_ns() : id seen from the ns specified. +* +* see also task_xid_nr() etc in include/linux/sched.h +*/ +static inline pid_t pid_nr (struct pid *pid) {pid_t nr =0 ;if (pid) - nr = pid->nr; + nr = pid->numbers[0 ].nr; +return nr; +} + +pid_t pid_nr_ns (struct pid *pid,struct pid_namespace *ns); + +static inline pid_t pid_vnr (struct pid *pid) +{ +pid_t nr =0 ; +if (pid) + nr = pid->numbers[pid->level].nr;return nr; }
include/linux/sched.h renamed from include/linux/sched.h.ve9 +98 -10
120 lines not on this page · raw message
kernel/pid.c renamed from kernel/pid.c.ve9 +13 -0
@@ -380,6 +380,19 @@ struct pid *find_get_pid(pid_t nr)return pid; } +pid_t pid_nr_ns (struct pid *pid,struct pid_namespace *ns) +{ +struct upid *upid; +pid_t nr =0 ; + +if (pid && ns->level <= pid->level) { + upid = &pid->numbers[ns->level]; +if (upid->ns == ns) + nr = upid->nr; + } +return nr; +} +/* * Used by proc to find the first pid that is greater then or equal to nr. *