1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#define KMSG_COMPONENT "IPVS"
23#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27
28#include <net/ip_vs.h>
29
30
31
32
33static struct ip_vs_dest *
34ip_vs_wlc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
35{
36 struct ip_vs_dest *dest, *least;
37 unsigned int loh, doh;
38
39 IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 list_for_each_entry(dest, &svc->destinations, n_list) {
55 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
56 atomic_read(&dest->weight) > 0) {
57 least = dest;
58 loh = ip_vs_dest_conn_overhead(least);
59 goto nextstage;
60 }
61 }
62 ip_vs_scheduler_err(svc, "no destination available");
63 return NULL;
64
65
66
67
68 nextstage:
69 list_for_each_entry_continue(dest, &svc->destinations, n_list) {
70 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
71 continue;
72 doh = ip_vs_dest_conn_overhead(dest);
73 if (loh * atomic_read(&dest->weight) >
74 doh * atomic_read(&least->weight)) {
75 least = dest;
76 loh = doh;
77 }
78 }
79
80 IP_VS_DBG_BUF(6, "WLC: server %s:%u "
81 "activeconns %d refcnt %d weight %d overhead %d\n",
82 IP_VS_DBG_ADDR(svc->af, &least->addr), ntohs(least->port),
83 atomic_read(&least->activeconns),
84 atomic_read(&least->refcnt),
85 atomic_read(&least->weight), loh);
86
87 return least;
88}
89
90
91static struct ip_vs_scheduler ip_vs_wlc_scheduler =
92{
93 .name = "wlc",
94 .refcnt = ATOMIC_INIT(0),
95 .module = THIS_MODULE,
96 .n_list = LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list),
97 .schedule = ip_vs_wlc_schedule,
98};
99
100
101static int __init ip_vs_wlc_init(void)
102{
103 return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
104}
105
106static void __exit ip_vs_wlc_cleanup(void)
107{
108 unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
109}
110
111module_init(ip_vs_wlc_init);
112module_exit(ip_vs_wlc_cleanup);
113MODULE_LICENSE("GPL");
114