Re: [PATCH] Consolidate IPC namespace cleanup functions

Previous thread: [PATCH] mark read_crX() asm code as volatile by Kirill Korotaev on Tuesday, October 2, 2007 - 7:08 am. (10 messages)

Next thread: get amount of "entropy" in /dev/random ? by Yakov Lerner on Tuesday, October 2, 2007 - 8:25 am. (3 messages)
From: Pavel Emelyanov
Date: Tuesday, October 2, 2007 - 7:17 am

When the IPC namespace is terminated all the IPC objects (i.e. ids)
living in it are freed. This is done in a similar way in X_exit_ns()
functions. All the code can be consolidated, saving 122 bytes when
the NAMESPACES are on.

This patch must be applied after the ones with the NAMESPACES config
option introduced.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>

---

 ipc/msg.c       |   23 ++++-------------------
 ipc/namespace.c |   39 +++++++++++++++++++++++++++++++++++++++
 ipc/sem.c       |   23 ++++-------------------
 ipc/shm.c       |   23 ++++-------------------
 ipc/util.h      |    6 +++---
 5 files changed, 54 insertions(+), 60 deletions(-)

diff --git a/ipc/namespace.c b/ipc/namespace.c
index cef1139..98de4e5 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -12,6 +12,45 @@
 
 #include "util.h"
 
+static void ipc_exit_ns(struct ipc_namespace *ns, struct ipc_ids *ids,
+		void (*free_fn)(struct ipc_namespace *ns, void *id))
+{
+	void *id;
+	int next_id;
+	int total, in_use;
+
+	mutex_lock(&ids->mutex);
+
+	in_use = ids->in_use;
+
+	for (total = 0, next_id = 0; total < in_use; next_id++) {
+		id = idr_find(&ids->ipcs_idr, next_id);
+		if (id == NULL)
+			continue;
+
+		free_fn(ns, id);
+		total++;
+	}
+	mutex_unlock(&ids->mutex);
+
+	kfree(ids);
+}
+
+static inline void sem_exit_ns(struct ipc_namespace *ns)
+{
+	ipc_exit_ns(ns, ns->ids[IPC_SEM_IDS], sem_free);
+}
+
+static inline void msg_exit_ns(struct ipc_namespace *ns)
+{
+	ipc_exit_ns(ns, ns->ids[IPC_MSG_IDS], msg_free);
+}
+
+static inline void shm_exit_ns(struct ipc_namespace *ns)
+{
+	ipc_exit_ns(ns, ns->ids[IPC_SHM_IDS], shm_free);
+}
+
 static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
 {
 	int err;
diff --git a/ipc/sem.c b/ipc/sem.c
index 2e9f449..8027a30 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -144,28 +144,13 @@ int sem_init_ns(struct ipc_namespace *ns
 	return 0;
 }
 
-void sem_exit_ns(struct ipc_namespace *ns)
+void ...
From: Cedric Le Goater
Date: Tuesday, October 2, 2007 - 8:01 am

Acked-by: Cedric Le Goater <clg@fr.ibm.com>

Thanks Pavel !


-

Previous thread: [PATCH] mark read_crX() asm code as volatile by Kirill Korotaev on Tuesday, October 2, 2007 - 7:08 am. (10 messages)

Next thread: get amount of "entropy" in /dev/random ? by Yakov Lerner on Tuesday, October 2, 2007 - 8:25 am. (3 messages)