[Devel] [PATCH RH9 26/33] ve/uts_ns: Implement cgroup interface to configure ve's os_release

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Thu Sep 23 22:08:29 MSK 2021


From: Kirill Tkhai <ktkhai at odin.com>

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>
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>

(cherry picked from vz8 commit d9c541f7a5f43f1f39df07f3b50d2704c3f2fe9b)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 kernel/ve/ve.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 751f43f..03eb636 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -647,6 +647,55 @@ static u64 ve_netns_avail_nr_read(struct cgroup_subsys_state *css, struct cftype
 	return atomic_read(&css_to_ve(css)->netns_avail_nr);
 }
 
+static int ve_os_release_read(struct seq_file *sf, void *v)
+{
+	struct cgroup_subsys_state *css = seq_css(sf);
+	struct ve_struct *ve = css_to_ve(css);
+	int ret = 0;
+
+	down_read(&ve->op_sem);
+
+	if (!ve->ve_ns) {
+		ret = -ENOENT;
+		goto up_opsem;
+	}
+
+	down_read(&uts_sem);
+	seq_puts(sf, ve->ve_ns->uts_ns->name.release);
+	seq_putc(sf, '\n');
+	up_read(&uts_sem);
+up_opsem:
+	up_read(&ve->op_sem);
+
+	return ret;
+}
+
+static ssize_t ve_os_release_write(struct kernfs_open_file *of, char *buf,
+				   size_t nbytes, loff_t off)
+{
+	struct cgroup_subsys_state *css = of_css(of);
+	struct ve_struct *ve = css_to_ve(css);
+	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, buf, __NEW_UTS_LEN);
+	release[__NEW_UTS_LEN] = '\0';
+	up_write(&uts_sem);
+up_opsem:
+	up_read(&ve->op_sem);
+
+	return ret ? ret : nbytes;
+}
+
 static struct cftype ve_cftypes[] = {
 
 	{
@@ -683,6 +732,13 @@ static u64 ve_netns_avail_nr_read(struct cgroup_subsys_state *css, struct cftype
 		.name			= "netns_avail_nr",
 		.read_u64		= ve_netns_avail_nr_read,
 	},
+	{
+		.name			= "os_release",
+		.max_write_len		= __NEW_UTS_LEN + 1,
+		.flags			= CFTYPE_NOT_ON_ROOT,
+		.seq_show		= ve_os_release_read,
+		.write			= ve_os_release_write,
+	},
 	{ }
 };
 
-- 
1.8.3.1



More information about the Devel mailing list