[PATCH] cgroups: skip processes from other namespaces when listing a cgroup

Balbir Singh balbir at linux.vnet.ibm.com
Mon Dec 8 07:14:12 PST 2008


* gowrishankar <gomuthuk at linux.vnet.ibm.com> [2008-12-07 20:16:01]:

> Once tasks are populated from system namespace inside cgroup,
> container replaces other namespace task with 0 while listing tasks,
> inside container.
>
> Though this is expected behaviour from container end, there is
> no use of showing unwanted 0s.
>
> In below patch, we check if a process is in same namespace before
> loading into pid array.
>
> Signed-off-by: Gowrishankar M <gowrishankar.m at in.ibm.com>
> Acked-by: Paul Menage <menage at google.com>
> Acked-by: Serge Hallyn <serue at us.ibm.com>
>
> changes for vpid and pid_t
> ---
> kernel/cgroup.c |    4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index 35eebd5..588d305 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -2012,13 +2012,15 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
> static int pid_array_load(pid_t *pidarray, int npids, struct cgroup *cgrp)
> {
>     int n = 0;
> +    pid_t vpid;

The formatting does not seem right, what is your tab space set to?

>     struct cgroup_iter it;
>     struct task_struct *tsk;
>     cgroup_iter_start(cgrp, &it);
>     while ((tsk = cgroup_iter_next(cgrp, &it))) {
>         if (unlikely(n == npids))
>             break;
> -        pidarray[n++] = task_pid_vnr(tsk);
> +        if ((vpid = task_pid_vnr(tsk)) > 0)
> +            pidarray[n++] = vpid;
>     }
>     cgroup_iter_end(cgrp, &it);
>     return n;
> -- 
> 1.5.5.1
>
>

-- 
	Balbir


More information about the Containers mailing list