IPVS: init and cleanup.
Subsystems (5)
v2 cover IPVS: init and cleanup.
This patch series handles exit from a network name space.
REVISION
This is version 3
OVERVIEW
Basically there was three faults in the netns implementation.
- Kernel threads hold devices and preventing an exit.
- dst cache holds references to devices.
- Services was not always released.
Patch 1 & 3 contains the functionality
4 renames funcctions
5 removes empty functions
6 Debuging.
IMPLEMENTATION
- Avoid to increment the usage counter for kernel threads. this is done in the first patch.
- Patch 3 tries to restore the cleanup order.
Add NETDEV_UNREGISTER notification for dst_reset
Revision 3
Residies in patch 3
Throttle renamed to enable.
Comments from Julian implemented
Check enable in ip_vs_in, ip_vs_out and ip_vs_forward_icmp* Remove in ip_vs_in_icmp*.
ip_vs_svc_reset() moved into ip_vs_dst_event(). ip_vs_service_cleanup() uses ip_vs_flush and mutex lock. ip_vs_unlink_service_nolock() added.
An netns exit could look like this
IPVS: Enter: __ip_vs_dev_cleanup, net/netfilter/ipvs/ip_vs_core.c
IPVS: stopping master sync thread 1286 ...
IPVS: stopping backup sync thread 1294 ...
IPVS: Leave: __ip_vs_dev_cleanup, net/netfilter/ipvs/ip_vs_core.c
IPVS: Enter: ip_vs_dst_event, net/netfilter/ipvs/ip_vs_ctl.c line
IPVS: Leave: ip_vs_dst_event, net/netfilter/ipvs/ip_vs_ctl.c line
...
IPVS: Enter: ip_vs_dst_event, net/netfilter/ipvs/ip_vs_ctl.c line
IPVS: Leave: ip_vs_dst_event, net/netfilter/ipvs/ip_vs_ctl.c line
IPVS: Enter: ip_vs_service_net_cleanup, net/netfilter/ipvs/ip_vs_ctl.c
IPVS: __ip_vs_del_service: enter
IPVS: Moving dest 192.168.1.6:0 into trash, dest->refcnt=43450
...
IPVS: Moving dest 192.168.1.3:0 into trash, dest->refcnt=43449
IPVS: __ip_vs_del_service: enter
IPVS: Removing destination 0/[2003:0000:0000:0000:0000:0002:0000:0006]:80
...
IPVS: Removing destination 0/[2003:0000:0000:0000:0000:0002:0000:0003]:80
IPVS: Removing service 0/[2003:0000:0000:0000:0000:0002:0004:0100]:80 usecnt=0
IPVS: Leave: ip_vs_service_net_cleanup, net/netfilter/ipvs/ip_vs_ctl.c
IPVS: Enter: ip_vs_control_net_cleanup, net/netfilter/ipvs/ip_vs_ctl.c
IPVS: Removing service 80/0.0.0.0:0 usecnt=0
IPVS: Leave: ip_vs_control_net_cleanup, net/netfilter/ipvs/ip_vs_ctl.c
IPVS: ipvs netns 8 released
PATCH SET
This patch set is based upon net-next-2.6 (2.6.39-rc2)
SUMMARY
include/net/ip_vs.h | 23 ++++-- net/netfilter/ipvs/ip_vs_app.c | 23 +----- net/netfilter/ipvs/ip_vs_conn.c | 14 +--- net/netfilter/ipvs/ip_vs_core.c | 132 +++++++++++++++++++++-------- net/netfilter/ipvs/ip_vs_ctl.c | 178 ++++++++++++++++++++++++++++++-------- net/netfilter/ipvs/ip_vs_est.c | 21 +---- net/netfilter/ipvs/ip_vs_proto.c | 11 +-- net/netfilter/ipvs/ip_vs_sync.c | 70 ++++++++-------- 8 files changed, 299 insertions(+), 173 deletions(-)
PATCH v3 1/6 IPVS: Change of socket usage to enable name space exit.
To work this patch also needs the other patches in this series.
VERSION: 2
DESCRIPTION
If the sync daemons run in a name space while it crashes
or get killed, there is no way to stop them except for a reboot. When all patches are there, ip_vs_core will handle register_pernet_(), i.e. ip_vs_sync_init() and ip_vs_sync_cleanup() will be removed.
Kernel threads should not increment the use count of a socket. By calling sk_change_net() after creating a socket this is avoided. sock_release cant be used intead sk_release_kernel() should be used.
Thanks Eric W Biederman for your advices.
This patch is based on net-next-2.6 ver 2.6.39-rc2
CHANGES
Rev 2
sock_create_kern() used instead of __sock_create() return codes of kthread_stop() used.
--- net/netfilter/ipvs/ip_vs_core.c | 2 +- net/netfilter/ipvs/ip_vs_sync.c | 58 +++++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 22 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +1 -1
@@ -1896,7 +1896,7 @@ static int __net_init __ip_vs_init(struct net *net) static void __net_exit __ip_vs_cleanup(struct net *net) { -IP_VS_DBG (10 ,"ipvs netns %d released\n" ,net_ipvs (net)->gen); +IP_VS_DBG (2 ,"ipvs netns %d released\n" ,net_ipvs (net)->gen); }static struct pernet_operations ipvs_core_ops = {
net/netfilter/ipvs/ip_vs_sync.c +37 -21
146 lines not on this page · raw message
Signature · 1 line
1.7.4
PATCH v3 2/6 IPVS: labels at pos 0
In reply to Hans SchillstromPut goto labels at the beginig of row
acording to coding style example.
--- net/netfilter/ipvs/ip_vs_core.c | 10 +++++----- net/netfilter/ipvs/ip_vs_ctl.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +5 -5
@@ -1388,7 +1388,7 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum) verdict =NF_DROP ; } - out: +out:__ip_vs_conn_put (cp);return verdict;
@@ -1955,14 +1955,14 @@ static int __init ip_vs_init(void) cleanup_sync:ip_vs_sync_cleanup (); - cleanup_conn: +cleanup_conn:ip_vs_conn_cleanup (); - cleanup_app: +cleanup_app:ip_vs_app_cleanup (); - cleanup_protocol: +cleanup_protocol:ip_vs_protocol_cleanup ();ip_vs_control_cleanup (); - cleanup_estimator: +cleanup_estimator:ip_vs_estimator_cleanup ();unregister_pernet_subsys (&ipvs_core_ops);/* free ip_vs struct */ return ret;
net/netfilter/ipvs/ip_vs_ctl.c +4 -4
@@ -1327,9 +1327,9 @@ ip_vs_edit_service(struct ip_vs_service *svc, struct ip_vs_service_user_kern *u)ip_vs_bind_pe (svc, pe); } - out_unlock: +out_unlock:write_unlock_bh (&__ip_vs_svc_lock); - out: +out:ip_vs_scheduler_put (old_sched);ip_vs_pe_put (old_pe);return ret;
@@ -2387,7 +2387,7 @@ __ip_vs_get_service_entries(struct net *net, count++; } } - out: +out:return ret; }
@@ -2625,7 +2625,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) ret = -EINVAL ; } - out: +out:mutex_unlock (&__ip_vs_mutex);return ret; }
Signature · 1 line
1.7.4
PATCH v3 3/6 IPVS: init and cleanup restructuring.
In reply to Hans SchillstromREVISION 3
DESCRIPTION
This patch tries to restore the initial init and cleanup sequences that was before namspace patch.
The number of calls to register_pernet_device have been reduced to one for the ip_vs.ko
Schedulers still have their own calls.
This patch adds a function __ip_vs_service_cleanup() and a throttle or actually on/off switch for the netfilter hooks.
The nf hooks will be enabled when the first service is loaded and disabled when the last service is removed or when a namespace exit starts.
CHANGES
Rev 2
receivening av device events, suggested by Julian. This change add 3 new functions ip_vs_dst_event() ip_vs_svc_reset() and __ip_vs_dev_reset().
Rev 3
Throttle renamed to enable.
Comments from Julian implemented
Check enable in ip_vs_in, ip_vs_out and ip_vs_forward_icmp* Remove in ip_vs_in_icmp*.
ip_vs_svc_reset() moved into ip_vs_dst_event(). ip_vs_service_cleanup() uses ip_vs_flush and mutex lock. ip_vs_unlink_service_nolock() added.
--- include/net/ip_vs.h | 17 +++++ net/netfilter/ipvs/ip_vs_app.c | 15 +--- net/netfilter/ipvs/ip_vs_conn.c | 12 +--- net/netfilter/ipvs/ip_vs_core.c | 101 ++++++++++++++++++++++++--- net/netfilter/ipvs/ip_vs_ctl.c | 143 +++++++++++++++++++++++++++++++------- net/netfilter/ipvs/ip_vs_est.c | 14 +--- net/netfilter/ipvs/ip_vs_proto.c | 11 +--- net/netfilter/ipvs/ip_vs_sync.c | 13 +--- 8 files changed, 240 insertions(+), 86 deletions(-)
include/net/ip_vs.h +17 -0
@@ -791,6 +791,7 @@ struct ip_vs_app {/* IPVS in network namespace */ struct netns_ipvs {int gen;/* Generation */ +int enable;/* enable like nf_hooks do */ /* * Hash table: for real service lookups */
@@ -1089,6 +1090,22 @@ ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)atomic_inc (&ctl_cp->n_control); } +/* +* IPVS netns init & cleanup functions +*/ +extern int __ip_vs_estimator_init (struct net *net); +extern int __ip_vs_control_init (struct net *net); +extern int __ip_vs_protocol_init (struct net *net); +extern int __ip_vs_app_init (struct net *net); +extern int __ip_vs_conn_init (struct net *net); +extern int __ip_vs_sync_init (struct net *net); +extern void __ip_vs_conn_cleanup (struct net *net); +extern void __ip_vs_app_cleanup (struct net *net); +extern void __ip_vs_protocol_cleanup (struct net *net); +extern void __ip_vs_control_cleanup (struct net *net); +extern void __ip_vs_estimator_cleanup (struct net *net); +extern void __ip_vs_sync_cleanup (struct net *net); +extern void __ip_vs_service_cleanup (struct net *net);/* * IPVS application functions
net/netfilter/ipvs/ip_vs_app.c +3 -12
@@ -576,7 +576,7 @@ static const struct file_operations ip_vs_app_fops = { };#endif -static int __net_init __ip_vs_app_init (struct net *net) +int __net_init __ip_vs_app_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -585,26 +585,17 @@ static int __net_init __ip_vs_app_init(struct net *net)return 0 ; } -static void __net_exit __ip_vs_app_cleanup(struct net *net) +void __net_exit __ip_vs_app_cleanup(struct net *net) {proc_net_remove (net,"ip_vs_app" ); } -static struct pernet_operations ip_vs_app_ops = { - .init = __ip_vs_app_init, - .exit = __ip_vs_app_cleanup, -}; -int __init ip_vs_app_init (void ) { -int rv; - - rv =register_pernet_subsys (&ip_vs_app_ops); -return rv; +return 0 ; }void ip_vs_app_cleanup (void ) { -unregister_pernet_subsys (&ip_vs_app_ops); }
net/netfilter/ipvs/ip_vs_conn.c +2 -10
@@ -1258,22 +1258,17 @@ int __net_init __ip_vs_conn_init(struct net *net)return 0 ; } -static void __net_exit __ip_vs_conn_cleanup(struct net *net) +void __net_exit __ip_vs_conn_cleanup(struct net *net) {/* flush all the connection entries first */ ip_vs_conn_flush (net);proc_net_remove (net,"ip_vs_conn" );proc_net_remove (net,"ip_vs_conn_sync" ); } -static struct pernet_operations ipvs_conn_ops = { - .init = __ip_vs_conn_init, - .exit = __ip_vs_conn_cleanup, -};int __init ip_vs_conn_init (void ) {int idx; -int retc;/* Compute size and mask */ ip_vs_conn_tab_size =1 << ip_vs_conn_tab_bits;
@@ -1309,17 +1304,14 @@ int __init ip_vs_conn_init(void)rwlock_init (&__ip_vs_conntbl_lock_array[idx].l); } - retc =register_pernet_subsys (&ipvs_conn_ops); -/* calculate the random value for connection hash */ get_random_bytes (&ip_vs_conn_rnd,sizeof (ip_vs_conn_rnd)); -return retc; +return 0 ; }void ip_vs_conn_cleanup (void ) { -unregister_pernet_subsys (&ipvs_conn_ops);/* Release the empty cache */ kmem_cache_destroy (ip_vs_conn_cachep);vfree (ip_vs_conn_tab);
net/netfilter/ipvs/ip_vs_core.c +92 -9
216 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +118 -25
242 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_est.c +3 -11
@@ -192,7 +192,7 @@ void ip_vs_read_estimator(struct ip_vs_stats_user *dst, dst->outbps = (e->outbps +0xF ) >>5 ; } -static int __net_init __ip_vs_estimator_init (struct net *net) +int __net_init __ip_vs_estimator_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -203,24 +203,16 @@ static int __net_init __ip_vs_estimator_init(struct net *net)return 0 ; } -static void __net_exit __ip_vs_estimator_exit(struct net *net) +void __net_exit __ip_vs_estimator_cleanup(struct net *net) {del_timer_sync (&net_ipvs (net)->est_timer); } -static struct pernet_operations ip_vs_app_ops = { - .init = __ip_vs_estimator_init, - .exit = __ip_vs_estimator_exit, -};int __init ip_vs_estimator_init (void ) { -int rv; - - rv =register_pernet_subsys (&ip_vs_app_ops); -return rv; +return 0 ; }void ip_vs_estimator_cleanup (void ) { -unregister_pernet_subsys (&ip_vs_app_ops); }
net/netfilter/ipvs/ip_vs_proto.c +2 -9
@@ -316,7 +316,7 @@ ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,/* * per network name-space init */ -static int __net_init __ip_vs_protocol_init (struct net *net) +int __net_init __ip_vs_protocol_init (struct net *net) {#ifdef CONFIG_IP_VS_PROTO_TCP register_ip_vs_proto_netns (net, &ip_vs_protocol_tcp);
@@ -336,7 +336,7 @@ static int __net_init __ip_vs_protocol_init(struct net *net)return 0 ; } -static void __net_exit __ip_vs_protocol_cleanup(struct net *net) +void __net_exit __ip_vs_protocol_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);struct ip_vs_proto_data *pd;
@@ -349,11 +349,6 @@ static void __net_exit __ip_vs_protocol_cleanup(struct net *net) } } -static struct pernet_operations ipvs_proto_ops = { - .init = __ip_vs_protocol_init, - .exit = __ip_vs_protocol_cleanup, -}; -int __init ip_vs_protocol_init (void ) {char protocols[64 ];
@@ -382,7 +377,6 @@ int __init ip_vs_protocol_init(void)REGISTER_PROTOCOL (&ip_vs_protocol_esp);#endif pr_info ("Registered protocols (%s)\n" , &protocols[2 ]); -return register_pernet_subsys (&ipvs_proto_ops);return 0 ; }
@@ -393,7 +387,6 @@ void ip_vs_protocol_cleanup(void)struct ip_vs_protocol *pp;int i; -unregister_pernet_subsys (&ipvs_proto_ops);/* unregister all the ipvs protocols */ for (i =0 ; i <IP_VS_PROTO_TAB_SIZE ; i++) {while ((pp = ip_vs_proto_table[i]) !=NULL )
net/netfilter/ipvs/ip_vs_sync.c +2 -7
@@ -1663,7 +1663,7 @@ int stop_sync_thread(struct net *net, int state)/* * Initialize data struct for each netns */ -static int __net_init __ip_vs_sync_init (struct net *net) +int __net_init __ip_vs_sync_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -1677,7 +1677,7 @@ static int __net_init __ip_vs_sync_init(struct net *net)return 0 ; } -static void __ip_vs_sync_cleanup (struct net *net) +void __ip_vs_sync_cleanup (struct net *net) {int retc;
@@ -1690,18 +1690,11 @@ static void __ip_vs_sync_cleanup(struct net *net)pr_err ("Failed to stop Backup Daemon\n" ); } -static struct pernet_operations ipvs_sync_ops = { - .init = __ip_vs_sync_init, - .exit = __ip_vs_sync_cleanup, -}; -
PATCH v3 4/6 IPVS: rename of netns init and cleanup functions.
In reply to Hans SchillstromMake it more clear what the functions does,
on request by Julian.
--- include/net/ip_vs.h | 26 +++++++++++++------------- net/netfilter/ipvs/ip_vs_app.c | 4 ++-- net/netfilter/ipvs/ip_vs_conn.c | 4 ++-- net/netfilter/ipvs/ip_vs_core.c | 36 ++++++++++++++++++------------------ net/netfilter/ipvs/ip_vs_ctl.c | 20 ++++++++++---------- net/netfilter/ipvs/ip_vs_est.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto.c | 4 ++-- net/netfilter/ipvs/ip_vs_sync.c | 4 ++-- 8 files changed, 51 insertions(+), 51 deletions(-)
include/net/ip_vs.h +13 -13
@@ -1093,19 +1093,19 @@ ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)/* * IPVS netns init & cleanup functions */ -extern int __ip_vs_estimator_init (struct net *net); -extern int __ip_vs_control_init (struct net *net); -extern int __ip_vs_protocol_init (struct net *net); -extern int __ip_vs_app_init (struct net *net); -extern int __ip_vs_conn_init (struct net *net); -extern int __ip_vs_sync_init (struct net *net); -extern void __ip_vs_conn_cleanup (struct net *net); -extern void __ip_vs_app_cleanup (struct net *net); -extern void __ip_vs_protocol_cleanup (struct net *net); -extern void __ip_vs_control_cleanup (struct net *net); -extern void __ip_vs_estimator_cleanup (struct net *net); -extern void __ip_vs_sync_cleanup (struct net *net); -extern void __ip_vs_service_cleanup (struct net *net); +extern int ip_vs_estimator_net_init (struct net *net); +extern int ip_vs_control_net_init (struct net *net); +extern int ip_vs_protocol_net_init (struct net *net); +extern int ip_vs_app_net_init (struct net *net); +extern int ip_vs_conn_net_init (struct net *net); +extern int ip_vs_sync_net_init (struct net *net); +extern void ip_vs_conn_net_cleanup (struct net *net); +extern void ip_vs_app_net_cleanup (struct net *net); +extern void ip_vs_protocol_net_cleanup (struct net *net); +extern void ip_vs_control_net_cleanup (struct net *net); +extern void ip_vs_estimator_net_cleanup (struct net *net); +extern void ip_vs_sync_net_cleanup (struct net *net); +extern void ip_vs_service_net_cleanup (struct net *net);/* * IPVS application functions
net/netfilter/ipvs/ip_vs_app.c +2 -2
@@ -576,7 +576,7 @@ static const struct file_operations ip_vs_app_fops = { };#endif -int __net_init __ip_vs_app_init (struct net *net) +int __net_init ip_vs_app_net_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -585,7 +585,7 @@ int __net_init __ip_vs_app_init(struct net *net)return 0 ; } -void __net_exit __ip_vs_app_cleanup(struct net *net) +void __net_exit ip_vs_app_net_cleanup(struct net *net) {proc_net_remove (net,"ip_vs_app" ); }
net/netfilter/ipvs/ip_vs_conn.c +2 -2
@@ -1247,7 +1247,7 @@ flush_again:/* * per netns init and exit */ -int __net_init __ip_vs_conn_init (struct net *net) +int __net_init ip_vs_conn_net_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -1258,7 +1258,7 @@ int __net_init __ip_vs_conn_init(struct net *net)return 0 ; } -void __net_exit __ip_vs_conn_cleanup(struct net *net) +void __net_exit ip_vs_conn_net_cleanup(struct net *net) {/* flush all the connection entries first */ ip_vs_conn_flush (net);
net/netfilter/ipvs/ip_vs_core.c +18 -18
@@ -1911,22 +1911,22 @@ static int __net_init __ip_vs_init(struct net *net)atomic_inc (&ipvs_netns_cnt); net->ipvs = ipvs; -if (__ip_vs_estimator_init (net) <0 ) +if (ip_vs_estimator_net_init (net) <0 ) goto estimator_fail; -if (__ip_vs_control_init (net) <0 ) +if (ip_vs_control_net_init (net) <0 ) goto control_fail; -if (__ip_vs_protocol_init (net) <0 ) +if (ip_vs_protocol_net_init (net) <0 ) goto protocol_fail; -if (__ip_vs_app_init (net) <0 ) +if (ip_vs_app_net_init (net) <0 ) goto app_fail; -if (__ip_vs_conn_init (net) <0 ) +if (ip_vs_conn_net_init (net) <0 ) goto conn_fail; -if (__ip_vs_sync_init (net) <0 ) +if (ip_vs_sync_net_init (net) <0 ) goto sync_fail; printk(KERN_INFO "IPVS: Creating netns size=%zu id=%d\n",
@@ -1937,27 +1937,27 @@ static int __net_init __ip_vs_init(struct net *net)*/ sync_fail: -__ip_vs_conn_cleanup (net); +ip_vs_conn_net_cleanup (net); conn_fail: -__ip_vs_app_cleanup (net); +ip_vs_app_net_cleanup (net); app_fail: -__ip_vs_protocol_cleanup (net); +ip_vs_protocol_net_cleanup (net); protocol_fail: -__ip_vs_control_cleanup (net); +ip_vs_control_net_cleanup (net); control_fail: -__ip_vs_estimator_cleanup (net); +ip_vs_estimator_net_cleanup (net); estimator_fail:return -ENOMEM ; } static void __net_exit __ip_vs_cleanup(struct net *net) { -__ip_vs_service_cleanup (net);/* ip_vs_flush() with locks */ -__ip_vs_conn_cleanup (net); -__ip_vs_app_cleanup (net); -__ip_vs_protocol_cleanup (net); -__ip_vs_control_cleanup (net); -__ip_vs_estimator_cleanup (net); +ip_vs_service_net_cleanup (net);/* ip_vs_flush() with locks */ +ip_vs_conn_net_cleanup (net); +ip_vs_app_net_cleanup (net); +ip_vs_protocol_net_cleanup (net); +ip_vs_control_net_cleanup (net); +ip_vs_estimator_net_cleanup (net);IP_VS_DBG (2 ,"ipvs netns %d released\n" ,net_ipvs (net)->gen); }
@@ -1965,7 +1965,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net) {EnterFunction (2 );net_ipvs (net)->enable =0 ;/* Disable packet reception */ -__ip_vs_sync_cleanup (net); +ip_vs_sync_net_cleanup (net);LeaveFunction (2 ); }
net/netfilter/ipvs/ip_vs_ctl.c +10 -10
@@ -1494,7 +1494,7 @@ static int ip_vs_flush(struct net *net)* Delete service by {netns} in the service table. * Called by __ip_vs_cleanup() */ -void __ip_vs_service_cleanup (struct net *net) +void ip_vs_service_net_cleanup (struct net *net) {EnterFunction (2 );/* Check for "full" addressed entries */
@@ -1673,7 +1673,7 @@ proc_do_sync_mode(ctl_table *table, int write,/* * IPVS sysctl table (under the /proc/sys/net/ipv4/vs/) * Do not change order or insert new entries without -* align with netns init in __ip_vs_control_init() +* align with netns init in ip_vs_control_net_init() */ static struct ctl_table vs_vars[] = {
@@ -3609,7 +3609,7 @@ static void ip_vs_genl_unregister(void)* per netns intit/exit func. */ #ifdef CONFIG_SYSCTL -int __net_init __ip_vs_control_init_sysctl (struct net *net) +int __net_init ip_vs_control_net_init_sysctl (struct net *net) {int idx;struct netns_ipvs *ipvs =net_ipvs (net);
@@ -3668,7 +3668,7 @@ int __net_init __ip_vs_control_init_sysctl(struct net *net)return 0 ; } -void __net_init __ip_vs_control_cleanup_sysctl (struct net *net) +void __net_init ip_vs_control_net_cleanup_sysctl (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -3679,8 +3679,8 @@ void __net_init __ip_vs_control_cleanup_sysctl(struct net *net)#else -int __net_init __ip_vs_control_init_sysctl (struct net *net) {return 0 ; } -void __net_init __ip_vs_control_cleanup_sysctl (struct net *net) { } +int __net_init ip_vs_control_net_init_sysctl (struct net *net) {return 0 ; } +void __net_init ip_vs_control_net_cleanup_sysctl (struct net *net) { }#endif
@@ -3688,7 +3688,7 @@ static struct notifier_block ip_vs_dst_notifier = { .notifier_call = ip_vs_dst_event, }; -int __net_init __ip_vs_control_init (struct net *net) +int __net_init ip_vs_control_net_init (struct net *net) {int idx;struct netns_ipvs *ipvs =net_ipvs (net);
@@ -3716,7 +3716,7 @@ int __net_init __ip_vs_control_init(struct net *net)proc_net_fops_create (net,"ip_vs_stats_percpu" ,0 , &ip_vs_stats_percpu_fops); -if (__ip_vs_control_init_sysctl (net)) +if (ip_vs_control_net_init_sysctl (net)) goto err;return 0 ;
@@ -3726,13 +3726,13 @@ err:return -ENOMEM ; } -void __net_exit __ip_vs_control_cleanup(struct net *net) +void __net_exit ip_vs_control_net_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);ip_vs_trash_cleanup (net);ip_vs_stop_estimator (net, &ipvs->tot_stats); -__ip_vs_control_cleanup_sysctl (net); +ip_vs_control_net_cleanup_sysctl (net);proc_net_remove (net,"ip_vs_stats_percpu" );proc_net_remove (net,"ip_vs_stats" );proc_net_remove (net,"ip_vs" );
net/netfilter/ipvs/ip_vs_est.c +2 -2
@@ -192,7 +192,7 @@ void ip_vs_read_estimator(struct ip_vs_stats_user *dst, dst->outbps = (e->outbps +0xF ) >>5 ; } -int __net_init __ip_vs_estimator_init (struct net *net) +int __net_init ip_vs_estimator_net_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -203,7 +203,7 @@ int __net_init __ip_vs_estimator_init(struct net *net)return 0 ; } -void __net_exit __ip_vs_estimator_cleanup(struct net *net) +void __net_exit ip_vs_estimator_net_cleanup(struct net *net) {del_timer_sync (&net_ipvs (net)->est_timer); }
net/netfilter/ipvs/ip_vs_proto.c +2 -2
@@ -316,7 +316,7 @@ ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,/* * per network name-space init */ -int __net_init __ip_vs_protocol_init (struct net *net) +int __net_init ip_vs_protocol_net_init (struct net *net) {#ifdef CONFIG_IP_VS_PROTO_TCP register_ip_vs_proto_netns (net, &ip_vs_protocol_tcp);
@@ -336,7 +336,7 @@ int __net_init __ip_vs_protocol_init(struct net *net)return 0 ; } -void __net_exit __ip_vs_protocol_cleanup(struct net *net) +void __net_exit ip_vs_protocol_net_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);struct ip_vs_proto_data *pd;
net/netfilter/ipvs/ip_vs_sync.c +2 -2
@@ -1663,7 +1663,7 @@ int stop_sync_thread(struct net *net, int state)/* * Initialize data struct for each netns */ -int __net_init __ip_vs_sync_init (struct net *net) +int __net_init ip_vs_sync_net_init (struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net);
@@ -1677,7 +1677,7 @@ int __net_init __ip_vs_sync_init(struct net *net)return 0 ; } -void __ip_vs_sync_cleanup (struct net *net) +void ip_vs_sync_net_cleanup (struct net *net) {int retc;
Signature · 1 line
1.7.4
PATCH v3 5/6 IPVS: remove unused init and cleanup functions.
In reply to Hans SchillstromAfter restructuring, there is some unused or empty functions left to be removed.
--- include/net/ip_vs.h | 6 ------ net/netfilter/ipvs/ip_vs_app.c | 10 ---------- net/netfilter/ipvs/ip_vs_core.c | 29 ++++------------------------- net/netfilter/ipvs/ip_vs_est.c | 9 --------- net/netfilter/ipvs/ip_vs_sync.c | 9 --------- 5 files changed, 4 insertions(+), 59 deletions(-)
include/net/ip_vs.h +0 -6
@@ -1123,8 +1123,6 @@ extern void ip_vs_app_inc_put(struct ip_vs_app *inc);extern int ip_vs_app_pkt_out (struct ip_vs_conn *,struct sk_buff *skb);extern int ip_vs_app_pkt_in (struct ip_vs_conn *,struct sk_buff *skb); -extern int ip_vs_app_init (void ); -extern void ip_vs_app_cleanup (void );void ip_vs_bind_pe (struct ip_vs_service *svc,struct ip_vs_pe *pe);void ip_vs_unbind_pe (struct ip_vs_service *svc);
@@ -1227,15 +1225,11 @@ extern int start_sync_thread(struct net *net, int state, char *mcast_ifn, __u8 syncid);extern int stop_sync_thread (struct net *net,int state);extern void ip_vs_sync_conn (struct net *net,struct ip_vs_conn *cp); -extern int ip_vs_sync_init (void ); -extern void ip_vs_sync_cleanup (void );/* * IPVS rate estimator prototypes (from ip_vs_est.c) */ -extern int ip_vs_estimator_init (void ); -extern void ip_vs_estimator_cleanup (void );extern void ip_vs_start_estimator (struct net *net,struct ip_vs_stats *stats);extern void ip_vs_stop_estimator (struct net *net,struct ip_vs_stats *stats);extern void ip_vs_zero_estimator (struct ip_vs_stats *stats);
net/netfilter/ipvs/ip_vs_app.c +0 -10
@@ -589,13 +589,3 @@ void __net_exit ip_vs_app_net_cleanup(struct net *net) {proc_net_remove (net,"ip_vs_app" ); } - -int __init ip_vs_app_init (void ) -{ -return 0 ; -} - - -void ip_vs_app_cleanup (void ) -{ -}
net/netfilter/ipvs/ip_vs_core.c +4 -25
@@ -1987,36 +1987,23 @@ static int __init ip_vs_init(void) {int ret; -ip_vs_estimator_init (); ret =ip_vs_control_init ();if (ret <0 ) {pr_err ("can't setup control.\n" ); - goto cleanup_estimator; + goto exit; }ip_vs_protocol_init (); - ret =ip_vs_app_init (); -if (ret <0 ) { -pr_err ("can't setup application helper.\n" ); - goto cleanup_protocol; - } - ret =ip_vs_conn_init ();if (ret <0 ) {pr_err ("can't setup connection table.\n" ); - goto cleanup_app; - } - - ret =ip_vs_sync_init (); -if (ret <0 ) { -pr_err ("can't setup sync data.\n" ); - goto cleanup_conn; + goto cleanup_protocol; } ret =register_pernet_subsys (&ipvs_core_ops);/* Alloc ip_vs struct */ if (ret <0 ) - goto cleanup_sync; + goto cleanup_conn; ret =register_pernet_device (&ipvs_core_dev_ops);if (ret <0 )
@@ -2036,17 +2023,12 @@ cleanup_dev:unregister_pernet_device (&ipvs_core_dev_ops); cleanup_sub:unregister_pernet_subsys (&ipvs_core_ops); -cleanup_sync: -ip_vs_sync_cleanup (); cleanup_conn:ip_vs_conn_cleanup (); -cleanup_app: -ip_vs_app_cleanup (); cleanup_protocol:ip_vs_protocol_cleanup ();ip_vs_control_cleanup (); -cleanup_estimator: -ip_vs_estimator_cleanup (); +exit:return ret; }
@@ -2055,12 +2037,9 @@ static void __exit ip_vs_cleanup(void)nf_unregister_hooks (ip_vs_ops,ARRAY_SIZE (ip_vs_ops));unregister_pernet_device (&ipvs_core_dev_ops);unregister_pernet_subsys (&ipvs_core_ops);/* free ip_vs struct */ -ip_vs_sync_cleanup ();ip_vs_conn_cleanup (); -ip_vs_app_cleanup ();ip_vs_protocol_cleanup ();ip_vs_control_cleanup (); -ip_vs_estimator_cleanup ();pr_info ("ipvs unloaded.\n" ); }
net/netfilter/ipvs/ip_vs_est.c +0 -9
@@ -207,12 +207,3 @@ void __net_exit ip_vs_estimator_net_cleanup(struct net *net) {del_timer_sync (&net_ipvs (net)->est_timer); } - -int __init ip_vs_estimator_init (void ) -{ -return 0 ; -} - -void ip_vs_estimator_cleanup (void ) -{ -}
net/netfilter/ipvs/ip_vs_sync.c +0 -5
@@ -1689,12 +1689,3 @@ void ip_vs_sync_net_cleanup(struct net *net)if (retc && retc != -EINVAL )pr_err ("Failed to stop Backup Daemon\n" ); } - -int __init ip_vs_sync_init (void ) -{ -return 0 ; -}
PATCH v3 6/6 IPVS: add debug functions
In reply to Hans SchillstromOptional patch, but it is nice to have.
--- net/netfilter/ipvs/ip_vs_ctl.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +12 -1
@@ -351,8 +351,11 @@ static int ip_vs_svc_unhash(struct ip_vs_service *svc) svc->flags &= ~IP_VS_SVC_F_HASHED ;atomic_dec (&svc->refcnt);/* No more services, no need for input */ -if (atomic_read (&svc->refcnt) ==0 ) +if (atomic_read (&svc->refcnt) ==0 ) {net_ipvs (svc->net)->enable =0 ; +IP_VS_DBG (2 ,"Last service removed in net(%d) input disabled\n" , +net_ipvs (svc->net)->gen); + }return 1 ; }
@@ -1222,6 +1225,10 @@ ip_vs_add_service(struct net *net, struct ip_vs_service_user_kern *u,write_unlock_bh (&__ip_vs_svc_lock); *svc_p = svc; +if (!ipvs->enable) +pr_info ("netns(%d) enabled first service added\n" , + ipvs->gen); +/* Now there is a service - full throttle */ ipvs->enable =1 ;return 0 ;
@@ -3693,6 +3700,7 @@ int __net_init ip_vs_control_net_init(struct net *net)int idx;struct netns_ipvs *ipvs =net_ipvs (net); +EnterFunction (2 ); ipvs->rs_lock =__RW_LOCK_UNLOCKED (ipvs->rs_lock);/* Initialize rs_table */
@@ -3719,6 +3727,7 @@ int __net_init ip_vs_control_net_init(struct net *net)if (ip_vs_control_net_init_sysctl (net)) goto err; +LeaveFunction (2 );return 0 ; err:
@@ -3730,6 +3739,7 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net) {struct netns_ipvs *ipvs =net_ipvs (net); +EnterFunction (2 );ip_vs_trash_cleanup (net);ip_vs_stop_estimator (net, &ipvs->tot_stats);ip_vs_control_net_cleanup_sysctl (net);
@@ -3737,6 +3747,7 @@ void __net_exit ip_vs_control_net_cleanup(struct net *net)proc_net_remove (net,"ip_vs_stats" );proc_net_remove (net,"ip_vs" );free_percpu (ipvs->tot_stats.cpustats); +LeaveFunction (2 ); }int __init ip_vs_control_init (void )
Signature · 1 line
1.7.4
Simon Horman
maintainerQuoted 1 line · Hans Schillstrom
This patch series handles exit from a network name space.
Hi Hans,
thanks for your work on this.
I've looked over the patches and nothing catches my eye - thanks for fixing up the things that I commented on previously.
I think that patches 1 and 2 should be targeted at 2.6.39, while the remainder look like 2.6.40 material. Does that sound reasonable to you?
Julian and Eric,
can you take a look over these?
I would appreciate your review.
Quoted 8 lines
Subject: Re: [v2 PATCH 0/6] IPVS: init and cleanup.
On Fri, Apr 29, 2011 at 08:25:28AM +0200, Hans Schillstrom wrote:
This patch series handles exit from a network name space.Hi Hans,
Quoted 7 lines
thanks for your work on this.
I've looked over the patches and nothing catches my eye - thanks for fixing up the things that I commented on previously.I think that patches 1 and 2 should be targeted at 2.6.39, while the remainder look like 2.6.40 material. Does that sound reasonable to you?
I do prefer to keep them together,
but if you want it in that way it's OK for me.
We are doing a lot of tests right now with this patch set. If we found any issues I'll let you know.
Regards
Hans
Simon Horman
maintainerQuoted 12 lines · Hans Schillström
Quoted 12 lines
Subject: Re: [v2 PATCH 0/6] IPVS: init and cleanup.
On Fri, Apr 29, 2011 at 08:25:28AM +0200, Hans Schillstrom wrote:
This patch series handles exit from a network name space.Hi Hans,
thanks for your work on this.
I've looked over the patches and nothing catches my eye - thanks for fixing up the things that I commented on previously.
Quoted 6 lines
Quoted 3 lines
I think that patches 1 and 2 should be targeted at 2.6.39, while the remainder look like 2.6.40 material. Does that sound reasonable to you?
I do prefer to keep them together,
but if you want it in that way it's OK for me.
I understand that you'd like to keep things together, but I think its too much change for .39 this late in the rc series.
Quoted 2 lines
We are doing a lot of tests right now with this patch set. If we found any issues I'll let you know.
Thanks
Julian Anastasov
maintainerHello,
Quoted 5 lines · Hans Schillstrom
This patch series handles exit from a network name space.
REVISION
This is version 3
Great! Only one missing lock:
Patch 3:
Missing write_[un]lock_bh(&__ip_vs_svc_lock) in ip_vs_flush, now we use ip_vs_unlink_service_nolock.
As you are going to create new version you can look also at these:
Patch 5:
Can you rename 'goto exit;' to 'goto cleanup;' or 'goto out;'
Patch 6:
Add at least one comma after 'enabled' here:
netns(%d) enabled first service added
Quoted 17 lines
OVERVIEW
Basically there was three faults in the netns implementation.
- Kernel threads hold devices and preventing an exit.
- dst cache holds references to devices.
- Services was not always released.Patch 1 & 3 contains the functionality
4 renames funcctions
5 removes empty functions
6 Debuging.IMPLEMENTATION
- Avoid to increment the usage counter for kernel threads. this is done in the first patch.
- Patch 3 tries to restore the cleanup order.
AddNETDEV_UNREGISTERnotification fordst_reset
Quoted 9 lines
Revision 3
Residies in patch 3
Throttle renamed to enable.
Comments from Julian implemented
Check enable inip_vs_in,ip_vs_outand ip_vs_forward_icmp* Remove in ip_vs_in_icmp*.
ip_vs_svc_reset()moved intoip_vs_dst_event().ip_vs_service_cleanup()usesip_vs_flushand mutex lock.ip_vs_unlink_service_nolock()added.
Regards
--
Julian Anastasov <[email protected]>