blob: 796d70e47dddfcd7f291df239ddab8270819cbe5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPVS: Locality-Based Least-Connection with Replication scheduler
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 * Julian Anastasov : Added the missing (dest->weight>0)
13 * condition in the ip_vs_dest_set_max.
14 *
15 */
16
17/*
18 * The lblc/r algorithm is as follows (pseudo code):
19 *
20 * if serverSet[dest_ip] is null then
21 * n, serverSet[dest_ip] <- {weighted least-conn node};
22 * else
23 * n <- {least-conn (alive) node in serverSet[dest_ip]};
24 * if (n is null) OR
25 * (n.conns>n.weight AND
26 * there is a node m with m.conns<m.weight/2) then
27 * n <- {weighted least-conn node};
28 * add n to serverSet[dest_ip];
29 * if |serverSet[dest_ip]| > 1 AND
30 * now - serverSet[dest_ip].lastMod > T then
31 * m <- {most conn node in serverSet[dest_ip]};
32 * remove m from serverSet[dest_ip];
33 * if serverSet[dest_ip] changed then
34 * serverSet[dest_ip].lastMod <- now;
35 *
36 * return n;
37 *
38 */
39
Hannes Eder9aada7a2009-07-30 14:29:44 -070040#define KMSG_COMPONENT "IPVS"
41#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
42
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020043#include <linux/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/module.h>
45#include <linux/kernel.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020046#include <linux/skbuff.h>
Al Virod7fe0f22006-12-03 23:15:30 -050047#include <linux/jiffies.h>
Simon Horman51f0bc72010-02-26 17:45:14 +010048#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090049#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/* for sysctl */
52#include <linux/fs.h>
53#include <linux/sysctl.h>
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020054#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <net/ip_vs.h>
57
58
59/*
60 * It is for garbage collection of stale IPVS lblcr entries,
61 * when the table is full.
62 */
63#define CHECK_EXPIRE_INTERVAL (60*HZ)
64#define ENTRY_TIMEOUT (6*60*HZ)
65
Simon Hormanb27d7772011-02-04 18:33:01 +090066#define DEFAULT_EXPIRATION (24*60*60*HZ)
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/*
69 * It is for full expiration check.
70 * When there is no partial expiration check (garbage collection)
71 * in a half hour, do a full expiration check to collect stale
72 * entries that haven't been touched for a day.
73 */
74#define COUNT_FOR_FULL_EXPIRATION 30
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * for IPVS lblcr entry hash table
78 */
79#ifndef CONFIG_IP_VS_LBLCR_TAB_BITS
80#define CONFIG_IP_VS_LBLCR_TAB_BITS 10
81#endif
82#define IP_VS_LBLCR_TAB_BITS CONFIG_IP_VS_LBLCR_TAB_BITS
83#define IP_VS_LBLCR_TAB_SIZE (1 << IP_VS_LBLCR_TAB_BITS)
84#define IP_VS_LBLCR_TAB_MASK (IP_VS_LBLCR_TAB_SIZE - 1)
85
86
87/*
88 * IPVS destination set structure and operations
89 */
Simon Horman51f0bc72010-02-26 17:45:14 +010090struct ip_vs_dest_set_elem {
91 struct list_head list; /* list link */
Julian Anastasov742617b2013-09-12 11:21:09 +030092 struct ip_vs_dest *dest; /* destination server */
Julian Anastasovc5549572013-03-22 11:46:41 +020093 struct rcu_head rcu_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96struct ip_vs_dest_set {
97 atomic_t size; /* set size */
98 unsigned long lastmod; /* last modified time */
Simon Horman51f0bc72010-02-26 17:45:14 +010099 struct list_head list; /* destination list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102
Julian Anastasovc5549572013-03-22 11:46:41 +0200103static void ip_vs_dest_set_insert(struct ip_vs_dest_set *set,
104 struct ip_vs_dest *dest, bool check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Simon Horman51f0bc72010-02-26 17:45:14 +0100106 struct ip_vs_dest_set_elem *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Julian Anastasovc5549572013-03-22 11:46:41 +0200108 if (check) {
109 list_for_each_entry(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300110 if (e->dest == dest)
Julian Anastasovc5549572013-03-22 11:46:41 +0200111 return;
112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114
Sven Wegenerf728baf2008-08-19 08:16:19 +0200115 e = kmalloc(sizeof(*e), GFP_ATOMIC);
Joe Perches0a9ee812011-08-29 14:17:25 -0700116 if (e == NULL)
Julian Anastasovc5549572013-03-22 11:46:41 +0200117 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Julian Anastasovc5549572013-03-22 11:46:41 +0200119 ip_vs_dest_hold(dest);
Julian Anastasov742617b2013-09-12 11:21:09 +0300120 e->dest = dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Julian Anastasovc5549572013-03-22 11:46:41 +0200122 list_add_rcu(&e->list, &set->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 atomic_inc(&set->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 set->lastmod = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Julian Anastasov742617b2013-09-12 11:21:09 +0300128static void ip_vs_lblcr_elem_rcu_free(struct rcu_head *head)
129{
130 struct ip_vs_dest_set_elem *e;
131
132 e = container_of(head, struct ip_vs_dest_set_elem, rcu_head);
Julian Anastasov9e4e9482013-10-09 09:24:27 +0300133 ip_vs_dest_put_and_free(e->dest);
Julian Anastasov742617b2013-09-12 11:21:09 +0300134 kfree(e);
135}
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static void
138ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
139{
Simon Horman51f0bc72010-02-26 17:45:14 +0100140 struct ip_vs_dest_set_elem *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Simon Horman51f0bc72010-02-26 17:45:14 +0100142 list_for_each_entry(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300143 if (e->dest == dest) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* HIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 atomic_dec(&set->size);
146 set->lastmod = jiffies;
Julian Anastasovc5549572013-03-22 11:46:41 +0200147 list_del_rcu(&e->list);
Julian Anastasov742617b2013-09-12 11:21:09 +0300148 call_rcu(&e->rcu_head, ip_vs_lblcr_elem_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 break;
150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
155{
Simon Horman51f0bc72010-02-26 17:45:14 +0100156 struct ip_vs_dest_set_elem *e, *ep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Simon Horman51f0bc72010-02-26 17:45:14 +0100158 list_for_each_entry_safe(e, ep, &set->list, list) {
Julian Anastasovc5549572013-03-22 11:46:41 +0200159 list_del_rcu(&e->list);
Julian Anastasov742617b2013-09-12 11:21:09 +0300160 call_rcu(&e->rcu_head, ip_vs_lblcr_elem_rcu_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164/* get weighted least-connection node in the destination set */
165static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
166{
Simon Horman51f0bc72010-02-26 17:45:14 +0100167 register struct ip_vs_dest_set_elem *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 struct ip_vs_dest *dest, *least;
169 int loh, doh;
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 /* select the first destination server, whose weight > 0 */
Julian Anastasovc5549572013-03-22 11:46:41 +0200172 list_for_each_entry_rcu(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300173 least = e->dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (least->flags & IP_VS_DEST_F_OVERLOAD)
175 continue;
176
177 if ((atomic_read(&least->weight) > 0)
178 && (least->flags & IP_VS_DEST_F_AVAILABLE)) {
Changli Gaob552f7e2011-02-19 17:32:28 +0800179 loh = ip_vs_dest_conn_overhead(least);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 goto nextstage;
181 }
182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return NULL;
184
185 /* find the destination with the weighted least load */
186 nextstage:
Julian Anastasovc5549572013-03-22 11:46:41 +0200187 list_for_each_entry_continue_rcu(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300188 dest = e->dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
190 continue;
191
Changli Gaob552f7e2011-02-19 17:32:28 +0800192 doh = ip_vs_dest_conn_overhead(dest);
Simon Kirbyc16526a2013-08-10 01:26:18 -0700193 if (((__s64)loh * atomic_read(&dest->weight) >
194 (__s64)doh * atomic_read(&least->weight))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 && (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
196 least = dest;
197 loh = doh;
198 }
199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Hannes Eder1e3e2382009-08-02 11:05:41 +0000201 IP_VS_DBG_BUF(6, "%s(): server %s:%d "
Julius Volz44548372008-11-03 17:08:28 -0800202 "activeconns %d refcnt %d weight %d overhead %d\n",
Hannes Eder1e3e2382009-08-02 11:05:41 +0000203 __func__,
Julius Volz44548372008-11-03 17:08:28 -0800204 IP_VS_DBG_ADDR(least->af, &least->addr),
205 ntohs(least->port),
206 atomic_read(&least->activeconns),
207 atomic_read(&least->refcnt),
208 atomic_read(&least->weight), loh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return least;
210}
211
212
213/* get weighted most-connection node in the destination set */
214static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
215{
Simon Horman51f0bc72010-02-26 17:45:14 +0100216 register struct ip_vs_dest_set_elem *e;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 struct ip_vs_dest *dest, *most;
218 int moh, doh;
219
220 if (set == NULL)
221 return NULL;
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 /* select the first destination server, whose weight > 0 */
Simon Horman51f0bc72010-02-26 17:45:14 +0100224 list_for_each_entry(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300225 most = e->dest;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (atomic_read(&most->weight) > 0) {
Changli Gaob552f7e2011-02-19 17:32:28 +0800227 moh = ip_vs_dest_conn_overhead(most);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 goto nextstage;
229 }
230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 return NULL;
232
233 /* find the destination with the weighted most load */
234 nextstage:
Julian Anastasovc5549572013-03-22 11:46:41 +0200235 list_for_each_entry_continue(e, &set->list, list) {
Julian Anastasov742617b2013-09-12 11:21:09 +0300236 dest = e->dest;
Changli Gaob552f7e2011-02-19 17:32:28 +0800237 doh = ip_vs_dest_conn_overhead(dest);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */
Simon Kirbyc16526a2013-08-10 01:26:18 -0700239 if (((__s64)moh * atomic_read(&dest->weight) <
240 (__s64)doh * atomic_read(&most->weight))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 && (atomic_read(&dest->weight) > 0)) {
242 most = dest;
243 moh = doh;
244 }
245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Hannes Eder1e3e2382009-08-02 11:05:41 +0000247 IP_VS_DBG_BUF(6, "%s(): server %s:%d "
Julius Volz44548372008-11-03 17:08:28 -0800248 "activeconns %d refcnt %d weight %d overhead %d\n",
Hannes Eder1e3e2382009-08-02 11:05:41 +0000249 __func__,
Julius Volz44548372008-11-03 17:08:28 -0800250 IP_VS_DBG_ADDR(most->af, &most->addr), ntohs(most->port),
251 atomic_read(&most->activeconns),
252 atomic_read(&most->refcnt),
253 atomic_read(&most->weight), moh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return most;
255}
256
257
258/*
259 * IPVS lblcr entry represents an association between destination
260 * IP address and its destination server set
261 */
262struct ip_vs_lblcr_entry {
Julian Anastasovc5549572013-03-22 11:46:41 +0200263 struct hlist_node list;
Julius Volz44548372008-11-03 17:08:28 -0800264 int af; /* address family */
265 union nf_inet_addr addr; /* destination IP address */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 struct ip_vs_dest_set set; /* destination server set */
267 unsigned long lastuse; /* last used time */
Julian Anastasovc5549572013-03-22 11:46:41 +0200268 struct rcu_head rcu_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269};
270
271
272/*
273 * IPVS lblcr hash table
274 */
275struct ip_vs_lblcr_table {
Julian Anastasovc5549572013-03-22 11:46:41 +0200276 struct rcu_head rcu_head;
Julian Anastasovf33c8b92013-04-17 23:50:47 +0300277 struct hlist_head bucket[IP_VS_LBLCR_TAB_SIZE]; /* hash bucket */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 atomic_t entries; /* number of entries */
279 int max_size; /* maximum size of entries */
280 struct timer_list periodic_timer; /* collect stale entries */
281 int rover; /* rover for expire check */
282 int counter; /* counter for no expire */
Julian Anastasovc5549572013-03-22 11:46:41 +0200283 bool dead;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284};
285
286
Simon Hormanfb1de432011-02-04 18:33:02 +0900287#ifdef CONFIG_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288/*
289 * IPVS LBLCR sysctl table
290 */
291
Joe Perchesfe2c6332013-06-11 23:04:25 -0700292static struct ctl_table vs_vars_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 .procname = "lblcr_expiration",
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100295 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 .maxlen = sizeof(int),
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900297 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800298 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800300 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301};
Simon Hormanfb1de432011-02-04 18:33:02 +0900302#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304static inline void ip_vs_lblcr_free(struct ip_vs_lblcr_entry *en)
305{
Julian Anastasovc5549572013-03-22 11:46:41 +0200306 hlist_del_rcu(&en->list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 ip_vs_dest_set_eraseall(&en->set);
Julian Anastasovc5549572013-03-22 11:46:41 +0200308 kfree_rcu(en, rcu_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
311
312/*
313 * Returns hash value for IPVS LBLCR entry
314 */
Eric Dumazet95c96172012-04-15 05:58:06 +0000315static inline unsigned int
Julius Volz44548372008-11-03 17:08:28 -0800316ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Julius Volz44548372008-11-03 17:08:28 -0800318 __be32 addr_fold = addr->ip;
319
320#ifdef CONFIG_IP_VS_IPV6
321 if (af == AF_INET6)
322 addr_fold = addr->ip6[0]^addr->ip6[1]^
323 addr->ip6[2]^addr->ip6[3];
324#endif
325 return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
328
329/*
330 * Hash an entry in the ip_vs_lblcr_table.
331 * returns bool success.
332 */
Sven Wegenerf728baf2008-08-19 08:16:19 +0200333static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en)
335{
Eric Dumazet95c96172012-04-15 05:58:06 +0000336 unsigned int hash = ip_vs_lblcr_hashkey(en->af, &en->addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Julian Anastasovc5549572013-03-22 11:46:41 +0200338 hlist_add_head_rcu(&en->list, &tbl->bucket[hash]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 atomic_inc(&tbl->entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
342
Julian Anastasovc5549572013-03-22 11:46:41 +0200343/* Get ip_vs_lblcr_entry associated with supplied parameters. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344static inline struct ip_vs_lblcr_entry *
Julius Volz44548372008-11-03 17:08:28 -0800345ip_vs_lblcr_get(int af, struct ip_vs_lblcr_table *tbl,
346 const union nf_inet_addr *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Eric Dumazet95c96172012-04-15 05:58:06 +0000348 unsigned int hash = ip_vs_lblcr_hashkey(af, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 struct ip_vs_lblcr_entry *en;
350
Julian Anastasovc5549572013-03-22 11:46:41 +0200351 hlist_for_each_entry_rcu(en, &tbl->bucket[hash], list)
Julius Volz44548372008-11-03 17:08:28 -0800352 if (ip_vs_addr_equal(af, &en->addr, addr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return en;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 return NULL;
356}
357
358
359/*
Sven Wegenerf728baf2008-08-19 08:16:19 +0200360 * Create or update an ip_vs_lblcr_entry, which is a mapping of a destination
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200361 * IP address to a server. Called under spin lock.
Sven Wegenerf728baf2008-08-19 08:16:19 +0200362 */
363static inline struct ip_vs_lblcr_entry *
Julius Volz44548372008-11-03 17:08:28 -0800364ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
Julian Anastasovcf34e642014-09-09 16:40:30 -0700365 u16 af, struct ip_vs_dest *dest)
Sven Wegenerf728baf2008-08-19 08:16:19 +0200366{
367 struct ip_vs_lblcr_entry *en;
368
Julian Anastasovcf34e642014-09-09 16:40:30 -0700369 en = ip_vs_lblcr_get(af, tbl, daddr);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200370 if (!en) {
371 en = kmalloc(sizeof(*en), GFP_ATOMIC);
Joe Perches0a9ee812011-08-29 14:17:25 -0700372 if (!en)
Sven Wegenerf728baf2008-08-19 08:16:19 +0200373 return NULL;
Sven Wegenerf728baf2008-08-19 08:16:19 +0200374
Julian Anastasovcf34e642014-09-09 16:40:30 -0700375 en->af = af;
376 ip_vs_addr_copy(af, &en->addr, daddr);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200377 en->lastuse = jiffies;
378
Uwe Kleine-König421f91d2010-06-11 12:17:00 +0200379 /* initialize its dest set */
Sven Wegenerf728baf2008-08-19 08:16:19 +0200380 atomic_set(&(en->set.size), 0);
Simon Horman51f0bc72010-02-26 17:45:14 +0100381 INIT_LIST_HEAD(&en->set.list);
Julian Anastasovc5549572013-03-22 11:46:41 +0200382
383 ip_vs_dest_set_insert(&en->set, dest, false);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200384
385 ip_vs_lblcr_hash(tbl, en);
Julian Anastasovc5549572013-03-22 11:46:41 +0200386 return en;
Sven Wegenerf728baf2008-08-19 08:16:19 +0200387 }
388
Julian Anastasovc5549572013-03-22 11:46:41 +0200389 ip_vs_dest_set_insert(&en->set, dest, true);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200390
391 return en;
392}
393
394
395/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 * Flush all the entries of the specified table.
397 */
Julian Anastasovc5549572013-03-22 11:46:41 +0200398static void ip_vs_lblcr_flush(struct ip_vs_service *svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Julian Anastasovc5549572013-03-22 11:46:41 +0200400 struct ip_vs_lblcr_table *tbl = svc->sched_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 int i;
Julian Anastasovc5549572013-03-22 11:46:41 +0200402 struct ip_vs_lblcr_entry *en;
403 struct hlist_node *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200405 spin_lock_bh(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200406 tbl->dead = 1;
Dragos Foianu70e3ca72013-07-11 09:45:42 +0300407 for (i = 0; i < IP_VS_LBLCR_TAB_SIZE; i++) {
Julian Anastasovc5549572013-03-22 11:46:41 +0200408 hlist_for_each_entry_safe(en, next, &tbl->bucket[i], list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 ip_vs_lblcr_free(en);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200412 spin_unlock_bh(&svc->sched_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Simon Hormanb27d7772011-02-04 18:33:01 +0900415static int sysctl_lblcr_expiration(struct ip_vs_service *svc)
416{
417#ifdef CONFIG_SYSCTL
Eric W. Biederman3109d2f2015-09-21 13:01:44 -0500418 return svc->ipvs->sysctl_lblcr_expiration;
Simon Hormanb27d7772011-02-04 18:33:01 +0900419#else
420 return DEFAULT_EXPIRATION;
421#endif
422}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Sven Wegenerf728baf2008-08-19 08:16:19 +0200424static inline void ip_vs_lblcr_full_check(struct ip_vs_service *svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
Sven Wegenerf728baf2008-08-19 08:16:19 +0200426 struct ip_vs_lblcr_table *tbl = svc->sched_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 unsigned long now = jiffies;
428 int i, j;
Julian Anastasovc5549572013-03-22 11:46:41 +0200429 struct ip_vs_lblcr_entry *en;
430 struct hlist_node *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Dragos Foianu70e3ca72013-07-11 09:45:42 +0300432 for (i = 0, j = tbl->rover; i < IP_VS_LBLCR_TAB_SIZE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
434
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200435 spin_lock(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200436 hlist_for_each_entry_safe(en, next, &tbl->bucket[j], list) {
Simon Hormanb27d7772011-02-04 18:33:01 +0900437 if (time_after(en->lastuse +
438 sysctl_lblcr_expiration(svc), now))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 continue;
440
441 ip_vs_lblcr_free(en);
442 atomic_dec(&tbl->entries);
443 }
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200444 spin_unlock(&svc->sched_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446 tbl->rover = j;
447}
448
449
450/*
451 * Periodical timer handler for IPVS lblcr table
452 * It is used to collect stale entries when the number of entries
453 * exceeds the maximum size of the table.
454 *
455 * Fixme: we probably need more complicated algorithm to collect
456 * entries that have not been used for a long time even
457 * if the number of entries doesn't exceed the maximum size
458 * of the table.
459 * The full expiration check is for this purpose now.
460 */
461static void ip_vs_lblcr_check_expire(unsigned long data)
462{
Sven Wegenerf728baf2008-08-19 08:16:19 +0200463 struct ip_vs_service *svc = (struct ip_vs_service *) data;
464 struct ip_vs_lblcr_table *tbl = svc->sched_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 unsigned long now = jiffies;
466 int goal;
467 int i, j;
Julian Anastasovc5549572013-03-22 11:46:41 +0200468 struct ip_vs_lblcr_entry *en;
469 struct hlist_node *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if ((tbl->counter % COUNT_FOR_FULL_EXPIRATION) == 0) {
472 /* do full expiration check */
Sven Wegenerf728baf2008-08-19 08:16:19 +0200473 ip_vs_lblcr_full_check(svc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 tbl->counter = 1;
475 goto out;
476 }
477
478 if (atomic_read(&tbl->entries) <= tbl->max_size) {
479 tbl->counter++;
480 goto out;
481 }
482
483 goal = (atomic_read(&tbl->entries) - tbl->max_size)*4/3;
484 if (goal > tbl->max_size/2)
485 goal = tbl->max_size/2;
486
Dragos Foianu70e3ca72013-07-11 09:45:42 +0300487 for (i = 0, j = tbl->rover; i < IP_VS_LBLCR_TAB_SIZE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
489
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200490 spin_lock(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200491 hlist_for_each_entry_safe(en, next, &tbl->bucket[j], list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (time_before(now, en->lastuse+ENTRY_TIMEOUT))
493 continue;
494
495 ip_vs_lblcr_free(en);
496 atomic_dec(&tbl->entries);
497 goal--;
498 }
Julian Anastasovba3a3ce2013-03-22 11:46:51 +0200499 spin_unlock(&svc->sched_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (goal <= 0)
501 break;
502 }
503 tbl->rover = j;
504
505 out:
506 mod_timer(&tbl->periodic_timer, jiffies+CHECK_EXPIRE_INTERVAL);
507}
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)
510{
511 int i;
512 struct ip_vs_lblcr_table *tbl;
513
514 /*
515 * Allocate the ip_vs_lblcr_table for this service
516 */
Julian Anastasov45d4e712012-04-13 16:49:41 +0300517 tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
Joe Perches0a9ee812011-08-29 14:17:25 -0700518 if (tbl == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return -ENOMEM;
Joe Perches0a9ee812011-08-29 14:17:25 -0700520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 svc->sched_data = tbl;
522 IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) allocated for "
Sven Wegenerf728baf2008-08-19 08:16:19 +0200523 "current service\n", sizeof(*tbl));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 /*
526 * Initialize the hash buckets
527 */
Dragos Foianu70e3ca72013-07-11 09:45:42 +0300528 for (i = 0; i < IP_VS_LBLCR_TAB_SIZE; i++) {
Julian Anastasovc5549572013-03-22 11:46:41 +0200529 INIT_HLIST_HEAD(&tbl->bucket[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 tbl->max_size = IP_VS_LBLCR_TAB_SIZE*16;
532 tbl->rover = 0;
533 tbl->counter = 1;
Julian Anastasovc5549572013-03-22 11:46:41 +0200534 tbl->dead = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /*
537 * Hook periodic timer for garbage collection
538 */
Pavel Emelyanovb24b8a22008-01-23 21:20:07 -0800539 setup_timer(&tbl->periodic_timer, ip_vs_lblcr_check_expire,
Sven Wegenerf728baf2008-08-19 08:16:19 +0200540 (unsigned long)svc);
541 mod_timer(&tbl->periodic_timer, jiffies + CHECK_EXPIRE_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return 0;
544}
545
546
Julian Anastasoved3ffc42013-03-22 11:46:50 +0200547static void ip_vs_lblcr_done_svc(struct ip_vs_service *svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
549 struct ip_vs_lblcr_table *tbl = svc->sched_data;
550
551 /* remove periodic timer */
552 del_timer_sync(&tbl->periodic_timer);
553
554 /* got to clean up table entries here */
Julian Anastasovc5549572013-03-22 11:46:41 +0200555 ip_vs_lblcr_flush(svc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /* release the table itself */
Julian Anastasovc5549572013-03-22 11:46:41 +0200558 kfree_rcu(tbl, rcu_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) released\n",
Sven Wegenerf728baf2008-08-19 08:16:19 +0200560 sizeof(*tbl));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564static inline struct ip_vs_dest *
Julius Volz44548372008-11-03 17:08:28 -0800565__ip_vs_lblcr_schedule(struct ip_vs_service *svc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
567 struct ip_vs_dest *dest, *least;
568 int loh, doh;
569
570 /*
Changli Gaob552f7e2011-02-19 17:32:28 +0800571 * We use the following formula to estimate the load:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * (dest overhead) / dest->weight
573 *
574 * Remember -- no floats in kernel mode!!!
575 * The comparison of h1*w2 > h2*w1 is equivalent to that of
576 * h1/w1 > h2/w2
577 * if every weight is larger than zero.
578 *
579 * The server with weight=0 is quiesced and will not receive any
580 * new connection.
581 */
Julian Anastasovc5549572013-03-22 11:46:41 +0200582 list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
584 continue;
585
586 if (atomic_read(&dest->weight) > 0) {
587 least = dest;
Changli Gaob552f7e2011-02-19 17:32:28 +0800588 loh = ip_vs_dest_conn_overhead(least);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 goto nextstage;
590 }
591 }
592 return NULL;
593
594 /*
595 * Find the destination with the least load.
596 */
597 nextstage:
Julian Anastasovc5549572013-03-22 11:46:41 +0200598 list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if (dest->flags & IP_VS_DEST_F_OVERLOAD)
600 continue;
601
Changli Gaob552f7e2011-02-19 17:32:28 +0800602 doh = ip_vs_dest_conn_overhead(dest);
Simon Kirbyc16526a2013-08-10 01:26:18 -0700603 if ((__s64)loh * atomic_read(&dest->weight) >
604 (__s64)doh * atomic_read(&least->weight)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 least = dest;
606 loh = doh;
607 }
608 }
609
Julius Volz44548372008-11-03 17:08:28 -0800610 IP_VS_DBG_BUF(6, "LBLCR: server %s:%d "
611 "activeconns %d refcnt %d weight %d overhead %d\n",
612 IP_VS_DBG_ADDR(least->af, &least->addr),
613 ntohs(least->port),
614 atomic_read(&least->activeconns),
615 atomic_read(&least->refcnt),
616 atomic_read(&least->weight), loh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 return least;
619}
620
621
622/*
623 * If this destination server is overloaded and there is a less loaded
624 * server, then return true.
625 */
626static inline int
627is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
628{
629 if (atomic_read(&dest->activeconns) > atomic_read(&dest->weight)) {
630 struct ip_vs_dest *d;
631
Julian Anastasovc5549572013-03-22 11:46:41 +0200632 list_for_each_entry_rcu(d, &svc->destinations, n_list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (atomic_read(&d->activeconns)*2
634 < atomic_read(&d->weight)) {
635 return 1;
636 }
637 }
638 }
639 return 0;
640}
641
642
643/*
644 * Locality-Based (weighted) Least-Connection scheduling
645 */
646static struct ip_vs_dest *
Julian Anastasovbba54de2013-06-16 09:09:36 +0300647ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
648 struct ip_vs_iphdr *iph)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Sven Wegenerf728baf2008-08-19 08:16:19 +0200650 struct ip_vs_lblcr_table *tbl = svc->sched_data;
Julian Anastasovc5549572013-03-22 11:46:41 +0200651 struct ip_vs_dest *dest;
Sven Wegenerf728baf2008-08-19 08:16:19 +0200652 struct ip_vs_lblcr_entry *en;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Hannes Eder1e3e2382009-08-02 11:05:41 +0000654 IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Sven Wegenerf728baf2008-08-19 08:16:19 +0200656 /* First look in our cache */
Julian Anastasovbba54de2013-06-16 09:09:36 +0300657 en = ip_vs_lblcr_get(svc->af, tbl, &iph->daddr);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200658 if (en) {
Sven Wegenerf728baf2008-08-19 08:16:19 +0200659 en->lastuse = jiffies;
660
661 /* Get the least loaded destination */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 dest = ip_vs_dest_set_min(&en->set);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200663
664 /* More than one destination + enough time passed by, cleanup */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 if (atomic_read(&en->set.size) > 1 &&
Julian Anastasovc5549572013-03-22 11:46:41 +0200666 time_after(jiffies, en->set.lastmod +
Simon Hormanb27d7772011-02-04 18:33:01 +0900667 sysctl_lblcr_expiration(svc))) {
Julian Anastasovac692692013-03-22 11:46:54 +0200668 spin_lock_bh(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200669 if (atomic_read(&en->set.size) > 1) {
670 struct ip_vs_dest *m;
Sven Wegenerf728baf2008-08-19 08:16:19 +0200671
Julian Anastasovc5549572013-03-22 11:46:41 +0200672 m = ip_vs_dest_set_max(&en->set);
673 if (m)
674 ip_vs_dest_set_erase(&en->set, m);
675 }
Julian Anastasovac692692013-03-22 11:46:54 +0200676 spin_unlock_bh(&svc->sched_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Sven Wegenerf728baf2008-08-19 08:16:19 +0200679 /* If the destination is not overloaded, use it */
Julian Anastasovc5549572013-03-22 11:46:41 +0200680 if (dest && !is_overloaded(dest, svc))
Sven Wegenerf728baf2008-08-19 08:16:19 +0200681 goto out;
Sven Wegenerf728baf2008-08-19 08:16:19 +0200682
683 /* The cache entry is invalid, time to schedule */
Julius Volz44548372008-11-03 17:08:28 -0800684 dest = __ip_vs_lblcr_schedule(svc);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200685 if (!dest) {
Patrick Schaaf41ac51e2011-02-11 14:01:12 +0100686 ip_vs_scheduler_err(svc, "no destination available");
Sven Wegenerf728baf2008-08-19 08:16:19 +0200687 return NULL;
688 }
689
690 /* Update our cache entry */
Julian Anastasovac692692013-03-22 11:46:54 +0200691 spin_lock_bh(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200692 if (!tbl->dead)
693 ip_vs_dest_set_insert(&en->set, dest, true);
Julian Anastasovac692692013-03-22 11:46:54 +0200694 spin_unlock_bh(&svc->sched_lock);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200695 goto out;
Julian Anastasovc5549572013-03-22 11:46:41 +0200696 }
Sven Wegenerf728baf2008-08-19 08:16:19 +0200697
698 /* No cache entry, time to schedule */
Julius Volz44548372008-11-03 17:08:28 -0800699 dest = __ip_vs_lblcr_schedule(svc);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200700 if (!dest) {
701 IP_VS_DBG(1, "no destination available\n");
702 return NULL;
703 }
704
705 /* If we fail to create a cache entry, we'll just use the valid dest */
Julian Anastasovac692692013-03-22 11:46:54 +0200706 spin_lock_bh(&svc->sched_lock);
Julian Anastasovc5549572013-03-22 11:46:41 +0200707 if (!tbl->dead)
Julian Anastasovcf34e642014-09-09 16:40:30 -0700708 ip_vs_lblcr_new(tbl, &iph->daddr, svc->af, dest);
Julian Anastasovac692692013-03-22 11:46:54 +0200709 spin_unlock_bh(&svc->sched_lock);
Sven Wegenerf728baf2008-08-19 08:16:19 +0200710
711out:
Julius Volz44548372008-11-03 17:08:28 -0800712 IP_VS_DBG_BUF(6, "LBLCR: destination IP address %s --> server %s:%d\n",
Julian Anastasovbba54de2013-06-16 09:09:36 +0300713 IP_VS_DBG_ADDR(svc->af, &iph->daddr),
Julian Anastasovcf34e642014-09-09 16:40:30 -0700714 IP_VS_DBG_ADDR(dest->af, &dest->addr), ntohs(dest->port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 return dest;
717}
718
719
720/*
721 * IPVS LBLCR Scheduler structure
722 */
723static struct ip_vs_scheduler ip_vs_lblcr_scheduler =
724{
725 .name = "lblcr",
726 .refcnt = ATOMIC_INIT(0),
727 .module = THIS_MODULE,
Sven Wegenerd149ccc2008-08-10 09:18:02 +0000728 .n_list = LIST_HEAD_INIT(ip_vs_lblcr_scheduler.n_list),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .init_service = ip_vs_lblcr_init_svc,
730 .done_service = ip_vs_lblcr_done_svc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .schedule = ip_vs_lblcr_schedule,
732};
733
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100734/*
735 * per netns init.
736 */
Simon Hormanfb1de432011-02-04 18:33:02 +0900737#ifdef CONFIG_SYSCTL
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100738static int __net_init __ip_vs_lblcr_init(struct net *net)
739{
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100740 struct netns_ipvs *ipvs = net_ipvs(net);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100741
Hans Schillstrom4b984cd2012-04-26 09:45:34 +0200742 if (!ipvs)
743 return -ENOENT;
744
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100745 if (!net_eq(net, &init_net)) {
746 ipvs->lblcr_ctl_table = kmemdup(vs_vars_table,
747 sizeof(vs_vars_table),
748 GFP_KERNEL);
749 if (ipvs->lblcr_ctl_table == NULL)
Simon Horman04439292011-02-01 18:29:04 +0100750 return -ENOMEM;
Eric W. Biederman464dc802012-11-16 03:02:59 +0000751
752 /* Don't export sysctls to unprivileged users */
753 if (net->user_ns != &init_user_ns)
754 ipvs->lblcr_ctl_table[0].procname = NULL;
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100755 } else
756 ipvs->lblcr_ctl_table = vs_vars_table;
Simon Hormanb27d7772011-02-04 18:33:01 +0900757 ipvs->sysctl_lblcr_expiration = DEFAULT_EXPIRATION;
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100758 ipvs->lblcr_ctl_table[0].data = &ipvs->sysctl_lblcr_expiration;
759
760 ipvs->lblcr_ctl_header =
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000761 register_net_sysctl(net, "net/ipv4/vs", ipvs->lblcr_ctl_table);
Simon Horman04439292011-02-01 18:29:04 +0100762 if (!ipvs->lblcr_ctl_header) {
763 if (!net_eq(net, &init_net))
764 kfree(ipvs->lblcr_ctl_table);
765 return -ENOMEM;
766 }
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100767
768 return 0;
769}
770
771static void __net_exit __ip_vs_lblcr_exit(struct net *net)
772{
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100773 struct netns_ipvs *ipvs = net_ipvs(net);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100774
Hans Schillstromd0a1eef2011-01-03 14:44:44 +0100775 unregister_net_sysctl_table(ipvs->lblcr_ctl_header);
776
777 if (!net_eq(net, &init_net))
778 kfree(ipvs->lblcr_ctl_table);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100779}
780
Simon Hormanfb1de432011-02-04 18:33:02 +0900781#else
782
783static int __net_init __ip_vs_lblcr_init(struct net *net) { return 0; }
784static void __net_exit __ip_vs_lblcr_exit(struct net *net) { }
785
786#endif
787
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100788static struct pernet_operations ip_vs_lblcr_ops = {
789 .init = __ip_vs_lblcr_init,
790 .exit = __ip_vs_lblcr_exit,
791};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793static int __init ip_vs_lblcr_init(void)
794{
Pavel Emelyanova014bc82007-12-04 00:43:24 -0800795 int ret;
796
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100797 ret = register_pernet_subsys(&ip_vs_lblcr_ops);
798 if (ret)
799 return ret;
800
Pavel Emelyanova014bc82007-12-04 00:43:24 -0800801 ret = register_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
802 if (ret)
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100803 unregister_pernet_subsys(&ip_vs_lblcr_ops);
Pavel Emelyanova014bc82007-12-04 00:43:24 -0800804 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807static void __exit ip_vs_lblcr_cleanup(void)
808{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 unregister_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
Hans Schillstrom61b1ab42011-01-03 14:44:42 +0100810 unregister_pernet_subsys(&ip_vs_lblcr_ops);
Julian Anastasov742617b2013-09-12 11:21:09 +0300811 rcu_barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
814
815module_init(ip_vs_lblcr_init);
816module_exit(ip_vs_lblcr_cleanup);
817MODULE_LICENSE("GPL");