Commit a75f0fa8 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

ns: Simplify create_net_ns()

Merge code with the same functionality in one
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent b54c7d3d
...@@ -1953,6 +1953,19 @@ static int open_net_ns(struct ns_id *nsid) ...@@ -1953,6 +1953,19 @@ static int open_net_ns(struct ns_id *nsid)
return 0; return 0;
} }
static int do_create_net_ns(struct ns_id *ns)
{
if (unshare(CLONE_NEWNET)) {
pr_perror("Unable to create a new netns");
return -1;
}
if (prepare_net_ns(ns->id))
return -1;
if (open_net_ns(ns))
return -1;
return 0;
}
int prepare_net_namespaces() int prepare_net_namespaces()
{ {
struct ns_id *nsid; struct ns_id *nsid;
...@@ -1964,15 +1977,7 @@ int prepare_net_namespaces() ...@@ -1964,15 +1977,7 @@ int prepare_net_namespaces()
if (nsid->nd != &net_ns_desc) if (nsid->nd != &net_ns_desc)
continue; continue;
if (unshare(CLONE_NEWNET)) { if (do_create_net_ns(nsid))
pr_perror("Unable to create a new netns");
goto err;
}
if (prepare_net_ns(nsid->id))
goto err;
if (open_net_ns(nsid))
goto err; goto err;
} }
......
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