RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / net / ipv4 / ipvs / ip_vs_rr.c
blob433f8a947924fa1b17091e0f9b8f292570dafcbf
1 /*
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.
14 * Fixes/Changes:
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;
33 return 0;
37 static int ip_vs_rr_done_svc(struct ip_vs_service *svc)
39 return 0;
43 static int ip_vs_rr_update_svc(struct ip_vs_service *svc)
45 svc->sched_data = &svc->destinations;
46 return 0;
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;
63 p = p->next;
64 q = p;
65 do {
66 /* skip list head */
67 if (q == &svc->destinations) {
68 q = q->next;
69 continue;
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)
75 /* HIT */
76 goto out;
77 q = q->next;
78 } while (q != p);
79 write_unlock(&svc->sched_lock);
80 return NULL;
82 out:
83 svc->sched_data = q;
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));
91 return dest;
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");