[Devel] [PATCH rh7 1/2] farisched: switch methods showing stats from numeric id to name

Vladimir Davydov vdavydov at parallels.com
Mon May 25 02:48:32 PDT 2015


farisched_get_cpu_stat, fairsched_get_cpu_avenrun, and
farisched_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.

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 34f318a3d5d2..89eb04ea8ec9 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 c944bed03d5b..568c25abffbf 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 2fd39cda14bb..7fe93d25cfd9 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 c60fd02e0087..346a070e036b 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;
 
-- 
2.1.4




More information about the Devel mailing list