[RH7,09/11] ve: Synchronize vznetstat pernet_operations

Submitted by Kirill Tkhai on May 27, 2020, 3:54 p.m.

Details

Message ID 159059486552.408928.3648847763657835520.stgit@localhost.localdomain
State New
Series "Parallel per-net init/exit"
Headers show

Commit Message

Kirill Tkhai May 27, 2020, 3:54 p.m.
Make impossible parallel init/exit

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 kernel/ve/vznetstat/vznetstat.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/ve/vznetstat/vznetstat.c b/kernel/ve/vznetstat/vznetstat.c
index e0ca8d2fb027..f37c137fbc15 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 = {