From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Serge E. Hallyn" Subject: Re: [PATCH 3/7] [PATCH] Add target_pid parameter to alloc_pidmap() Date: Wed, 27 May 2009 12:56:02 -0500 Message-ID: <20090527175602.GC332@us.ibm.com> References: <20090527154212.GA3107@us.ibm.com> <20090527154333.GC3107@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20090527154333.GC3107-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Sukadev Bhattiprolu Cc: Containers , "David C. Hansen" List-Id: containers.vger.kernel.org Quoting Sukadev Bhattiprolu (sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org): > > From: Sukadev Bhattiprolu > Date: Mon, 4 May 2009 01:17:41 -0700 > Subject: [PATCH 3/7] [PATCH] Add target_pid parameter to alloc_pidmap() > > Signed-off-by: Sukadev Bhattiprolu How about #define TARGET_PID_UNSPECIFIED 0 or something to pass to alloc_pidmap() from alloc_pid()? Up to you.... More importantly: > --- > kernel/pid.c | 28 ++++++++++++++++++++++++++-- > 1 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/kernel/pid.c b/kernel/pid.c > index fd72ad9..93406c6 100644 > --- a/kernel/pid.c > +++ b/kernel/pid.c > @@ -147,12 +147,36 @@ static int alloc_pidmap_page(struct pidmap *map) > return 0; > } > > -static int alloc_pidmap(struct pid_namespace *pid_ns) > +static int set_pidmap(struct pid_namespace *pid_ns, int pid) > +{ > + int offset; > + struct pidmap *map; > + > + if (pid >= pid_max) > + return -EINVAL; what about pid < 0? > + > + offset = pid & BITS_PER_PAGE_MASK; > + map = &pid_ns->pidmap[pid/BITS_PER_PAGE]; > + > + if (alloc_pidmap_page(map)) > + return -ENOMEM; > + > + if (test_and_set_bit(offset, map->page)) > + return -EBUSY; > + > + atomic_dec(&map->nr_free); > + return pid; > +} > + > +static int alloc_pidmap(struct pid_namespace *pid_ns, int target_pid) > { > int i, offset, max_scan, pid, last = pid_ns->last_pid; > struct pidmap *map; > int rc = -EAGAIN; > > + if (target_pid) > + return set_pidmap(pid_ns, target_pid); > + > pid = last + 1; > if (pid >= pid_max) > pid = RESERVED_PIDS; > @@ -269,7 +293,7 @@ struct pid *alloc_pid(struct pid_namespace *ns) > > tmp = ns; > for (i = ns->level; i >= 0; i--) { > - nr = alloc_pidmap(tmp); > + nr = alloc_pidmap(tmp, 0); > if (nr < 0) > goto out_free; > > -- > 1.5.2.5