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 2
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
From Julian -
"For __ip_vs_service_cleanup: it still has to use mutex. Or we can avoid it by introducing ip_vs_unlink_service_nolock:ip_vs_flush will look like your __ip_vs_service_cleanup and will call ip_vs_unlink_service_nolock. ip_vs_unlink_service_nolock will be called by ip_vs_flush and by ip_vs_unlink_service."
I will give above another try later on see if I can get it to work. Right now ip_vs_service_net_cleanup() seems to work.
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 | 118 +++++++++++++++++++-------- net/netfilter/ipvs/ip_vs_ctl.c | 168 +++++++++++++++++++++++++++++++------- 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, 281 insertions(+), 167 deletions(-)
PATCH v2 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
--
1.7.2.3
PATCH v2 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.2.3
PATCH v2 3/6 IPVS: init and cleanup restructuring.
In reply to Hans SchillstromREVISION 2
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 R2
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().
--- 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 | 87 ++++++++++++++++++++++--- net/netfilter/ipvs/ip_vs_ctl.c | 133 ++++++++++++++++++++++++++++++++------ 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, 222 insertions(+), 80 deletions(-)
include/net/ip_vs.h +17 -0
@@ -830,6 +830,7 @@ struct netns_ipvs {struct list_head sctp_apps[SCTP_APP_TAB_SIZE ];spinlock_t sctp_app_lock;#endif +atomic_t enable;/* enable like nf_hooks do */ /* ip_vs_conn */ atomic_t conn_count;/* connection counter */
@@ -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 +78 -9
176 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +114 -19
203 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 v2 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
@@ -1897,22 +1897,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",
@@ -1923,27 +1923,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); }
@@ -1951,7 +1951,7 @@ static void __net_exit __ip_vs_dev_cleanup(struct net *net) {EnterFunction (2 );atomic_set (&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
@@ -1486,7 +1486,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) {unsigned hash;struct ip_vs_service *svc, *tmp;
@@ -1675,7 +1675,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[] = {
@@ -3611,7 +3611,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);
@@ -3670,7 +3670,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);
@@ -3681,8 +3681,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
@@ -3690,7 +3690,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);
@@ -3718,7 +3718,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 ;
@@ -3728,13 +3728,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;
--
1.7.2.3
PATCH v2 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
@@ -1973,36 +1973,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 )
@@ -2022,17 +2009,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; }
@@ -2041,12 +2023,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 -9
@@ -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 ; -} - -void ip_vs_sync_cleanup (void ) -{ -}
Signature · 1 line
1.7.2.3
PATCH v2 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 then no need for input */ -if (atomic_read (&svc->refcnt) ==0 ) +if (!atomic_read (&svc->refcnt)) {atomic_set (&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 (atomic_read (&ipvs->enable) ==0 ) +pr_info ("netns(%d) enabled first service added\n" , + ipvs->gen); +/* Now there is a service - full throttle */ atomic_set (&ipvs->enable,1 );return 0 ;
@@ -3695,6 +3702,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 */
@@ -3721,6 +3729,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:
@@ -3732,6 +3741,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);
@@ -3739,6 +3749,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 )
--
1.7.2.3
Julian Anastasov
maintainerHello,
Quoted 51 lines · Hans Schillstrom
This patch series handles exit from a network name space.
REVISION
This is version 2
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_resetQuoted 1 line
From Julian -
"For
__ip_vs_service_cleanup: it still has to use mutex. Or we can avoid it by introducingip_vs_unlink_service_nolock:ip_vs_flushwill look like your__ip_vs_service_cleanupand will callip_vs_unlink_service_nolock.ip_vs_unlink_service_nolockwill be called byip_vs_flushand byip_vs_unlink_service."I will give above another try later on see if I can get it to work. Right now
ip_vs_service_net_cleanup()seems to work.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.cline
IPVS: Leave:ip_vs_dst_event,net/netfilter/ipvs/ip_vs_ctl.cline
...
IPVS: Enter:ip_vs_dst_event,net/netfilter/ipvs/ip_vs_ctl.cline
IPVS: Leave:ip_vs_dst_event,net/netfilter/ipvs/ip_vs_ctl.cline
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
Quoted 8 lines
...
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
Notes only about PATCH 3/6:
- I was worried that throttle was used during cleanup with the idea to stop traffic. But as now it is only an optimization to avoid traffic to spend cycles in IPVS code I'll suggest to use it without atomic operations. It is not fatal if some packet does not see the disabling immediately. So, may be using 'if (net_ipvs(net)->enable)' is enough.
As result, there is no need to disable traffic in __ip_vs_dev_cleanup, it is going to stop during _device cleanup anyways.
- Please move check for 'enable' in ip_vs_in() before ip_vs_fill_iphdr, this is the preferred place:
+ net = skb_net(skb);
+ if (!net_ipvs(net)->enable)
+ return NF_ACCEPT; ip_vs_fill_iphdr(af, skb_network_header(skb), &iph);
Note that only ip_vs_in, ip_vs_out and ip_vs_forward_icmp* need check for 'enable'. Then we can remove them from ip_vs_in_icmp*
- As device can change its name space it was mandatory we to add support for NETDEV_UNREGISTER. As we are using _subsys pernet operations I expect we to see NETDEV_UNREGISTER while the _device pernet methods are called, so before our _subsys cleanup.
We can see in log that ip_vs_dst_event() is called before ip_vs_service_net_cleanup, i.e. before our subsys cleanup. net/core/dev.c uses register_pernet_device(&default_device_ops) to call NETDEV_UNREGISTER* during _device cleanup and to move devices to init_net. So, it should be safe
to rely on NETDEV_UNREGISTER event while we are subsys.
- __ip_vs_service_cleanup needs to call ip_vs_flush after converting to ip_vs_unlink_service_nolock.
- For ip_vs_dst_event: I prefer to put everything in this function, the ip_vs_svc_reset is not needed (name is not good too). For example:
struct ip_vs_dest *dest;
unsigned int hash;
mutex_lock(&__ip_vs_mutex);
/* No need to use rs_lock, the mutex protects the list */
for (hash = 0; hash < IP_VS_RTAB_SIZE; hash++) {
list_for_each_entry(dest, &ipvs->rs_table[hash], d_list) {
__ip_vs_dev_reset(dest, dev);
}
}
/* The mutex protects the trash list */
list_for_each_entry(dest, &ipvs->dest_trash, n_list) {
__ip_vs_dev_reset(dest, dev);
}
mutex_unlock(&__ip_vs_mutex);
No need to use __ip_vs_svc_lock or rs_lock because wedo not change the lists, __ip_vs_dev_reset has the needed dst_cache locking (dst_lock). I assume we can safely use our __ip_vs_mutex from netdevice notifier.
Regards
--
Julian Anastasov <[email protected]>