2 * IPVS: Round-Robin Scheduling module
4 * Version: $Id: ip_vs_rr.c,v 1.9 2002/09/15 08:14:08 wensong Exp $
6 * Authors: Wensong Zhang <wensong@linuxvirtualserver.org>
7 * Peter Kese <peter.kese@ijs.si>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 * Wensong Zhang : changed the ip_vs_rr_schedule to return dest
16 * Julian Anastasov : fixed the NULL pointer access bug in debugging
17 * Wensong Zhang : changed some comestics things for debugging
18 * Wensong Zhang : changed for the d-linked destination list
19 * Wensong Zhang : added the ip_vs_rr_update_svc
20 * Wensong Zhang : added any dest with weight=0 is quiesced
24 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <net/ip_vs.h>
30 static int ip_vs_rr_init_svc(struct ip_vs_service
*svc
)
32 svc
->sched_data
= &svc
->destinations
;
37 static int ip_vs_rr_done_svc(struct ip_vs_service
*svc
)
43 static int ip_vs_rr_update_svc(struct ip_vs_service
*svc
)
45 svc
->sched_data
= &svc
->destinations
;
51 * Round-Robin Scheduling
53 static struct ip_vs_dest
*
54 ip_vs_rr_schedule(struct ip_vs_service
*svc
, const struct sk_buff
*skb
)
56 struct list_head
*p
, *q
;
57 struct ip_vs_dest
*dest
;
59 IP_VS_DBG(6, "ip_vs_rr_schedule(): Scheduling...\n");
61 write_lock(&svc
->sched_lock
);
62 p
= (struct list_head
*)svc
->sched_data
;
67 if (q
== &svc
->destinations
) {
72 dest
= list_entry(q
, struct ip_vs_dest
, n_list
);
73 if (!(dest
->flags
& IP_VS_DEST_F_OVERLOAD
) &&
74 atomic_read(&dest
->weight
) > 0)
79 write_unlock(&svc
->sched_lock
);
84 write_unlock(&svc
->sched_lock
);
85 IP_VS_DBG(6, "RR: server %u.%u.%u.%u:%u "
86 "activeconns %d refcnt %d weight %d\n",
87 NIPQUAD(dest
->addr
), ntohs(dest
->port
),
88 atomic_read(&dest
->activeconns
),
89 atomic_read(&dest
->refcnt
), atomic_read(&dest
->weight
));
95 static struct ip_vs_scheduler ip_vs_rr_scheduler
= {
96 .name
= "rr", /* name */
97 .refcnt
= ATOMIC_INIT(0),
98 .module
= THIS_MODULE
,
99 .init_service
= ip_vs_rr_init_svc
,
100 .done_service
= ip_vs_rr_done_svc
,
101 .update_service
= ip_vs_rr_update_svc
,
102 .schedule
= ip_vs_rr_schedule
,
105 static int __init
ip_vs_rr_init(void)
107 INIT_LIST_HEAD(&ip_vs_rr_scheduler
.n_list
);
108 return register_ip_vs_scheduler(&ip_vs_rr_scheduler
);
111 static void __exit
ip_vs_rr_cleanup(void)
113 unregister_ip_vs_scheduler(&ip_vs_rr_scheduler
);
116 module_init(ip_vs_rr_init
);
117 module_exit(ip_vs_rr_cleanup
);
118 MODULE_LICENSE("GPL");