[CRIU] [PATCH] net: set the root net ns after restoring all namespaces

Andrei Vagin avagin at openvz.org
Tue Mar 28 12:56:55 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Then we will create transport sockets and we want to know where
they will be created.

Cc: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/net.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/criu/net.c b/criu/net.c
index e06d32b..0f1736b 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2035,7 +2035,10 @@ static int prepare_net_ns_second_stage(struct ns_id *ns)
 		ns->net.nsfd_id = fdstore_add(fd);
 		if (ns->net.nsfd_id < 0)
 			ret = -1;
-		close(fd);
+
+		/* fd for the root is closed in prepare_net_namespaces() */
+		if (ns->type != NS_ROOT)
+			close(fd);
 	}
 
 	ns->ns_populated = true;
@@ -2094,7 +2097,7 @@ static int create_net_ns(void *arg)
 int prepare_net_namespaces()
 {
 	struct ns_id *nsid;
-	int ret = -1;
+	int ret = -1, rst = -1;
 
 	if (!(root_ns_mask & CLONE_NEWNET))
 		return 0;
@@ -2137,6 +2140,9 @@ int prepare_net_namespaces()
 		if (nsid->nd != &net_ns_desc)
 			continue;
 
+		if (nsid->type == NS_ROOT)
+			rst = nsid->net.ns_fd;
+
 		if (switch_ns_by_fd(nsid->net.ns_fd, &net_ns_desc, NULL))
 			goto err;
 
@@ -2146,11 +2152,20 @@ int prepare_net_namespaces()
 		close_safe(&nsid->net.nlsk);
 	}
 
+	if (rst < 0) {
+		pr_err("Unable to find the root net namespace");
+		goto err;
+	}
+
+	if (switch_ns_by_fd(rst, &net_ns_desc, NULL))
+		goto err;
+
 	close_service_fd(NS_FD_OFF);
 	ret = 0;
 err:
 	if (ret)
 		pr_err("Can't create net_ns\n");
+	close_safe(&rst);
 
 	return ret;
 }
-- 
2.7.4



More information about the CRIU mailing list