[CRIU] [PATCH v4 03/41] ns: Do not change net_ns in prepare_net_namespaces()

Kirill Tkhai ktkhai at virtuozzo.com
Thu May 4 09:05:22 PDT 2017


In next patches usernsd will need to create transport
socket in the same net_ns as other tasks do their
TRANSPORT_FD_OFF sockets.

Choose criu net_ns for that: this allows usernsd
to do not wait for creation of other net_ns, i.e.
to do not introduce new dependencies between tasks.

In case of (root_ns_mask & CLONE_NEWUSER) != 0
root_item's user_ns does not allow to restore criu net_ns,
so do prepare_net_namespaces() in sub-process to do not
lose criu net.

v3: Introduce __prepare_net_namespaces and execute it in cloned task.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/net.c                |   14 ++++++++++----
 test/zdtm/static/tun.desc |    2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/criu/net.c b/criu/net.c
index b4230007c..8b9a10b46 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2091,14 +2091,11 @@ static int create_net_ns(void *arg)
 	exit(ret);
 }
 
-int prepare_net_namespaces()
+static int __prepare_net_namespaces(void *unused)
 {
 	struct ns_id *nsid;
 	int ret = -1;
 
-	if (!(root_ns_mask & CLONE_NEWNET))
-		return 0;
-
 	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
 		if (nsid->nd != &net_ns_desc)
 			continue;
@@ -2155,6 +2152,15 @@ int prepare_net_namespaces()
 	return ret;
 }
 
+
+int prepare_net_namespaces(void)
+{
+	if (!(root_ns_mask & CLONE_NEWNET))
+		return 0;
+
+	return call_in_child_process(__prepare_net_namespaces, NULL);
+}
+
 static int do_restore_task_net_ns(struct ns_id *nsid, struct pstree_item *current)
 {
 	int fd;
diff --git a/test/zdtm/static/tun.desc b/test/zdtm/static/tun.desc
index 8c7cfe860..eac32c2d0 100644
--- a/test/zdtm/static/tun.desc
+++ b/test/zdtm/static/tun.desc
@@ -1 +1 @@
-{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'tun'}
+{'flavor': 'ns uns', 'flags': 'suid noauto', 'feature': 'tun'}



More information about the CRIU mailing list