]> err.no Git - linux-2.6/blobdiff - kernel/nsproxy.c
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[linux-2.6] / kernel / nsproxy.c
index 15a6015a849d1f7044d8f07df4d87c26dfc6b2c2..10f0bbba382bed8c37d498cd55cf5871eb9b8bd4 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/utsname.h>
 #include <linux/pid_namespace.h>
 
+static struct kmem_cache *nsproxy_cachep;
+
 struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
 
 static inline void get_nsproxy(struct nsproxy *ns)
@@ -43,9 +45,11 @@ static inline struct nsproxy *clone_nsproxy(struct nsproxy *orig)
 {
        struct nsproxy *ns;
 
-       ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
-       if (ns)
+       ns = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
+       if (ns) {
+               memcpy(ns, orig, sizeof(struct nsproxy));
                atomic_set(&ns->count, 1);
+       }
        return ns;
 }
 
@@ -54,8 +58,8 @@ static inline struct nsproxy *clone_nsproxy(struct nsproxy *orig)
  * Return the newly created nsproxy.  Do not attach this to the task,
  * leave it to the caller to do proper locking and attach it to task.
  */
-static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
-                       struct fs_struct *new_fs)
+static struct nsproxy *create_new_namespaces(unsigned long flags,
+                       struct task_struct *tsk, struct fs_struct *new_fs)
 {
        struct nsproxy *new_nsp;
        int err;
@@ -109,7 +113,7 @@ out_uts:
        if (new_nsp->mnt_ns)
                put_mnt_ns(new_nsp->mnt_ns);
 out_ns:
-       kfree(new_nsp);
+       kmem_cache_free(nsproxy_cachep, new_nsp);
        return ERR_PTR(err);
 }
 
@@ -117,7 +121,7 @@ out_ns:
  * called from clone.  This now handles copy for nsproxy and all
  * namespaces therein.
  */
-int copy_namespaces(int flags, struct task_struct *tsk)
+int copy_namespaces(unsigned long flags, struct task_struct *tsk)
 {
        struct nsproxy *old_ns = tsk->nsproxy;
        struct nsproxy *new_ns;
@@ -160,7 +164,7 @@ void free_nsproxy(struct nsproxy *ns)
                put_pid_ns(ns->pid_ns);
        if (ns->user_ns)
                put_user_ns(ns->user_ns);
-       kfree(ns);
+       kmem_cache_free(nsproxy_cachep, ns);
 }
 
 /*
@@ -185,3 +189,12 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
                err = PTR_ERR(*new_nsp);
        return err;
 }
+
+static int __init nsproxy_cache_init(void)
+{
+       nsproxy_cachep = kmem_cache_create("nsproxy", sizeof(struct nsproxy),
+                                          0, SLAB_PANIC, NULL, NULL);
+       return 0;
+}
+
+module_init(nsproxy_cache_init);