diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-05-04 14:12:14 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-05-04 14:12:14 -0400 |
commit | 088eb2d905de9518dad913995bb8aef493d4a7c5 (patch) | |
tree | efdd299b3d87cafe05b77ddaa4ecc032c2e27262 /net/core | |
parent | 4a84822c60afa2b0e2d3370041f69f9526a34757 (diff) |
netns 2/2: extract net_create()
net_create() will be used by C/R to create fresh netns on restart.
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/net_namespace.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 4488010d5a52..6b3edc9e6f19 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
@@ -115,38 +115,34 @@ static void net_free(struct net *net) | |||
115 | kmem_cache_free(net_cachep, net); | 115 | kmem_cache_free(net_cachep, net); |
116 | } | 116 | } |
117 | 117 | ||
118 | struct net *copy_net_ns(unsigned long flags, struct net *old_net) | 118 | static struct net *net_create(void) |
119 | { | 119 | { |
120 | struct net *new_net = NULL; | 120 | struct net *net; |
121 | int err; | 121 | int rv; |
122 | |||
123 | if (!(flags & CLONE_NEWNET)) | ||
124 | return get_net(old_net); | ||
125 | |||
126 | err = -ENOMEM; | ||
127 | new_net = net_alloc(); | ||
128 | if (!new_net) | ||
129 | goto out_err; | ||
130 | 122 | ||
123 | net = net_alloc(); | ||
124 | if (!net) | ||
125 | return ERR_PTR(-ENOMEM); | ||
131 | mutex_lock(&net_mutex); | 126 | mutex_lock(&net_mutex); |
132 | err = setup_net(new_net); | 127 | rv = setup_net(net); |
133 | if (!err) { | 128 | if (rv == 0) { |
134 | rtnl_lock(); | 129 | rtnl_lock(); |
135 | list_add_tail(&new_net->list, &net_namespace_list); | 130 | list_add_tail(&net->list, &net_namespace_list); |
136 | rtnl_unlock(); | 131 | rtnl_unlock(); |
137 | } | 132 | } |
138 | mutex_unlock(&net_mutex); | 133 | mutex_unlock(&net_mutex); |
134 | if (rv < 0) { | ||
135 | net_free(net); | ||
136 | return ERR_PTR(rv); | ||
137 | } | ||
138 | return net; | ||
139 | } | ||
139 | 140 | ||
140 | if (err) | 141 | struct net *copy_net_ns(unsigned long flags, struct net *old_net) |
141 | goto out_free; | 142 | { |
142 | out: | 143 | if (!(flags & CLONE_NEWNET)) |
143 | return new_net; | 144 | return get_net(old_net); |
144 | 145 | return net_create(); | |
145 | out_free: | ||
146 | net_free(new_net); | ||
147 | out_err: | ||
148 | new_net = ERR_PTR(err); | ||
149 | goto out; | ||
150 | } | 146 | } |
151 | 147 | ||
152 | static void cleanup_net(struct work_struct *work) | 148 | static void cleanup_net(struct work_struct *work) |