Commit 7688fbc1 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

restore: Defer new net-namespace creation until forked

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4cb9eaf3
......@@ -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);
......@@ -1411,6 +1419,14 @@ static int restore_task_with_children(void *_arg)
if (ret < 0)
goto err;
if (ca->clone_flags & CLONE_NEWNET) {
ret = unshare(CLONE_NEWNET);
if (ret) {
pr_perror("Can't unshare net-namespace");
goto err;
}
}
/* Restore root task */
if (current->parent == NULL) {
if (restore_finish_stage(CR_STATE_RESTORE_NS) < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment