namespaces: move the IPC namespace under IPC_NS option
[safe/jmp/linux-2.6] / ipc / util.c
index b42fbd5..5432b8e 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/audit.h>
 #include <linux/nsproxy.h>
 #include <linux/rwsem.h>
+#include <linux/ipc_namespace.h>
 
 #include <asm/unistd.h>
 
@@ -51,66 +52,6 @@ struct ipc_namespace init_ipc_ns = {
        },
 };
 
-static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
-{
-       int err;
-       struct ipc_namespace *ns;
-
-       err = -ENOMEM;
-       ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
-       if (ns == NULL)
-               goto err_mem;
-
-       err = sem_init_ns(ns);
-       if (err)
-               goto err_sem;
-       err = msg_init_ns(ns);
-       if (err)
-               goto err_msg;
-       err = shm_init_ns(ns);
-       if (err)
-               goto err_shm;
-
-       kref_init(&ns->kref);
-       return ns;
-
-err_shm:
-       msg_exit_ns(ns);
-err_msg:
-       sem_exit_ns(ns);
-err_sem:
-       kfree(ns);
-err_mem:
-       return ERR_PTR(err);
-}
-
-struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
-{
-       struct ipc_namespace *new_ns;
-
-       BUG_ON(!ns);
-       get_ipc_ns(ns);
-
-       if (!(flags & CLONE_NEWIPC))
-               return ns;
-
-       new_ns = clone_ipc_ns(ns);
-
-       put_ipc_ns(ns);
-       return new_ns;
-}
-
-void free_ipc_ns(struct kref *kref)
-{
-       struct ipc_namespace *ns;
-
-       ns = container_of(kref, struct ipc_namespace, kref);
-       sem_exit_ns(ns);
-       msg_exit_ns(ns);
-       shm_exit_ns(ns);
-       kfree(ns);
-}
-
 /**
  *     ipc_init        -       initialise IPC subsystem
  *
@@ -262,7 +203,7 @@ int ipc_get_maxid(struct ipc_ids *ids)
  *     Add an entry 'new' to the IPC ids idr. The permissions object is
  *     initialised and the first free entry is set up and the id assigned
  *     is returned. The 'new' entry is returned in a locked state on success.
- *     On failure the entry is not locked and -1 is returned.
+ *     On failure the entry is not locked and a negative err-code is returned.
  *
  *     Called with ipc_ids.rw_mutex held as a writer.
  */
@@ -275,11 +216,11 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
                size = IPCMNI;
 
        if (ids->in_use >= size)
-               return -1;
+               return -ENOSPC;
 
        err = idr_get_new(&ids->ipcs_idr, new, &id);
        if (err)
-               return -1;
+               return err;
 
        ids->in_use++;
 
@@ -311,7 +252,7 @@ int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
                struct ipc_ops *ops, struct ipc_params *params)
 {
        int err;
-
+retry:
        err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);
 
        if (!err)
@@ -321,6 +262,9 @@ int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
        err = ops->getnew(ns, params);
        up_write(&ids->rw_mutex);
 
+       if (err == -EAGAIN)
+               goto retry;
+
        return err;
 }
 
@@ -374,7 +318,7 @@ int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
        struct kern_ipc_perm *ipcp;
        int flg = params->flg;
        int err;
-
+retry:
        err = idr_pre_get(&ids->ipcs_idr, GFP_KERNEL);
 
        /*
@@ -411,6 +355,9 @@ int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
        }
        up_write(&ids->rw_mutex);
 
+       if (err == -EAGAIN)
+               goto retry;
+
        return err;
 }
 
@@ -796,8 +743,8 @@ struct ipc_proc_iter {
 /*
  * This routine locks the ipc structure found at least at position pos.
  */
-struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
-                                       loff_t *new_pos)
+static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
+                                             loff_t *new_pos)
 {
        struct kern_ipc_perm *ipc;
        int total, id;