[CRIU] [PATCH v5 42/42] ns: Nested pid_ns support

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 5 09:19:57 PDT 2017


Allow nested pid_ns, but turn restoring of pgid and sid off for the cases,
when there are child pid namespaces. This functionality will be realized
by Pavel Tikhomirov, he is working on that.

v4: Also make restore_before_setsid() always return false if there are
child pid namespaces

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c         |    5 +++++
 criu/include/namespaces.h |    2 +-
 criu/pstree.c             |    5 +++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index dc3ecc63f..3b67176ee 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1522,6 +1522,8 @@ static void restore_sid(void)
 {
 	pid_t sid;
 
+	if (!list_empty(&top_pid_ns->children))
+		return;
 	/*
 	 * SID can only be reset to pid or inherited from parent.
 	 * Thus we restore it right here to let our kids inherit
@@ -1565,6 +1567,9 @@ static void restore_pgid(void)
 
 	pid_t pgid, my_pgid = last_level_pid(current->pgid);
 
+	if (!list_empty(&top_pid_ns->children))
+		return;
+
 	pr_info("Restoring %d to %d pgid\n", vpid(current), my_pgid);
 
 	pgid = getpgrp();
diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index b81957668..52072a6e2 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -40,7 +40,7 @@
 #define CLONE_ALLNS	(CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER | CLONE_NEWCGROUP)
 
 /* Nested namespaces are supported only for these types */
-#define CLONE_SUBNS	(CLONE_NEWNS | CLONE_NEWNET | CLONE_NEWUSER)
+#define CLONE_SUBNS	(CLONE_NEWNS | CLONE_NEWNET | CLONE_NEWUSER | CLONE_NEWPID)
 
 #define MAX_NS_NESTING	32
 #define EXTRA_SIZE	20
diff --git a/criu/pstree.c b/criu/pstree.c
index 5171cec0f..2cc084430 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -867,6 +867,8 @@ static int prepare_pstree_ids(void)
 	LIST_HEAD(helpers);
 
 	pid_t current_pgid = getpgid(getpid());
+	if (!list_empty(&top_pid_ns->children))
+		return 0;
 
 	/*
 	 * Some task can be reparented to init. A helper task should be added
@@ -1233,6 +1235,9 @@ bool restore_before_setsid(struct pstree_item *child)
 {
 	int csid = child->born_sid == -1 ? vsid(child) : child->born_sid;
 
+	if (!list_empty(&top_pid_ns->children))
+		return false;
+
 	if (child->parent->born_sid == csid)
 		return true;
 



More information about the CRIU mailing list