[Devel] [PATCH RHEL7 COMMIT] ve: Synchronize vznetstat pernet_operations

Konstantin Khorenko khorenko at virtuozzo.com
Wed May 27 21:35:01 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.3
------>
commit dc1b4d39ca367654791635b0c685818c2105dedc
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Wed May 27 21:35:01 2020 +0300

    ve: Synchronize vznetstat pernet_operations
    
    Make impossible parallel init/exit
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    Parallel per-net init/exit
    
    https://jira.sw.ru/browse/PSBM-104158
---
 kernel/ve/vznetstat/vznetstat.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/kernel/ve/vznetstat/vznetstat.c b/kernel/ve/vznetstat/vznetstat.c
index e0ca8d2fb027c..f37c137fbc15b 100644
--- a/kernel/ve/vznetstat/vznetstat.c
+++ b/kernel/ve/vznetstat/vznetstat.c
@@ -1083,29 +1083,39 @@ static struct file_operations proc_venetstat_v6_operations = {
         .release	= seq_release,
 };
 
+/* TODO: Use tc_lock? */
+static DEFINE_MUTEX(ve_stat_mutex);
+
 static int __net_init net_init_acct(struct net *net)
 {
 	struct ve_struct *ve = net->owner_ve;
+	int ret = 0;
 
+	mutex_lock(&ve_stat_mutex);
 	if (!ve->stat) {
 		ve->stat = venet_acct_find_create_stat(ve->veid);
-		if (!ve->stat)
-			return -ENOMEM;
+		if (!ve->stat) {
+			ret = -ENOMEM;
+			goto out;
+		}
 	} else
 		venet_acct_get_stat(ve->stat);
-
-	return 0;
+	mutex_unlock(&ve_stat_mutex);
+out:
+	return ret;
 }
 
 static void __net_exit net_exit_acct(struct net *net)
 {
 	struct ve_struct *ve = net->owner_ve;
 
+	mutex_lock(&ve_stat_mutex);
 	if (ve->stat) {
 		venet_acct_put_stat(ve->stat);
 		if (ve->ve_netns == net)
 			ve->stat = NULL;
 	}
+	mutex_unlock(&ve_stat_mutex);
 }
 
 static struct pernet_operations __net_initdata net_acct_ops = {


More information about the Devel mailing list