[CRIU] [PATCH v2 24/30] ns: Replace last_ns_id with pstree_item->net_ns

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jun 7 14:30:08 MSK 2017


Keep currently set net_ns in pstree_item struct.
This will be used in next patch.

Also delete CLONE_NEWNET check in set_netns(),
as (ns_id == current->net_ns->id) check covers
both cases (CLONE_NEWNET set and not set).

v2: New

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/cr-restore.c     |    8 ++++++--
 criu/include/pstree.h |    1 +
 criu/sockets.c        |    9 ++-------
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 298fb693a..96269872d 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -483,8 +483,11 @@ static int setup_child_task_namespaces(struct pstree_item *item, struct ns_id **
 			item->user_ns = pid_ns->user_ns;
 		else
 			item->user_ns = current->user_ns;
-	} else
+		item->net_ns = current->net_ns;
+	} else {
 		item->user_ns = top_user_ns;
+		item->net_ns = top_net_ns;
+	}
 
 	wait_pid_ns_helper_prepared(pid_ns, item->pid);
 
@@ -1724,7 +1727,8 @@ static int restore_task_with_children(void *_arg)
 	if (current->parent == NULL) {
 		/*
 		 * The root task has to be in its namespaces before executing
-		 * ACT_SETUP_NS scripts, so the root netns has to be created here
+		 * ACT_SETUP_NS scripts, so the top_net_ns has to be created here
+		 * (current->net_ns is already set in setup_child_task_namespaces())
 		 */
 		if (root_ns_mask & CLONE_NEWNET) {
 			ret = unshare(CLONE_NEWNET);
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index a3d8c3123..35acb11aa 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -30,6 +30,7 @@ struct pstree_item {
 		unsigned long	task_st_le_bits;
 	};
 	struct ns_id		*user_ns;
+	struct ns_id		*net_ns;
 	struct ns_id		*pid_for_children_ns;
 };
 
diff --git a/criu/sockets.c b/criu/sockets.c
index 9b0c4df99..0768888f7 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -745,17 +745,12 @@ int collect_sockets(struct ns_id *ns)
 	return err;
 }
 
-static uint32_t last_ns_id = 0;
-
 int set_netns(uint32_t ns_id)
 {
 	struct ns_id *ns;
 	int nsfd;
 
-	if (!(root_ns_mask & CLONE_NEWNET))
-		return 0;
-
-	if (ns_id == last_ns_id)
+	if (ns_id == current->net_ns->id)
 		return 0;
 
 	ns = lookup_ns_by_id(ns_id, &net_ns_desc);
@@ -771,7 +766,7 @@ int set_netns(uint32_t ns_id)
 		close(nsfd);
 		return -1;
 	}
-	last_ns_id = ns_id;
+	current->net_ns = ns;
 	close(nsfd);
 
 	close_pid_proc();



More information about the CRIU mailing list