Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752368AbZIWX6V (ORCPT ); Wed, 23 Sep 2009 19:58:21 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752225AbZIWX6P (ORCPT ); Wed, 23 Sep 2009 19:58:15 -0400 Received: from smtp231.iad.emailsrvr.com ([207.97.245.231]:34745 "EHLO smtp231.iad.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751716AbZIWX55 (ORCPT ); Wed, 23 Sep 2009 19:57:57 -0400 X-Greylist: delayed 312 seconds by postgrey-1.27 at vger.kernel.org; Wed, 23 Sep 2009 19:57:55 EDT From: Oren Laadan To: Andrew Morton Cc: Linus Torvalds , containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Serge Hallyn , Ingo Molnar , Pavel Emelyanov , Sukadev Bhattiprolu Subject: [PATCH v18 13/80] pids 3/7: Add target_pid parameter to alloc_pidmap() Date: Wed, 23 Sep 2009 19:50:53 -0400 Message-Id: <1253749920-18673-14-git-send-email-orenl@librato.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1253749920-18673-1-git-send-email-orenl@librato.com> References: <1253749920-18673-1-git-send-email-orenl@librato.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1981 Lines: 74 From: Sukadev Bhattiprolu With support for setting a specific pid number for a process, alloc_pidmap() will need a paramter 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(-) diff --git a/kernel/pid.c b/kernel/pid.c index 9c678ce..29cf119 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -147,11 +147,35 @@ 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 <= 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 @@ 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.6.0.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/