[v2,57/57] ns: Nested pid_ns support

Submitted by Kirill Tkhai on March 28, 2017, 3:42 p.m.

Details

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

Commit Message

Kirill Tkhai March 28, 2017, 3:42 p.m.
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.

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 8e93a8b3..8a0632b8 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1263,6 +1263,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
@@ -1306,6 +1308,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 70e06386..80428c6b 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 09a7ac8c..b2703dd0 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -859,6 +859,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