From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755215AbZHGGMs (ORCPT ); Fri, 7 Aug 2009 02:12:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755119AbZHGGMr (ORCPT ); Fri, 7 Aug 2009 02:12:47 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:43651 "EHLO e33.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755102AbZHGGMq (ORCPT ); Fri, 7 Aug 2009 02:12:46 -0400 Date: Thu, 6 Aug 2009 23:13:04 -0700 From: Sukadev Bhattiprolu To: linux-kernel@vger.kernel.org Cc: Oren Laadan , "Eric W. Biederman" , serue@us.ibm.com, Alexey Dobriyan , Pavel Emelyanov , Andrew Morton , torvalds@linux-foundation.org, mikew@google.com, mingo@elte.hu, hpa@zytor.com, Containers , sukadev@us.ibm.com Subject: [RFC][v4][PATCH 3/7]: Add target_pid parameter to alloc_pidmap() Message-ID: <20090807061304.GC20672@us.ibm.com> References: <20090807061103.GA19343@us.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090807061103.GA19343@us.ibm.com> X-Operating-System: Linux 2.0.32 on an i486 User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Subject: [RFC][v4][PATCH 3/7]: Add target_pid parameter to alloc_pidmap() With support for setting a specific pid number for a process, alloc_pidmap() will need a 'target_pid' parameter. Changelog[v2]: - (Serge Hallyn) Check for 'pid < 0' in set_pidmap().(Code actually checks for 'pid <= 0' for completeness). Signed-off-by: Sukadev Bhattiprolu Acked-by: Serge Hallyn Reviewed-by: Oren Laadan --- kernel/pid.c | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) Index: linux-2.6/kernel/pid.c =================================================================== --- linux-2.6.orig/kernel/pid.c 2009-08-05 17:02:45.000000000 -0700 +++ linux-2.6/kernel/pid.c 2009-08-05 19:34:37.000000000 -0700 @@ -147,11 +147,35 @@ 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 <= 0 || pid >= pid_max) + return -EINVAL; + + 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, rc, offset, max_scan, pid, last = pid_ns->last_pid; struct pidmap *map; + if (target_pid) + return set_pidmap(pid_ns, target_pid); + pid = last + 1; if (pid >= pid_max) pid = RESERVED_PIDS; @@ -270,7 +294,7 @@ tmp = ns; for (i = ns->level; i >= 0; i--) { - nr = alloc_pidmap(tmp); + nr = alloc_pidmap(tmp, 0); if (nr < 0) goto out_free;