IPVS: Conditinally use sysctl_lblc{r}_expiration
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / netfilter / ipvs / ip_vs_lblcr.c
1 /*
2 * IPVS: Locality-Based Least-Connection with Replication scheduler
3 *
4 * Authors: Wensong Zhang <wensong@gnuchina.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * Changes:
12 * Julian Anastasov : Added the missing (dest->weight>0)
13 * condition in the ip_vs_dest_set_max.
14 *
15 */
16
17 /*
18 * The lblc/r algorithm is as follows (pseudo code):
19 *
20 * if serverSet[dest_ip] is null then
21 * n, serverSet[dest_ip] <- {weighted least-conn node};
22 * else
23 * n <- {least-conn (alive) node in serverSet[dest_ip]};
24 * if (n is null) OR
25 * (n.conns>n.weight AND
26 * there is a node m with m.conns<m.weight/2) then
27 * n <- {weighted least-conn node};
28 * add n to serverSet[dest_ip];
29 * if |serverSet[dest_ip]| > 1 AND
30 * now - serverSet[dest_ip].lastMod > T then
31 * m <- {most conn node in serverSet[dest_ip]};
32 * remove m from serverSet[dest_ip];
33 * if serverSet[dest_ip] changed then
34 * serverSet[dest_ip].lastMod <- now;
35 *
36 * return n;
37 *
38 */
39
40 #define KMSG_COMPONENT "IPVS"
41 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
42
43 #include <linux/ip.h>
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/skbuff.h>
47 #include <linux/jiffies.h>
48 #include <linux/list.h>
49 #include <linux/slab.h>
50
51 /* for sysctl */
52 #include <linux/fs.h>
53 #include <linux/sysctl.h>
54 #include <net/net_namespace.h>
55
56 #include <net/ip_vs.h>
57
58
59 /*
60 * It is for garbage collection of stale IPVS lblcr entries,
61 * when the table is full.
62 */
63 #define CHECK_EXPIRE_INTERVAL (60*HZ)
64 #define ENTRY_TIMEOUT (6*60*HZ)
65
66 #define DEFAULT_EXPIRATION (24*60*60*HZ)
67
68 /*
69 * It is for full expiration check.
70 * When there is no partial expiration check (garbage collection)
71 * in a half hour, do a full expiration check to collect stale
72 * entries that haven't been touched for a day.
73 */
74 #define COUNT_FOR_FULL_EXPIRATION 30
75
76 /*
77 * for IPVS lblcr entry hash table
78 */
79 #ifndef CONFIG_IP_VS_LBLCR_TAB_BITS
80 #define CONFIG_IP_VS_LBLCR_TAB_BITS 10
81 #endif
82 #define IP_VS_LBLCR_TAB_BITS CONFIG_IP_VS_LBLCR_TAB_BITS
83 #define IP_VS_LBLCR_TAB_SIZE (1 << IP_VS_LBLCR_TAB_BITS)
84 #define IP_VS_LBLCR_TAB_MASK (IP_VS_LBLCR_TAB_SIZE - 1)
85
86
87 /*
88 * IPVS destination set structure and operations
89 */
90 struct ip_vs_dest_set_elem {
91 struct list_head list; /* list link */
92 struct ip_vs_dest *dest; /* destination server */
93 };
94
95 struct ip_vs_dest_set {
96 atomic_t size; /* set size */
97 unsigned long lastmod; /* last modified time */
98 struct list_head list; /* destination list */
99 rwlock_t lock; /* lock for this list */
100 };
101
102
103 static struct ip_vs_dest_set_elem *
104 ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
105 {
106 struct ip_vs_dest_set_elem *e;
107
108 list_for_each_entry(e, &set->list, list) {
109 if (e->dest == dest)
110 /* already existed */
111 return NULL;
112 }
113
114 e = kmalloc(sizeof(*e), GFP_ATOMIC);
115 if (e == NULL) {
116 pr_err("%s(): no memory\n", __func__);
117 return NULL;
118 }
119
120 atomic_inc(&dest->refcnt);
121 e->dest = dest;
122
123 list_add(&e->list, &set->list);
124 atomic_inc(&set->size);
125
126 set->lastmod = jiffies;
127 return e;
128 }
129
130 static void
131 ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
132 {
133 struct ip_vs_dest_set_elem *e;
134
135 list_for_each_entry(e, &set->list, list) {
136 if (e->dest == dest) {
137 /* HIT */
138 atomic_dec(&set->size);
139 set->lastmod = jiffies;
140 atomic_dec(&e->dest->refcnt);
141 list_del(&e->list);
142 kfree(e);
143 break;
144 }
145 }
146 }
147
148 static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
149 {
150 struct ip_vs_dest_set_elem *e, *ep;
151
152 write_lock(&set->lock);
153 list_for_each_entry_safe(e, ep, &set->list, list) {
154 /*
155 * We don't kfree dest because it is refered either
156 * by its service or by the trash dest list.
157 */
158 atomic_dec(&e->dest->refcnt);
159 list_del(&e->list);
160 kfree(e);
161 }
162 write_unlock(&set->lock);
163 }
164
165 /* get weighted least-connection node in the destination set */
166 static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
167 {
168 register struct ip_vs_dest_set_elem *e;
169 struct ip_vs_dest *dest, *least;
170 int loh, doh;
171
172 if (set == NULL)
173 return NULL;
174
175 /* select the first destination server, whose weight > 0 */
176 list_for_each_entry(e, &set->list, list) {
177 least = e->dest;
178 if (least->flags & IP_VS_DEST_F_OVERLOAD)
179 continue;
180
181 if ((atomic_read(&least->weight) > 0)
182 && (least->flags & IP_VS_DEST_F_AVAILABLE)) {
183 loh = ip_vs_dest_conn_overhead(least);
184 goto nextstage;
185 }
186 }
187 return NULL;
188
189 /* find the destination with the weighted least load */
190 nextstage:
191 list_for_each_entry(e, &set->list, list) {
192 dest = e->dest;
193 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
194 continue;
195
196 doh = ip_vs_dest_conn_overhead(dest);
197 if ((loh * atomic_read(&dest->weight) >
198 doh * atomic_read(&least->weight))
199 && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
200 least = dest;
201 loh = doh;
202 }
203 }
204
205 IP_VS_DBG_BUF(6, "%s(): server %s:%d "
206 "activeconns %d refcnt %d weight %d overhead %d\n",
207 __func__,
208 IP_VS_DBG_ADDR(least->af, &least->addr),
209 ntohs(least->port),
210 atomic_read(&least->activeconns),
211 atomic_read(&least->refcnt),
212 atomic_read(&least->weight), loh);
213 return least;
214 }
215
216
217 /* get weighted most-connection node in the destination set */
218 static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
219 {
220 register struct ip_vs_dest_set_elem *e;
221 struct ip_vs_dest *dest, *most;
222 int moh, doh;
223
224 if (set == NULL)
225 return NULL;
226
227 /* select the first destination server, whose weight > 0 */
228 list_for_each_entry(e, &set->list, list) {
229 most = e->dest;
230 if (atomic_read(&most->weight) > 0) {
231 moh = ip_vs_dest_conn_overhead(most);
232 goto nextstage;
233 }
234 }
235 return NULL;
236
237 /* find the destination with the weighted most load */
238 nextstage:
239 list_for_each_entry(e, &set->list, list) {
240 dest = e->dest;
241 doh = ip_vs_dest_conn_overhead(dest);
242 /* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */
243 if ((moh * atomic_read(&dest->weight) <
244 doh * atomic_read(&most->weight))
245 && (atomic_read(&dest->weight) > 0)) {
246 most = dest;
247 moh = doh;
248 }
249 }
250
251 IP_VS_DBG_BUF(6, "%s(): server %s:%d "
252 "activeconns %d refcnt %d weight %d overhead %d\n",
253 __func__,
254 IP_VS_DBG_ADDR(most->af, &most->addr), ntohs(most->port),
255 atomic_read(&most->activeconns),
256 atomic_read(&most->refcnt),
257 atomic_read(&most->weight), moh);
258 return most;
259 }
260
261
262 /*
263 * IPVS lblcr entry represents an association between destination
264 * IP address and its destination server set
265 */
266 struct ip_vs_lblcr_entry {
267 struct list_head list;
268 int af; /* address family */
269 union nf_inet_addr addr; /* destination IP address */
270 struct ip_vs_dest_set set; /* destination server set */
271 unsigned long lastuse; /* last used time */
272 };
273
274
275 /*
276 * IPVS lblcr hash table
277 */
278 struct ip_vs_lblcr_table {
279 struct list_head bucket[IP_VS_LBLCR_TAB_SIZE]; /* hash bucket */
280 atomic_t entries; /* number of entries */
281 int max_size; /* maximum size of entries */
282 struct timer_list periodic_timer; /* collect stale entries */
283 int rover; /* rover for expire check */
284 int counter; /* counter for no expire */
285 };
286
287
288 /*
289 * IPVS LBLCR sysctl table
290 */
291
292 static ctl_table vs_vars_table[] = {
293 {
294 .procname = "lblcr_expiration",
295 .data = NULL,
296 .maxlen = sizeof(int),
297 .mode = 0644,
298 .proc_handler = proc_dointvec_jiffies,
299 },
300 { }
301 };
302
303 static inline void ip_vs_lblcr_free(struct ip_vs_lblcr_entry *en)
304 {
305 list_del(&en->list);
306 ip_vs_dest_set_eraseall(&en->set);
307 kfree(en);
308 }
309
310
311 /*
312 * Returns hash value for IPVS LBLCR entry
313 */
314 static inline unsigned
315 ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
316 {
317 __be32 addr_fold = addr->ip;
318
319 #ifdef CONFIG_IP_VS_IPV6
320 if (af == AF_INET6)
321 addr_fold = addr->ip6[0]^addr->ip6[1]^
322 addr->ip6[2]^addr->ip6[3];
323 #endif
324 return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
325 }
326
327
328 /*
329 * Hash an entry in the ip_vs_lblcr_table.
330 * returns bool success.
331 */
332 static void
333 ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en)
334 {
335 unsigned hash = ip_vs_lblcr_hashkey(en->af, &en->addr);
336
337 list_add(&en->list, &tbl->bucket[hash]);
338 atomic_inc(&tbl->entries);
339 }
340
341
342 /*
343 * Get ip_vs_lblcr_entry associated with supplied parameters. Called under
344 * read lock.
345 */
346 static inline struct ip_vs_lblcr_entry *
347 ip_vs_lblcr_get(int af, struct ip_vs_lblcr_table *tbl,
348 const union nf_inet_addr *addr)
349 {
350 unsigned hash = ip_vs_lblcr_hashkey(af, addr);
351 struct ip_vs_lblcr_entry *en;
352
353 list_for_each_entry(en, &tbl->bucket[hash], list)
354 if (ip_vs_addr_equal(af, &en->addr, addr))
355 return en;
356
357 return NULL;
358 }
359
360
361 /*
362 * Create or update an ip_vs_lblcr_entry, which is a mapping of a destination
363 * IP address to a server. Called under write lock.
364 */
365 static inline struct ip_vs_lblcr_entry *
366 ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
367 struct ip_vs_dest *dest)
368 {
369 struct ip_vs_lblcr_entry *en;
370
371 en = ip_vs_lblcr_get(dest->af, tbl, daddr);
372 if (!en) {
373 en = kmalloc(sizeof(*en), GFP_ATOMIC);
374 if (!en) {
375 pr_err("%s(): no memory\n", __func__);
376 return NULL;
377 }
378
379 en->af = dest->af;
380 ip_vs_addr_copy(dest->af, &en->addr, daddr);
381 en->lastuse = jiffies;
382
383 /* initialize its dest set */
384 atomic_set(&(en->set.size), 0);
385 INIT_LIST_HEAD(&en->set.list);
386 rwlock_init(&en->set.lock);
387
388 ip_vs_lblcr_hash(tbl, en);
389 }
390
391 write_lock(&en->set.lock);
392 ip_vs_dest_set_insert(&en->set, dest);
393 write_unlock(&en->set.lock);
394
395 return en;
396 }
397
398
399 /*
400 * Flush all the entries of the specified table.
401 */
402 static void ip_vs_lblcr_flush(struct ip_vs_lblcr_table *tbl)
403 {
404 int i;
405 struct ip_vs_lblcr_entry *en, *nxt;
406
407 /* No locking required, only called during cleanup. */
408 for (i=0; i<IP_VS_LBLCR_TAB_SIZE; i++) {
409 list_for_each_entry_safe(en, nxt, &tbl->bucket[i], list) {
410 ip_vs_lblcr_free(en);
411 }
412 }
413 }
414
415 static int sysctl_lblcr_expiration(struct ip_vs_service *svc)
416 {
417 #ifdef CONFIG_SYSCTL
418 struct netns_ipvs *ipvs = net_ipvs(svc->net);
419 return ipvs->sysctl_lblcr_expiration;
420 #else
421 return DEFAULT_EXPIRATION;
422 #endif
423 }
424
425 static inline void ip_vs_lblcr_full_check(struct ip_vs_service *svc)
426 {
427 struct ip_vs_lblcr_table *tbl = svc->sched_data;
428 unsigned long now = jiffies;
429 int i, j;
430 struct ip_vs_lblcr_entry *en, *nxt;
431
432 for (i=0, j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE; i++) {
433 j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
434
435 write_lock(&svc->sched_lock);
436 list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) {
437 if (time_after(en->lastuse +
438 sysctl_lblcr_expiration(svc), now))
439 continue;
440
441 ip_vs_lblcr_free(en);
442 atomic_dec(&tbl->entries);
443 }
444 write_unlock(&svc->sched_lock);
445 }
446 tbl->rover = j;
447 }
448
449
450 /*
451 * Periodical timer handler for IPVS lblcr table
452 * It is used to collect stale entries when the number of entries
453 * exceeds the maximum size of the table.
454 *
455 * Fixme: we probably need more complicated algorithm to collect
456 * entries that have not been used for a long time even
457 * if the number of entries doesn't exceed the maximum size
458 * of the table.
459 * The full expiration check is for this purpose now.
460 */
461 static void ip_vs_lblcr_check_expire(unsigned long data)
462 {
463 struct ip_vs_service *svc = (struct ip_vs_service *) data;
464 struct ip_vs_lblcr_table *tbl = svc->sched_data;
465 unsigned long now = jiffies;
466 int goal;
467 int i, j;
468 struct ip_vs_lblcr_entry *en, *nxt;
469
470 if ((tbl->counter % COUNT_FOR_FULL_EXPIRATION) == 0) {
471 /* do full expiration check */
472 ip_vs_lblcr_full_check(svc);
473 tbl->counter = 1;
474 goto out;
475 }
476
477 if (atomic_read(&tbl->entries) <= tbl->max_size) {
478 tbl->counter++;
479 goto out;
480 }
481
482 goal = (atomic_read(&tbl->entries) - tbl->max_size)*4/3;
483 if (goal > tbl->max_size/2)
484 goal = tbl->max_size/2;
485
486 for (i=0, j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE; i++) {
487 j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
488
489 write_lock(&svc->sched_lock);
490 list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) {
491 if (time_before(now, en->lastuse+ENTRY_TIMEOUT))
492 continue;
493
494 ip_vs_lblcr_free(en);
495 atomic_dec(&tbl->entries);
496 goal--;
497 }
498 write_unlock(&svc->sched_lock);
499 if (goal <= 0)
500 break;
501 }
502 tbl->rover = j;
503
504 out:
505 mod_timer(&tbl->periodic_timer, jiffies+CHECK_EXPIRE_INTERVAL);
506 }
507
508 static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)
509 {
510 int i;
511 struct ip_vs_lblcr_table *tbl;
512
513 /*
514 * Allocate the ip_vs_lblcr_table for this service
515 */
516 tbl = kmalloc(sizeof(*tbl), GFP_ATOMIC);
517 if (tbl == NULL) {
518 pr_err("%s(): no memory\n", __func__);
519 return -ENOMEM;
520 }
521 svc->sched_data = tbl;
522 IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) allocated for "
523 "current service\n", sizeof(*tbl));
524
525 /*
526 * Initialize the hash buckets
527 */
528 for (i=0; i<IP_VS_LBLCR_TAB_SIZE; i++) {
529 INIT_LIST_HEAD(&tbl->bucket[i]);
530 }
531 tbl->max_size = IP_VS_LBLCR_TAB_SIZE*16;
532 tbl->rover = 0;
533 tbl->counter = 1;
534
535 /*
536 * Hook periodic timer for garbage collection
537 */
538 setup_timer(&tbl->periodic_timer, ip_vs_lblcr_check_expire,
539 (unsigned long)svc);
540 mod_timer(&tbl->periodic_timer, jiffies + CHECK_EXPIRE_INTERVAL);
541
542 return 0;
543 }
544
545
546 static int ip_vs_lblcr_done_svc(struct ip_vs_service *svc)
547 {
548 struct ip_vs_lblcr_table *tbl = svc->sched_data;
549
550 /* remove periodic timer */
551 del_timer_sync(&tbl->periodic_timer);
552
553 /* got to clean up table entries here */
554 ip_vs_lblcr_flush(tbl);
555
556 /* release the table itself */
557 kfree(tbl);
558 IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) released\n",
559 sizeof(*tbl));
560
561 return 0;
562 }
563
564
565 static inline struct ip_vs_dest *
566 __ip_vs_lblcr_schedule(struct ip_vs_service *svc)
567 {
568 struct ip_vs_dest *dest, *least;
569 int loh, doh;
570
571 /*
572 * We use the following formula to estimate the load:
573 * (dest overhead) / dest->weight
574 *
575 * Remember -- no floats in kernel mode!!!
576 * The comparison of h1*w2 > h2*w1 is equivalent to that of
577 * h1/w1 > h2/w2
578 * if every weight is larger than zero.
579 *
580 * The server with weight=0 is quiesced and will not receive any
581 * new connection.
582 */
583 list_for_each_entry(dest, &svc->destinations, n_list) {
584 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
585 continue;
586
587 if (atomic_read(&dest->weight) > 0) {
588 least = dest;
589 loh = ip_vs_dest_conn_overhead(least);
590 goto nextstage;
591 }
592 }
593 return NULL;
594
595 /*
596 * Find the destination with the least load.
597 */
598 nextstage:
599 list_for_each_entry_continue(dest, &svc->destinations, n_list) {
600 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
601 continue;
602
603 doh = ip_vs_dest_conn_overhead(dest);
604 if (loh * atomic_read(&dest->weight) >
605 doh * atomic_read(&least->weight)) {
606 least = dest;
607 loh = doh;
608 }
609 }
610
611 IP_VS_DBG_BUF(6, "LBLCR: server %s:%d "
612 "activeconns %d refcnt %d weight %d overhead %d\n",
613 IP_VS_DBG_ADDR(least->af, &least->addr),
614 ntohs(least->port),
615 atomic_read(&least->activeconns),
616 atomic_read(&least->refcnt),
617 atomic_read(&least->weight), loh);
618
619 return least;
620 }
621
622
623 /*
624 * If this destination server is overloaded and there is a less loaded
625 * server, then return true.
626 */
627 static inline int
628 is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
629 {
630 if (atomic_read(&dest->activeconns) > atomic_read(&dest->weight)) {
631 struct ip_vs_dest *d;
632
633 list_for_each_entry(d, &svc->destinations, n_list) {
634 if (atomic_read(&d->activeconns)*2
635 < atomic_read(&d->weight)) {
636 return 1;
637 }
638 }
639 }
640 return 0;
641 }
642
643
644 /*
645 * Locality-Based (weighted) Least-Connection scheduling
646 */
647 static struct ip_vs_dest *
648 ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
649 {
650 struct ip_vs_lblcr_table *tbl = svc->sched_data;
651 struct ip_vs_iphdr iph;
652 struct ip_vs_dest *dest = NULL;
653 struct ip_vs_lblcr_entry *en;
654
655 ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
656
657 IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
658
659 /* First look in our cache */
660 read_lock(&svc->sched_lock);
661 en = ip_vs_lblcr_get(svc->af, tbl, &iph.daddr);
662 if (en) {
663 /* We only hold a read lock, but this is atomic */
664 en->lastuse = jiffies;
665
666 /* Get the least loaded destination */
667 read_lock(&en->set.lock);
668 dest = ip_vs_dest_set_min(&en->set);
669 read_unlock(&en->set.lock);
670
671 /* More than one destination + enough time passed by, cleanup */
672 if (atomic_read(&en->set.size) > 1 &&
673 time_after(jiffies, en->set.lastmod +
674 sysctl_lblcr_expiration(svc))) {
675 struct ip_vs_dest *m;
676
677 write_lock(&en->set.lock);
678 m = ip_vs_dest_set_max(&en->set);
679 if (m)
680 ip_vs_dest_set_erase(&en->set, m);
681 write_unlock(&en->set.lock);
682 }
683
684 /* If the destination is not overloaded, use it */
685 if (dest && !is_overloaded(dest, svc)) {
686 read_unlock(&svc->sched_lock);
687 goto out;
688 }
689
690 /* The cache entry is invalid, time to schedule */
691 dest = __ip_vs_lblcr_schedule(svc);
692 if (!dest) {
693 ip_vs_scheduler_err(svc, "no destination available");
694 read_unlock(&svc->sched_lock);
695 return NULL;
696 }
697
698 /* Update our cache entry */
699 write_lock(&en->set.lock);
700 ip_vs_dest_set_insert(&en->set, dest);
701 write_unlock(&en->set.lock);
702 }
703 read_unlock(&svc->sched_lock);
704
705 if (dest)
706 goto out;
707
708 /* No cache entry, time to schedule */
709 dest = __ip_vs_lblcr_schedule(svc);
710 if (!dest) {
711 IP_VS_DBG(1, "no destination available\n");
712 return NULL;
713 }
714
715 /* If we fail to create a cache entry, we'll just use the valid dest */
716 write_lock(&svc->sched_lock);
717 ip_vs_lblcr_new(tbl, &iph.daddr, dest);
718 write_unlock(&svc->sched_lock);
719
720 out:
721 IP_VS_DBG_BUF(6, "LBLCR: destination IP address %s --> server %s:%d\n",
722 IP_VS_DBG_ADDR(svc->af, &iph.daddr),
723 IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
724
725 return dest;
726 }
727
728
729 /*
730 * IPVS LBLCR Scheduler structure
731 */
732 static struct ip_vs_scheduler ip_vs_lblcr_scheduler =
733 {
734 .name = "lblcr",
735 .refcnt = ATOMIC_INIT(0),
736 .module = THIS_MODULE,
737 .n_list = LIST_HEAD_INIT(ip_vs_lblcr_scheduler.n_list),
738 .init_service = ip_vs_lblcr_init_svc,
739 .done_service = ip_vs_lblcr_done_svc,
740 .schedule = ip_vs_lblcr_schedule,
741 };
742
743 /*
744 * per netns init.
745 */
746 static int __net_init __ip_vs_lblcr_init(struct net *net)
747 {
748 struct netns_ipvs *ipvs = net_ipvs(net);
749
750 if (!net_eq(net, &init_net)) {
751 ipvs->lblcr_ctl_table = kmemdup(vs_vars_table,
752 sizeof(vs_vars_table),
753 GFP_KERNEL);
754 if (ipvs->lblcr_ctl_table == NULL)
755 return -ENOMEM;
756 } else
757 ipvs->lblcr_ctl_table = vs_vars_table;
758 ipvs->sysctl_lblcr_expiration = DEFAULT_EXPIRATION;
759 ipvs->lblcr_ctl_table[0].data = &ipvs->sysctl_lblcr_expiration;
760
761 #ifdef CONFIG_SYSCTL
762 ipvs->lblcr_ctl_header =
763 register_net_sysctl_table(net, net_vs_ctl_path,
764 ipvs->lblcr_ctl_table);
765 if (!ipvs->lblcr_ctl_header) {
766 if (!net_eq(net, &init_net))
767 kfree(ipvs->lblcr_ctl_table);
768 return -ENOMEM;
769 }
770 #endif
771
772 return 0;
773 }
774
775 static void __net_exit __ip_vs_lblcr_exit(struct net *net)
776 {
777 struct netns_ipvs *ipvs = net_ipvs(net);
778
779 #ifdef CONFIG_SYSCTL
780 unregister_net_sysctl_table(ipvs->lblcr_ctl_header);
781 #endif
782
783 if (!net_eq(net, &init_net))
784 kfree(ipvs->lblcr_ctl_table);
785 }
786
787 static struct pernet_operations ip_vs_lblcr_ops = {
788 .init = __ip_vs_lblcr_init,
789 .exit = __ip_vs_lblcr_exit,
790 };
791
792 static int __init ip_vs_lblcr_init(void)
793 {
794 int ret;
795
796 ret = register_pernet_subsys(&ip_vs_lblcr_ops);
797 if (ret)
798 return ret;
799
800 ret = register_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
801 if (ret)
802 unregister_pernet_subsys(&ip_vs_lblcr_ops);
803 return ret;
804 }
805
806 static void __exit ip_vs_lblcr_cleanup(void)
807 {
808 unregister_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
809 unregister_pernet_subsys(&ip_vs_lblcr_ops);
810 }
811
812
813 module_init(ip_vs_lblcr_init);
814 module_exit(ip_vs_lblcr_cleanup);
815 MODULE_LICENSE("GPL");