[Devel] [PATCH rh7] ve/accounting: Make sure the statistics is allocated for VE

Cyrill Gorcunov gorcunov at virtuozzo.com
Fri Jul 10 12:31:42 PDT 2015


Currently the ip_vznetstat doesn't allocate statistics for new
VEs but rather relies on fact that ip6_vznetstat module is loaded,
which is not always the true. It's rather messy at moment:
ip_vznetstat allocates stat for all existing VE's in module
init procedure, while ip6_vznetstat allocates statistics for
every new VE's, better might be to move all this stuff into
general vznetstat module in future.

https://jira.sw.ru/browse/PSBM-34837

Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
CC: Andrey Vagin <avagin at virtuozzo.com>
CC: Vladimir Davydov <vdavydov at virtuozzo.com>
CC: Konstantin Khorenko <khorenko at virtuozzo.com>
CC: Igor Sukhih <igor at parallels.com>
---
 kernel/ve/vznetstat/ip_vznetstat.c |   38 +++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Index: linux-pcs7.git/kernel/ve/vznetstat/ip_vznetstat.c
===================================================================
--- linux-pcs7.git.orig/kernel/ve/vznetstat/ip_vznetstat.c
+++ linux-pcs7.git/kernel/ve/vznetstat/ip_vznetstat.c
@@ -192,6 +192,42 @@ void ip_vznetstat_touch(void)
 }
 EXPORT_SYMBOL(ip_vznetstat_touch);
 
+static int init_venet_acct_ip_stat_hook(void *data)
+{
+	struct ve_struct *ve = (struct ve_struct *)data;
+	struct venet_stat *stat;
+
+	if (!ve->stat) {
+		stat = venet_acct_find_create_stat(ve->veid);
+		if (!stat)
+			return -ENOMEM;
+		init_venet_acct_ip_stat(ve, stat);
+	} else
+		venet_acct_get_stat(ve->stat);
+
+	__module_get(THIS_MODULE);
+	return 0;
+}
+
+static void fini_venet_acct_ip_stat_hook(void *data)
+{
+	struct ve_struct *ve = (struct ve_struct *)data;
+
+	/* module was load after VE ? */
+	if (!ve->stat)
+		return;
+
+	venet_acct_put_stat(ve->stat);
+	module_put(THIS_MODULE);
+}
+
+static struct ve_hook venet_acct_ip_stat_hook = {
+	.init		= init_venet_acct_ip_stat_hook,
+	.fini		= fini_venet_acct_ip_stat_hook,
+	.priority	= HOOK_PRIO_NET_ACCT,
+	.owner		= THIS_MODULE,
+};
+
 /*
  * ---------------------------------------------------------------------------
  * Initialization
@@ -216,6 +252,7 @@ int __init ip_venetstat_init(void)
 	if (ret < 0)
 		goto err;
 
+	ve_hook_register(VE_SS_CHAIN, &venet_acct_ip_stat_hook);
 	return 0;
 err:
 	mutex_lock(&ve_list_lock);
@@ -233,6 +270,7 @@ void __exit ip_venetstat_exit(void)
 	struct ve_struct *ve;
 
 	venet_acct_unregister_ip_hooks();
+	ve_hook_unregister(&venet_acct_ip_stat_hook);
 
 	mutex_lock(&ve_list_lock);
 	for_each_ve(ve) {



More information about the Devel mailing list