[Devel] [PATCH RHEL7 COMMIT] fairsched: switch methods showing stats from numeric id to name

Konstantin Khorenko khorenko at virtuozzo.com
Thu May 28 07:01:37 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.7
------>
commit 1105cbff976808b0e60231ae407ba309963ff289
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Thu May 28 18:01:37 2015 +0400

    fairsched: switch methods showing stats from numeric id to name
    
    Patchset description:
    
    Currently, cpu stats are broken for UUID-named CTs. First, reading
    /proc/stat from inside a container or /proc/vz/vestat on the host fails
    with ENOENT if there is a UUID-named CT. Patch 1 fixes that. Second,
    there is no new interface for getting loadavg for UUID-named CTs, which
    would be a successor of the legacy VZCTL_GET_CPU_STAT ioctl. Patch 2
    adds cpu.proc.loadavg that mimics behavior of /proc/loadavg.
    
    This patch description:
    
    fairsched_get_cpu_stat, fairsched_get_cpu_avenrun, and
    fairsched_show_stat can be called on UUID-named containers (e.g. reading
    /proc/stat inside a CT or reading /proc/vz/vestat on the host).
    Currently, they return ENOENT for such containers, because they try to
    open cgroup with name equal to the passed ID while UUID-named container
    cgroups are named not by ID, but by UUID.
    
    This patch makes them accept a string name instead of a numeric id. All
    the function calling them now pass ve->ve_name instead of ve->veid.
    
    As a side effect, after this patch is applied, VZCTL_GET_CPU_STAT ioctl
    will work on UUID-named containers provided the caller passes
    ve.legacy_veid.
    
    https://jira.sw.ru/browse/PSBM-32284
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 fs/proc/stat.c            |  2 +-
 include/linux/fairsched.h | 12 ++++++------
 kernel/fairsched.c        | 24 ++++++++++++------------
 kernel/ve/vecalls.c       | 25 +++++++++----------------
 4 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 34f318a..89eb04e 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -98,7 +98,7 @@ static int show_stat(struct seq_file *p, void *v)
 	ve = get_exec_env();
 	if (!ve_is_super(ve)) {
 		int ret;
-		ret = fairsched_show_stat(p, ve->veid);
+		ret = fairsched_show_stat(ve_name(ve), p);
 		if (ret != -ENOSYS)
 			return ret;
 	}
diff --git a/include/linux/fairsched.h b/include/linux/fairsched.h
index c944bed..568c25a 100644
--- a/include/linux/fairsched.h
+++ b/include/linux/fairsched.h
@@ -53,24 +53,24 @@ int fairsched_new_node(int id, unsigned int vcpus);
 int fairsched_move_task(int id, struct task_struct *tsk);
 void fairsched_drop_node(int id, int leave);
 
-int fairsched_get_cpu_stat(int id, struct kernel_cpustat *kstat);
+int fairsched_get_cpu_stat(const char *name, struct kernel_cpustat *kstat);
 
 int cpu_cgroup_get_avenrun(struct cgroup *cgrp, unsigned long *avenrun);
-int fairsched_get_cpu_avenrun(int id, unsigned long *avenrun);
+int fairsched_get_cpu_avenrun(const char *name, unsigned long *avenrun);
 
 struct cftype;
 int cpu_cgroup_proc_stat(struct cgroup *cgrp, struct cftype *cft,
 				struct seq_file *p);
-int fairsched_show_stat(struct seq_file *p, int id);
+int fairsched_show_stat(const char *name, struct seq_file *p);
 
 #else /* CONFIG_VZ_FAIRSCHED */
 
 static inline int fairsched_new_node(int id, unsigned int vcpus) { return 0; }
 static inline int fairsched_move_task(int id, struct task_struct *tsk) { return 0; }
 static inline void fairsched_drop_node(int id, int leave) { }
-static inline int fairsched_show_stat(struct seq_file *p, int id) { return -ENOSYS; }
-static inline int fairsched_get_cpu_avenrun(int id, unsigned long *avenrun) { return -ENOSYS; }
-static inline int fairsched_get_cpu_stat(int id, struct kernel_cpustat *kstat) { return -ENOSYS; }
+static inline int fairsched_show_stat(const char *name, struct seq_file *p) { return -ENOSYS; }
+static inline int fairsched_get_cpu_avenrun(const char *name, unsigned long *avenrun) { return -ENOSYS; }
+static inline int fairsched_get_cpu_stat(const char *name, struct kernel_cpustat *kstat) { return -ENOSYS; }
 
 #endif /* CONFIG_VZ_FAIRSCHED */
 
diff --git a/kernel/fairsched.c b/kernel/fairsched.c
index 2fd39cd..7fe93d2 100644
--- a/kernel/fairsched.c
+++ b/kernel/fairsched.c
@@ -715,14 +715,14 @@ static struct file_operations proc_fairsched_operations = {
 	.release	= fairsched_seq_release
 };
 
