aboutsummaryrefslogtreecommitdiffstats
path: root/ipc/ipcns_notifier.c
diff options
context:
space:
mode:
authorNadia Derbey <Nadia.Derbey@bull.net>2008-04-29 04:00:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-29 11:06:12 -0400
commitb6b337ad1c1d6fe11b09b35d75464b84b3e11f07 (patch)
treedf174a23a827cc43db76900d1ddbbef3ac9ddc90 /ipc/ipcns_notifier.c
parent0c40ba4fd64f98e7a5cba8ffaedbd68642a85700 (diff)
ipc: recompute msgmni on memory add / remove
Introduce the registration of a callback routine that recomputes msg_ctlmni upon memory add / remove. A single notifier block is registered in the hotplug memory chain for all the ipc namespaces. Since the ipc namespaces are not linked together, they have their own notification chain: one notifier_block is defined per ipc namespace. Each time an ipc namespace is created (removed) it registers (unregisters) its notifier block in (from) the ipcns chain. The callback routine registered in the memory chain invokes the ipcns notifier chain with the IPCNS_LOWMEM event. Each callback routine registered in the ipcns namespace, in turn, recomputes msgmni for the owning namespace. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Mingming Cao <cmm@us.ibm.com> Cc: Pierre Peiffer <pierre.peiffer@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/ipcns_notifier.c')
-rw-r--r--ipc/ipcns_notifier.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/ipc/ipcns_notifier.c b/ipc/ipcns_notifier.c
new file mode 100644
index 000000000000..0786af6ce3ec
--- /dev/null
+++ b/ipc/ipcns_notifier.c
@@ -0,0 +1,71 @@
1/*
2 * linux/ipc/ipcns_notifier.c
3 * Copyright (C) 2007 BULL SA. Nadia Derbey
4 *
5 * Notification mechanism for ipc namespaces:
6 * The callback routine registered in the memory chain invokes the ipcns
7 * notifier chain with the IPCNS_MEMCHANGED event.
8 * Each callback routine registered in the ipcns namespace recomputes msgmni
9 * for the owning namespace.
10 */
11
12#include <linux/msg.h>
13#include <linux/rcupdate.h>
14#include <linux/notifier.h>
15#include <linux/nsproxy.h>
16#include <linux/ipc_namespace.h>
17
18#include "util.h"
19
20
21
22static BLOCKING_NOTIFIER_HEAD(ipcns_chain);
23
24
25static int ipcns_callback(struct notifier_block *self,
26 unsigned long action, void *arg)
27{
28 struct ipc_namespace *ns;
29
30 switch (action) {
31 case IPCNS_MEMCHANGED: /* amount of lowmem has changed */
32 /*
33 * It's time to recompute msgmni
34 */
35 ns = container_of(self, struct ipc_namespace, ipcns_nb);
36 /*
37 * No need to get a reference on the ns: the 1st job of
38 * free_ipc_ns() is to unregister the callback routine.
39 * blocking_notifier_chain_unregister takes the wr lock to do
40 * it.
41 * When this callback routine is called the rd lock is held by
42 * blocking_notifier_call_chain.
43 * So the ipc ns cannot be freed while we are here.
44 */
45 recompute_msgmni(ns);
46 break;
47 default:
48 break;
49 }
50
51 return NOTIFY_OK;
52}
53
54int register_ipcns_notifier(struct ipc_namespace *ns)
55{
56 memset(&ns->ipcns_nb, 0, sizeof(ns->ipcns_nb));
57 ns->ipcns_nb.notifier_call = ipcns_callback;
58 ns->ipcns_nb.priority = IPCNS_CALLBACK_PRI;
59 return blocking_notifier_chain_register(&ipcns_chain, &ns->ipcns_nb);
60}
61
62int unregister_ipcns_notifier(struct ipc_namespace *ns)
63{
64 return blocking_notifier_chain_unregister(&ipcns_chain,
65 &ns->ipcns_nb);
66}
67
68int ipcns_notify(unsigned long val)
69{
70 return blocking_notifier_call_chain(&ipcns_chain, val, NULL);
71}