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 struct ip_vs_iphdr *iph)
36{
37 struct ip_vs_dest *dest, *least;
38 int loh, doh;
39
40 IP_VS_DBG(6, "ip_vs_wlc_schedule(): Scheduling...\n");
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
56 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
57 atomic_read(&dest->weight) > 0) {
58 least = dest;
59 loh = ip_vs_dest_conn_overhead(least);
60 goto nextstage;
61 }
62 }
63 ip_vs_scheduler_err(svc, "no destination available");
64 return NULL;
65
66
67
68
69 nextstage:
70 list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) {
71 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
72 continue;
73 doh = ip_vs_dest_conn_overhead(dest);
74 if ((__s64)loh * atomic_read(&dest->weight) >
75 (__s64)doh * atomic_read(&least->weight)) {
76 least = dest;
77 loh = doh;
78 }
79 }
80
81 IP_VS_DBG_BUF(6, "WLC: server %s:%u "
82 "activeconns %d refcnt %d weight %d overhead %d\n",
83 IP_VS_DBG_ADDR(least->af, &least->addr),
84 ntohs(least->port),
85 atomic_read(&least->activeconns),
86 atomic_read(&least->refcnt),
87 atomic_read(&least->weight), loh);
88
89 return least;
90}
91
92
93static struct ip_vs_scheduler ip_vs_wlc_scheduler =
94{
95 .name = "wlc",
96 .refcnt = ATOMIC_INIT(0),
97 .module = THIS_MODULE,
98 .n_list = LIST_HEAD_INIT(ip_vs_wlc_scheduler.n_list),
99 .schedule = ip_vs_wlc_schedule,
100};
101
102
103static int __init ip_vs_wlc_init(void)
104{
105 return register_ip_vs_scheduler(&ip_vs_wlc_scheduler);
106}
107
108static void __exit ip_vs_wlc_cleanup(void)
109{
110 unregister_ip_vs_scheduler(&ip_vs_wlc_scheduler);
111 synchronize_rcu();
112}
113
114module_init(ip_vs_wlc_init);
115module_exit(ip_vs_wlc_cleanup);
116MODULE_LICENSE("GPL");
117