-int fairsched_show_stat(struct seq_file *p, int id)
+int fairsched_show_stat(const char *name, struct seq_file *p)
 {
 	struct cgroup *cgrp;
 	int err;
 
-	cgrp = ve_cgroup_open(root_node.cpu, 0, id);
-	if (IS_ERR(cgrp))
-		return PTR_ERR(cgrp);
+	cgrp = cgroup_kernel_open(root_node.cpu, 0, name);
+	if (IS_ERR_OR_NULL(cgrp))
+		return cgrp ? PTR_ERR(cgrp) : -ENOENT;
 
 	err = cpu_cgroup_proc_stat(cgrp, NULL, p);
 	cgroup_kernel_close(cgrp);
@@ -730,14 +730,14 @@ int fairsched_show_stat(struct seq_file *p, int id)
 	return err;
 }
 
-int fairsched_get_cpu_avenrun(int id, unsigned long *avenrun)
+int fairsched_get_cpu_avenrun(const char *name, unsigned long *avenrun)
 {
 	struct cgroup *cgrp;
 	int err;
 
-	cgrp = ve_cgroup_open(root_node.cpu, 0, fairsched_id(id));
-	if (IS_ERR(cgrp))
-		return PTR_ERR(cgrp);
+	cgrp = cgroup_kernel_open(root_node.cpu, 0, name);
+	if (IS_ERR_OR_NULL(cgrp))
+		return cgrp ? PTR_ERR(cgrp) : -ENOENT;
 
 	err = cpu_cgroup_get_avenrun(cgrp, avenrun);
 	cgroup_kernel_close(cgrp);
@@ -746,13 +746,13 @@ int fairsched_get_cpu_avenrun(int id, unsigned long *avenrun)
 }
 EXPORT_SYMBOL(fairsched_get_cpu_avenrun);
 
-int fairsched_get_cpu_stat(int id, struct kernel_cpustat *kstat)
+int fairsched_get_cpu_stat(const char *name, struct kernel_cpustat *kstat)
 {
 	struct cgroup *cgrp;
 
-	cgrp = ve_cgroup_open(root_node.cpu, 0, fairsched_id(id));
-	if (IS_ERR(cgrp))
-		return PTR_ERR(cgrp);
+	cgrp = cgroup_kernel_open(root_node.cpu, 0, name);
+	if (IS_ERR_OR_NULL(cgrp))
+		return cgrp ? PTR_ERR(cgrp) : -ENOENT;
 
 	cpu_cgroup_get_stat(cgrp, kstat);
 	cgroup_kernel_close(cgrp);
diff --git a/kernel/ve/vecalls.c b/kernel/ve/vecalls.c
index 8390843..73ae9ef 100644
--- a/kernel/ve/vecalls.c
+++ b/kernel/ve/vecalls.c
@@ -104,27 +104,23 @@ static int ve_get_cpu_stat(envid_t veid, struct vz_cpu_stat __user *buf)
 
 	if (!ve_is_super(get_exec_env()) && (veid != get_exec_env()->veid))
 		return -EPERM;
-	if (veid == 0)
+	ve = get_ve_by_id(veid);
+	if (!ve)
 		return -ESRCH;
 
+	retval = -ENOMEM;
 	vstat = kzalloc(sizeof(*vstat), GFP_KERNEL);
 	if (!vstat)
-		return -ENOMEM;
+		goto out_put_ve;
 
-	retval = fairsched_get_cpu_stat(veid, &kstat);
+	retval = fairsched_get_cpu_stat(ve->ve_name, &kstat);
 	if (retval)
 		goto out_free;
 
-	retval = fairsched_get_cpu_avenrun(veid, avenrun);
+	retval = fairsched_get_cpu_avenrun(ve->ve_name, avenrun);
 	if (retval)
 		goto out_free;
 
-	retval = -ESRCH;
-	mutex_lock(&ve_list_lock);
-	ve = __find_ve_by_id(veid);
-	if (ve == NULL)
-		goto out_unlock;
-
 	vstat->user_jif += (unsigned long)cputime64_to_clock_t(kstat.cpustat[CPUTIME_USER]);
 	vstat->nice_jif += (unsigned long)cputime64_to_clock_t(kstat.cpustat[CPUTIME_NICE]);
 	vstat->system_jif += (unsigned long)cputime64_to_clock_t(kstat.cpustat[CPUTIME_SYSTEM]);
@@ -139,18 +135,15 @@ static int ve_get_cpu_stat(envid_t veid, struct vz_cpu_stat __user *buf)
 		vstat->avenrun[i].val_int = LOAD_INT(tmp);
 		vstat->avenrun[i].val_frac = LOAD_FRAC(tmp);
 	}
-	mutex_unlock(&ve_list_lock);
 
 	retval = 0;
 	if (copy_to_user(buf, vstat, sizeof(*vstat)))
 		retval = -EFAULT;
 out_free:
 	kfree(vstat);
+out_put_ve:
+	put_ve(ve);
 	return retval;
-
-out_unlock:
-	mutex_unlock(&ve_list_lock);
-	goto out_free;
 }
 
 static int real_setdevperms(envid_t veid, unsigned type,
@@ -800,7 +793,7 @@ static int vestat_seq_show(struct seq_file *m, void *v)
 	if (ve == get_ve0())
 		return 0;
 
-	ret = fairsched_get_cpu_stat(ve->veid, &kstat);
+	ret = fairsched_get_cpu_stat(ve->ve_name, &kstat);
 	if (ret)
 		return ret;
 



More information about the Devel mailing list