[CRIU] [PATCH v2 52/57] pid: Teach set_next_pid() working with nested pid_ns

Kirill Tkhai ktkhai at virtuozzo.com
Tue Mar 28 08:41:48 PDT 2017


Request helpers to set ns_last_pid in their active pid_ns.
Of course, optimizations are possible here, but not for now.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c |   24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 81b7229b..24724d3b 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -303,11 +303,27 @@ int __set_next_pid(pid_t pid)
 	return 0;
 }
 
-static int set_next_pid(struct ns_id *ns, struct pid *pid)
+static int set_next_pid(struct ns_id *pid_ns, struct pid *pid)
 {
-	if (pid->ns[0].virt == INIT_PID)
-		return 0;
-	return __set_next_pid(pid->ns[0].virt);
+	int i, sk, level = pid->level;
+
+	if (!(root_ns_mask & CLONE_NEWPID)) {
+		if (last_level_pid(pid) == INIT_PID)
+			return 0;
+		return __set_next_pid(last_level_pid(pid));
+	}
+
+	sk = get_service_fd(TRANSPORT_FD_OFF);
+
+	for (i = level - 1; i >= 0; i--, pid_ns = pid_ns->parent) {
+		if (i == level - 1 && last_level_pid(pid) == INIT_PID)
+			continue;
+		if (request_set_next_pid(pid_ns->id, pid->ns[i].virt, sk) < 0) {
+			pr_err("Can't request next pid\n");
+			return -1;
+		}
+	}
+	return 0;
 }
 
 static void wait_pid_ns_helper_prepared(struct ns_id *pid_ns, struct pid *pid)



More information about the CRIU mailing list