aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian Anastasov <ja@ssi.bg>2013-03-22 05:46:36 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2013-04-01 18:23:47 -0400
commit71dfa982f177d7b1e51e8d48b4c69da0b0e17e3c (patch)
tree6649e984de084a0347b6a8b3378557296e52ec35
parent9a05475cebdd6341884b5901e53870be26e65158 (diff)
ipvs: change ip_vs_sched_lock to mutex
The global list with schedulers ip_vs_schedulers is accessed only from user context - configuration and scheduler module [un]registration. Use ip_vs_sched_mutex instead. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: Simon Horman <horms@verge.net.au>
-rw-r--r--net/netfilter/ipvs/ip_vs_sched.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/net/netfilter/ipvs/ip_vs_sched.c b/net/netfilter/ipvs/ip_vs_sched.c
index d6bf20d6cdbe..7f11d3d37a42 100644
--- a/net/netfilter/ipvs/ip_vs_sched.c
+++ b/net/netfilter/ipvs/ip_vs_sched.c
@@ -35,8 +35,8 @@ EXPORT_SYMBOL(ip_vs_scheduler_err);
35 */ 35 */
36static LIST_HEAD(ip_vs_schedulers); 36static LIST_HEAD(ip_vs_schedulers);
37 37
38/* lock for service table */ 38/* semaphore for schedulers */
39static DEFINE_SPINLOCK(ip_vs_sched_lock); 39static DEFINE_MUTEX(ip_vs_sched_mutex);
40 40
41 41
42/* 42/*
@@ -92,7 +92,7 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
92 92
93 IP_VS_DBG(2, "%s(): sched_name \"%s\"\n", __func__, sched_name); 93 IP_VS_DBG(2, "%s(): sched_name \"%s\"\n", __func__, sched_name);
94 94
95 spin_lock_bh(&ip_vs_sched_lock); 95 mutex_lock(&ip_vs_sched_mutex);
96 96
97 list_for_each_entry(sched, &ip_vs_schedulers, n_list) { 97 list_for_each_entry(sched, &ip_vs_schedulers, n_list) {
98 /* 98 /*
@@ -106,14 +106,14 @@ static struct ip_vs_scheduler *ip_vs_sched_getbyname(const char *sched_name)
106 } 106 }
107 if (strcmp(sched_name, sched->name)==0) { 107 if (strcmp(sched_name, sched->name)==0) {
108 /* HIT */ 108 /* HIT */
109 spin_unlock_bh(&ip_vs_sched_lock); 109 mutex_unlock(&ip_vs_sched_mutex);
110 return sched; 110 return sched;
111 } 111 }
112 if (sched->module) 112 if (sched->module)
113 module_put(sched->module); 113 module_put(sched->module);
114 } 114 }
115 115
116 spin_unlock_bh(&ip_vs_sched_lock); 116 mutex_unlock(&ip_vs_sched_mutex);
117 return NULL; 117 return NULL;
118} 118}
119 119
@@ -192,10 +192,10 @@ int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
192 /* increase the module use count */ 192 /* increase the module use count */
193 ip_vs_use_count_inc(); 193 ip_vs_use_count_inc();
194 194
195 spin_lock_bh(&ip_vs_sched_lock); 195 mutex_lock(&ip_vs_sched_mutex);
196 196
197 if (!list_empty(&scheduler->n_list)) { 197 if (!list_empty(&scheduler->n_list)) {
198 spin_unlock_bh(&ip_vs_sched_lock); 198 mutex_unlock(&ip_vs_sched_mutex);
199 ip_vs_use_count_dec(); 199 ip_vs_use_count_dec();
200 pr_err("%s(): [%s] scheduler already linked\n", 200 pr_err("%s(): [%s] scheduler already linked\n",
201 __func__, scheduler->name); 201 __func__, scheduler->name);
@@ -208,7 +208,7 @@ int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
208 */ 208 */
209 list_for_each_entry(sched, &ip_vs_schedulers, n_list) { 209 list_for_each_entry(sched, &ip_vs_schedulers, n_list) {
210 if (strcmp(scheduler->name, sched->name) == 0) { 210 if (strcmp(scheduler->name, sched->name) == 0) {
211 spin_unlock_bh(&ip_vs_sched_lock); 211 mutex_unlock(&ip_vs_sched_mutex);
212 ip_vs_use_count_dec(); 212 ip_vs_use_count_dec();
213 pr_err("%s(): [%s] scheduler already existed " 213 pr_err("%s(): [%s] scheduler already existed "
214 "in the system\n", __func__, scheduler->name); 214 "in the system\n", __func__, scheduler->name);
@@ -219,7 +219,7 @@ int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
219 * Add it into the d-linked scheduler list 219 * Add it into the d-linked scheduler list
220 */ 220 */
221 list_add(&scheduler->n_list, &ip_vs_schedulers); 221 list_add(&scheduler->n_list, &ip_vs_schedulers);
222 spin_unlock_bh(&ip_vs_sched_lock); 222 mutex_unlock(&ip_vs_sched_mutex);
223 223
224 pr_info("[%s] scheduler registered.\n", scheduler->name); 224 pr_info("[%s] scheduler registered.\n", scheduler->name);
225 225
@@ -237,9 +237,9 @@ int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
237 return -EINVAL; 237 return -EINVAL;
238 } 238 }
239 239
240 spin_lock_bh(&ip_vs_sched_lock); 240 mutex_lock(&ip_vs_sched_mutex);
241 if (list_empty(&scheduler->n_list)) { 241 if (list_empty(&scheduler->n_list)) {
242 spin_unlock_bh(&ip_vs_sched_lock); 242 mutex_unlock(&ip_vs_sched_mutex);
243 pr_err("%s(): [%s] scheduler is not in the list. failed\n", 243 pr_err("%s(): [%s] scheduler is not in the list. failed\n",
244 __func__, scheduler->name); 244 __func__, scheduler->name);
245 return -EINVAL; 245 return -EINVAL;
@@ -249,7 +249,7 @@ int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler)
249 * Remove it from the d-linked scheduler list 249 * Remove it from the d-linked scheduler list
250 */ 250 */
251 list_del(&scheduler->n_list); 251 list_del(&scheduler->n_list);
252 spin_unlock_bh(&ip_vs_sched_lock); 252 mutex_unlock(&ip_vs_sched_mutex);
253 253
254 /* decrease the module use count */ 254 /* decrease the module use count */
255 ip_vs_use_count_dec(); 255 ip_vs_use_count_dec();