[CRIU] [PATCH] restore: Defer new net-namespace creation until forked

Cyrill Gorcunov gorcunov at openvz.org
Mon Oct 27 09:19:03 PDT 2014


Some kernel modules such as pktgen runs kthred upon
new-net creation taking last_pid we were requested.
Lets workaround this problem using clone + unshare
bundle.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-restore.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/cr-restore.c b/cr-restore.c
index d046f4bd0921..d3811cb7b5d7 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1086,8 +1086,16 @@ static inline int fork_with_pid(struct pstree_item *item)
 		if (netns_pre_create())
 			goto err_unlock;
 
+	/*
+	 * Some kernel modules, such as netwrok packet generator
+	 * run kernel thread upon net-namespace creattion taking
+	 * the @pid we've been requeting via LAST_PID_PATH interface
+	 * so that we can't restore a take with pid needed.
+	 *
+	 * Here is an idea -- unhare net namespace in callee instead.
+	 */
 	ret = clone(restore_task_with_children, ca.stack_ptr,
-			ca.clone_flags | SIGCHLD, &ca);
+		    (ca.clone_flags & ~CLONE_NEWNET) | SIGCHLD, &ca);
 
 	if (ret < 0) {
 		pr_perror("Can't fork for %d", pid);
@@ -1395,6 +1403,14 @@ static int restore_task_with_children(void *_arg)
 	if ( !(ca->clone_flags & CLONE_FILES))
 		close_safe(&ca->fd);
 
+	if (ca->clone_flags & CLONE_NEWNET) {
+		ret = unshare(CLONE_NEWNET);
+		if (ret) {
+			pr_perror("Can't unshare net-namespace");
+			goto err;
+		}
+	}
+
 	if (current->state != TASK_HELPER) {
 		ret = clone_service_fd(rsti(current)->service_fd_id);
 		if (ret)
-- 
1.9.3



More information about the CRIU mailing list