[RESEND,v1,50/55] pid: Teach set_next_pid() working with nested pid_ns

Submitted by Kirill Tkhai on March 24, 2017, 3:16 p.m.

Details

Message ID 149036861402.23093.5021561888783565104.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 24, 2017, 3:16 p.m.
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@virtuozzo.com>
---
 criu/cr-restore.c |   24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 948aba16..6e2ce232 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)