]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * IPVS: Round-Robin Scheduling module | |
3 | * | |
1da177e4 LT |
4 | * 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 | ||
9aada7ac HE |
22 | #define KMSG_COMPONENT "IPVS" |
23 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
24 | ||
1da177e4 LT |
25 | #include <linux/module.h> |
26 | #include <linux/kernel.h> | |
27 | ||
28 | #include <net/ip_vs.h> | |
29 | ||
30 | ||
31 | static int ip_vs_rr_init_svc(struct ip_vs_service *svc) | |
32 | { | |
33 | svc->sched_data = &svc->destinations; | |
34 | return 0; | |
35 | } | |
36 | ||
37 | ||
c0d0c0a1 | 38 | static int ip_vs_rr_del_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest) |
1da177e4 | 39 | { |
c0d0c0a1 JA |
40 | struct list_head *p; |
41 | ||
ba3a3ce1 | 42 | spin_lock_bh(&svc->sched_lock); |
c0d0c0a1 JA |
43 | p = (struct list_head *) svc->sched_data; |
44 | /* dest is already unlinked, so p->prev is not valid but | |
45 | * p->next is valid, use it to reach previous entry. | |
46 | */ | |
47 | if (p == &dest->n_list) | |
48 | svc->sched_data = p->next->prev; | |
ba3a3ce1 | 49 | spin_unlock_bh(&svc->sched_lock); |
1da177e4 LT |
50 | return 0; |
51 | } | |
52 | ||
53 | ||
54 | /* | |
55 | * Round-Robin Scheduling | |
56 | */ | |
57 | static struct ip_vs_dest * | |
58 | ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb) | |
59 | { | |
c0d0c0a1 JA |
60 | struct list_head *p; |
61 | struct ip_vs_dest *dest, *last; | |
62 | int pass = 0; | |
1da177e4 | 63 | |
1e3e238e | 64 | IP_VS_DBG(6, "%s(): Scheduling...\n", __func__); |
1da177e4 | 65 | |
ba3a3ce1 | 66 | spin_lock(&svc->sched_lock); |
c0d0c0a1 JA |
67 | p = (struct list_head *) svc->sched_data; |
68 | last = dest = list_entry(p, struct ip_vs_dest, n_list); | |
69 | ||
1da177e4 | 70 | do { |
c0d0c0a1 JA |
71 | list_for_each_entry_continue_rcu(dest, |
72 | &svc->destinations, | |
73 | n_list) { | |
74 | if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) && | |
75 | atomic_read(&dest->weight) > 0) | |
76 | /* HIT */ | |
77 | goto out; | |
78 | if (dest == last) | |
79 | goto stop; | |
1da177e4 | 80 | } |
c0d0c0a1 JA |
81 | pass++; |
82 | /* Previous dest could be unlinked, do not loop forever. | |
83 | * If we stay at head there is no need for 2nd pass. | |
84 | */ | |
85 | } while (pass < 2 && p != &svc->destinations); | |
e905a9ed | 86 | |
c0d0c0a1 | 87 | stop: |
ba3a3ce1 | 88 | spin_unlock(&svc->sched_lock); |
41ac51ee | 89 | ip_vs_scheduler_err(svc, "no destination available"); |
1da177e4 LT |
90 | return NULL; |
91 | ||
92 | out: | |
c0d0c0a1 | 93 | svc->sched_data = &dest->n_list; |
ba3a3ce1 | 94 | spin_unlock(&svc->sched_lock); |
b14198f6 JV |
95 | IP_VS_DBG_BUF(6, "RR: server %s:%u " |
96 | "activeconns %d refcnt %d weight %d\n", | |
97 | IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port), | |
98 | atomic_read(&dest->activeconns), | |
99 | atomic_read(&dest->refcnt), atomic_read(&dest->weight)); | |
1da177e4 LT |
100 | |
101 | return dest; | |
102 | } | |
103 | ||
104 | ||
105 | static struct ip_vs_scheduler ip_vs_rr_scheduler = { | |
106 | .name = "rr", /* name */ | |
107 | .refcnt = ATOMIC_INIT(0), | |
108 | .module = THIS_MODULE, | |
d149ccc9 | 109 | .n_list = LIST_HEAD_INIT(ip_vs_rr_scheduler.n_list), |
1da177e4 | 110 | .init_service = ip_vs_rr_init_svc, |
c0d0c0a1 JA |
111 | .add_dest = NULL, |
112 | .del_dest = ip_vs_rr_del_dest, | |
1da177e4 LT |
113 | .schedule = ip_vs_rr_schedule, |
114 | }; | |
115 | ||
116 | static int __init ip_vs_rr_init(void) | |
117 | { | |
1da177e4 LT |
118 | return register_ip_vs_scheduler(&ip_vs_rr_scheduler); |
119 | } | |
120 | ||
121 | static void __exit ip_vs_rr_cleanup(void) | |
122 | { | |
123 | unregister_ip_vs_scheduler(&ip_vs_rr_scheduler); | |
ceec4c38 | 124 | synchronize_rcu(); |
1da177e4 LT |
125 | } |
126 | ||
127 | module_init(ip_vs_rr_init); | |
128 | module_exit(ip_vs_rr_cleanup); | |
129 | MODULE_LICENSE("GPL"); |