2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00

ns: Collect/read pid_for_children ns

Handle it as other namespaces, except of case of
just unshared pid ns w/o child reaper (fail if so),
and in case of we don't have it on restore (old
images -- then get pid_for_children ns from pid ns).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kirill Tkhai
2017-05-31 20:53:57 +03:00
committed by Andrei Vagin
parent 517b399745
commit e3e1d8afd7
3 changed files with 38 additions and 0 deletions

View File

@@ -139,6 +139,7 @@ extern int pstree_alloc_cores(struct pstree_item *item);
extern void pstree_free_cores(struct pstree_item *item);
extern int collect_pstree_ids(void);
extern int fixup_pid_for_children_ns(TaskKobjIdsEntry *ids);
extern int preorder_pstree_traversal(struct pstree_item *item, int (*f)(struct pstree_item *));
extern int __set_next_pid(pid_t pid);

View File

@@ -690,6 +690,25 @@ struct collect_image_info nsfile_cinfo = {
.collect = collect_one_nsfile,
};
static int get_pid_for_children_ns_id(pid_t pid, TaskKobjIdsEntry *ids)
{
ids->has_pid_for_children_ns_id = false;
if (kdat.has_pid_for_children_ns) {
ids->pid_for_children_ns_id = __get_ns_id(pid, &pid_ns_desc, true,
&ids->has_pid_for_children_ns_id, NULL);
if (!ids->pid_for_children_ns_id) {
pr_err("Can't make pid_for_children id\n");
return -1;
}
if (ids->pid_for_children_ns_id == UINT_MAX) {
pr_err("Just unshared pid namespaces are not supported yet\n");
return -1;
}
}
return 0;
}
/*
* Same as dump_task_ns_ids(), but
* a) doesn't keep IDs (don't need them)
@@ -775,6 +794,9 @@ int dump_task_ns_ids(struct pstree_item *item)
return -1;
}
if (get_pid_for_children_ns_id(pid, ids) < 0)
return -1;
return 0;
}

View File

@@ -617,6 +617,18 @@ struct pid *__pstree_pid_by_virt(struct ns_id *ns, pid_t pid)
return NULL;
}
int fixup_pid_for_children_ns(TaskKobjIdsEntry *ids)
{
if (!ids->has_pid_for_children_ns_id) {
ids->has_pid_for_children_ns_id = true;
ids->pid_for_children_ns_id = ids->pid_ns_id;
} else if (!lookup_ns_by_id(ids->pid_for_children_ns_id, &pid_ns_desc)) {
pr_err("Can't find pid_for_children ns linked\n");
return -1;
}
return 0;
}
static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
{
struct cr_img *img;
@@ -661,6 +673,9 @@ static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
ret = -1;
}
if (!ret)
ret = fixup_pid_for_children_ns(*ids);
if (!ret && !top_pid_ns) {
/*
* If top_pid_ns is not set, this means that here is old dump,