From: sukadev@us.ibm.com
To: Pavel Emelianov <xemul@openvz.org>
Cc: Andrew Morton <akpm@osdl.org>, Serge Hallyn <serue@us.ibm.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Linux Containers <containers@lists.osdl.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Kirill Korotaev <dev@openvz.org>
Subject: Re: [PATCH 6/16] Helpers to obtain pid numbers
Date: Mon, 9 Jul 2007 22:18:01 -0700 [thread overview]
Message-ID: <20070710051801.GE15214@us.ibm.com> (raw)
In-Reply-To: <468DF7FE.5080201@openvz.org>
Pavel Emelianov [xemul@openvz.org] wrote:
| 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 Emelianov <xemul@openvz.org>
|
| ---
|
| include/linux/pid.h | 27 ++++++++++++
| include/linux/sched.h | 108 +++++++++++++++++++++++++++++++++++++++++++++-----
| kernel/pid.c | 8 +++
| 3 files changed, 132 insertions(+), 11 deletions(-)
|
| diff -upr linux-2.6.22-rc4-mm2.orig/include/linux/pid.h linux-2.6.22-rc4-mm2-2/include/linux/pid.h
| --- linux-2.6.22-rc4-mm2.orig/include/linux/pid.h 2007-06-14 12:14:29.000000000 +0400
| +++ linux-2.6.22-rc4-mm2-2/include/linux/pid.h 2007-07-04 19:00:38.000000000 +0400
| @@ -83,6 +89,9 @@ extern void FASTCALL(detach_pid(struct t
| extern void FASTCALL(transfer_pid(struct task_struct *old,
| struct task_struct *new, enum pid_type));
|
| +struct pid_namespace;
| +extern struct pid_namespace init_pid_ns;
| +
| /*
| * look up a PID in the hash table. Must be called with the tasklist_lock
| * or rcu_read_lock() held.
| @@ -93,14 +99,36 @@ extern void FASTCALL(detach_pid(struct t
| extern struct pid *alloc_pid(void);
| 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
| + */
I think its a bit confusing and error-prone to have both pid_nr() and pid_vnr().
BTW, shouldn't you use pid_vnr() in do_task_stat() ? You currently use pid_nr()
and that returns the init-pid-ns id right ?
| +
| 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;
| +}
| +
| #define do_each_pid_task(pid, type, task) \
| do { \
| struct hlist_node *pos___; \
| diff -upr linux-2.6.22-rc4-mm2.orig/kernel/pid.c linux-2.6.22-rc4-mm2-2/kernel/pid.c
| --- linux-2.6.22-rc4-mm2.orig/kernel/pid.c 2007-06-14 12:14:29.000000000 +0400
| +++ linux-2.6.22-rc4-mm2-2/kernel/pid.c 2007-07-04 19:00:38.000000000 +0400
| @@ -339,6 +379,14 @@ struct pid *find_get_pid(pid_t nr)
| return pid;
| }
|
| +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
| +{
| + pid_t nr = 0;
| + if (pid && ns->level <= pid->level)
| + nr = pid->numbers[ns->level].nr;
| + return nr;
| +}
| +
| /*
| * Used by proc to find the first pid that is greater then or equal to nr.
| *
| diff -upr linux-2.6.22-rc4-mm2.orig/include/linux/sched.h linux-2.6.22-rc4-mm2-2/include/linux/sched.h
| --- linux-2.6.22-rc4-mm2.orig/include/linux/sched.h 2007-07-04 19:00:38.000000000 +0400
| +++ linux-2.6.22-rc4-mm2-2/include/linux/sched.h 2007-07-04 19:00:38.000000000 +0400
| @@ -1153,16 +1154,6 @@ struct task_struct {
| #endif
| };
|
| -static inline pid_t task_pgrp_nr(struct task_struct *tsk)
| -{
| - return tsk->signal->pgrp;
| -}
| -
| -static inline pid_t task_session_nr(struct task_struct *tsk)
| -{
| - return tsk->signal->__session;
| -}
| -
| static inline void set_task_session(struct task_struct *tsk, pid_t session)
| {
| tsk->signal->__session = session;
| @@ -1188,6 +1179,104 @@ static inline struct pid *task_session(s
| return task->group_leader->pids[PIDTYPE_SID].pid;
| }
|
| +struct pid_namespace;
| +
| +/*
| + * the helpers to get the task's different pids as they are seen
| + * from various namespaces
| + *
| + * task_xid_nr() : global id, i.e. the id seen from the init namespace;
| + * task_xid_vnr() : virtual id, i.e. the id seen from the namespace the task
| + * belongs to. this only makes sence when called in the
| + * context of the task that belongs to the same namespace;
| + * task_xid_nr_ns() : id seen from the ns specified;
| + *
| + * set_task_vxid() : assigns a virtual id to a task;
| + *
| + * task_ppid_nr_ns() : the parent's id as seen from the namespace specified.
| + * the result depends on the namespace and whether the
| + * task in question is the namespace's init. e.g. for the
| + * namespace's init this will return 0 when called from
| + * the namespace of this init, or appropriate id otherwise.
| + *
| + *
| + * see also pid_nr() etc in include/linux/pid.h
| + */
| +
| +static inline pid_t task_pid_nr(struct task_struct *tsk)
| +{
| + return tsk->pid;
| +}
| +
| +static inline pid_t task_pid_nr_ns(struct task_struct *tsk,
| + struct pid_namespace *ns)
| +{
| + return pid_nr_ns(task_pid(tsk), ns);
| +}
| +
| +static inline pid_t task_pid_vnr(struct task_struct *tsk)
| +{
| + return pid_vnr(task_pid(tsk));
| +}
| +
| +
| +static inline pid_t task_tgid_nr(struct task_struct *tsk)
| +{
| + return tsk->tgid;
| +}
| +
| +static inline pid_t task_tgid_nr_ns(struct task_struct *tsk,
| + struct pid_namespace *ns)
| +{
| + return pid_nr_ns(task_tgid(tsk), ns);
| +}
| +
| +static inline pid_t task_tgid_vnr(struct task_struct *tsk)
| +{
| + return pid_vnr(task_tgid(tsk));
| +}
| +
| +
| +static inline pid_t task_pgrp_nr(struct task_struct *tsk)
| +{
| + return tsk->signal->pgrp;
| +}
| +
| +static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk,
| + struct pid_namespace *ns)
| +{
| + return pid_nr_ns(task_pgrp(tsk), ns);
| +}
| +
| +static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
| +{
| + return pid_vnr(task_pgrp(tsk));
| +}
| +
| +
| +static inline pid_t task_session_nr(struct task_struct *tsk)
| +{
| + return tsk->signal->__session;
| +}
| +
| +static inline pid_t task_session_nr_ns(struct task_struct *tsk,
| + struct pid_namespace *ns)
| +{
| + return pid_nr_ns(task_session(tsk), ns);
| +}
| +
| +static inline pid_t task_session_vnr(struct task_struct *tsk)
| +{
| + return pid_vnr(task_session(tsk));
| +}
| +
| +
| +static inline pid_t task_ppid_nr_ns(struct task_struct *tsk,
| + struct pid_namespace *ns)
| +{
| + return pid_nr_ns(task_pid(rcu_dereference(tsk->real_parent)), ns);
| +}
| +
| /**
| * pid_alive - check that a task structure is not stale
| * @p: Task structure to be checked.
next prev parent reply other threads:[~2007-07-10 5:18 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 8:01 [PATCH 0/16] Pid namespaces Pavel Emelianov
2007-07-06 8:03 ` [PATCH 1/16] Round up the API Pavel Emelianov
2007-07-09 20:18 ` Cedric Le Goater
2007-07-10 6:40 ` Pavel Emelianov
2007-07-10 7:34 ` Andrew Morton
2007-07-06 8:03 ` [PATCH 2/16] Miscelaneous preparations for namespaces Pavel Emelianov
2007-07-09 20:22 ` Cedric Le Goater
2007-07-10 6:42 ` Pavel Emelianov
2007-07-06 8:04 ` [PATCH 3/16] Introduce MS_KERNMOUNT flag Pavel Emelianov
2007-07-06 8:05 ` [PATCH 4/16] Change data structures for pid namespaces Pavel Emelianov
2007-07-09 20:25 ` Cedric Le Goater
2007-07-10 4:32 ` sukadev
2007-07-10 7:04 ` Pavel Emelianov
2007-07-10 12:07 ` Cedric Le Goater
2007-07-06 8:05 ` [PATCH 5/16] Make proc be mountable from different " Pavel Emelianov
2007-07-06 8:06 ` [PATCH 6/16] Helpers to obtain pid numbers Pavel Emelianov
2007-07-10 5:18 ` sukadev [this message]
2007-07-10 6:49 ` Pavel Emelianov
2007-07-06 8:07 ` [PATCH 7/16] Helpers to find the task by its numerical ids Pavel Emelianov
2007-07-10 4:00 ` sukadev
2007-07-10 6:47 ` Pavel Emelianov
2007-07-06 8:07 ` [PATCH 8/16] Masquerade the siginfo when sending a pid to a foreign namespace Pavel Emelianov
2007-07-10 4:18 ` sukadev
2007-07-10 6:56 ` Pavel Emelianov
2007-07-06 8:08 ` [PATCH 9/16] Make proc_flust_task to flush entries from multiple proc trees Pavel Emelianov
2007-07-06 8:08 ` [PATCH 10/16] Changes in copy_process() to work with pid namespaces Pavel Emelianov
2007-07-12 0:21 ` sukadev
2007-07-06 8:09 ` [PATCH 11/16] Add support for multiple kmem caches for pids Pavel Emelianov
2007-07-06 8:10 ` [PATCH 12/16] Reference counting of pid naspaces by pids Pavel Emelianov
2007-07-06 8:10 ` [PATCH 13/16] Switch to operating with pid_numbers instead of pids Pavel Emelianov
2007-07-25 0:36 ` sukadev
2007-07-25 10:07 ` Pavel Emelyanov
2007-07-25 19:13 ` sukadev
2007-07-26 6:42 ` Pavel Emelyanov
2007-07-06 8:11 ` [PATCH 14/16] Make pid namespaces clonnable Pavel Emelianov
2007-07-06 8:13 ` [PATCH 15/16] Changes to show virtual ids to user Pavel Emelianov
2007-07-06 8:16 ` [PATCH 16/16] Remove already unneeded memners from struct pid Pavel Emelianov
2007-07-06 16:26 ` [PATCH 0/16] Pid namespaces Dave Hansen
2007-07-09 5:58 ` Pavel Emelianov
2007-07-09 19:58 ` Dave Hansen
2007-07-09 12:02 ` Herbert Poetzl
2007-07-09 13:16 ` Pavel Emelianov
2007-07-09 19:52 ` Herbert Poetzl
2007-07-09 20:12 ` Cedric Le Goater
2007-07-10 6:59 ` Pavel Emelianov
2007-07-09 17:46 ` Badari Pulavarty
2007-07-09 20:06 ` Cedric Le Goater
2007-07-09 23:00 ` Badari Pulavarty
2007-07-10 7:05 ` Pavel Emelianov
2007-07-10 11:30 ` Pavel Emelianov
2007-07-10 12:05 ` Daniel Lezcano
2007-07-10 13:03 ` Pavel Emelianov
2007-07-10 20:34 ` Badari Pulavarty
2007-07-10 13:06 ` Pavel Emelianov
2007-07-10 20:33 ` Badari Pulavarty
2007-07-09 21:42 ` sukadev
2007-07-10 0:29 ` sukadev
2007-07-10 9:41 ` Pavel Emelianov
2007-07-10 13:08 ` Pavel Emelianov
2007-07-10 4:26 ` sukadev
2007-07-10 7:02 ` Pavel Emelianov
2007-07-11 1:16 ` Matt Mackall
2007-07-11 6:39 ` Pavel Emelianov
2007-07-11 15:14 ` Matt Mackall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070710051801.GE15214@us.ibm.com \
--to=sukadev@us.ibm.com \
--cc=akpm@osdl.org \
--cc=containers@lists.osdl.org \
--cc=dev@openvz.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serue@us.ibm.com \
--cc=xemul@openvz.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox