[Devel] [PATCH rh7] cgroup: do not virtualize output of cgroup_path

Cyrill Gorcunov gorcunov at virtuozzo.com
Mon Aug 24 04:46:31 PDT 2015


On Mon, Aug 24, 2015 at 01:04:35PM +0300, Vladimir Davydov wrote:
> When cgroup_path() is called from inside a container, its output is
> "virtualized", i.e. cgroup /CTID/A/B is reported as /A/B. This was done
> for userspace tools to not get confused by the output of some proc files
> (namely, /proc/PID/{cgroup,cpuset}). However, it is wrong to virtualize
> cgroup_path() anytime it is called by a container. For instance, it is
> called from inside a container on OOM in order to dump memcg info to
> system log, in which case mangling its output would be incorrect.
> 
> Therefore this patch makes cgroup_path() always return an absolute path.
> To get a container-relative path, one should now use cgroup_path_ve().
> Currently, cgroup_path_ve() is only used for /proc files output (it
> seems to be enough for now).
> 
> https://jira.sw.ru/browse/PSBM-34852
> 
> Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
> ---
>  include/linux/cgroup.h |  1 +
>  kernel/cgroup.c        | 20 ++++++++++++++++----
>  kernel/cpuset.c        |  2 +-
>  3 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
> index b7eb28ffd0d6..146a924664cf 100644
> --- a/include/linux/cgroup.h
> +++ b/include/linux/cgroup.h
> @@ -561,6 +561,7 @@ int cgroup_is_removed(const struct cgroup *cgrp);
>  bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
>  
>  int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen);
> +int cgroup_path_ve(const struct cgroup *cgrp, char *buf, int buflen);
>  
>  int cgroup_task_count(const struct cgroup *cgrp);
>  
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index aa3546d93f88..0ff3b5254b5f 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -1804,11 +1804,13 @@ static struct kobject *cgroup_kobj;
>   * inode's i_mutex, while on the other hand cgroup_path() can be called
>   * with some irq-safe spinlocks held.
>   */
> -int cgroup_path(const struct cgroup *cgrp, char *buf, int buflen)
> +int __cgroup_path(const struct cgroup *cgrp, char *buf, int buflen, bool virt)
>  {
>  	int ret = -ENAMETOOLONG;
>  	char *start;
> -	struct ve_struct *ve = get_exec_env();
> +
> +	if (ve_is_super(get_exec_env()))
> +		virt = false;

May we not modify argument here? Won't the follow be better?

cgroup_path_ve
	return __cgroup_path(cgrp, buf, buflen, ve_is_super(get_exec_env()) ? false : true);

and drop ve_is_super from __cgroup_path itself.



More information about the Devel mailing list