2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* IPVS: Locality-Based Least-Connection with Replication scheduler
|
|
|
|
*
|
|
|
|
* Authors: Wensong Zhang <wensong@gnuchina.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* Julian Anastasov : Added the missing (dest->weight>0)
|
|
|
|
* condition in the ip_vs_dest_set_max.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The lblc/r algorithm is as follows (pseudo code):
|
|
|
|
*
|
|
|
|
* if serverSet[dest_ip] is null then
|
|
|
|
* n, serverSet[dest_ip] <- {weighted least-conn node};
|
|
|
|
* else
|
|
|
|
* n <- {least-conn (alive) node in serverSet[dest_ip]};
|
|
|
|
* if (n is null) OR
|
|
|
|
* (n.conns>n.weight AND
|
|
|
|
* there is a node m with m.conns<m.weight/2) then
|
|
|
|
* n <- {weighted least-conn node};
|
|
|
|
* add n to serverSet[dest_ip];
|
|
|
|
* if |serverSet[dest_ip]| > 1 AND
|
|
|
|
* now - serverSet[dest_ip].lastMod > T then
|
|
|
|
* m <- {most conn node in serverSet[dest_ip]};
|
|
|
|
* remove m from serverSet[dest_ip];
|
|
|
|
* if serverSet[dest_ip] changed then
|
|
|
|
* serverSet[dest_ip].lastMod <- now;
|
|
|
|
*
|
|
|
|
* return n;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-30 23:29:44 +02:00
|
|
|
#define KMSG_COMPONENT "IPVS"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-12-27 05:43:12 +01:00
|
|
|
#include <linux/ip.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
2005-12-27 05:43:12 +01:00
|
|
|
#include <linux/skbuff.h>
|
2006-12-04 05:15:30 +01:00
|
|
|
#include <linux/jiffies.h>
|
2010-02-26 17:45:14 +01:00
|
|
|
#include <linux/list.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* for sysctl */
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/sysctl.h>
|
2007-09-12 12:01:34 +02:00
|
|
|
#include <net/net_namespace.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
#include <net/ip_vs.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is for garbage collection of stale IPVS lblcr entries,
|
|
|
|
* when the table is full.
|
|
|
|
*/
|
|
|
|
#define CHECK_EXPIRE_INTERVAL (60*HZ)
|
|
|
|
#define ENTRY_TIMEOUT (6*60*HZ)
|
|
|
|
|
2011-02-04 10:33:01 +01:00
|
|
|
#define DEFAULT_EXPIRATION (24*60*60*HZ)
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* It is for full expiration check.
|
|
|
|
* When there is no partial expiration check (garbage collection)
|
|
|
|
* in a half hour, do a full expiration check to collect stale
|
|
|
|
* entries that haven't been touched for a day.
|
|
|
|
*/
|
|
|
|
#define COUNT_FOR_FULL_EXPIRATION 30
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for IPVS lblcr entry hash table
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_IP_VS_LBLCR_TAB_BITS
|
|
|
|
#define CONFIG_IP_VS_LBLCR_TAB_BITS 10
|
|
|
|
#endif
|
|
|
|
#define IP_VS_LBLCR_TAB_BITS CONFIG_IP_VS_LBLCR_TAB_BITS
|
|
|
|
#define IP_VS_LBLCR_TAB_SIZE (1 << IP_VS_LBLCR_TAB_BITS)
|
|
|
|
#define IP_VS_LBLCR_TAB_MASK (IP_VS_LBLCR_TAB_SIZE - 1)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS destination set structure and operations
|
|
|
|
*/
|
2010-02-26 17:45:14 +01:00
|
|
|
struct ip_vs_dest_set_elem {
|
|
|
|
struct list_head list; /* list link */
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_dest *dest; /* destination server */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ip_vs_dest_set {
|
|
|
|
atomic_t size; /* set size */
|
|
|
|
unsigned long lastmod; /* last modified time */
|
2010-02-26 17:45:14 +01:00
|
|
|
struct list_head list; /* destination list */
|
2005-04-17 00:20:36 +02:00
|
|
|
rwlock_t lock; /* lock for this list */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-26 17:45:14 +01:00
|
|
|
static struct ip_vs_dest_set_elem *
|
2005-04-17 00:20:36 +02:00
|
|
|
ip_vs_dest_set_insert(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
|
|
|
|
{
|
2010-02-26 17:45:14 +01:00
|
|
|
struct ip_vs_dest_set_elem *e;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
if (e->dest == dest)
|
|
|
|
/* already existed */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
e = kmalloc(sizeof(*e), GFP_ATOMIC);
|
2011-08-29 23:17:25 +02:00
|
|
|
if (e == NULL)
|
2005-04-17 00:20:36 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
atomic_inc(&dest->refcnt);
|
|
|
|
e->dest = dest;
|
|
|
|
|
2010-02-26 17:45:14 +01:00
|
|
|
list_add(&e->list, &set->list);
|
2005-04-17 00:20:36 +02:00
|
|
|
atomic_inc(&set->size);
|
|
|
|
|
|
|
|
set->lastmod = jiffies;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ip_vs_dest_set_erase(struct ip_vs_dest_set *set, struct ip_vs_dest *dest)
|
|
|
|
{
|
2010-02-26 17:45:14 +01:00
|
|
|
struct ip_vs_dest_set_elem *e;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
if (e->dest == dest) {
|
|
|
|
/* HIT */
|
|
|
|
atomic_dec(&set->size);
|
|
|
|
set->lastmod = jiffies;
|
|
|
|
atomic_dec(&e->dest->refcnt);
|
2010-02-26 17:45:14 +01:00
|
|
|
list_del(&e->list);
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(e);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ip_vs_dest_set_eraseall(struct ip_vs_dest_set *set)
|
|
|
|
{
|
2010-02-26 17:45:14 +01:00
|
|
|
struct ip_vs_dest_set_elem *e, *ep;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
write_lock(&set->lock);
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry_safe(e, ep, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
2011-03-31 03:57:33 +02:00
|
|
|
* We don't kfree dest because it is referred either
|
2005-04-17 00:20:36 +02:00
|
|
|
* by its service or by the trash dest list.
|
|
|
|
*/
|
|
|
|
atomic_dec(&e->dest->refcnt);
|
2010-02-26 17:45:14 +01:00
|
|
|
list_del(&e->list);
|
2005-04-17 00:20:36 +02:00
|
|
|
kfree(e);
|
|
|
|
}
|
|
|
|
write_unlock(&set->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get weighted least-connection node in the destination set */
|
|
|
|
static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set)
|
|
|
|
{
|
2010-02-26 17:45:14 +01:00
|
|
|
register struct ip_vs_dest_set_elem *e;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_dest *dest, *least;
|
|
|
|
int loh, doh;
|
|
|
|
|
|
|
|
if (set == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* select the first destination server, whose weight > 0 */
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
least = e->dest;
|
|
|
|
if (least->flags & IP_VS_DEST_F_OVERLOAD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((atomic_read(&least->weight) > 0)
|
|
|
|
&& (least->flags & IP_VS_DEST_F_AVAILABLE)) {
|
2011-02-19 10:32:28 +01:00
|
|
|
loh = ip_vs_dest_conn_overhead(least);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto nextstage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* find the destination with the weighted least load */
|
|
|
|
nextstage:
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
dest = e->dest;
|
|
|
|
if (dest->flags & IP_VS_DEST_F_OVERLOAD)
|
|
|
|
continue;
|
|
|
|
|
2011-02-19 10:32:28 +01:00
|
|
|
doh = ip_vs_dest_conn_overhead(dest);
|
2005-04-17 00:20:36 +02:00
|
|
|
if ((loh * atomic_read(&dest->weight) >
|
|
|
|
doh * atomic_read(&least->weight))
|
|
|
|
&& (dest->flags & IP_VS_DEST_F_AVAILABLE)) {
|
|
|
|
least = dest;
|
|
|
|
loh = doh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG_BUF(6, "%s(): server %s:%d "
|
2008-11-04 02:08:28 +01:00
|
|
|
"activeconns %d refcnt %d weight %d overhead %d\n",
|
2009-08-02 13:05:41 +02:00
|
|
|
__func__,
|
2008-11-04 02:08:28 +01:00
|
|
|
IP_VS_DBG_ADDR(least->af, &least->addr),
|
|
|
|
ntohs(least->port),
|
|
|
|
atomic_read(&least->activeconns),
|
|
|
|
atomic_read(&least->refcnt),
|
|
|
|
atomic_read(&least->weight), loh);
|
2005-04-17 00:20:36 +02:00
|
|
|
return least;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get weighted most-connection node in the destination set */
|
|
|
|
static inline struct ip_vs_dest *ip_vs_dest_set_max(struct ip_vs_dest_set *set)
|
|
|
|
{
|
2010-02-26 17:45:14 +01:00
|
|
|
register struct ip_vs_dest_set_elem *e;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_dest *dest, *most;
|
|
|
|
int moh, doh;
|
|
|
|
|
|
|
|
if (set == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* select the first destination server, whose weight > 0 */
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
most = e->dest;
|
|
|
|
if (atomic_read(&most->weight) > 0) {
|
2011-02-19 10:32:28 +01:00
|
|
|
moh = ip_vs_dest_conn_overhead(most);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto nextstage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* find the destination with the weighted most load */
|
|
|
|
nextstage:
|
2010-02-26 17:45:14 +01:00
|
|
|
list_for_each_entry(e, &set->list, list) {
|
2005-04-17 00:20:36 +02:00
|
|
|
dest = e->dest;
|
2011-02-19 10:32:28 +01:00
|
|
|
doh = ip_vs_dest_conn_overhead(dest);
|
2005-04-17 00:20:36 +02:00
|
|
|
/* moh/mw < doh/dw ==> moh*dw < doh*mw, where mw,dw>0 */
|
|
|
|
if ((moh * atomic_read(&dest->weight) <
|
|
|
|
doh * atomic_read(&most->weight))
|
|
|
|
&& (atomic_read(&dest->weight) > 0)) {
|
|
|
|
most = dest;
|
|
|
|
moh = doh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG_BUF(6, "%s(): server %s:%d "
|
2008-11-04 02:08:28 +01:00
|
|
|
"activeconns %d refcnt %d weight %d overhead %d\n",
|
2009-08-02 13:05:41 +02:00
|
|
|
__func__,
|
2008-11-04 02:08:28 +01:00
|
|
|
IP_VS_DBG_ADDR(most->af, &most->addr), ntohs(most->port),
|
|
|
|
atomic_read(&most->activeconns),
|
|
|
|
atomic_read(&most->refcnt),
|
|
|
|
atomic_read(&most->weight), moh);
|
2005-04-17 00:20:36 +02:00
|
|
|
return most;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS lblcr entry represents an association between destination
|
|
|
|
* IP address and its destination server set
|
|
|
|
*/
|
|
|
|
struct ip_vs_lblcr_entry {
|
|
|
|
struct list_head list;
|
2008-11-04 02:08:28 +01:00
|
|
|
int af; /* address family */
|
|
|
|
union nf_inet_addr addr; /* destination IP address */
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_dest_set set; /* destination server set */
|
|
|
|
unsigned long lastuse; /* last used time */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS lblcr hash table
|
|
|
|
*/
|
|
|
|
struct ip_vs_lblcr_table {
|
|
|
|
struct list_head bucket[IP_VS_LBLCR_TAB_SIZE]; /* hash bucket */
|
|
|
|
atomic_t entries; /* number of entries */
|
|
|
|
int max_size; /* maximum size of entries */
|
|
|
|
struct timer_list periodic_timer; /* collect stale entries */
|
|
|
|
int rover; /* rover for expire check */
|
|
|
|
int counter; /* counter for no expire */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-04 10:33:02 +01:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* IPVS LBLCR sysctl table
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ctl_table vs_vars_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "lblcr_expiration",
|
2011-01-03 14:44:44 +01:00
|
|
|
.data = NULL,
|
2005-04-17 00:20:36 +02:00
|
|
|
.maxlen = sizeof(int),
|
2007-02-09 15:24:47 +01:00
|
|
|
.mode = 0644,
|
2008-11-04 03:21:05 +01:00
|
|
|
.proc_handler = proc_dointvec_jiffies,
|
2005-04-17 00:20:36 +02:00
|
|
|
},
|
2009-11-05 22:32:03 +01:00
|
|
|
{ }
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
2011-02-04 10:33:02 +01:00
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static inline void ip_vs_lblcr_free(struct ip_vs_lblcr_entry *en)
|
|
|
|
{
|
|
|
|
list_del(&en->list);
|
|
|
|
ip_vs_dest_set_eraseall(&en->set);
|
|
|
|
kfree(en);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns hash value for IPVS LBLCR entry
|
|
|
|
*/
|
2008-11-04 02:08:28 +01:00
|
|
|
static inline unsigned
|
|
|
|
ip_vs_lblcr_hashkey(int af, const union nf_inet_addr *addr)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-11-04 02:08:28 +01:00
|
|
|
__be32 addr_fold = addr->ip;
|
|
|
|
|
|
|
|
#ifdef CONFIG_IP_VS_IPV6
|
|
|
|
if (af == AF_INET6)
|
|
|
|
addr_fold = addr->ip6[0]^addr->ip6[1]^
|
|
|
|
addr->ip6[2]^addr->ip6[3];
|
|
|
|
#endif
|
|
|
|
return (ntohl(addr_fold)*2654435761UL) & IP_VS_LBLCR_TAB_MASK;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hash an entry in the ip_vs_lblcr_table.
|
|
|
|
* returns bool success.
|
|
|
|
*/
|
2008-08-19 08:16:19 +02:00
|
|
|
static void
|
2005-04-17 00:20:36 +02:00
|
|
|
ip_vs_lblcr_hash(struct ip_vs_lblcr_table *tbl, struct ip_vs_lblcr_entry *en)
|
|
|
|
{
|
2008-11-04 02:08:28 +01:00
|
|
|
unsigned hash = ip_vs_lblcr_hashkey(en->af, &en->addr);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
list_add(&en->list, &tbl->bucket[hash]);
|
|
|
|
atomic_inc(&tbl->entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-08-19 08:16:19 +02:00
|
|
|
* Get ip_vs_lblcr_entry associated with supplied parameters. Called under
|
|
|
|
* read lock.
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
static inline struct ip_vs_lblcr_entry *
|
2008-11-04 02:08:28 +01:00
|
|
|
ip_vs_lblcr_get(int af, struct ip_vs_lblcr_table *tbl,
|
|
|
|
const union nf_inet_addr *addr)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-11-04 02:08:28 +01:00
|
|
|
unsigned hash = ip_vs_lblcr_hashkey(af, addr);
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_lblcr_entry *en;
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
list_for_each_entry(en, &tbl->bucket[hash], list)
|
2008-11-04 02:08:28 +01:00
|
|
|
if (ip_vs_addr_equal(af, &en->addr, addr))
|
2008-08-19 08:16:19 +02:00
|
|
|
return en;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
/*
|
|
|
|
* Create or update an ip_vs_lblcr_entry, which is a mapping of a destination
|
|
|
|
* IP address to a server. Called under write lock.
|
|
|
|
*/
|
|
|
|
static inline struct ip_vs_lblcr_entry *
|
2008-11-04 02:08:28 +01:00
|
|
|
ip_vs_lblcr_new(struct ip_vs_lblcr_table *tbl, const union nf_inet_addr *daddr,
|
2008-08-19 08:16:19 +02:00
|
|
|
struct ip_vs_dest *dest)
|
|
|
|
{
|
|
|
|
struct ip_vs_lblcr_entry *en;
|
|
|
|
|
2008-11-04 02:08:28 +01:00
|
|
|
en = ip_vs_lblcr_get(dest->af, tbl, daddr);
|
2008-08-19 08:16:19 +02:00
|
|
|
if (!en) {
|
|
|
|
en = kmalloc(sizeof(*en), GFP_ATOMIC);
|
2011-08-29 23:17:25 +02:00
|
|
|
if (!en)
|
2008-08-19 08:16:19 +02:00
|
|
|
return NULL;
|
|
|
|
|
2008-11-04 02:08:28 +01:00
|
|
|
en->af = dest->af;
|
|
|
|
ip_vs_addr_copy(dest->af, &en->addr, daddr);
|
2008-08-19 08:16:19 +02:00
|
|
|
en->lastuse = jiffies;
|
|
|
|
|
2010-06-11 12:17:00 +02:00
|
|
|
/* initialize its dest set */
|
2008-08-19 08:16:19 +02:00
|
|
|
atomic_set(&(en->set.size), 0);
|
2010-02-26 17:45:14 +01:00
|
|
|
INIT_LIST_HEAD(&en->set.list);
|
2008-08-19 08:16:19 +02:00
|
|
|
rwlock_init(&en->set.lock);
|
|
|
|
|
|
|
|
ip_vs_lblcr_hash(tbl, en);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
write_lock(&en->set.lock);
|
|
|
|
ip_vs_dest_set_insert(&en->set, dest);
|
|
|
|
write_unlock(&en->set.lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
return en;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush all the entries of the specified table.
|
|
|
|
*/
|
|
|
|
static void ip_vs_lblcr_flush(struct ip_vs_lblcr_table *tbl)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct ip_vs_lblcr_entry *en, *nxt;
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
/* No locking required, only called during cleanup. */
|
2005-04-17 00:20:36 +02:00
|
|
|
for (i=0; i<IP_VS_LBLCR_TAB_SIZE; i++) {
|
|
|
|
list_for_each_entry_safe(en, nxt, &tbl->bucket[i], list) {
|
|
|
|
ip_vs_lblcr_free(en);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 10:33:01 +01:00
|
|
|
static int sysctl_lblcr_expiration(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYSCTL
|
|
|
|
struct netns_ipvs *ipvs = net_ipvs(svc->net);
|
|
|
|
return ipvs->sysctl_lblcr_expiration;
|
|
|
|
#else
|
|
|
|
return DEFAULT_EXPIRATION;
|
|
|
|
#endif
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
static inline void ip_vs_lblcr_full_check(struct ip_vs_service *svc)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-08-19 08:16:19 +02:00
|
|
|
struct ip_vs_lblcr_table *tbl = svc->sched_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long now = jiffies;
|
|
|
|
int i, j;
|
|
|
|
struct ip_vs_lblcr_entry *en, *nxt;
|
|
|
|
|
|
|
|
for (i=0, j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE; i++) {
|
|
|
|
j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
write_lock(&svc->sched_lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) {
|
2011-02-04 10:33:01 +01:00
|
|
|
if (time_after(en->lastuse +
|
|
|
|
sysctl_lblcr_expiration(svc), now))
|
2005-04-17 00:20:36 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
ip_vs_lblcr_free(en);
|
|
|
|
atomic_dec(&tbl->entries);
|
|
|
|
}
|
2008-08-19 08:16:19 +02:00
|
|
|
write_unlock(&svc->sched_lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
tbl->rover = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Periodical timer handler for IPVS lblcr table
|
|
|
|
* It is used to collect stale entries when the number of entries
|
|
|
|
* exceeds the maximum size of the table.
|
|
|
|
*
|
|
|
|
* Fixme: we probably need more complicated algorithm to collect
|
|
|
|
* entries that have not been used for a long time even
|
|
|
|
* if the number of entries doesn't exceed the maximum size
|
|
|
|
* of the table.
|
|
|
|
* The full expiration check is for this purpose now.
|
|
|
|
*/
|
|
|
|
static void ip_vs_lblcr_check_expire(unsigned long data)
|
|
|
|
{
|
2008-08-19 08:16:19 +02:00
|
|
|
struct ip_vs_service *svc = (struct ip_vs_service *) data;
|
|
|
|
struct ip_vs_lblcr_table *tbl = svc->sched_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned long now = jiffies;
|
|
|
|
int goal;
|
|
|
|
int i, j;
|
|
|
|
struct ip_vs_lblcr_entry *en, *nxt;
|
|
|
|
|
|
|
|
if ((tbl->counter % COUNT_FOR_FULL_EXPIRATION) == 0) {
|
|
|
|
/* do full expiration check */
|
2008-08-19 08:16:19 +02:00
|
|
|
ip_vs_lblcr_full_check(svc);
|
2005-04-17 00:20:36 +02:00
|
|
|
tbl->counter = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atomic_read(&tbl->entries) <= tbl->max_size) {
|
|
|
|
tbl->counter++;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
goal = (atomic_read(&tbl->entries) - tbl->max_size)*4/3;
|
|
|
|
if (goal > tbl->max_size/2)
|
|
|
|
goal = tbl->max_size/2;
|
|
|
|
|
|
|
|
for (i=0, j=tbl->rover; i<IP_VS_LBLCR_TAB_SIZE; i++) {
|
|
|
|
j = (j + 1) & IP_VS_LBLCR_TAB_MASK;
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
write_lock(&svc->sched_lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_for_each_entry_safe(en, nxt, &tbl->bucket[j], list) {
|
|
|
|
if (time_before(now, en->lastuse+ENTRY_TIMEOUT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ip_vs_lblcr_free(en);
|
|
|
|
atomic_dec(&tbl->entries);
|
|
|
|
goal--;
|
|
|
|
}
|
2008-08-19 08:16:19 +02:00
|
|
|
write_unlock(&svc->sched_lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (goal <= 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tbl->rover = j;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mod_timer(&tbl->periodic_timer, jiffies+CHECK_EXPIRE_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct ip_vs_lblcr_table *tbl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the ip_vs_lblcr_table for this service
|
|
|
|
*/
|
2008-08-19 08:16:19 +02:00
|
|
|
tbl = kmalloc(sizeof(*tbl), GFP_ATOMIC);
|
2011-08-29 23:17:25 +02:00
|
|
|
if (tbl == NULL)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENOMEM;
|
2011-08-29 23:17:25 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
svc->sched_data = tbl;
|
|
|
|
IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) allocated for "
|
2008-08-19 08:16:19 +02:00
|
|
|
"current service\n", sizeof(*tbl));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the hash buckets
|
|
|
|
*/
|
|
|
|
for (i=0; i<IP_VS_LBLCR_TAB_SIZE; i++) {
|
|
|
|
INIT_LIST_HEAD(&tbl->bucket[i]);
|
|
|
|
}
|
|
|
|
tbl->max_size = IP_VS_LBLCR_TAB_SIZE*16;
|
|
|
|
tbl->rover = 0;
|
|
|
|
tbl->counter = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook periodic timer for garbage collection
|
|
|
|
*/
|
2008-01-24 06:20:07 +01:00
|
|
|
setup_timer(&tbl->periodic_timer, ip_vs_lblcr_check_expire,
|
2008-08-19 08:16:19 +02:00
|
|
|
(unsigned long)svc);
|
|
|
|
mod_timer(&tbl->periodic_timer, jiffies + CHECK_EXPIRE_INTERVAL);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ip_vs_lblcr_done_svc(struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
struct ip_vs_lblcr_table *tbl = svc->sched_data;
|
|
|
|
|
|
|
|
/* remove periodic timer */
|
|
|
|
del_timer_sync(&tbl->periodic_timer);
|
|
|
|
|
|
|
|
/* got to clean up table entries here */
|
|
|
|
ip_vs_lblcr_flush(tbl);
|
|
|
|
|
|
|
|
/* release the table itself */
|
2008-08-19 08:16:19 +02:00
|
|
|
kfree(tbl);
|
2005-04-17 00:20:36 +02:00
|
|
|
IP_VS_DBG(6, "LBLCR hash table (memory=%Zdbytes) released\n",
|
2008-08-19 08:16:19 +02:00
|
|
|
sizeof(*tbl));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline struct ip_vs_dest *
|
2008-11-04 02:08:28 +01:00
|
|
|
__ip_vs_lblcr_schedule(struct ip_vs_service *svc)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct ip_vs_dest *dest, *least;
|
|
|
|
int loh, doh;
|
|
|
|
|
|
|
|
/*
|
2011-02-19 10:32:28 +01:00
|
|
|
* We use the following formula to estimate the load:
|
2005-04-17 00:20:36 +02:00
|
|
|
* (dest overhead) / dest->weight
|
|
|
|
*
|
|
|
|
* Remember -- no floats in kernel mode!!!
|
|
|
|
* The comparison of h1*w2 > h2*w1 is equivalent to that of
|
|
|
|
* h1/w1 > h2/w2
|
|
|
|
* if every weight is larger than zero.
|
|
|
|
*
|
|
|
|
* The server with weight=0 is quiesced and will not receive any
|
|
|
|
* new connection.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(dest, &svc->destinations, n_list) {
|
|
|
|
if (dest->flags & IP_VS_DEST_F_OVERLOAD)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (atomic_read(&dest->weight) > 0) {
|
|
|
|
least = dest;
|
2011-02-19 10:32:28 +01:00
|
|
|
loh = ip_vs_dest_conn_overhead(least);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto nextstage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the destination with the least load.
|
|
|
|
*/
|
|
|
|
nextstage:
|
|
|
|
list_for_each_entry_continue(dest, &svc->destinations, n_list) {
|
|
|
|
if (dest->flags & IP_VS_DEST_F_OVERLOAD)
|
|
|
|
continue;
|
|
|
|
|
2011-02-19 10:32:28 +01:00
|
|
|
doh = ip_vs_dest_conn_overhead(dest);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (loh * atomic_read(&dest->weight) >
|
|
|
|
doh * atomic_read(&least->weight)) {
|
|
|
|
least = dest;
|
|
|
|
loh = doh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 02:08:28 +01:00
|
|
|
IP_VS_DBG_BUF(6, "LBLCR: server %s:%d "
|
|
|
|
"activeconns %d refcnt %d weight %d overhead %d\n",
|
|
|
|
IP_VS_DBG_ADDR(least->af, &least->addr),
|
|
|
|
ntohs(least->port),
|
|
|
|
atomic_read(&least->activeconns),
|
|
|
|
atomic_read(&least->refcnt),
|
|
|
|
atomic_read(&least->weight), loh);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return least;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this destination server is overloaded and there is a less loaded
|
|
|
|
* server, then return true.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
is_overloaded(struct ip_vs_dest *dest, struct ip_vs_service *svc)
|
|
|
|
{
|
|
|
|
if (atomic_read(&dest->activeconns) > atomic_read(&dest->weight)) {
|
|
|
|
struct ip_vs_dest *d;
|
|
|
|
|
|
|
|
list_for_each_entry(d, &svc->destinations, n_list) {
|
|
|
|
if (atomic_read(&d->activeconns)*2
|
|
|
|
< atomic_read(&d->weight)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Locality-Based (weighted) Least-Connection scheduling
|
|
|
|
*/
|
|
|
|
static struct ip_vs_dest *
|
|
|
|
ip_vs_lblcr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
|
|
|
|
{
|
2008-08-19 08:16:19 +02:00
|
|
|
struct ip_vs_lblcr_table *tbl = svc->sched_data;
|
2008-11-04 02:08:28 +01:00
|
|
|
struct ip_vs_iphdr iph;
|
2008-08-19 08:16:19 +02:00
|
|
|
struct ip_vs_dest *dest = NULL;
|
|
|
|
struct ip_vs_lblcr_entry *en;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-11-04 02:08:28 +01:00
|
|
|
ip_vs_fill_iphdr(svc->af, skb_network_header(skb), &iph);
|
|
|
|
|
2009-08-02 13:05:41 +02:00
|
|
|
IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
/* First look in our cache */
|
|
|
|
read_lock(&svc->sched_lock);
|
2008-11-04 02:08:28 +01:00
|
|
|
en = ip_vs_lblcr_get(svc->af, tbl, &iph.daddr);
|
2008-08-19 08:16:19 +02:00
|
|
|
if (en) {
|
|
|
|
/* We only hold a read lock, but this is atomic */
|
|
|
|
en->lastuse = jiffies;
|
|
|
|
|
|
|
|
/* Get the least loaded destination */
|
|
|
|
read_lock(&en->set.lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
dest = ip_vs_dest_set_min(&en->set);
|
2008-08-19 08:16:19 +02:00
|
|
|
read_unlock(&en->set.lock);
|
|
|
|
|
|
|
|
/* More than one destination + enough time passed by, cleanup */
|
2005-04-17 00:20:36 +02:00
|
|
|
if (atomic_read(&en->set.size) > 1 &&
|
2008-08-19 08:16:19 +02:00
|
|
|
time_after(jiffies, en->set.lastmod +
|
2011-02-04 10:33:01 +01:00
|
|
|
sysctl_lblcr_expiration(svc))) {
|
2005-04-17 00:20:36 +02:00
|
|
|
struct ip_vs_dest *m;
|
2008-08-19 08:16:19 +02:00
|
|
|
|
|
|
|
write_lock(&en->set.lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
m = ip_vs_dest_set_max(&en->set);
|
|
|
|
if (m)
|
|
|
|
ip_vs_dest_set_erase(&en->set, m);
|
2008-08-19 08:16:19 +02:00
|
|
|
write_unlock(&en->set.lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the destination is not overloaded, use it */
|
|
|
|
if (dest && !is_overloaded(dest, svc)) {
|
|
|
|
read_unlock(&svc->sched_lock);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The cache entry is invalid, time to schedule */
|
2008-11-04 02:08:28 +01:00
|
|
|
dest = __ip_vs_lblcr_schedule(svc);
|
2008-08-19 08:16:19 +02:00
|
|
|
if (!dest) {
|
2011-02-11 14:01:12 +01:00
|
|
|
ip_vs_scheduler_err(svc, "no destination available");
|
2008-08-19 08:16:19 +02:00
|
|
|
read_unlock(&svc->sched_lock);
|
|
|
|
return NULL;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-08-19 08:16:19 +02:00
|
|
|
|
|
|
|
/* Update our cache entry */
|
|
|
|
write_lock(&en->set.lock);
|
|
|
|
ip_vs_dest_set_insert(&en->set, dest);
|
|
|
|
write_unlock(&en->set.lock);
|
|
|
|
}
|
|
|
|
read_unlock(&svc->sched_lock);
|
|
|
|
|
|
|
|
if (dest)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* No cache entry, time to schedule */
|
2008-11-04 02:08:28 +01:00
|
|
|
dest = __ip_vs_lblcr_schedule(svc);
|
2008-08-19 08:16:19 +02:00
|
|
|
if (!dest) {
|
|
|
|
IP_VS_DBG(1, "no destination available\n");
|
|
|
|
return NULL;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-08-19 08:16:19 +02:00
|
|
|
/* If we fail to create a cache entry, we'll just use the valid dest */
|
|
|
|
write_lock(&svc->sched_lock);
|
2008-11-04 02:08:28 +01:00
|
|
|
ip_vs_lblcr_new(tbl, &iph.daddr, dest);
|
2008-08-19 08:16:19 +02:00
|
|
|
write_unlock(&svc->sched_lock);
|
|
|
|
|
|
|
|
out:
|
2008-11-04 02:08:28 +01:00
|
|
|
IP_VS_DBG_BUF(6, "LBLCR: destination IP address %s --> server %s:%d\n",
|
|
|
|
IP_VS_DBG_ADDR(svc->af, &iph.daddr),
|
|
|
|
IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPVS LBLCR Scheduler structure
|
|
|
|
*/
|
|
|
|
static struct ip_vs_scheduler ip_vs_lblcr_scheduler =
|
|
|
|
{
|
|
|
|
.name = "lblcr",
|
|
|
|
.refcnt = ATOMIC_INIT(0),
|
|
|
|
.module = THIS_MODULE,
|
2008-08-10 11:18:02 +02:00
|
|
|
.n_list = LIST_HEAD_INIT(ip_vs_lblcr_scheduler.n_list),
|
2005-04-17 00:20:36 +02:00
|
|
|
.init_service = ip_vs_lblcr_init_svc,
|
|
|
|
.done_service = ip_vs_lblcr_done_svc,
|
|
|
|
.schedule = ip_vs_lblcr_schedule,
|
|
|
|
};
|
|
|
|
|
2011-01-03 14:44:42 +01:00
|
|
|
/*
|
|
|
|
* per netns init.
|
|
|
|
*/
|
2011-02-04 10:33:02 +01:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2011-01-03 14:44:42 +01:00
|
|
|
static int __net_init __ip_vs_lblcr_init(struct net *net)
|
|
|
|
{
|
2011-01-03 14:44:44 +01:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
2012-04-26 09:45:34 +02:00
|
|
|
if (!ipvs)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2011-01-03 14:44:44 +01:00
|
|
|
if (!net_eq(net, &init_net)) {
|
|
|
|
ipvs->lblcr_ctl_table = kmemdup(vs_vars_table,
|
|
|
|
sizeof(vs_vars_table),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (ipvs->lblcr_ctl_table == NULL)
|
2011-02-01 18:29:04 +01:00
|
|
|
return -ENOMEM;
|
2011-01-03 14:44:44 +01:00
|
|
|
} else
|
|
|
|
ipvs->lblcr_ctl_table = vs_vars_table;
|
2011-02-04 10:33:01 +01:00
|
|
|
ipvs->sysctl_lblcr_expiration = DEFAULT_EXPIRATION;
|
2011-01-03 14:44:44 +01:00
|
|
|
ipvs->lblcr_ctl_table[0].data = &ipvs->sysctl_lblcr_expiration;
|
|
|
|
|
|
|
|
ipvs->lblcr_ctl_header =
|
|
|
|
register_net_sysctl_table(net, net_vs_ctl_path,
|
|
|
|
ipvs->lblcr_ctl_table);
|
2011-02-01 18:29:04 +01:00
|
|
|
if (!ipvs->lblcr_ctl_header) {
|
|
|
|
if (!net_eq(net, &init_net))
|
|
|
|
kfree(ipvs->lblcr_ctl_table);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-01-03 14:44:42 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __net_exit __ip_vs_lblcr_exit(struct net *net)
|
|
|
|
{
|
2011-01-03 14:44:44 +01:00
|
|
|
struct netns_ipvs *ipvs = net_ipvs(net);
|
|
|
|
|
|
|
|
unregister_net_sysctl_table(ipvs->lblcr_ctl_header);
|
2011-01-03 14:44:42 +01:00
|
|
|
|
2011-01-03 14:44:44 +01:00
|
|
|
if (!net_eq(net, &init_net))
|
|
|
|
kfree(ipvs->lblcr_ctl_table);
|
2011-01-03 14:44:42 +01:00
|
|
|
}
|
|
|
|
|
2011-02-04 10:33:02 +01:00
|
|
|
#else
|
|
|
|
|
|
|
|
static int __net_init __ip_vs_lblcr_init(struct net *net) { return 0; }
|
|
|
|
static void __net_exit __ip_vs_lblcr_exit(struct net *net) { }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 14:44:42 +01:00
|
|
|
static struct pernet_operations ip_vs_lblcr_ops = {
|
|
|
|
.init = __ip_vs_lblcr_init,
|
|
|
|
.exit = __ip_vs_lblcr_exit,
|
|
|
|
};
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static int __init ip_vs_lblcr_init(void)
|
|
|
|
{
|
2007-12-04 09:43:24 +01:00
|
|
|
int ret;
|
|
|
|
|
2011-01-03 14:44:42 +01:00
|
|
|
ret = register_pernet_subsys(&ip_vs_lblcr_ops);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2007-12-04 09:43:24 +01:00
|
|
|
ret = register_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
|
|
|
|
if (ret)
|
2011-01-03 14:44:42 +01:00
|
|
|
unregister_pernet_subsys(&ip_vs_lblcr_ops);
|
2007-12-04 09:43:24 +01:00
|
|
|
return ret;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit ip_vs_lblcr_cleanup(void)
|
|
|
|
{
|
|
|
|
unregister_ip_vs_scheduler(&ip_vs_lblcr_scheduler);
|
2011-01-03 14:44:42 +01:00
|
|
|
unregister_pernet_subsys(&ip_vs_lblcr_ops);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(ip_vs_lblcr_init);
|
|
|
|
module_exit(ip_vs_lblcr_cleanup);
|
|
|
|
MODULE_LICENSE("GPL");
|