[2/8] ns: Replace last_ns_id with pstree_item->net_ns

Submitted by Kirill Tkhai on June 28, 2017, 11:48 a.m.

Details

Message ID 149865051559.12218.3304073432426319718.stgit@localhost.localdomain
State New
Series "One-level leaked net_ns support"
Headers show

Commit Message

Kirill Tkhai June 28, 2017, 11:48 a.m.
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).

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

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 2c505f6ea..ed042cc97 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -487,8 +487,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);
 
@@ -1728,7 +1731,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();