1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#define KMSG_COMPONENT "IPVS"
39#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43
44#include <net/ip_vs.h>
45
46
47static inline int
48ip_vs_sed_dest_overhead(struct ip_vs_dest *dest)
49{
50
51
52
53
54 return atomic_read(&dest->activeconns) + 1;
55}
56
57
58
59
60
61static struct ip_vs_dest *
62ip_vs_sed_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
63 struct ip_vs_iphdr *iph)
64{
65 struct ip_vs_dest *dest, *least;
66 int loh, doh;
67
68 IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
84 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
85 atomic_read(&dest->weight) > 0) {
86 least = dest;
87 loh = ip_vs_sed_dest_overhead(least);
88 goto nextstage;
89 }
90 }
91 ip_vs_scheduler_err(svc, "no destination available");
92 return NULL;
93
94
95
96
97 nextstage:
98 list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) {
99 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
100 continue;
101 doh = ip_vs_sed_dest_overhead(dest);
102 if ((__s64)loh * atomic_read(&dest->weight) >
103 (__s64)doh * atomic_read(&least->weight)) {
104 least = dest;
105 loh = doh;
106 }
107 }
108
109 IP_VS_DBG_BUF(6, "SED: server %s:%u "
110 "activeconns %d refcnt %d weight %d overhead %d\n",
111 IP_VS_DBG_ADDR(least->af, &least->addr),
112 ntohs(least->port),
113 atomic_read(&least->activeconns),
114 atomic_read(&least->refcnt),
115 atomic_read(&least->weight), loh);
116
117 return least;
118}
119
120
121static struct ip_vs_scheduler ip_vs_sed_scheduler =
122{
123 .name = "sed",
124 .refcnt = ATOMIC_INIT(0),
125 .module = THIS_MODULE,
126 .n_list = LIST_HEAD_INIT(ip_vs_sed_scheduler.n_list),
127 .schedule = ip_vs_sed_schedule,
128};
129
130
131static int __init ip_vs_sed_init(void)
132{
133 return register_ip_vs_scheduler(&ip_vs_sed_scheduler);
134}
135
136static void __exit ip_vs_sed_cleanup(void)
137{
138 unregister_ip_vs_scheduler(&ip_vs_sed_scheduler);
139 synchronize_rcu();
140}
141
142module_init(ip_vs_sed_init);
143module_exit(ip_vs_sed_cleanup);
144MODULE_LICENSE("GPL");
145