2 * IPVS: Overflow-Connection Scheduling module
4 * Authors: Raducu Deaconu <rhadoo_io@yahoo.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Scheduler implements "overflow" loadbalancing according to number of active
12 * connections , will keep all conections to the node with the highest weight
13 * and overflow to the next node if the number of connections exceeds the node's
15 * Note that this scheduler might not be suitable for UDP because it only uses
20 #define KMSG_COMPONENT "IPVS"
21 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
23 #include <linux/module.h>
24 #include <linux/kernel.h>
26 #include <net/ip_vs.h>
28 /* OVF Connection scheduling */
29 static struct ip_vs_dest
*
30 ip_vs_ovf_schedule(struct ip_vs_service
*svc
, const struct sk_buff
*skb
,
31 struct ip_vs_iphdr
*iph
)
33 struct ip_vs_dest
*dest
, *h
= NULL
;
36 IP_VS_DBG(6, "ip_vs_ovf_schedule(): Scheduling...\n");
37 /* select the node with highest weight, go to next in line if active
38 * connections exceed weight
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
||
53 IP_VS_DBG_BUF(6, "OVF: server %s:%u active %d w %d\n",
54 IP_VS_DBG_ADDR(h
->af
, &h
->addr
),
56 atomic_read(&h
->activeconns
),
57 atomic_read(&h
->weight
));
61 ip_vs_scheduler_err(svc
, "no destination available");
65 static struct ip_vs_scheduler ip_vs_ovf_scheduler
= {
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
,
73 static int __init
ip_vs_ovf_init(void)
75 return register_ip_vs_scheduler(&ip_vs_ovf_scheduler
);
78 static void __exit
ip_vs_ovf_cleanup(void)
80 unregister_ip_vs_scheduler(&ip_vs_ovf_scheduler
);
84 module_init(ip_vs_ovf_init
);
85 module_exit(ip_vs_ovf_cleanup
);
86 MODULE_LICENSE("GPL");