1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21
22#include <net/ip_vs.h>
23
24
25static int ip_vs_lc_init_svc(struct ip_vs_service *svc)
26{
27 return 0;
28}
29
30
31static int ip_vs_lc_done_svc(struct ip_vs_service *svc)
32{
33 return 0;
34}
35
36
37static int ip_vs_lc_update_svc(struct ip_vs_service *svc)
38{
39 return 0;
40}
41
42
43static inline unsigned int
44ip_vs_lc_dest_overhead(struct ip_vs_dest *dest)
45{
46
47
48
49
50
51
52
53 return (atomic_read(&dest->activeconns) << 8) +
54 atomic_read(&dest->inactconns);
55}
56
57
58
59
60
61static struct ip_vs_dest *
62ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
63{
64 struct ip_vs_dest *dest, *least = NULL;
65 unsigned int loh = 0, doh;
66
67 IP_VS_DBG(6, "ip_vs_lc_schedule(): Scheduling...\n");
68
69
70
71
72
73
74
75
76
77
78 list_for_each_entry(dest, &svc->destinations, n_list) {
79 if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
80 atomic_read(&dest->weight) == 0)
81 continue;
82 doh = ip_vs_lc_dest_overhead(dest);
83 if (!least || doh < loh) {
84 least = dest;
85 loh = doh;
86 }
87 }
88
89 if (least)
90 IP_VS_DBG(6, "LC: server %u.%u.%u.%u:%u activeconns %d inactconns %d\n",
91 NIPQUAD(least->addr), ntohs(least->port),
92 atomic_read(&least->activeconns),
93 atomic_read(&least->inactconns));
94
95 return least;
96}
97
98
99static struct ip_vs_scheduler ip_vs_lc_scheduler = {
100 .name = "lc",
101 .refcnt = ATOMIC_INIT(0),
102 .module = THIS_MODULE,
103 .init_service = ip_vs_lc_init_svc,
104 .done_service = ip_vs_lc_done_svc,
105 .update_service = ip_vs_lc_update_svc,
106 .schedule = ip_vs_lc_schedule,
107};
108
109
110static int __init ip_vs_lc_init(void)
111{
112 INIT_LIST_HEAD(&ip_vs_lc_scheduler.n_list);
113 return register_ip_vs_scheduler(&ip_vs_lc_scheduler) ;
114}
115
116static void __exit ip_vs_lc_cleanup(void)
117{
118 unregister_ip_vs_scheduler(&ip_vs_lc_scheduler);
119}
120
121module_init(ip_vs_lc_init);
122module_exit(ip_vs_lc_cleanup);
123MODULE_LICENSE("GPL");
124