aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-11-01 03:44:50 -0400
committerDavid S. Miller <davem@davemloft.net>2007-11-01 03:44:50 -0400
commit6a1a3b9f686bb04820a232cc1657ef2c45670709 (patch)
treed59d63b516d57cfa825592b893c9fd3bff7b21b7
parentd46557955f2a35e58772518775464cdf354b3245 (diff)
[NET]: Hide the dead code in the net_namespace.c
The namespace creation/destruction code is never called if the CONFIG_NET_NS is n, so it's OK to move it under appropriate ifdef. The copy_net_ns() in the "n" case checks for flags and returns -EINVAL when new net ns is requested. In a perfect world this stub must be in net_namespace.h, but this function need to know the CLONE_NEWNET value and thus requires sched.h. On the other hand this header is to be injected into almost every .c file in the networking code, and making all this code depend on the sched.h is a suicidal attempt. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/core/net_namespace.c131
1 files changed, 68 insertions, 63 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 4e52921ade09..d5bf8b28bbf4 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -22,65 +22,6 @@ static struct kmem_cache *net_cachep;
22struct net init_net; 22struct net init_net;
23EXPORT_SYMBOL_GPL(init_net); 23EXPORT_SYMBOL_GPL(init_net);
24 24
25static struct net *net_alloc(void)
26{
27 return kmem_cache_zalloc(net_cachep, GFP_KERNEL);
28}
29
30static void net_free(struct net *net)
31{
32 if (!net)
33 return;
34
35 if (unlikely(atomic_read(&net->use_count) != 0)) {
36 printk(KERN_EMERG "network namespace not free! Usage: %d\n",
37 atomic_read(&net->use_count));
38 return;
39 }
40
41 kmem_cache_free(net_cachep, net);
42}
43
44static void cleanup_net(struct work_struct *work)
45{
46 struct pernet_operations *ops;
47 struct net *net;
48
49 net = container_of(work, struct net, work);
50
51 mutex_lock(&net_mutex);
52
53 /* Don't let anyone else find us. */
54 rtnl_lock();
55 list_del(&net->list);
56 rtnl_unlock();
57
58 /* Run all of the network namespace exit methods */
59 list_for_each_entry_reverse(ops, &pernet_list, list) {
60 if (ops->exit)
61 ops->exit(net);
62 }
63
64 mutex_unlock(&net_mutex);
65
66 /* Ensure there are no outstanding rcu callbacks using this
67 * network namespace.
68 */
69 rcu_barrier();
70
71 /* Finally it is safe to free my network namespace structure */
72 net_free(net);
73}
74
75
76void __put_net(struct net *net)
77{
78 /* Cleanup the network namespace in process context */
79 INIT_WORK(&net->work, cleanup_net);
80 schedule_work(&net->work);
81}
82EXPORT_SYMBOL_GPL(__put_net);
83
84/* 25/*
85 * setup_net runs the initializers for the network namespace object. 26 * setup_net runs the initializers for the network namespace object.
86 */ 27 */
@@ -117,6 +58,12 @@ out_undo:
117 goto out; 58 goto out;
118} 59}
119 60
61#ifdef CONFIG_NET_NS
62static struct net *net_alloc(void)
63{
64 return kmem_cache_zalloc(net_cachep, GFP_KERNEL);
65}
66
120struct net *copy_net_ns(unsigned long flags, struct net *old_net) 67struct net *copy_net_ns(unsigned long flags, struct net *old_net)
121{ 68{
122 struct net *new_net = NULL; 69 struct net *new_net = NULL;
@@ -127,10 +74,6 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net)
127 if (!(flags & CLONE_NEWNET)) 74 if (!(flags & CLONE_NEWNET))
128 return old_net; 75 return old_net;
129 76
130#ifndef CONFIG_NET_NS
131 return ERR_PTR(-EINVAL);
132#endif
133
134 err = -ENOMEM; 77 err = -ENOMEM;
135 new_net = net_alloc(); 78 new_net = net_alloc();
136 if (!new_net) 79 if (!new_net)
@@ -157,6 +100,68 @@ out:
157 return new_net; 100 return new_net;
158} 101}
159 102
103static void net_free(struct net *net)
104{
105 if (!net)
106 return;
107
108 if (unlikely(atomic_read(&net->use_count) != 0)) {
109 printk(KERN_EMERG "network namespace not free! Usage: %d\n",
110 atomic_read(&net->use_count));
111 return;
112 }
113
114 kmem_cache_free(net_cachep, net);
115}
116
117static void cleanup_net(struct work_struct *work)
118{
119 struct pernet_operations *ops;
120 struct net *net;
121
122 net = container_of(work, struct net, work);
123
124 mutex_lock(&net_mutex);
125
126 /* Don't let anyone else find us. */
127 rtnl_lock();
128 list_del(&net->list);
129 rtnl_unlock();
130
131 /* Run all of the network namespace exit methods */
132 list_for_each_entry_reverse(ops, &pernet_list, list) {
133 if (ops->exit)
134 ops->exit(net);
135 }
136
137 mutex_unlock(&net_mutex);
138
139 /* Ensure there are no outstanding rcu callbacks using this
140 * network namespace.
141 */
142 rcu_barrier();
143
144 /* Finally it is safe to free my network namespace structure */
145 net_free(net);
146}
147
148void __put_net(struct net *net)
149{
150 /* Cleanup the network namespace in process context */
151 INIT_WORK(&net->work, cleanup_net);
152 schedule_work(&net->work);
153}
154EXPORT_SYMBOL_GPL(__put_net);
155
156#else
157struct net *copy_net_ns(unsigned long flags, struct net *old_net)
158{
159 if (flags & CLONE_NEWNET)
160 return ERR_PTR(-EINVAL);
161 return old_net;
162}
163#endif
164
160static int __init net_ns_init(void) 165static int __init net_ns_init(void)
161{ 166{
162 int err; 167 int err;