Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IPVS: Locality-Based Least-Connection 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 | * Martin Hamilton : fixed the terrible locking bugs |
| 13 | * *lock(tbl->lock) ==> *lock(&tbl->lock) |
Uwe Kleine-König | 421f91d | 2010-06-11 12:17:00 +0200 | [diff] [blame] | 14 | * Wensong Zhang : fixed the uninitialized tbl->lock bug |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Wensong Zhang : added doing full expiration check to |
| 16 | * collect stale entries of 24+ hours when |
| 17 | * no partial expire check in a half hour |
| 18 | * Julian Anastasov : replaced del_timer call with del_timer_sync |
| 19 | * to avoid the possible race between timer |
| 20 | * handler and del_timer thread in SMP |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * The lblc algorithm is as follows (pseudo code): |
| 26 | * |
| 27 | * if cachenode[dest_ip] is null then |
| 28 | * n, cachenode[dest_ip] <- {weighted least-conn node}; |
| 29 | * else |
| 30 | * n <- cachenode[dest_ip]; |
| 31 | * if (n is dead) OR |
| 32 | * (n.conns>n.weight AND |
| 33 | * there is a node m with m.conns<m.weight/2) then |
| 34 | * n, cachenode[dest_ip] <- {weighted least-conn node}; |
| 35 | * |
| 36 | * return n; |
| 37 | * |
| 38 | * Thanks must go to Wenzhuo Zhang for talking WCCP to me and pushing |
| 39 | * me to write this module. |
| 40 | */ |
| 41 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 42 | #define KMSG_COMPONENT "IPVS" |
| 43 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 44 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 45 | #include <linux/ip.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 46 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/kernel.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 49 | #include <linux/skbuff.h> |
Al Viro | d7fe0f2 | 2006-12-03 23:15:30 -0500 | [diff] [blame] | 50 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* for sysctl */ |
| 53 | #include <linux/fs.h> |
| 54 | #include <linux/sysctl.h> |
| 55 | |
| 56 | #include <net/ip_vs.h> |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | * It is for garbage collection of stale IPVS lblc entries, |
| 61 | * when the table is full. |
| 62 | */ |
| 63 | #define CHECK_EXPIRE_INTERVAL (60*HZ) |
| 64 | #define ENTRY_TIMEOUT (6*60*HZ) |
| 65 | |
Simon Horman | b27d777 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 66 | #define DEFAULT_EXPIRATION (24*60*60*HZ) |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | |
| 77 | /* |
| 78 | * for IPVS lblc entry hash table |
| 79 | */ |
| 80 | #ifndef CONFIG_IP_VS_LBLC_TAB_BITS |
| 81 | #define CONFIG_IP_VS_LBLC_TAB_BITS 10 |
| 82 | #endif |
| 83 | #define IP_VS_LBLC_TAB_BITS CONFIG_IP_VS_LBLC_TAB_BITS |
| 84 | #define IP_VS_LBLC_TAB_SIZE (1 << IP_VS_LBLC_TAB_BITS) |
| 85 | #define IP_VS_LBLC_TAB_MASK (IP_VS_LBLC_TAB_SIZE - 1) |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * IPVS lblc entry represents an association between destination |
| 90 | * IP address and its destination server |
| 91 | */ |
| 92 | struct ip_vs_lblc_entry { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 93 | struct hlist_node list; |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 94 | int af; /* address family */ |
| 95 | union nf_inet_addr addr; /* destination IP address */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 96 | struct ip_vs_dest __rcu *dest; /* real server (cache) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | unsigned long lastuse; /* last used time */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 98 | struct rcu_head rcu_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | * IPVS lblc hash table |
| 104 | */ |
| 105 | struct ip_vs_lblc_table { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 106 | struct rcu_head rcu_head; |
Julian Anastasov | f33c8b9 | 2013-04-17 23:50:47 +0300 | [diff] [blame] | 107 | struct hlist_head bucket[IP_VS_LBLC_TAB_SIZE]; /* hash bucket */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 108 | struct timer_list periodic_timer; /* collect stale entries */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | atomic_t entries; /* number of entries */ |
| 110 | int max_size; /* maximum size of entries */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int rover; /* rover for expire check */ |
| 112 | int counter; /* counter for no expire */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 113 | bool dead; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * IPVS LBLC sysctl table |
| 119 | */ |
Simon Horman | fb1de43 | 2011-02-04 18:33:02 +0900 | [diff] [blame] | 120 | #ifdef CONFIG_SYSCTL |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 121 | static struct ctl_table vs_vars_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | .procname = "lblc_expiration", |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 124 | .data = NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | .maxlen = sizeof(int), |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 126 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 127 | .proc_handler = proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 129 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | }; |
Simon Horman | fb1de43 | 2011-02-04 18:33:02 +0900 | [diff] [blame] | 131 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static inline void ip_vs_lblc_free(struct ip_vs_lblc_entry *en) |
| 134 | { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 135 | struct ip_vs_dest *dest; |
| 136 | |
| 137 | hlist_del_rcu(&en->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 139 | * We don't kfree dest because it is referred either by its service |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * or the trash dest list. |
| 141 | */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 142 | dest = rcu_dereference_protected(en->dest, 1); |
| 143 | ip_vs_dest_put(dest); |
| 144 | kfree_rcu(en, rcu_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | * Returns hash value for IPVS LBLC entry |
| 150 | */ |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 151 | static inline unsigned int |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 152 | ip_vs_lblc_hashkey(int af, const union nf_inet_addr *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 154 | __be32 addr_fold = addr->ip; |
| 155 | |
| 156 | #ifdef CONFIG_IP_VS_IPV6 |
| 157 | if (af == AF_INET6) |
| 158 | addr_fold = addr->ip6[0]^addr->ip6[1]^ |
| 159 | addr->ip6[2]^addr->ip6[3]; |
| 160 | #endif |
| 161 | return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLC_TAB_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
| 165 | /* |
| 166 | * Hash an entry in the ip_vs_lblc_table. |
| 167 | * returns bool success. |
| 168 | */ |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 169 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | ip_vs_lblc_hash(struct ip_vs_lblc_table *tbl, struct ip_vs_lblc_entry *en) |
| 171 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 172 | unsigned int hash = ip_vs_lblc_hashkey(en->af, &en->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 174 | hlist_add_head_rcu(&en->list, &tbl->bucket[hash]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | atomic_inc(&tbl->entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 179 | /* Get ip_vs_lblc_entry associated with supplied parameters. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | static inline struct ip_vs_lblc_entry * |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 181 | ip_vs_lblc_get(int af, struct ip_vs_lblc_table *tbl, |
| 182 | const union nf_inet_addr *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 184 | unsigned int hash = ip_vs_lblc_hashkey(af, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct ip_vs_lblc_entry *en; |
| 186 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 187 | hlist_for_each_entry_rcu(en, &tbl->bucket[hash], list) |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 188 | if (ip_vs_addr_equal(af, &en->addr, addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return en; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | /* |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 196 | * Create or update an ip_vs_lblc_entry, which is a mapping of a destination IP |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 197 | * address to a server. Called under spin lock. |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 198 | */ |
| 199 | static inline struct ip_vs_lblc_entry * |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 200 | ip_vs_lblc_new(struct ip_vs_lblc_table *tbl, const union nf_inet_addr *daddr, |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 201 | struct ip_vs_dest *dest) |
| 202 | { |
| 203 | struct ip_vs_lblc_entry *en; |
| 204 | |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 205 | en = ip_vs_lblc_get(dest->af, tbl, daddr); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 206 | if (!en) { |
| 207 | en = kmalloc(sizeof(*en), GFP_ATOMIC); |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 208 | if (!en) |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 209 | return NULL; |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 210 | |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 211 | en->af = dest->af; |
| 212 | ip_vs_addr_copy(dest->af, &en->addr, daddr); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 213 | en->lastuse = jiffies; |
| 214 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 215 | ip_vs_dest_hold(dest); |
| 216 | RCU_INIT_POINTER(en->dest, dest); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 217 | |
| 218 | ip_vs_lblc_hash(tbl, en); |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 219 | } else { |
| 220 | struct ip_vs_dest *old_dest; |
| 221 | |
| 222 | old_dest = rcu_dereference_protected(en->dest, 1); |
| 223 | if (old_dest != dest) { |
| 224 | ip_vs_dest_put(old_dest); |
| 225 | ip_vs_dest_hold(dest); |
| 226 | /* No ordering constraints for refcnt */ |
| 227 | RCU_INIT_POINTER(en->dest, dest); |
| 228 | } |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return en; |
| 232 | } |
| 233 | |
| 234 | |
| 235 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | * Flush all the entries of the specified table. |
| 237 | */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 238 | static void ip_vs_lblc_flush(struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 240 | struct ip_vs_lblc_table *tbl = svc->sched_data; |
| 241 | struct ip_vs_lblc_entry *en; |
| 242 | struct hlist_node *next; |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 243 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 245 | spin_lock_bh(&svc->sched_lock); |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 246 | tbl->dead = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | for (i=0; i<IP_VS_LBLC_TAB_SIZE; i++) { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 248 | hlist_for_each_entry_safe(en, next, &tbl->bucket[i], list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | ip_vs_lblc_free(en); |
| 250 | atomic_dec(&tbl->entries); |
| 251 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | } |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 253 | spin_unlock_bh(&svc->sched_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Simon Horman | b27d777 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 256 | static int sysctl_lblc_expiration(struct ip_vs_service *svc) |
| 257 | { |
| 258 | #ifdef CONFIG_SYSCTL |
| 259 | struct netns_ipvs *ipvs = net_ipvs(svc->net); |
| 260 | return ipvs->sysctl_lblc_expiration; |
| 261 | #else |
| 262 | return DEFAULT_EXPIRATION; |
| 263 | #endif |
| 264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 266 | static inline void ip_vs_lblc_full_check(struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 268 | struct ip_vs_lblc_table *tbl = svc->sched_data; |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 269 | struct ip_vs_lblc_entry *en; |
| 270 | struct hlist_node *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned long now = jiffies; |
| 272 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | for (i=0, j=tbl->rover; i<IP_VS_LBLC_TAB_SIZE; i++) { |
| 275 | j = (j + 1) & IP_VS_LBLC_TAB_MASK; |
| 276 | |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 277 | spin_lock(&svc->sched_lock); |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 278 | hlist_for_each_entry_safe(en, next, &tbl->bucket[j], list) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 279 | if (time_before(now, |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 280 | en->lastuse + |
Simon Horman | b27d777 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 281 | sysctl_lblc_expiration(svc))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | continue; |
| 283 | |
| 284 | ip_vs_lblc_free(en); |
| 285 | atomic_dec(&tbl->entries); |
| 286 | } |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 287 | spin_unlock(&svc->sched_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | tbl->rover = j; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /* |
| 294 | * Periodical timer handler for IPVS lblc table |
| 295 | * It is used to collect stale entries when the number of entries |
| 296 | * exceeds the maximum size of the table. |
| 297 | * |
| 298 | * Fixme: we probably need more complicated algorithm to collect |
| 299 | * entries that have not been used for a long time even |
| 300 | * if the number of entries doesn't exceed the maximum size |
| 301 | * of the table. |
| 302 | * The full expiration check is for this purpose now. |
| 303 | */ |
| 304 | static void ip_vs_lblc_check_expire(unsigned long data) |
| 305 | { |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 306 | struct ip_vs_service *svc = (struct ip_vs_service *) data; |
| 307 | struct ip_vs_lblc_table *tbl = svc->sched_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | unsigned long now = jiffies; |
| 309 | int goal; |
| 310 | int i, j; |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 311 | struct ip_vs_lblc_entry *en; |
| 312 | struct hlist_node *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if ((tbl->counter % COUNT_FOR_FULL_EXPIRATION) == 0) { |
| 315 | /* do full expiration check */ |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 316 | ip_vs_lblc_full_check(svc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | tbl->counter = 1; |
| 318 | goto out; |
| 319 | } |
| 320 | |
| 321 | if (atomic_read(&tbl->entries) <= tbl->max_size) { |
| 322 | tbl->counter++; |
| 323 | goto out; |
| 324 | } |
| 325 | |
| 326 | goal = (atomic_read(&tbl->entries) - tbl->max_size)*4/3; |
| 327 | if (goal > tbl->max_size/2) |
| 328 | goal = tbl->max_size/2; |
| 329 | |
| 330 | for (i=0, j=tbl->rover; i<IP_VS_LBLC_TAB_SIZE; i++) { |
| 331 | j = (j + 1) & IP_VS_LBLC_TAB_MASK; |
| 332 | |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 333 | spin_lock(&svc->sched_lock); |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 334 | hlist_for_each_entry_safe(en, next, &tbl->bucket[j], list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if (time_before(now, en->lastuse + ENTRY_TIMEOUT)) |
| 336 | continue; |
| 337 | |
| 338 | ip_vs_lblc_free(en); |
| 339 | atomic_dec(&tbl->entries); |
| 340 | goal--; |
| 341 | } |
Julian Anastasov | ba3a3ce | 2013-03-22 11:46:51 +0200 | [diff] [blame] | 342 | spin_unlock(&svc->sched_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (goal <= 0) |
| 344 | break; |
| 345 | } |
| 346 | tbl->rover = j; |
| 347 | |
| 348 | out: |
| 349 | mod_timer(&tbl->periodic_timer, jiffies+CHECK_EXPIRE_INTERVAL); |
| 350 | } |
| 351 | |
| 352 | |
| 353 | static int ip_vs_lblc_init_svc(struct ip_vs_service *svc) |
| 354 | { |
| 355 | int i; |
| 356 | struct ip_vs_lblc_table *tbl; |
| 357 | |
| 358 | /* |
| 359 | * Allocate the ip_vs_lblc_table for this service |
| 360 | */ |
Julian Anastasov | 748d845 | 2012-04-13 16:49:40 +0300 | [diff] [blame] | 361 | tbl = kmalloc(sizeof(*tbl), GFP_KERNEL); |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 362 | if (tbl == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | return -ENOMEM; |
Joe Perches | 0a9ee81 | 2011-08-29 14:17:25 -0700 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | svc->sched_data = tbl; |
| 366 | IP_VS_DBG(6, "LBLC hash table (memory=%Zdbytes) allocated for " |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 367 | "current service\n", sizeof(*tbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * Initialize the hash buckets |
| 371 | */ |
| 372 | for (i=0; i<IP_VS_LBLC_TAB_SIZE; i++) { |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 373 | INIT_HLIST_HEAD(&tbl->bucket[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | tbl->max_size = IP_VS_LBLC_TAB_SIZE*16; |
| 376 | tbl->rover = 0; |
| 377 | tbl->counter = 1; |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 378 | tbl->dead = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | /* |
| 381 | * Hook periodic timer for garbage collection |
| 382 | */ |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 383 | setup_timer(&tbl->periodic_timer, ip_vs_lblc_check_expire, |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 384 | (unsigned long)svc); |
| 385 | mod_timer(&tbl->periodic_timer, jiffies + CHECK_EXPIRE_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | |
Julian Anastasov | ed3ffc4 | 2013-03-22 11:46:50 +0200 | [diff] [blame] | 391 | static void ip_vs_lblc_done_svc(struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
| 393 | struct ip_vs_lblc_table *tbl = svc->sched_data; |
| 394 | |
| 395 | /* remove periodic timer */ |
| 396 | del_timer_sync(&tbl->periodic_timer); |
| 397 | |
| 398 | /* got to clean up table entries here */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 399 | ip_vs_lblc_flush(svc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | /* release the table itself */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 402 | kfree_rcu(tbl, rcu_head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | IP_VS_DBG(6, "LBLC hash table (memory=%Zdbytes) released\n", |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 404 | sizeof(*tbl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | static inline struct ip_vs_dest * |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 409 | __ip_vs_lblc_schedule(struct ip_vs_service *svc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
| 411 | struct ip_vs_dest *dest, *least; |
| 412 | int loh, doh; |
| 413 | |
| 414 | /* |
Changli Gao | b552f7e | 2011-02-19 17:32:28 +0800 | [diff] [blame] | 415 | * We use the following formula to estimate the load: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | * (dest overhead) / dest->weight |
| 417 | * |
| 418 | * Remember -- no floats in kernel mode!!! |
| 419 | * The comparison of h1*w2 > h2*w1 is equivalent to that of |
| 420 | * h1/w1 > h2/w2 |
| 421 | * if every weight is larger than zero. |
| 422 | * |
| 423 | * The server with weight=0 is quiesced and will not receive any |
| 424 | * new connection. |
| 425 | */ |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 426 | list_for_each_entry_rcu(dest, &svc->destinations, n_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (dest->flags & IP_VS_DEST_F_OVERLOAD) |
| 428 | continue; |
| 429 | if (atomic_read(&dest->weight) > 0) { |
| 430 | least = dest; |
Changli Gao | b552f7e | 2011-02-19 17:32:28 +0800 | [diff] [blame] | 431 | loh = ip_vs_dest_conn_overhead(least); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | goto nextstage; |
| 433 | } |
| 434 | } |
| 435 | return NULL; |
| 436 | |
| 437 | /* |
| 438 | * Find the destination with the least load. |
| 439 | */ |
| 440 | nextstage: |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 441 | list_for_each_entry_continue_rcu(dest, &svc->destinations, n_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | if (dest->flags & IP_VS_DEST_F_OVERLOAD) |
| 443 | continue; |
| 444 | |
Changli Gao | b552f7e | 2011-02-19 17:32:28 +0800 | [diff] [blame] | 445 | doh = ip_vs_dest_conn_overhead(dest); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (loh * atomic_read(&dest->weight) > |
| 447 | doh * atomic_read(&least->weight)) { |
| 448 | least = dest; |
| 449 | loh = doh; |
| 450 | } |
| 451 | } |
| 452 | |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 453 | IP_VS_DBG_BUF(6, "LBLC: server %s:%d " |
| 454 | "activeconns %d refcnt %d weight %d overhead %d\n", |
| 455 | IP_VS_DBG_ADDR(least->af, &least->addr), |
| 456 | ntohs(least->port), |
| 457 | atomic_read(&least->activeconns), |
| 458 | atomic_read(&least->refcnt), |
| 459 | atomic_read(&least->weight), loh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | return least; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /* |
| 466 | * If this destination server is overloaded and there is a less loaded |
| 467 | * server, then return true. |
| 468 | */ |
| 469 | static inline int |
| 470 | is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc) |
| 471 | { |
| 472 | if (atomic_read(&dest->activeconns) > atomic_read(&dest->weight)) { |
| 473 | struct ip_vs_dest *d; |
| 474 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 475 | list_for_each_entry_rcu(d, &svc->destinations, n_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | if (atomic_read(&d->activeconns)*2 |
| 477 | < atomic_read(&d->weight)) { |
| 478 | return 1; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /* |
| 487 | * Locality-Based (weighted) Least-Connection scheduling |
| 488 | */ |
| 489 | static struct ip_vs_dest * |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 490 | ip_vs_lblc_schedule(struct ip_vs_service *svc, const struct sk_buff *skb, |
| 491 | struct ip_vs_iphdr *iph) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 493 | struct ip_vs_lblc_table *tbl = svc->sched_data; |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 494 | struct ip_vs_dest *dest = NULL; |
| 495 | struct ip_vs_lblc_entry *en; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 497 | IP_VS_DBG(6, "%s(): Scheduling...\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 499 | /* First look in our cache */ |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 500 | en = ip_vs_lblc_get(svc->af, tbl, &iph->daddr); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 501 | if (en) { |
| 502 | /* We only hold a read lock, but this is atomic */ |
| 503 | en->lastuse = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 505 | /* |
| 506 | * If the destination is not available, i.e. it's in the trash, |
| 507 | * we must ignore it, as it may be removed from under our feet, |
| 508 | * if someone drops our reference count. Our caller only makes |
| 509 | * sure that destinations, that are not in the trash, are not |
| 510 | * moved to the trash, while we are scheduling. But anyone can |
| 511 | * free up entries from the trash at any time. |
| 512 | */ |
| 513 | |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 514 | dest = rcu_dereference(en->dest); |
| 515 | if ((dest->flags & IP_VS_DEST_F_AVAILABLE) && |
| 516 | atomic_read(&dest->weight) > 0 && !is_overloaded(dest, svc)) |
| 517 | goto out; |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 518 | } |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 519 | |
| 520 | /* No cache entry or it is invalid, time to schedule */ |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 521 | dest = __ip_vs_lblc_schedule(svc); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 522 | if (!dest) { |
Patrick Schaaf | 41ac51e | 2011-02-11 14:01:12 +0100 | [diff] [blame] | 523 | ip_vs_scheduler_err(svc, "no destination available"); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | /* If we fail to create a cache entry, we'll just use the valid dest */ |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 528 | spin_lock_bh(&svc->sched_lock); |
Julian Anastasov | c2a4ffb | 2013-03-22 11:46:40 +0200 | [diff] [blame] | 529 | if (!tbl->dead) |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 530 | ip_vs_lblc_new(tbl, &iph->daddr, dest); |
Julian Anastasov | ac69269 | 2013-03-22 11:46:54 +0200 | [diff] [blame] | 531 | spin_unlock_bh(&svc->sched_lock); |
Sven Wegener | 39ac50d | 2008-08-18 00:52:08 +0200 | [diff] [blame] | 532 | |
| 533 | out: |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 534 | IP_VS_DBG_BUF(6, "LBLC: destination IP address %s --> server %s:%d\n", |
Julian Anastasov | bba54de | 2013-06-16 09:09:36 +0300 | [diff] [blame] | 535 | IP_VS_DBG_ADDR(svc->af, &iph->daddr), |
Julius Volz | 4454837 | 2008-11-03 17:08:28 -0800 | [diff] [blame] | 536 | IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | return dest; |
| 539 | } |
| 540 | |
| 541 | |
| 542 | /* |
| 543 | * IPVS LBLC Scheduler structure |
| 544 | */ |
| 545 | static struct ip_vs_scheduler ip_vs_lblc_scheduler = |
| 546 | { |
| 547 | .name = "lblc", |
| 548 | .refcnt = ATOMIC_INIT(0), |
| 549 | .module = THIS_MODULE, |
Sven Wegener | d149ccc | 2008-08-10 09:18:02 +0000 | [diff] [blame] | 550 | .n_list = LIST_HEAD_INIT(ip_vs_lblc_scheduler.n_list), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | .init_service = ip_vs_lblc_init_svc, |
| 552 | .done_service = ip_vs_lblc_done_svc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | .schedule = ip_vs_lblc_schedule, |
| 554 | }; |
| 555 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 556 | /* |
| 557 | * per netns init. |
| 558 | */ |
Simon Horman | fb1de43 | 2011-02-04 18:33:02 +0900 | [diff] [blame] | 559 | #ifdef CONFIG_SYSCTL |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 560 | static int __net_init __ip_vs_lblc_init(struct net *net) |
| 561 | { |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 562 | struct netns_ipvs *ipvs = net_ipvs(net); |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 563 | |
Hans Schillstrom | 4b984cd | 2012-04-26 09:45:34 +0200 | [diff] [blame] | 564 | if (!ipvs) |
| 565 | return -ENOENT; |
| 566 | |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 567 | if (!net_eq(net, &init_net)) { |
| 568 | ipvs->lblc_ctl_table = kmemdup(vs_vars_table, |
| 569 | sizeof(vs_vars_table), |
| 570 | GFP_KERNEL); |
| 571 | if (ipvs->lblc_ctl_table == NULL) |
Simon Horman | 0443929 | 2011-02-01 18:29:04 +0100 | [diff] [blame] | 572 | return -ENOMEM; |
Eric W. Biederman | 464dc80 | 2012-11-16 03:02:59 +0000 | [diff] [blame] | 573 | |
| 574 | /* Don't export sysctls to unprivileged users */ |
| 575 | if (net->user_ns != &init_user_ns) |
| 576 | ipvs->lblc_ctl_table[0].procname = NULL; |
| 577 | |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 578 | } else |
| 579 | ipvs->lblc_ctl_table = vs_vars_table; |
Simon Horman | b27d777 | 2011-02-04 18:33:01 +0900 | [diff] [blame] | 580 | ipvs->sysctl_lblc_expiration = DEFAULT_EXPIRATION; |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 581 | ipvs->lblc_ctl_table[0].data = &ipvs->sysctl_lblc_expiration; |
| 582 | |
| 583 | ipvs->lblc_ctl_header = |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 584 | register_net_sysctl(net, "net/ipv4/vs", ipvs->lblc_ctl_table); |
Simon Horman | 0443929 | 2011-02-01 18:29:04 +0100 | [diff] [blame] | 585 | if (!ipvs->lblc_ctl_header) { |
| 586 | if (!net_eq(net, &init_net)) |
Eric W. Biederman | e5ef39e | 2012-11-19 05:26:30 +0000 | [diff] [blame] | 587 | kfree(ipvs->lblc_ctl_table); |
Simon Horman | 0443929 | 2011-02-01 18:29:04 +0100 | [diff] [blame] | 588 | return -ENOMEM; |
| 589 | } |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static void __net_exit __ip_vs_lblc_exit(struct net *net) |
| 595 | { |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 596 | struct netns_ipvs *ipvs = net_ipvs(net); |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 597 | |
Hans Schillstrom | b6e885d | 2011-01-03 14:44:45 +0100 | [diff] [blame] | 598 | unregister_net_sysctl_table(ipvs->lblc_ctl_header); |
| 599 | |
| 600 | if (!net_eq(net, &init_net)) |
| 601 | kfree(ipvs->lblc_ctl_table); |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 602 | } |
| 603 | |
Simon Horman | fb1de43 | 2011-02-04 18:33:02 +0900 | [diff] [blame] | 604 | #else |
| 605 | |
| 606 | static int __net_init __ip_vs_lblc_init(struct net *net) { return 0; } |
| 607 | static void __net_exit __ip_vs_lblc_exit(struct net *net) { } |
| 608 | |
| 609 | #endif |
| 610 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 611 | static struct pernet_operations ip_vs_lblc_ops = { |
| 612 | .init = __ip_vs_lblc_init, |
| 613 | .exit = __ip_vs_lblc_exit, |
| 614 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | static int __init ip_vs_lblc_init(void) |
| 617 | { |
Pavel Emelyanov | a014bc8 | 2007-12-04 00:43:24 -0800 | [diff] [blame] | 618 | int ret; |
| 619 | |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 620 | ret = register_pernet_subsys(&ip_vs_lblc_ops); |
| 621 | if (ret) |
| 622 | return ret; |
| 623 | |
Pavel Emelyanov | a014bc8 | 2007-12-04 00:43:24 -0800 | [diff] [blame] | 624 | ret = register_ip_vs_scheduler(&ip_vs_lblc_scheduler); |
| 625 | if (ret) |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 626 | unregister_pernet_subsys(&ip_vs_lblc_ops); |
Pavel Emelyanov | a014bc8 | 2007-12-04 00:43:24 -0800 | [diff] [blame] | 627 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | static void __exit ip_vs_lblc_cleanup(void) |
| 631 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | unregister_ip_vs_scheduler(&ip_vs_lblc_scheduler); |
Hans Schillstrom | 61b1ab4 | 2011-01-03 14:44:42 +0100 | [diff] [blame] | 633 | unregister_pernet_subsys(&ip_vs_lblc_ops); |
Julian Anastasov | ceec4c3 | 2013-03-22 11:46:53 +0200 | [diff] [blame] | 634 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
| 638 | module_init(ip_vs_lblc_init); |
| 639 | module_exit(ip_vs_lblc_cleanup); |
| 640 | MODULE_LICENSE("GPL"); |