[CRIU] [PATCH 2/5] pstree: save ids on pstree_entry
Andrey Vagin
avagin at openvz.org
Fri Nov 23 03:24:28 EST 2012
All this ids have sense when processes are created,
so they should be in pstree_entry.
Currently ids are not used and the field is optional,
we can move it to anywhere.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
cr-dump.c | 27 ++++++++++++++-------------
include/pstree.h | 5 +++++
protobuf/pstree.proto | 8 ++++++++
pstree.c | 24 +++++++++++++++++++++++-
4 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index 279381c..3957c1b 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -748,8 +748,9 @@ static DECLARE_KCMP_TREE(fs_tree, KCMP_FS);
static DECLARE_KCMP_TREE(files_tree, KCMP_FILES);
static DECLARE_KCMP_TREE(sighand_tree, KCMP_SIGHAND);
-static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
+static int dump_task_kobj_ids(struct pstree_item *item)
{
+ pid_t pid = item->pid.real;
int new;
struct kid_elem elem;
@@ -758,29 +759,29 @@ static int dump_task_kobj_ids(pid_t pid, CoreEntry *core)
elem.genid = 0; /* FIXME optimize */
new = 0;
- core->ids->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
- if (!core->ids->vm_id || !new) {
+ item->vm_id = kid_generate_gen(&vm_tree, &elem, &new);
+ if (!item->vm_id || !new) {
pr_err("Can't make VM id for %d\n", pid);
return -1;
}
new = 0;
- core->ids->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
- if (!core->ids->fs_id || !new) {
+ item->fs_id = kid_generate_gen(&fs_tree, &elem, &new);
+ if (!item->fs_id || !new) {
pr_err("Can't make FS id for %d\n", pid);
return -1;
}
new = 0;
- core->ids->files_id = kid_generate_gen(&files_tree, &elem, &new);
- if (!core->ids->files_id || !new) {
+ item->files_id = kid_generate_gen(&files_tree, &elem, &new);
+ if (!item->files_id || (!new && item->parent->files_id != item->files_id )) {
pr_err("Can't make FILES id for %d\n", pid);
return -1;
}
new = 0;
- core->ids->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
- if (!core->ids->sighand_id || !new) {
+ item->sighand_id = kid_generate_gen(&sighand_tree, &elem, &new);
+ if (!item->sighand_id || !new) {
pr_err("Can't make IO id for %d\n", pid);
return -1;
}
@@ -905,10 +906,6 @@ static int dump_task_core_all(pid_t pid, const struct proc_pid_stat *stat,
pr_info("Dumping core (pid: %d)\n", pid);
pr_info("----------------------------------------\n");
- ret = dump_task_kobj_ids(pid, core);
- if (ret)
- goto err_free;
-
ret = dump_task_mm(pid, stat, misc, cr_fdset);
if (ret)
goto err_free;
@@ -1564,6 +1561,10 @@ static int dump_one_task(struct pstree_item *item)
if (!cr_fdset)
goto err_cure;
+ ret = dump_task_kobj_ids(item);
+ if (ret)
+ goto err_cure;
+
ret = dump_task_files_seized(parasite_ctl, cr_fdset, dfds);
if (ret) {
pr_err("Dump files (pid: %d) failed with %d\n", pid, ret);
diff --git a/include/pstree.h b/include/pstree.h
index 8536844..307113d 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -35,6 +35,11 @@ struct pstree_item {
pid_t sid;
pid_t born_sid;
+ u32 vm_id;
+ u32 fs_id;
+ u32 files_id;
+ u32 sighand_id;
+
int state; /* TASK_XXX constants */
int nr_threads; /* number of threads */
diff --git a/protobuf/pstree.proto b/protobuf/pstree.proto
index 6cbcfd3..0658133 100644
--- a/protobuf/pstree.proto
+++ b/protobuf/pstree.proto
@@ -1,7 +1,15 @@
+message pstree_kobj_ids_entry {
+ required uint32 vm_id = 1;
+ required uint32 files_id = 2;
+ required uint32 fs_id = 3;
+ required uint32 sighand_id = 4;
+}
+
message pstree_entry {
required uint32 pid = 1;
required uint32 ppid = 2;
required uint32 pgid = 3;
required uint32 sid = 4;
repeated uint32 threads = 5;
+ optional pstree_kobj_ids_entry ids = 6;
}
diff --git a/pstree.c b/pstree.c
index 95120ba..7534344 100644
--- a/pstree.c
+++ b/pstree.c
@@ -66,6 +66,7 @@ int dump_pstree(struct pstree_item *root_item)
{
struct pstree_item *item = root_item;
PstreeEntry e = PSTREE_ENTRY__INIT;
+ PstreeKobjIdsEntry *ids;
int ret = -1, i;
int pstree_fd;
@@ -103,6 +104,21 @@ int dump_pstree(struct pstree_item *root_item)
e.sid = item->sid;
e.n_threads = item->nr_threads;
+ if (item->state != TASK_DEAD) {
+ ids = xmalloc(sizeof(*ids));
+ if (!ids)
+ goto err;
+
+ pstree_kobj_ids_entry__init(ids);
+ e.ids = ids;
+
+ e.ids->vm_id = item->vm_id;
+ e.ids->fs_id = item->fs_id;
+ e.ids->files_id = item->files_id;
+ e.ids->sighand_id = item->sighand_id;
+ } else
+ e.ids = NULL;
+
e.threads = xmalloc(sizeof(e.threads[0]) * e.n_threads);
if (!e.threads)
goto err;
@@ -252,7 +268,13 @@ int prepare_pstree(void)
if (!pi->threads)
break;
- ret = 0;
+ if (e->ids) {
+ pi->vm_id = e->ids->vm_id;
+ pi->fs_id = e->ids->fs_id;
+ pi->files_id = e->ids->files_id;
+ pi->sighand_id = e->ids->sighand_id;
+ }
+
for (i = 0; i < e->n_threads; i++)
pi->threads[i].virt = e->threads[i];
--
1.7.11.7
More information about the CRIU
mailing list