Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IPVS: Source Hashing scheduling module |
| 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Authors: Wensong Zhang <wensong@gnuchina.org> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * Changes: |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * The sh algorithm is to select server by the hash key of source IP |
| 17 | * address. The pseudo code is as follows: |
| 18 | * |
| 19 | * n <- servernode[src_ip]; |
| 20 | * if (n is dead) OR |
| 21 | * (n is overloaded) or (n.weight <= 0) then |
| 22 | * return NULL; |
| 23 | * |
| 24 | * return n; |
| 25 | * |
| 26 | * Notes that servernode is a 256-bucket hash table that maps the hash |
| 27 | * index derived from packet source IP address to the current server |
| 28 | * array. If the sh scheduler is used in cache cluster, it is good to |
| 29 | * combine it with cache_bypass feature. When the statically assigned |
| 30 | * server is dead or overloaded, the load balancer can bypass the cache |
| 31 | * server and send requests to the original server directly. |
| 32 | * |
Michael Maxim | 76ad94f | 2011-12-08 10:55:09 -0500 | [diff] [blame] | 33 | * The weight destination attribute can be used to control the |
| 34 | * distribution of connections to the destinations in servernode. The |
| 35 | * greater the weight, the more connections the destination |
| 36 | * will receive. |
| 37 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 40 | #define KMSG_COMPONENT "IPVS" |
| 41 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 42 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 43 | #include <linux/ip.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/module.h> |
| 46 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 47 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #include <net/ip_vs.h> |
| 50 | |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 51 | #include <net/tcp.h> |
| 52 | #include <linux/udp.h> |
| 53 | #include <linux/sctp.h> |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * IPVS SH bucket |
| 58 | */ |
| 59 | struct ip_vs_sh_bucket { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 60 | struct ip_vs_dest __rcu *dest; /* real server (cache) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * for IPVS SH entry hash table |
| 65 | */ |
| 66 | #ifndef CONFIG_IP_VS_SH_TAB_BITS |
| 67 | #define CONFIG_IP_VS_SH_TAB_BITS 8 |
| 68 | #endif |
| 69 | #define IP_VS_SH_TAB_BITS CONFIG_IP_VS_SH_TAB_BITS |
| 70 | #define IP_VS_SH_TAB_SIZE (1 << IP_VS_SH_TAB_BITS) |
| 71 | #define IP_VS_SH_TAB_MASK (IP_VS_SH_TAB_SIZE - 1) |
| 72 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 73 | struct ip_vs_sh_state { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 74 | struct rcu_head rcu_head; |
Jan Beulich | a70b964 | 2013-05-29 13:33:51 +0100 | [diff] [blame] | 75 | struct ip_vs_sh_bucket buckets[IP_VS_SH_TAB_SIZE]; |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 76 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 78 | /* Helper function to determine if server is unavailable */ |
| 79 | static inline bool is_unavailable(struct ip_vs_dest *dest) |
| 80 | { |
| 81 | return atomic_read(&dest->weight) <= 0 || |
| 82 | dest->flags & IP_VS_DEST_F_OVERLOAD; |
| 83 | } |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* |
| 86 | * Returns hash value for IPVS SH entry |
| 87 | */ |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 88 | static inline unsigned int |
| 89 | ip_vs_sh_hashkey(int af, const union nf_inet_addr *addr, |
| 90 | __be16 port, unsigned int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Julius Volz | 20971a0 | 2008-11-01 13:13:19 +0000 | [diff] [blame] | 92 | __be32 addr_fold = addr->ip; |
| 93 | |
| 94 | #ifdef CONFIG_IP_VS_IPV6 |
| 95 | if (af == AF_INET6) |
| 96 | addr_fold = addr->ip6[0]^addr->ip6[1]^ |
| 97 | addr->ip6[2]^addr->ip6[3]; |
| 98 | #endif |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 99 | return (offset + (ntohs(port) + ntohl(addr_fold))*2654435761UL) & |
| 100 | IP_VS_SH_TAB_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | /* |
| 105 | * Get ip_vs_dest associated with supplied parameters. |
| 106 | */ |
| 107 | static inline struct ip_vs_dest * |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 108 | ip_vs_sh_get(struct ip_vs_service *svc, struct ip_vs_sh_state *s, |
| 109 | const union nf_inet_addr *addr, __be16 port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 111 | unsigned int hash = ip_vs_sh_hashkey(svc->af, addr, port, 0); |
| 112 | struct ip_vs_dest *dest = rcu_dereference(s->buckets[hash].dest); |
| 113 | |
| 114 | return (!dest || is_unavailable(dest)) ? NULL : dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 118 | /* As ip_vs_sh_get, but with fallback if selected server is unavailable */ |
| 119 | static inline struct ip_vs_dest * |
| 120 | ip_vs_sh_get_fallback(struct ip_vs_service *svc, struct ip_vs_sh_state *s, |
| 121 | const union nf_inet_addr *addr, __be16 port) |
| 122 | { |
| 123 | unsigned int offset; |
| 124 | unsigned int hash; |
| 125 | struct ip_vs_dest *dest; |
| 126 | |
| 127 | for (offset = 0; offset < IP_VS_SH_TAB_SIZE; offset++) { |
| 128 | hash = ip_vs_sh_hashkey(svc->af, addr, port, offset); |
| 129 | dest = rcu_dereference(s->buckets[hash].dest); |
| 130 | if (!dest) |
| 131 | break; |
| 132 | if (is_unavailable(dest)) |
| 133 | IP_VS_DBG_BUF(6, "SH: selected unavailable server " |
| 134 | "%s:%d (offset %d)", |
| 135 | IP_VS_DBG_ADDR(svc->af, &dest->addr), |
| 136 | ntohs(dest->port), offset); |
| 137 | else |
| 138 | return dest; |
| 139 | } |
| 140 | |
| 141 | return NULL; |
| 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Assign all the hash buckets of the specified table with the service. |
| 146 | */ |
| 147 | static int |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 148 | ip_vs_sh_reassign(struct ip_vs_sh_state *s, struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | int i; |
| 151 | struct ip_vs_sh_bucket *b; |
| 152 | struct list_head *p; |
| 153 | struct ip_vs_dest *dest; |
Michael Maxim | 76ad94f | 2011-12-08 10:55:09 -0500 | [diff] [blame] | 154 | int d_count; |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 155 | bool empty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 157 | b = &s->buckets[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | p = &svc->destinations; |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 159 | empty = list_empty(p); |
Michael Maxim | 76ad94f | 2011-12-08 10:55:09 -0500 | [diff] [blame] | 160 | d_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | for (i=0; i<IP_VS_SH_TAB_SIZE; i++) { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 162 | dest = rcu_dereference_protected(b->dest, 1); |
| 163 | if (dest) |
| 164 | ip_vs_dest_put(dest); |
| 165 | if (empty) |
| 166 | RCU_INIT_POINTER(b->dest, NULL); |
| 167 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | if (p == &svc->destinations) |
| 169 | p = p->next; |
| 170 | |
| 171 | dest = list_entry(p, struct ip_vs_dest, n_list); |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 172 | ip_vs_dest_hold(dest); |
| 173 | RCU_INIT_POINTER(b->dest, dest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Michael Maxim | 76ad94f | 2011-12-08 10:55:09 -0500 | [diff] [blame] | 175 | IP_VS_DBG_BUF(6, "assigned i: %d dest: %s weight: %d\n", |
| 176 | i, IP_VS_DBG_ADDR(svc->af, &dest->addr), |
| 177 | atomic_read(&dest->weight)); |
| 178 | |
| 179 | /* Don't move to next dest until filling weight */ |
| 180 | if (++d_count >= atomic_read(&dest->weight)) { |
| 181 | p = p->next; |
| 182 | d_count = 0; |
| 183 | } |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | b++; |
| 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /* |
| 193 | * Flush all the hash buckets of the specified table. |
| 194 | */ |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 195 | static void ip_vs_sh_flush(struct ip_vs_sh_state *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | int i; |
| 198 | struct ip_vs_sh_bucket *b; |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 199 | struct ip_vs_dest *dest; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 201 | b = &s->buckets[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | for (i=0; i<IP_VS_SH_TAB_SIZE; i++) { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 203 | dest = rcu_dereference_protected(b->dest, 1); |
| 204 | if (dest) { |
| 205 | ip_vs_dest_put(dest); |
| 206 | RCU_INIT_POINTER(b->dest, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | b++; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | static int ip_vs_sh_init_svc(struct ip_vs_service *svc) |
| 214 | { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 215 | struct ip_vs_sh_state *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | /* allocate the SH table for this service */ |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 218 | s = kzalloc(sizeof(struct ip_vs_sh_state), GFP_KERNEL); |
| 219 | if (s == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return -ENOMEM; |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 221 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 222 | svc->sched_data = s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | IP_VS_DBG(6, "SH hash table (memory=%Zdbytes) allocated for " |
| 224 | "current service\n", |
| 225 | sizeof(struct ip_vs_sh_bucket)*IP_VS_SH_TAB_SIZE); |
| 226 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 227 | /* assign the hash buckets with current dests */ |
| 228 | ip_vs_sh_reassign(s, svc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | |
Julian Anastasov | ed3ffc4 | 2013-03-22 11:46:50 +0200 | [diff] [blame] | 234 | static void ip_vs_sh_done_svc(struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 236 | struct ip_vs_sh_state *s = svc->sched_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | /* got to clean up hash buckets here */ |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 239 | ip_vs_sh_flush(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | /* release the table itself */ |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 242 | kfree_rcu(s, rcu_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | IP_VS_DBG(6, "SH hash table (memory=%Zdbytes) released\n", |
| 244 | sizeof(struct ip_vs_sh_bucket)*IP_VS_SH_TAB_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 248 | static int ip_vs_sh_dest_changed(struct ip_vs_service *svc, |
| 249 | struct ip_vs_dest *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 251 | struct ip_vs_sh_state *s = svc->sched_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* assign the hash buckets with the updated service */ |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 254 | ip_vs_sh_reassign(s, svc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 260 | /* Helper function to get port number */ |
| 261 | static inline __be16 |
| 262 | ip_vs_sh_get_port(const struct sk_buff *skb, struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 264 | __be16 port; |
| 265 | struct tcphdr _tcph, *th; |
| 266 | struct udphdr _udph, *uh; |
| 267 | sctp_sctphdr_t _sctph, *sh; |
| 268 | |
| 269 | switch (iph->protocol) { |
| 270 | case IPPROTO_TCP: |
| 271 | th = skb_header_pointer(skb, iph->len, sizeof(_tcph), &_tcph); |
| 272 | port = th->source; |
| 273 | break; |
| 274 | case IPPROTO_UDP: |
| 275 | uh = skb_header_pointer(skb, iph->len, sizeof(_udph), &_udph); |
| 276 | port = uh->source; |
| 277 | break; |
| 278 | case IPPROTO_SCTP: |
| 279 | sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph); |
| 280 | port = sh->source; |
| 281 | break; |
| 282 | default: |
| 283 | port = 0; |
| 284 | } |
| 285 | |
| 286 | return port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | |
| 290 | /* |
| 291 | * Source Hashing scheduling |
| 292 | */ |
| 293 | static struct ip_vs_dest * |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 294 | ip_vs_sh_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, |
| 295 | struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | struct ip_vs_dest *dest; |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 298 | struct ip_vs_sh_state *s; |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 299 | __be16 port = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | IP_VS_DBG(6, "ip_vs_sh_schedule(): Scheduling...\n"); |
| 302 | |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 303 | if (svc->flags & IP_VS_SVC_F_SCHED_SH_PORT) |
| 304 | port = ip_vs_sh_get_port(skb, iph); |
| 305 | |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 306 | s = (struct ip_vs_sh_state *) svc->sched_data; |
Alexander Frolkin | eba3b5a | 2013-06-19 10:54:25 +0100 | [diff] [blame] | 307 | |
| 308 | if (svc->flags & IP_VS_SVC_F_SCHED_SH_FALLBACK) |
| 309 | dest = ip_vs_sh_get_fallback(svc, s, &iph->saddr, port); |
| 310 | else |
| 311 | dest = ip_vs_sh_get(svc, s, &iph->saddr, port); |
| 312 | |
| 313 | if (!dest) { |
Patrick Schaaf | 41ac51e | 2011-02-11 14:01:12 +0100 | [diff] [blame] | 314 | ip_vs_scheduler_err(svc, "no destination available"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return NULL; |
| 316 | } |
| 317 | |
Julius Volz | 20971a0 | 2008-11-01 13:13:19 +0000 | [diff] [blame] | 318 | IP_VS_DBG_BUF(6, "SH: source IP address %s --> server %s:%d\n", |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 319 | IP_VS_DBG_ADDR(svc->af, &iph->saddr), |
Julius Volz | 20971a0 | 2008-11-01 13:13:19 +0000 | [diff] [blame] | 320 | IP_VS_DBG_ADDR(svc->af, &dest->addr), |
| 321 | ntohs(dest->port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | return dest; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* |
| 328 | * IPVS SH Scheduler structure |
| 329 | */ |
| 330 | static struct ip_vs_scheduler ip_vs_sh_scheduler = |
| 331 | { |
| 332 | .name = "sh", |
| 333 | .refcnt = ATOMIC_INIT(0), |
| 334 | .module = THIS_MODULE, |
Sven Wegener | d149ccc | 2008-08-10 09:18:02 +0000 | [diff] [blame] | 335 | .n_list = LIST_HEAD_INIT(ip_vs_sh_scheduler.n_list), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | .init_service = ip_vs_sh_init_svc, |
| 337 | .done_service = ip_vs_sh_done_svc, |
Julian Anastasov | 1acb7f6 | 2013-03-22 11:46:46 +0200 | [diff] [blame] | 338 | .add_dest = ip_vs_sh_dest_changed, |
| 339 | .del_dest = ip_vs_sh_dest_changed, |
| 340 | .upd_dest = ip_vs_sh_dest_changed, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | .schedule = ip_vs_sh_schedule, |
| 342 | }; |
| 343 | |
| 344 | |
| 345 | static int __init ip_vs_sh_init(void) |
| 346 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return register_ip_vs_scheduler(&ip_vs_sh_scheduler); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | static void __exit ip_vs_sh_cleanup(void) |
| 352 | { |
| 353 | unregister_ip_vs_scheduler(&ip_vs_sh_scheduler); |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 354 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
| 358 | module_init(ip_vs_sh_init); |
| 359 | module_exit(ip_vs_sh_cleanup); |
| 360 | MODULE_LICENSE("GPL"); |