sysvipc: properly name ipc_addid() limit parameter
[linux-2.6-microblaze.git] / ipc / util.c
index 79b30ee..e09bf76 100644 (file)
@@ -116,13 +116,15 @@ int ipc_init_ids(struct ipc_ids *ids)
        int err;
        ids->in_use = 0;
        ids->seq = 0;
-       ids->next_id = -1;
        init_rwsem(&ids->rwsem);
        err = rhashtable_init(&ids->key_ht, &ipc_kht_params);
        if (err)
                return err;
        idr_init(&ids->ipcs_idr);
        ids->tables_initialized = true;
+#ifdef CONFIG_CHECKPOINT_RESTORE
+       ids->next_id = -1;
+#endif
        return 0;
 }
 
@@ -216,11 +218,51 @@ int ipc_get_maxid(struct ipc_ids *ids)
        return max_id;
 }
 
+#ifdef CONFIG_CHECKPOINT_RESTORE
+/*
+ * Specify desired id for next allocated IPC object.
+ */
+#define ipc_idr_alloc(ids, new)                                                \
+       idr_alloc(&(ids)->ipcs_idr, (new),                              \
+                 (ids)->next_id < 0 ? 0 : ipcid_to_idx((ids)->next_id),\
+                 0, GFP_NOWAIT)
+
+static inline int ipc_buildid(int id, struct ipc_ids *ids,
+                             struct kern_ipc_perm *new)
+{
+       if (ids->next_id < 0) { /* default, behave as !CHECKPOINT_RESTORE */
+               new->seq = ids->seq++;
+               if (ids->seq > IPCID_SEQ_MAX)
+                       ids->seq = 0;
+       } else {
+               new->seq = ipcid_to_seqx(ids->next_id);
+               ids->next_id = -1;
+       }
+
+       return SEQ_MULTIPLIER * new->seq + id;
+}
+
+#else
+#define ipc_idr_alloc(ids, new)                                        \
+       idr_alloc(&(ids)->ipcs_idr, (new), 0, 0, GFP_NOWAIT)
+
+static inline int ipc_buildid(int id, struct ipc_ids *ids,
+                             struct kern_ipc_perm *new)
+{
+       new->seq = ids->seq++;
+       if (ids->seq > IPCID_SEQ_MAX)
+               ids->seq = 0;
+
+       return SEQ_MULTIPLIER * new->seq + id;
+}
+
+#endif /* CONFIG_CHECKPOINT_RESTORE */
+
 /**
  * ipc_addid - add an ipc identifier
  * @ids: ipc identifier set
  * @new: new ipc permission set
- * @size: limit for the number of used ids
+ * @limit: limit for the number of used 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
@@ -229,17 +271,16 @@ int ipc_get_maxid(struct ipc_ids *ids)
  *
  * Called with writer ipc_ids.rwsem held.
  */
-int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
+int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit)
 {
        kuid_t euid;
        kgid_t egid;
        int id, err;
-       int next_id = ids->next_id;
 
-       if (size > IPCMNI)
-               size = IPCMNI;
+       if (limit > IPCMNI)
+               limit = IPCMNI;
 
-       if (!ids->tables_initialized || ids->in_use >= size)
+       if (!ids->tables_initialized || ids->in_use >= limit)
                return -ENOSPC;
 
        idr_preload(GFP_KERNEL);
@@ -254,9 +295,7 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
        new->cuid = new->uid = euid;
        new->gid = new->cgid = egid;
 
-       id = idr_alloc(&ids->ipcs_idr, new,
-                      (next_id < 0) ? 0 : ipcid_to_idx(next_id), 0,
-                      GFP_NOWAIT);
+       id = ipc_idr_alloc(ids, new);
        idr_preload_end();
 
        if (id >= 0 && new->key != IPC_PRIVATE) {
@@ -274,17 +313,8 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int size)
        }
 
        ids->in_use++;
+       new->id = ipc_buildid(id, ids, new);
 
-       if (next_id < 0) {
-               new->seq = ids->seq++;
-               if (ids->seq > IPCID_SEQ_MAX)
-                       ids->seq = 0;
-       } else {
-               new->seq = ipcid_to_seqx(next_id);
-               ids->next_id = -1;
-       }
-
-       new->id = ipc_buildid(id, new->seq);
        return id;
 }