From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
To: <containers@lists.linux-foundation.org>, <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Serge Hallyn <serge.hallyn@ubuntu.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
Oleg Nesterov <oleg@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
David Howells <dhowells@redhat.com>,
Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Subject: [Resend][PATCH] ns,proc: introduce pid_in_ns
Date: Fri, 25 Apr 2014 16:43:25 +0800 [thread overview]
Message-ID: <1398415405-19872-1-git-send-email-chenhanxiao@cn.fujitsu.com> (raw)
We lacked of convenient method of getting the pid inside containers.
If some issues occurred inside container guest, host user
could not know which process is in trouble just by guest pid:
the users of container guest only knew the pid inside containers.
This will bring obstacle for trouble shooting.
This patch introduces pid_in_ns:
If one process is in init_pid_ns, /proc/PID/pid_in_ns
equals to /proc/PID;
if one process is in pidns, /proc/PID/pid_in_ns
will tell the pid inside containers;
if pidns is nested, it depends on which pidns are you in.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
---
fs/proc/array.c | 13 +++++++++++++
fs/proc/base.c | 1 +
fs/proc/internal.h | 2 ++
3 files changed, 16 insertions(+)
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 64db2bc..3ff7050 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -562,6 +562,19 @@ int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
return do_task_stat(m, ns, pid, task, 1);
}
+int proc_pid_in_ns(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ pid_t pid_in_ns;
+ unsigned int level;
+
+ level = pid->level;
+ pid_in_ns = task_pid_nr_ns(task, pid->numbers[level].ns);
+ seq_put_decimal_ull(m, 0, pid_in_ns);
+ seq_putc(m, '\n');
+ return 0;
+}
+
int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
{
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 2d696b0..42904b7 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2574,6 +2574,7 @@ static const struct pid_entry tgid_base_stuff[] = {
INF("cmdline", S_IRUGO, proc_pid_cmdline),
ONE("stat", S_IRUGO, proc_tgid_stat),
ONE("statm", S_IRUGO, proc_pid_statm),
+ ONE("pid_in_ns", S_IRUGO, proc_pid_in_ns),
REG("maps", S_IRUGO, proc_pid_maps_operations),
#ifdef CONFIG_NUMA
REG("numa_maps", S_IRUGO, proc_pid_numa_maps_operations),
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 3ab6d14..573841a 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -155,6 +155,8 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
struct pid *, struct task_struct *);
extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
struct pid *, struct task_struct *);
+extern int proc_pid_in_ns(struct seq_file *, struct pid_namespace *,
+ struct pid *, struct task_struct *);
/*
* base.c
--
1.9.0
next reply other threads:[~2014-04-25 8:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-25 8:43 Chen Hanxiao [this message]
2014-04-25 18:56 ` Oleg Nesterov
2014-04-25 19:17 ` Eric W. Biederman
2014-05-13 9:15 ` chenhanxiao
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=1398415405-19872-1-git-send-email-chenhanxiao@cn.fujitsu.com \
--to=chenhanxiao@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=berrange@redhat.com \
--cc=containers@lists.linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=serge.hallyn@ubuntu.com \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®