Commit 63fea930 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

dump: Switch to /proc/$pid/children parsing to obtain children set

This also depends on kernel's inteface being changed,
so kernel/ is updated as well.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent baf69d67
......@@ -727,6 +727,23 @@ static struct pstree_item *find_pstree_entry(pid_t pid)
pr_debug("pid: %d\n", pid);
file = fopen_proc("%d/children", "r", pid);
if (!file) {
pr_perror("Can't open %d children", pid);
goto err;
}
if (!(fgets(loc_buf, sizeof(loc_buf), file))) {
pr_perror("Can't read %d children content", pid);
goto err;
}
children_str = xstrdup(loc_buf);
if (!children_str)
goto err;
fclose(file), file = NULL;
file = fopen_proc("%d/status", "r", pid);
if (!file) {
pr_perror("Can't open %d status", pid);
......@@ -734,13 +751,7 @@ static struct pstree_item *find_pstree_entry(pid_t pid)
}
while ((fgets(loc_buf, sizeof(loc_buf), file))) {
if (!strncmp(loc_buf, "Children:", 9)) {
children_str = xstrdup(&loc_buf[10]);
if (!children_str)
goto err;
if (nr_threads)
break;
} else if (!strncmp(loc_buf, "Threads:", 8)) {
if (!strncmp(loc_buf, "Threads:", 8)) {
nr_threads = atoi(&loc_buf[9]);
if (children_str)
break;
......@@ -790,6 +801,8 @@ static struct pstree_item *find_pstree_entry(pid_t pid)
item->threads = threads;
err:
if (file)
fclose(file);
xfree(children_str);
return item;
......
fs, proc: Introduce the Children: line in /proc/<pid>/status
From: Pavel Emelyanov <xemul@parallels.com>
There is no easy way to make a reverse parent->children chain
from the task status, in turn children->parent provided with "PPid"
field.
So instead of walking over all pids in system to figure out what
children the task have -- we add explicit "Children" member to
/proc/<pid>/status since kernel already knows this kind of information
but it was not yet exported.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
fs/proc/array.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -158,6 +158,18 @@ static inline const char *get_task_state(struct task_struct *tsk)
return *p;
}
+static void task_children(struct seq_file *m, struct task_struct *p, struct pid_namespace *ns)
+{
+ struct task_struct *c;
+
+ seq_printf(m, "Children:");
+ read_lock(&tasklist_lock);
+ list_for_each_entry(c, &p->children, sibling)
+ seq_printf(m, " %d", pid_nr_ns(task_pid(c), ns));
+ read_unlock(&tasklist_lock);
+ seq_putc(m, '\n');
+}
+
static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *p)
{
@@ -192,6 +204,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
cred->uid, cred->euid, cred->suid, cred->fsuid,
cred->gid, cred->egid, cred->sgid, cred->fsgid);
+ task_children(m, p, ns);
+
task_lock(p);
if (p->files)
fdt = files_fdtable(p->files);
--
1.7.7.3
fs, proc: Introduce the /proc/<pid>/children entry
There is no easy way to make a reverse parent->children chain
from the task status, in turn children->parent provided with "PPid"
field.
So instead of walking over all pids in system to figure out what
children the task have -- we add explicit /proc/<pid>/children entry,
since kernel already knows this kind of information but it was not
yet exported.
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Pavel Emelyanov <xemul@parallels.com>
Cc: Serge Hallyn <serge.hallyn@canonical.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
fs/proc/array.c | 14 ++++++++++++++
fs/proc/base.c | 1 +
fs/proc/internal.h | 3 +++
3 files changed, 18 insertions(+)
Index: linux-2.6.git/fs/proc/array.c
===================================================================
--- linux-2.6.git.orig/fs/proc/array.c
+++ linux-2.6.git/fs/proc/array.c
@@ -547,3 +547,17 @@ int proc_pid_statm(struct seq_file *m, s
return 0;
}
+
+int proc_pid_children(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ struct task_struct *c;
+
+ read_lock(&tasklist_lock);
+ list_for_each_entry(c, &task->children, sibling)
+ seq_printf(m, " %d", pid_nr_ns(task_pid(c), ns));
+ read_unlock(&tasklist_lock);
+ seq_putc(m, '\n');
+
+ return 0;
+}
Index: linux-2.6.git/fs/proc/base.c
===================================================================
--- linux-2.6.git.orig/fs/proc/base.c
+++ linux-2.6.git/fs/proc/base.c
@@ -3204,6 +3204,7 @@ static const struct pid_entry tgid_base_
INF("cmdline", S_IRUGO, proc_pid_cmdline),
ONE("stat", S_IRUGO, proc_tgid_stat),
ONE("statm", S_IRUGO, proc_pid_statm),
+ ONE("children", S_IRUGO, proc_pid_children),
REG("maps", S_IRUGO, proc_maps_operations),
#ifdef CONFIG_NUMA
REG("numa_maps", S_IRUGO, proc_numa_maps_operations),
Index: linux-2.6.git/fs/proc/internal.h
===================================================================
--- linux-2.6.git.orig/fs/proc/internal.h
+++ linux-2.6.git/fs/proc/internal.h
@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_fi
struct pid *pid, struct task_struct *task);
extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task);
+extern int proc_pid_children(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task);
+
extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
extern const struct file_operations proc_maps_operations;
......@@ -3,7 +3,7 @@ fs-proc-Introduce-the-proc-pid-map_files-directory
procfs-introduce-the-proc-pid-map_files-directory-checkpatch
clone-Introduce-the-CLONE_CHILD_USEPID-functionality
fs-proc-Add-start_data-end_data-start_brk-members
fs-proc-Introduce-the-Children-line-in-proc-pid-stat
fs-proc-add-children-entry
prctl-tune-up-mm_struct-members-2
mincore-Add-named-constant-for-reported-present-bit
mincore-Report-whether-page-is-anon-or-not
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment