[Devel] [PATCH RHEL COMMIT] ve/uts_ns: Implement cgroup interface to configure ve's os_release

Konstantin Khorenko khorenko at virtuozzo.com
Fri Sep 24 15:48:49 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 e4a4535af65d5afb7dc6bf2962be402f600ca374
Author: Kirill Tkhai <ktkhai at odin.com>
Date:   Fri Sep 24 15:48:49 2021 +0300

    ve/uts_ns: Implement cgroup interface to configure ve's os_release
    
    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 560a63902127..75299258d677 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -718,6 +718,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[] = {
 
 	{
@@ -754,6 +803,13 @@ static struct cftype ve_cftypes[] = {
 		.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,
+	},
 	{ }
 };
 


More information about the Devel mailing list