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