[Devel] [PATCH RH7] ve/pid: Export kernel.pid_max via ve cgroup

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Tue Jul 19 04:00:20 PDT 2016


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.

Will send libvzctl PR after these one is commited.

https://jira.sw.ru/browse/PSBM-48397
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/ve/ve.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

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,
+	},
 	{ }
 };
 
-- 
2.5.5



More information about the Devel mailing list