2 * IPVS: Round-Robin Scheduling module
4 * Version: $Id: ip_vs_rr.c,v 1.8 2001/10/19 15:05:17 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, struct iphdr *iph)
56 register 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;
66 if (q == &svc->destinations) {
70 dest = list_entry(q, struct ip_vs_dest, n_list);
71 if (atomic_read(&dest->weight) > 0)
76 write_unlock(&svc->sched_lock);
81 write_unlock(&svc->sched_lock);
82 IP_VS_DBG(6, "RR: server %u.%u.%u.%u:%u "
83 "activeconns %d refcnt %d weight %d\n",
84 NIPQUAD(dest->addr), ntohs(dest->port),
85 atomic_read(&dest->activeconns),
86 atomic_read(&dest->refcnt), atomic_read(&dest->weight));
92 static struct ip_vs_scheduler ip_vs_rr_scheduler = {
95 ATOMIC_INIT(0), /* refcnt */
96 THIS_MODULE, /* this module */
97 ip_vs_rr_init_svc, /* service initializer */
98 ip_vs_rr_done_svc, /* service done */
99 ip_vs_rr_update_svc, /* service updater */
100 ip_vs_rr_schedule, /* select a server from the destination list */
103 static int __init ip_vs_rr_init(void)
105 INIT_LIST_HEAD(&ip_vs_rr_scheduler.n_list);
106 return register_ip_vs_scheduler(&ip_vs_rr_scheduler);
109 static void __exit ip_vs_rr_cleanup(void)
111 unregister_ip_vs_scheduler(&ip_vs_rr_scheduler);
114 module_init(ip_vs_rr_init);
115 module_exit(ip_vs_rr_cleanup);
116 MODULE_LICENSE("GPL");