dump: More obvious assignment of top_pid_ns

Currently it's set in generate_ns_id() and it's equal to:
1)NS_CRIU, if root_ns_mask does not contain CLONE_NEWPID,
2)NS_ROOT, if it contains.

The assignment is not obvious, as it's set NS_CRIU firstly,
and then rewrites in NS_ROOT, if it exists.

Mark top_pid_ns after ns_ids population in more clear way.

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:52:48 +03:00 committed by Andrei Vagin
parent c204fb101e
commit 6f4a4e1bbd
2 changed files with 26 additions and 6 deletions

View file

@ -822,6 +822,29 @@ static int predump_criu_ns_ids(void)
return predump_task_ns_ids(&crt.i);
}
static int set_top_pid_ns(void)
{
struct ns_id *ns;
for (ns = ns_ids; ns != NULL; ns = ns->next) {
if (ns->nd != &pid_ns_desc)
continue;
if (ns->type == NS_ROOT) {
top_pid_ns = ns;
break;
}
if (ns->type == NS_CRIU)
top_pid_ns = ns;
}
if (!top_pid_ns) {
pr_err("Can't set top_pid_ns\n");
return -1;
}
return 0;
}
static int collect_pstree_ids_predump()
{
struct pstree_item *item;
@ -834,7 +857,7 @@ static int collect_pstree_ids_predump()
return -1;
}
return 0;
return set_top_pid_ns();
}
int collect_pstree_ids(void)
@ -845,7 +868,7 @@ int collect_pstree_ids(void)
if (get_task_ids(item))
return -1;
return 0;
return set_top_pid_ns();
}
static int collect_file_locks(void)

View file

@ -448,11 +448,8 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
if (nd == &net_ns_desc) {
INIT_LIST_HEAD(&nsid->net.ids);
INIT_LIST_HEAD(&nsid->net.links);
} else if (nd == &pid_ns_desc) {
} else if (nd == &pid_ns_desc)
nsid->pid.rb_root = RB_ROOT;
if (type == NS_ROOT || (type == NS_CRIU && !top_pid_ns))
top_pid_ns = nsid;
}
found:
if (ns_ret)
*ns_ret = nsid;