[Devel] [PATCH RHEL9 COMMIT] ve/net: add is_ve_init_net helper

Konstantin Khorenko khorenko at virtuozzo.com
Wed Feb 2 16:19:52 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-4.vz9.12.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.12.5
------>
commit 98736521510a003d2c93f716b8105d0a2a25faf6
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Wed Feb 2 16:19:51 2022 +0300

    ve/net: add is_ve_init_net helper
    
    This is an analogy of net_eq(net, &init_net) which also works for
    container init netns.
    
    Feature: ve/printk: printk virtualization
    
    https://jira.sw.ru/browse/PSBM-138110
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 include/linux/ve.h |  6 ++++++
 kernel/ve/ve.c     | 19 +++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index 5691bd624a30..843f1754a555 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -228,6 +228,7 @@ extern int vz_security_protocol_check(struct net *net, int protocol);
 int ve_net_hide_sysctl(struct net *net);
 
 extern struct net *ve_get_net_ns(struct ve_struct* ve);
+extern bool is_ve_init_net(struct net *net);
 
 #else	/* CONFIG_VE */
 #include <linux/init_task.h>
@@ -249,6 +250,11 @@ static inline struct user_namespace *ve_init_user_ns(void)
 	return &init_user_ns;
 }
 
+static inline bool is_ve_init_net(struct net *net)
+{
+	return net_eq(net, &init_net);
+}
+
 static inline struct cgroup *cgroup_ve_root1(struct cgroup *cgrp)
 {
 	return NULL;
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 95ab131f0363..2dbe524fc067 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -289,6 +289,25 @@ struct net *ve_get_net_ns(struct ve_struct* ve)
 }
 EXPORT_SYMBOL(ve_get_net_ns);
 
+bool is_ve_init_net(struct net *net)
+{
+	struct ve_struct *ve = net->owner_ve;
+	struct nsproxy *ve_ns;
+	bool ret = false;
+
+	if (ve_is_super(ve))
+		return net_eq(net, &init_net);
+
+	rcu_read_lock();
+	ve_ns = rcu_dereference(ve->ve_ns);
+	if (ve_ns)
+		ret = net_eq(ve_ns->net_ns, net);
+	rcu_read_unlock();
+
+	return ret;
+}
+EXPORT_SYMBOL(is_ve_init_net);
+
 int nr_threads_ve(struct ve_struct *ve)
 {
         return cgroup_task_count(ve->css.cgroup);


More information about the Devel mailing list