[Devel] [PATCH RH9 v2 2/3] ve/net: add is_ve_init_net helper
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Mon Jan 31 19:38:48 MSK 2022
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 4c8f7d308829..3bf098a95755 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -221,6 +221,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>
@@ -242,6 +243,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 557a14f216c4..9be931f7e62d 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -287,6 +287,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);
--
2.33.1
More information about the Devel
mailing list