RE: [PATCH] ns: introduce getnspid syscall
From: chenhanxiao@xxxxxxxxxxxxxx
Date: Wed Jun 18 2014 - 04:29:26 EST
> -----Original Message-----
> From: Pavel Emelyanov [mailto:xemul@xxxxxxxxxxxxx]
> Sent: Tuesday, June 17, 2014 8:13 PM
> To: Chen, Hanxiao/陈 晗霄
> Cc: containers@xxxxxxxxxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> Andrew Morton; Eric W. Biederman; Serge Hallyn; Daniel P. Berrange; Oleg Nesterov;
> Al Viro; David Howells; Richard Weinberger; Vasiliy Kulikov; Gotou, Yasunori/
> 五? 康文
> Subject: Re: [PATCH] ns: introduce getnspid syscall
>
> On 06/17/2014 02:21 PM, Chen Hanxiao wrote:
> > We need a direct method of getting the pid inside containers.
> > If some issues occurred inside container guest, host user
> > could not know which process is in trouble just by guest pid:
> > the users of container guest only knew the pid inside containers.
> > This will bring obstacle for trouble shooting.
> >
> > int getnspid(pid_t pid, int fd1, int fd2, int pidtype);
> >
> > pid: the pid number need to be translated.
> >
> > fd: a file descriptor referring to one of
> > the namespace entries in a /proc/[pid]/ns/pid.
> > fd1 for destination ns(ns1), where the pid came from.
> > fd2 for reference ns(ns2), while fd2 = -2 means for current ns.
> >
> > pidtype: 0 PIDTYPE_PID; 1 PIDTYPE_PGID; 2 PIDTYPE_SID.
> >
> > return value:
> > >0: translated pid in ns1(fd1) seen from ns2(fd2).
> > <0: on failure.
> >
> > + }
> > +
> > + switch (pidtype) {
>
> There's no need in switch, the __task_pid_nr_ns() accepts
> the type argument.
>
Yes, I think we still have that kind of functions, so I used them...
> > + case PIDTYPE_PID:
> > + ret = task_pid_nr_ns(task, ns2);
>
> But this is not correct. If task doesn't live in ns2, but ns2
> just has the ns->level small enough, then the wrong pid value
> would be reported.
>
Right, we should check whether the task belonged to that namespace firstly.
Thanks,
- Chen
> > + break;
> > + case PIDTYPE_PGID:
> > + ret = task_pgrp_nr_ns(task, ns2);
> > + break;
> > + case PIDTYPE_SID:
> > + ret = task_session_nr_ns(task, ns2);
> > + break;
> > + default:
> > + ret = -EINVAL;
> > + }
> > + ret = (ret == 0) ? -ESRCH : ret;
> > +
> > +out:
> > + fput(file1);
> > + if (file2)
> > + fput(file2);
> > + return ret;
> > +}
> > +
> > int __init nsproxy_cache_init(void)
> > {
> > nsproxy_cachep = KMEM_CACHE(nsproxy, SLAB_PANIC);
> >
>