[CRIU] [PATCH cr 2/6] pstree: save ids on pstree_entry
Andrey Vagin
avagin at openvz.org
Tue Oct 2 10:07:18 EDT 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 | 6 ++++++
protobuf/pstree.proto | 8 ++++++++
pstree.c | 24 +++++++++++++++++++++++-
4 files changed, 51 insertions(+), 14 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index 0541e5c..4881592 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -692,8 +692,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;
@@ -702,29 +703,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;
}
@@ -849,10 +850,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;
@@ -1495,6 +1492,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 dc7f232..0790b49 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -11,6 +11,12 @@ struct pstree_item {
pid_t pgid;
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 */
struct pid *threads; /* array 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 6033e7e..8df5a63 100644
--- a/pstree.c
+++ b/pstree.c
@@ -75,6 +75,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;
@@ -95,6 +96,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;
@@ -192,7 +208,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.1
More information about the CRIU
mailing list