[CRIU] [PATCH v2 07/21] dump: More obvious assignment of top_pid_ns

Kirill Tkhai ktkhai at virtuozzo.com
Wed May 31 10:52:48 PDT 2017


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 at virtuozzo.com>
---
 criu/cr-dump.c    |   27 +++++++++++++++++++++++++--
 criu/namespaces.c |    5 +----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 1d661e7b1..b3df881dc 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -805,6 +805,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;
@@ -817,7 +840,7 @@ static int collect_pstree_ids_predump()
 			return -1;
 	}
 
-	return 0;
+	return set_top_pid_ns();
 }
 
 int collect_pstree_ids(void)
@@ -828,7 +851,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)
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 3473ab13b..fb6c77552 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -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;



More information about the CRIU mailing list