[Devel] [PATCH RHEL COMMIT] ve/umh: add per-container usermodehelper thread

Konstantin Khorenko khorenko at virtuozzo.com
Tue Sep 28 14:42:36 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 07a024cc540630c67156b0db494a7cd2bc0dbda6
Author: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
Date:   Tue Sep 28 14:42:36 2021 +0300

    ve/umh: add per-container usermodehelper thread
    
    Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
    
    +++
    ve, kthread: Remove some useless crud.
    
    Simplify the code by removing useless macroses.
    
    Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    (cherry-picked from vz8 commit 890476830003 ("ve/umh: add per-container
    usermodehelper thread"))
    
    Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 include/linux/ve.h |  4 ++++
 kernel/ve/ve.c     | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index cea4fa48d939..f80dca3d3d84 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -14,6 +14,7 @@
 #include <linux/ve_proto.h>
 #include <linux/cgroup.h>
 #include <linux/kmapset.h>
+#include <linux/kthread.h>
 #include <linux/vzstat.h>
 
 struct nsproxy;
@@ -62,6 +63,9 @@ struct ve_struct {
 
 	struct kthread_worker	*kthreadd_worker;
 	struct task_struct	*kthreadd_task;
+
+	struct kthread_worker	umh_worker;
+	struct task_struct	*umh_task;
 };
 
 extern int nr_ve;
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 9c0070c39eb4..2f0eff24156a 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -265,6 +265,31 @@ static void ve_drop_context(struct ve_struct *ve)
 	ve->init_cred = NULL;
 }
 
+static void ve_stop_umh(struct ve_struct *ve)
+{
+	kthread_flush_worker(&ve->umh_worker);
+	kthread_stop(ve->umh_task);
+	ve->umh_task = NULL;
+}
+
+static int ve_start_umh(struct ve_struct *ve)
+{
+	struct task_struct *task;
+
+	kthread_init_worker(&ve->umh_worker);
+
+	task = kthread_create_on_node_ve_flags(ve, 0, kthread_worker_fn,
+				      &ve->umh_worker, NUMA_NO_NODE,
+				      "khelper");
+	if (IS_ERR(task))
+		return PTR_ERR(task);
+
+	wake_up_process(task);
+
+	ve->umh_task = task;
+	return 0;
+}
+
 static void ve_stop_kthreadd(struct ve_struct *ve)
 {
 	kthread_flush_worker(ve->kthreadd_worker);
@@ -430,6 +455,10 @@ static int ve_start_container(struct ve_struct *ve)
 	if (err)
 		goto err_kthreadd;
 
+	err = ve_start_umh(ve);
+	if (err)
+		goto err_umh;
+
 	err = ve_hook_iterate_init(VE_SS_CHAIN, ve);
 	if (err < 0)
 		goto err_iterate;
@@ -445,6 +474,8 @@ static int ve_start_container(struct ve_struct *ve)
 	return 0;
 
 err_iterate:
+	ve_stop_umh(ve);
+err_umh:
 	ve_stop_kthreadd(ve);
 err_kthreadd:
 	ve_list_del(ve);
@@ -480,6 +511,7 @@ void ve_stop_ns(struct pid_namespace *pid_ns)
 	/*
 	 * Stop kthreads, or zap_pid_ns_processes() will wait them forever.
 	 */
+	ve_stop_umh(ve);
 	ve_stop_kthreadd(ve);
 unlock:
 	up_write(&ve->op_sem);


More information about the Devel mailing list