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