Add idr struct and the mutex lock corresponding to
this struct to pid_namespace struct. Use IDR API for implementing
create_pid_namespace. The only change in the function is that instead of
allocating a bitmap, now idr_init is used to initialise the radix tree
associated with this namespace. This tree will be then used by
alloc_pid, free_pid and pid lookup functions to perform their respective
tasks.

Signed-off-by: Gargi Sharma <[email protected]>
---
 include/linux/pid_namespace.h |  3 ++-
 kernel/pid_namespace.c        | 20 +++++---------------
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index b089791..88cda3f 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -29,7 +29,8 @@ enum { /* definitions for pid_namespace's hide_pid field */
 
 struct pid_namespace {
        struct kref kref;
-       struct pidmap pidmap[PIDMAP_ENTRIES];
+       struct idr *idr;
+       struct mutex idr_mutex_lock;
        struct rcu_head rcu;
        int last_pid;
        unsigned int nr_hashed;
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 32c4645..fa994d4 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -98,7 +98,6 @@ static struct pid_namespace *create_pid_namespace(struct 
user_namespace *user_ns
        struct pid_namespace *ns;
        unsigned int level = parent_pid_ns->level + 1;
        struct ucounts *ucounts;
-       int i;
        int err;
 
        err = -ENOSPC;
@@ -113,17 +112,15 @@ static struct pid_namespace *create_pid_namespace(struct 
user_namespace *user_ns
        if (ns == NULL)
                goto out_dec;
 
-       ns->pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL);
-       if (!ns->pidmap[0].page)
-               goto out_free;
+       idr_init(ns->idr);
 
        ns->pid_cachep = create_pid_cachep(level + 1);
        if (ns->pid_cachep == NULL)
-               goto out_free_map;
+               goto out_free_idr;
 
        err = ns_alloc_inum(&ns->ns);
        if (err)
-               goto out_free_map;
+               goto out_free_idr;
        ns->ns.ops = &pidns_operations;
 
        kref_init(&ns->kref);
@@ -134,17 +131,10 @@ static struct pid_namespace *create_pid_namespace(struct 
user_namespace *user_ns
        ns->nr_hashed = PIDNS_HASH_ADDING;
        INIT_WORK(&ns->proc_work, proc_cleanup_work);
 
-       set_bit(0, ns->pidmap[0].page);
-       atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1);
-
-       for (i = 1; i < PIDMAP_ENTRIES; i++)
-               atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
-
        return ns;
 
-out_free_map:
-       kfree(ns->pidmap[0].page);
-out_free:
+out_free_idr:
+       idr_destroy(ns->idr);
        kmem_cache_free(pid_ns_cachep, ns);
 out_dec:
        dec_pid_namespaces(ucounts);
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to