[Devel] [PATCH rh7] ve: Implement cgroup interface to configure ve's os_release

Kirill Tkhai ktkhai at odin.com
Fri May 15 11:03:07 PDT 2015


It's the similar to VZCTL_VE_CONFIGURE ioctl in PCS6.

Note: max_write_len is __NEW_UTS_LEN + 1, because I want to allow

echo ... > ve.os_release, which adds trailing '\n' to the string
(see man echo for details).

Extra symbol will be cut in ve_os_release_write().

https://jira.sw.ru/browse/PSBM-32273

Signed-off-by: Kirill Tkhai <ktkhai at odin.com>
---
 kernel/ve/ve.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 6ab409f..e598d15 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -1032,6 +1032,54 @@ static int ve_mount_opts_write(struct cgroup *cg, struct cftype *cft,
 	return 0;
 }
 
+static int ve_os_release_read(struct cgroup *cg, struct cftype *cft,
+			      struct seq_file *m)
+{
+	struct ve_struct *ve = cgroup_ve(cg);
+	int ret = 0;
+
+	down_read(&ve->op_sem);
+
+	if (!ve->ve_ns) {
+		ret = -ENOENT;
+		goto up_opsem;
+	}
+
+	down_read(&uts_sem);
+	seq_puts(m, ve->ve_ns->uts_ns->name.release);
+	seq_putc(m, '\n');
+	up_read(&uts_sem);
+up_opsem:
+	up_read(&ve->op_sem);
+
+	return ret;
+}
+
+static int ve_os_release_write(struct cgroup *cg, struct cftype *cft,
+			       const char *buffer)
+{
+	struct ve_struct *ve = cgroup_ve(cg);
+	char *release;
+	int ret = 0;
+
+	down_read(&ve->op_sem);
+
+	if (!ve->ve_ns) {
+		ret = -ENOENT;
+		goto up_opsem;
+	}
+
+	down_write(&uts_sem);
+	release = ve->ve_ns->uts_ns->name.release;
+	strncpy(release, buffer, __NEW_UTS_LEN);
+	release[__NEW_UTS_LEN] = '\0';
+	up_write(&uts_sem);
+up_opsem:
+	up_read(&ve->op_sem);
+
+	return ret;
+}
+
 static struct cftype ve_cftypes[] = {
 	{
 		.name = "state",
@@ -1049,6 +1097,13 @@ static struct cftype ve_cftypes[] = {
 		.flags = CFTYPE_NOT_ON_ROOT,
 		.write_string = ve_mount_opts_write,
 	},
+	{
+		.name = "os_release",
+		.max_write_len = __NEW_UTS_LEN + 1,
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.read_seq_string = ve_os_release_read,
+		.write_string = ve_os_release_write,
+	},
 	{ }
 };
 




More information about the Devel mailing list