[Devel,RHEL7,COMMIT] ve/pid: Export kernel.pid_max via ve cgroup

Submitted by Konstantin Khorenko on Aug. 9, 2016, 2 p.m.

Details

Message ID 201608091400.u79E0mlX024486@finist_cl7.x64_64.work.ct
State New
Series "ve/pid: Export kernel.pid_max via ve cgroup"
Headers show

Commit Message

Konstantin Khorenko Aug. 9, 2016, 2 p.m.
The commit is pushed to "branch-rh7-3.10.0-327.22.2.vz7.16.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-327.22.2.vz7.16.4
------>
commit d7105549896339ecc40bbb1cdae7599ee5a4fadf
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date:   Tue Aug 9 18:00:48 2016 +0400

    ve/pid: Export kernel.pid_max via ve cgroup
    
    This member represents kernel.pid_max sysctl it is vz-specific but
    lays on pid namespace. To be able to c/r from libvzctl script it is
    better put pid_max in ve cgroup, these way we do not need to enter
    container root pid namespace to get/set these sysctl.
    
    Add ve_write_running_u64 helper to be able to set pid_max on running
    container, as we can't set pid_max before we have ve's pidns.
    
    https://jira.sw.ru/browse/PSBM-48397
    
    Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
    Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
 kernel/ve/ve.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index b5399e1..f7eb445 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1194,6 +1194,7 @@  enum {
 	VE_CF_CLOCK_MONOTONIC,
 	VE_CF_CLOCK_BOOTBASED,
 	VE_CF_AIO_MAX_NR,
+	VE_CF_PID_MAX,
 };
 
 static int ve_ts_read(struct cgroup *cg, struct cftype *cft, struct seq_file *m)
@@ -1255,6 +1256,11 @@  static u64 ve_read_u64(struct cgroup *cg, struct cftype *cft)
 		return cgroup_ve(cg)->is_pseudosuper;
 	else if (cft->private == VE_CF_AIO_MAX_NR)
 		return cgroup_ve(cg)->aio_max_nr;
+	else if (cft->private == VE_CF_PID_MAX) {
+		struct ve_struct *ve = cgroup_ve(cg);
+		if (ve->ve_ns && ve->ve_ns->pid_ns)
+			return ve->ve_ns->pid_ns->pid_max;
+	}
 	return 0;
 }
 
@@ -1287,7 +1293,26 @@  static int ve_write_pseudosuper(struct cgroup *cg,
 	return 0;
 }
 
-static int ve_write_u64(struct cgroup *cg, struct cftype *cft, u64 value)
+extern int pid_max_min, pid_max_max;
+
+static int ve_write_pid_max(struct cgroup *cg,
+			    struct cftype *cft,
+			    u64 value)
+{
+	struct ve_struct *ve = cgroup_ve(cg);
+	if (!ve->ve_ns || !ve->ve_ns->pid_ns)
+		return -EBUSY;
+
+	if (pid_max_min > value ||
+	     pid_max_max < value)
+		return -EINVAL;
+
+	ve->ve_ns->pid_ns->pid_max = value;
+	return 0;
+}
+
+static int _ve_write_u64(struct cgroup *cg, struct cftype *cft,
+                         u64 value, int running)
 {
 	struct ve_struct *ve = cgroup_ve(cg);
 
@@ -1296,7 +1321,7 @@  static int ve_write_u64(struct cgroup *cg, struct cftype *cft, u64 value)
 		return -EPERM;
 
 	down_write(&ve->op_sem);
-	if (ve->is_running || ve->ve_ns) {
+	if (!running && (ve->is_running || ve->ve_ns)) {
 		up_write(&ve->op_sem);
 		return -EBUSY;
 	}
@@ -1309,10 +1334,26 @@  static int ve_write_u64(struct cgroup *cg, struct cftype *cft, u64 value)
 #endif
 	else if (cft->private == VE_CF_AIO_MAX_NR)
 		ve->aio_max_nr = value;
+	else if (cft->private == VE_CF_PID_MAX) {
+		int ret;
+		ret = ve_write_pid_max(cg, cft, value);
+		up_write(&ve->op_sem);
+		return ret;
+	}
 	up_write(&ve->op_sem);
 	return 0;
 }
 
+static int ve_write_u64(struct cgroup *cg, struct cftype *cft, u64 value)
+{
+	return _ve_write_u64(cg, cft, value, 0);
+}
+
+static int ve_write_running_u64(struct cgroup *cg, struct cftype *cft, u64 value)
+{
+	return _ve_write_u64(cg, cft, value, 1);
+}
+
 static struct cftype ve_cftypes[] = {
 	{
 		.name			= "state",
@@ -1384,6 +1425,13 @@  static struct cftype ve_cftypes[] = {
 		.write_u64		= ve_write_u64,
 		.private		= VE_CF_AIO_MAX_NR,
 	},
+	{
+		.name			= "pid_max",
+		.flags			= CFTYPE_NOT_ON_ROOT,
+		.read_u64		= ve_read_u64,
+		.write_u64		= ve_write_running_u64,
+		.private		= VE_CF_PID_MAX,
+	},
 	{ }
 };