1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define KMSG_COMPONENT "IPVS"
21#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
22
23#include <linux/module.h>
24#include <linux/kernel.h>
25
26#include <net/ip_vs.h>
27
28
29static struct ip_vs_dest *
30ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
31 struct ip_vs_iphdr *iph)
32{
33 struct ip_vs_dest *dest, *h = NULL;
34 int hw = 0, w;
35
36 IP_VS_DBG(6, "ip_vs_ovf_schedule(): Scheduling...\n");
37
38
39
40 list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
41 w = atomic_read(&dest->weight);
42 if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
43 atomic_read(&dest->activeconns) > w ||
44 w == 0)
45 continue;
46 if (!h || w > hw) {
47 h = dest;
48 hw = w;
49 }
50 }
51
52 if (h) {
53 IP_VS_DBG_BUF(6, "OVF: server %s:%u active %d w %d\n",
54 IP_VS_DBG_ADDR(h->af, &h->addr),
55 ntohs(h->port),
56 atomic_read(&h->activeconns),
57 atomic_read(&h->weight));
58 return h;
59 }
60
61 ip_vs_scheduler_err(svc, "no destination available");
62 return NULL;
63}
64
65static struct ip_vs_scheduler ip_vs_ovf_scheduler = {
66 .name = "ovf",
67 .refcnt = ATOMIC_INIT(0),
68 .module = THIS_MODULE,
69 .n_list = LIST_HEAD_INIT(ip_vs_ovf_scheduler.n_list),
70 .schedule = ip_vs_ovf_schedule,
71};
72
73static int __init ip_vs_ovf_init(void)
74{
75 return register_ip_vs_scheduler(&ip_vs_ovf_scheduler);
76}
77
78static void __exit ip_vs_ovf_cleanup(void)
79{
80 unregister_ip_vs_scheduler(&ip_vs_ovf_scheduler);
81 synchronize_rcu();
82}
83
84module_init(ip_vs_ovf_init);
85module_exit(ip_vs_ovf_cleanup);
86MODULE_LICENSE("GPL");
87