IPVS: Make "no destination available" message more consistent between schedulers
[deliverable/linux.git] / net / netfilter / ipvs / ip_vs_lc.c
CommitLineData
1da177e4
LT
1/*
2 * IPVS: Least-Connection Scheduling module
3 *
1da177e4
LT
4 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
5 *
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.
10 *
11 * Changes:
12 * Wensong Zhang : added the ip_vs_lc_update_svc
13 * Wensong Zhang : added any dest with weight=0 is quiesced
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/kernel.h>
19
20#include <net/ip_vs.h>
21
22
1da177e4
LT
23static inline unsigned int
24ip_vs_lc_dest_overhead(struct ip_vs_dest *dest)
25{
26 /*
27 * We think the overhead of processing active connections is 256
28 * times higher than that of inactive connections in average. (This
29 * 256 times might not be accurate, we will change it later) We
30 * use the following formula to estimate the overhead now:
31 * dest->activeconns*256 + dest->inactconns
32 */
33 return (atomic_read(&dest->activeconns) << 8) +
34 atomic_read(&dest->inactconns);
35}
36
37
38/*
39 * Least Connection scheduling
40 */
41static struct ip_vs_dest *
42ip_vs_lc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
43{
44 struct ip_vs_dest *dest, *least = NULL;
45 unsigned int loh = 0, doh;
46
47 IP_VS_DBG(6, "ip_vs_lc_schedule(): Scheduling...\n");
48
49 /*
50 * Simply select the server with the least number of
51 * (activeconns<<5) + inactconns
52 * Except whose weight is equal to zero.
53 * If the weight is equal to zero, it means that the server is
54 * quiesced, the existing connections to the server still get
55 * served, but no new connection is assigned to the server.
56 */
57
58 list_for_each_entry(dest, &svc->destinations, n_list) {
59 if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
60 atomic_read(&dest->weight) == 0)
61 continue;
62 doh = ip_vs_lc_dest_overhead(dest);
63 if (!least || doh < loh) {
64 least = dest;
65 loh = doh;
66 }
67 }
68
68888d10
SH
69 if (!least)
70 IP_VS_ERR_RL("LC: no destination available\n");
71 else
72 IP_VS_DBG_BUF(6, "LC: server %s:%u activeconns %d "
73 "inactconns %d\n",
74 IP_VS_DBG_ADDR(svc->af, &least->addr),
75 ntohs(least->port),
76 atomic_read(&least->activeconns),
77 atomic_read(&least->inactconns));
1da177e4
LT
78
79 return least;
80}
81
82
83static struct ip_vs_scheduler ip_vs_lc_scheduler = {
84 .name = "lc",
85 .refcnt = ATOMIC_INIT(0),
86 .module = THIS_MODULE,
d149ccc9 87 .n_list = LIST_HEAD_INIT(ip_vs_lc_scheduler.n_list),
1da177e4
LT
88 .schedule = ip_vs_lc_schedule,
89};
90
91
92static int __init ip_vs_lc_init(void)
93{
1da177e4
LT
94 return register_ip_vs_scheduler(&ip_vs_lc_scheduler) ;
95}
96
97static void __exit ip_vs_lc_cleanup(void)
98{
99 unregister_ip_vs_scheduler(&ip_vs_lc_scheduler);
100}
101
102module_init(ip_vs_lc_init);
103module_exit(ip_vs_lc_cleanup);
104MODULE_LICENSE("GPL");
This page took 0.339222 seconds and 5 git commands to generate.