blob: 358110d17e5957dd871af44faa83cfe88bbc26b4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPVS: Round-Robin Scheduling module
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
5 * Peter Kese <peter.kese@ijs.si>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Fixes/Changes:
13 * Wensong Zhang : changed the ip_vs_rr_schedule to return dest
14 * Julian Anastasov : fixed the NULL pointer access bug in debugging
15 * Wensong Zhang : changed some comestics things for debugging
16 * Wensong Zhang : changed for the d-linked destination list
17 * Wensong Zhang : added the ip_vs_rr_update_svc
18 * Wensong Zhang : added any dest with weight=0 is quiesced
19 *
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24
25#include <net/ip_vs.h>
26
27
28static int ip_vs_rr_init_svc(struct ip_vs_service *svc)
29{
30 svc->sched_data = &svc->destinations;
31 return 0;
32}
33
34
35static int ip_vs_rr_done_svc(struct ip_vs_service *svc)
36{
37 return 0;
38}
39
40
41static int ip_vs_rr_update_svc(struct ip_vs_service *svc)
42{
43 svc->sched_data = &svc->destinations;
44 return 0;
45}
46
47
48/*
49 * Round-Robin Scheduling
50 */
51static struct ip_vs_dest *
52ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
53{
54 struct list_head *p, *q;
55 struct ip_vs_dest *dest;
56
57 IP_VS_DBG(6, "ip_vs_rr_schedule(): Scheduling...\n");
58
59 write_lock(&svc->sched_lock);
60 p = (struct list_head *)svc->sched_data;
61 p = p->next;
62 q = p;
63 do {
64 /* skip list head */
65 if (q == &svc->destinations) {
66 q = q->next;
67 continue;
68 }
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 dest = list_entry(q, struct ip_vs_dest, n_list);
71 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
72 atomic_read(&dest->weight) > 0)
73 /* HIT */
74 goto out;
75 q = q->next;
76 } while (q != p);
77 write_unlock(&svc->sched_lock);
78 return NULL;
79
80 out:
81 svc->sched_data = q;
82 write_unlock(&svc->sched_lock);
83 IP_VS_DBG(6, "RR: server %u.%u.%u.%u:%u "
84 "activeconns %d refcnt %d weight %d\n",
85 NIPQUAD(dest->addr), ntohs(dest->port),
86 atomic_read(&dest->activeconns),
87 atomic_read(&dest->refcnt), atomic_read(&dest->weight));
88
89 return dest;
90}
91
92
93static struct ip_vs_scheduler ip_vs_rr_scheduler = {
94 .name = "rr", /* name */
95 .refcnt = ATOMIC_INIT(0),
96 .module = THIS_MODULE,
Sven Wegenerd149ccc2008-08-10 09:18:02 +000097 .n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list),
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .init_service = ip_vs_rr_init_svc,
99 .done_service = ip_vs_rr_done_svc,
100 .update_service = ip_vs_rr_update_svc,
101 .schedule = ip_vs_rr_schedule,
102};
103
104static int __init ip_vs_rr_init(void)
105{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return register_ip_vs_scheduler(&ip_vs_rr_scheduler);
107}
108
109static void __exit ip_vs_rr_cleanup(void)
110{
111 unregister_ip_vs_scheduler(&ip_vs_rr_scheduler);
112}
113
114module_init(ip_vs_rr_init);
115module_exit(ip_vs_rr_cleanup);
116MODULE_LICENSE("GPL");