diff options
author | Alexey Dobriyan <adobriyan@sw.ru> | 2007-10-19 02:39:16 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-19 14:53:34 -0400 |
commit | fe9d4f576324999ac521c931f3b3eee0c8e45544 (patch) | |
tree | 8ff6ad770e15e81d00c87b945cb60326f28aee6b /kernel | |
parent | 3ed75eb8f1cd89565966599c4f77d2edb086d5b0 (diff) |
Add kernel/notifier.c
There is separate notifier header, but no separate notifier .c file.
Extract notifier code out of kernel/sys.c which will remain for
misc syscalls I hope. Merge kernel/die_notifier.c into kernel/notifier.c.
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Alexey Dobriyan <adobriyan@sw.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/Makefile | 4 | ||||
-rw-r--r-- | kernel/die_notifier.c | 38 | ||||
-rw-r--r-- | kernel/notifier.c | 539 | ||||
-rw-r--r-- | kernel/sys.c | 531 |
4 files changed, 541 insertions, 571 deletions
diff --git a/kernel/Makefile b/kernel/Makefile index d63fbb18798a..001bd3b65dd1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile | |||
@@ -8,8 +8,8 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ | |||
8 | signal.o sys.o kmod.o workqueue.o pid.o \ | 8 | signal.o sys.o kmod.o workqueue.o pid.o \ |
9 | rcupdate.o extable.o params.o posix-timers.o \ | 9 | rcupdate.o extable.o params.o posix-timers.o \ |
10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ | 10 | kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ |
11 | hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o \ | 11 | hrtimer.o rwsem.o latency.o nsproxy.o srcu.o \ |
12 | utsname.o sysctl_check.o | 12 | utsname.o sysctl_check.o notifier.o |
13 | 13 | ||
14 | obj-$(CONFIG_STACKTRACE) += stacktrace.o | 14 | obj-$(CONFIG_STACKTRACE) += stacktrace.o |
15 | obj-y += time/ | 15 | obj-y += time/ |
diff --git a/kernel/die_notifier.c b/kernel/die_notifier.c deleted file mode 100644 index 0d98827887a7..000000000000 --- a/kernel/die_notifier.c +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | |||
2 | #include <linux/module.h> | ||
3 | #include <linux/notifier.h> | ||
4 | #include <linux/vmalloc.h> | ||
5 | #include <linux/kdebug.h> | ||
6 | |||
7 | |||
8 | static ATOMIC_NOTIFIER_HEAD(die_chain); | ||
9 | |||
10 | int notify_die(enum die_val val, const char *str, | ||
11 | struct pt_regs *regs, long err, int trap, int sig) | ||
12 | { | ||
13 | struct die_args args = { | ||
14 | .regs = regs, | ||
15 | .str = str, | ||
16 | .err = err, | ||
17 | .trapnr = trap, | ||
18 | .signr = sig, | ||
19 | |||
20 | }; | ||
21 | |||
22 | return atomic_notifier_call_chain(&die_chain, val, &args); | ||
23 | } | ||
24 | |||
25 | int register_die_notifier(struct notifier_block *nb) | ||
26 | { | ||
27 | vmalloc_sync_all(); | ||
28 | return atomic_notifier_chain_register(&die_chain, nb); | ||
29 | } | ||
30 | EXPORT_SYMBOL_GPL(register_die_notifier); | ||
31 | |||
32 | int unregister_die_notifier(struct notifier_block *nb) | ||
33 | { | ||
34 | return atomic_notifier_chain_unregister(&die_chain, nb); | ||
35 | } | ||
36 | EXPORT_SYMBOL_GPL(unregister_die_notifier); | ||
37 | |||
38 | |||
diff --git a/kernel/notifier.c b/kernel/notifier.c new file mode 100644 index 000000000000..4253f472f060 --- /dev/null +++ b/kernel/notifier.c | |||
@@ -0,0 +1,539 @@ | |||
1 | #include <linux/kdebug.h> | ||
2 | #include <linux/kprobes.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/notifier.h> | ||
5 | #include <linux/rcupdate.h> | ||
6 | #include <linux/vmalloc.h> | ||
7 | |||
8 | /* | ||
9 | * Notifier list for kernel code which wants to be called | ||
10 | * at shutdown. This is used to stop any idling DMA operations | ||
11 | * and the like. | ||
12 | */ | ||
13 | BLOCKING_NOTIFIER_HEAD(reboot_notifier_list); | ||
14 | |||
15 | /* | ||
16 | * Notifier chain core routines. The exported routines below | ||
17 | * are layered on top of these, with appropriate locking added. | ||
18 | */ | ||
19 | |||
20 | static int notifier_chain_register(struct notifier_block **nl, | ||
21 | struct notifier_block *n) | ||
22 | { | ||
23 | while ((*nl) != NULL) { | ||
24 | if (n->priority > (*nl)->priority) | ||
25 | break; | ||
26 | nl = &((*nl)->next); | ||
27 | } | ||
28 | n->next = *nl; | ||
29 | rcu_assign_pointer(*nl, n); | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static int notifier_chain_unregister(struct notifier_block **nl, | ||
34 | struct notifier_block *n) | ||
35 | { | ||
36 | while ((*nl) != NULL) { | ||
37 | if ((*nl) == n) { | ||
38 | rcu_assign_pointer(*nl, n->next); | ||
39 | return 0; | ||
40 | } | ||
41 | nl = &((*nl)->next); | ||
42 | } | ||
43 | return -ENOENT; | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * notifier_call_chain - Informs the registered notifiers about an event. | ||
48 | * @nl: Pointer to head of the blocking notifier chain | ||
49 | * @val: Value passed unmodified to notifier function | ||
50 | * @v: Pointer passed unmodified to notifier function | ||
51 | * @nr_to_call: Number of notifier functions to be called. Don't care | ||
52 | * value of this parameter is -1. | ||
53 | * @nr_calls: Records the number of notifications sent. Don't care | ||
54 | * value of this field is NULL. | ||
55 | * @returns: notifier_call_chain returns the value returned by the | ||
56 | * last notifier function called. | ||
57 | */ | ||
58 | static int __kprobes notifier_call_chain(struct notifier_block **nl, | ||
59 | unsigned long val, void *v, | ||
60 | int nr_to_call, int *nr_calls) | ||
61 | { | ||
62 | int ret = NOTIFY_DONE; | ||
63 | struct notifier_block *nb, *next_nb; | ||
64 | |||
65 | nb = rcu_dereference(*nl); | ||
66 | |||
67 | while (nb && nr_to_call) { | ||
68 | next_nb = rcu_dereference(nb->next); | ||
69 | ret = nb->notifier_call(nb, val, v); | ||
70 | |||
71 | if (nr_calls) | ||
72 | (*nr_calls)++; | ||
73 | |||
74 | if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK) | ||
75 | break; | ||
76 | nb = next_nb; | ||
77 | nr_to_call--; | ||
78 | } | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | * Atomic notifier chain routines. Registration and unregistration | ||
84 | * use a spinlock, and call_chain is synchronized by RCU (no locks). | ||
85 | */ | ||
86 | |||
87 | /** | ||
88 | * atomic_notifier_chain_register - Add notifier to an atomic notifier chain | ||
89 | * @nh: Pointer to head of the atomic notifier chain | ||
90 | * @n: New entry in notifier chain | ||
91 | * | ||
92 | * Adds a notifier to an atomic notifier chain. | ||
93 | * | ||
94 | * Currently always returns zero. | ||
95 | */ | ||
96 | int atomic_notifier_chain_register(struct atomic_notifier_head *nh, | ||
97 | struct notifier_block *n) | ||
98 | { | ||
99 | unsigned long flags; | ||
100 | int ret; | ||
101 | |||
102 | spin_lock_irqsave(&nh->lock, flags); | ||
103 | ret = notifier_chain_register(&nh->head, n); | ||
104 | spin_unlock_irqrestore(&nh->lock, flags); | ||
105 | return ret; | ||
106 | } | ||
107 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_register); | ||
108 | |||
109 | /** | ||
110 | * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain | ||
111 | * @nh: Pointer to head of the atomic notifier chain | ||
112 | * @n: Entry to remove from notifier chain | ||
113 | * | ||
114 | * Removes a notifier from an atomic notifier chain. | ||
115 | * | ||
116 | * Returns zero on success or %-ENOENT on failure. | ||
117 | */ | ||
118 | int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, | ||
119 | struct notifier_block *n) | ||
120 | { | ||
121 | unsigned long flags; | ||
122 | int ret; | ||
123 | |||
124 | spin_lock_irqsave(&nh->lock, flags); | ||
125 | ret = notifier_chain_unregister(&nh->head, n); | ||
126 | spin_unlock_irqrestore(&nh->lock, flags); | ||
127 | synchronize_rcu(); | ||
128 | return ret; | ||
129 | } | ||
130 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister); | ||
131 | |||
132 | /** | ||
133 | * __atomic_notifier_call_chain - Call functions in an atomic notifier chain | ||
134 | * @nh: Pointer to head of the atomic notifier chain | ||
135 | * @val: Value passed unmodified to notifier function | ||
136 | * @v: Pointer passed unmodified to notifier function | ||
137 | * @nr_to_call: See the comment for notifier_call_chain. | ||
138 | * @nr_calls: See the comment for notifier_call_chain. | ||
139 | * | ||
140 | * Calls each function in a notifier chain in turn. The functions | ||
141 | * run in an atomic context, so they must not block. | ||
142 | * This routine uses RCU to synchronize with changes to the chain. | ||
143 | * | ||
144 | * If the return value of the notifier can be and'ed | ||
145 | * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain() | ||
146 | * will return immediately, with the return value of | ||
147 | * the notifier function which halted execution. | ||
148 | * Otherwise the return value is the return value | ||
149 | * of the last notifier function called. | ||
150 | */ | ||
151 | int __kprobes __atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
152 | unsigned long val, void *v, | ||
153 | int nr_to_call, int *nr_calls) | ||
154 | { | ||
155 | int ret; | ||
156 | |||
157 | rcu_read_lock(); | ||
158 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
159 | rcu_read_unlock(); | ||
160 | return ret; | ||
161 | } | ||
162 | EXPORT_SYMBOL_GPL(__atomic_notifier_call_chain); | ||
163 | |||
164 | int __kprobes atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
165 | unsigned long val, void *v) | ||
166 | { | ||
167 | return __atomic_notifier_call_chain(nh, val, v, -1, NULL); | ||
168 | } | ||
169 | EXPORT_SYMBOL_GPL(atomic_notifier_call_chain); | ||
170 | |||
171 | /* | ||
172 | * Blocking notifier chain routines. All access to the chain is | ||
173 | * synchronized by an rwsem. | ||
174 | */ | ||
175 | |||
176 | /** | ||
177 | * blocking_notifier_chain_register - Add notifier to a blocking notifier chain | ||
178 | * @nh: Pointer to head of the blocking notifier chain | ||
179 | * @n: New entry in notifier chain | ||
180 | * | ||
181 | * Adds a notifier to a blocking notifier chain. | ||
182 | * Must be called in process context. | ||
183 | * | ||
184 | * Currently always returns zero. | ||
185 | */ | ||
186 | int blocking_notifier_chain_register(struct blocking_notifier_head *nh, | ||
187 | struct notifier_block *n) | ||
188 | { | ||
189 | int ret; | ||
190 | |||
191 | /* | ||
192 | * This code gets used during boot-up, when task switching is | ||
193 | * not yet working and interrupts must remain disabled. At | ||
194 | * such times we must not call down_write(). | ||
195 | */ | ||
196 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
197 | return notifier_chain_register(&nh->head, n); | ||
198 | |||
199 | down_write(&nh->rwsem); | ||
200 | ret = notifier_chain_register(&nh->head, n); | ||
201 | up_write(&nh->rwsem); | ||
202 | return ret; | ||
203 | } | ||
204 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_register); | ||
205 | |||
206 | /** | ||
207 | * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain | ||
208 | * @nh: Pointer to head of the blocking notifier chain | ||
209 | * @n: Entry to remove from notifier chain | ||
210 | * | ||
211 | * Removes a notifier from a blocking notifier chain. | ||
212 | * Must be called from process context. | ||
213 | * | ||
214 | * Returns zero on success or %-ENOENT on failure. | ||
215 | */ | ||
216 | int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh, | ||
217 | struct notifier_block *n) | ||
218 | { | ||
219 | int ret; | ||
220 | |||
221 | /* | ||
222 | * This code gets used during boot-up, when task switching is | ||
223 | * not yet working and interrupts must remain disabled. At | ||
224 | * such times we must not call down_write(). | ||
225 | */ | ||
226 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
227 | return notifier_chain_unregister(&nh->head, n); | ||
228 | |||
229 | down_write(&nh->rwsem); | ||
230 | ret = notifier_chain_unregister(&nh->head, n); | ||
231 | up_write(&nh->rwsem); | ||
232 | return ret; | ||
233 | } | ||
234 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister); | ||
235 | |||
236 | /** | ||
237 | * __blocking_notifier_call_chain - Call functions in a blocking notifier chain | ||
238 | * @nh: Pointer to head of the blocking notifier chain | ||
239 | * @val: Value passed unmodified to notifier function | ||
240 | * @v: Pointer passed unmodified to notifier function | ||
241 | * @nr_to_call: See comment for notifier_call_chain. | ||
242 | * @nr_calls: See comment for notifier_call_chain. | ||
243 | * | ||
244 | * Calls each function in a notifier chain in turn. The functions | ||
245 | * run in a process context, so they are allowed to block. | ||
246 | * | ||
247 | * If the return value of the notifier can be and'ed | ||
248 | * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain() | ||
249 | * will return immediately, with the return value of | ||
250 | * the notifier function which halted execution. | ||
251 | * Otherwise the return value is the return value | ||
252 | * of the last notifier function called. | ||
253 | */ | ||
254 | int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
255 | unsigned long val, void *v, | ||
256 | int nr_to_call, int *nr_calls) | ||
257 | { | ||
258 | int ret = NOTIFY_DONE; | ||
259 | |||
260 | /* | ||
261 | * We check the head outside the lock, but if this access is | ||
262 | * racy then it does not matter what the result of the test | ||
263 | * is, we re-check the list after having taken the lock anyway: | ||
264 | */ | ||
265 | if (rcu_dereference(nh->head)) { | ||
266 | down_read(&nh->rwsem); | ||
267 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, | ||
268 | nr_calls); | ||
269 | up_read(&nh->rwsem); | ||
270 | } | ||
271 | return ret; | ||
272 | } | ||
273 | EXPORT_SYMBOL_GPL(__blocking_notifier_call_chain); | ||
274 | |||
275 | int blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
276 | unsigned long val, void *v) | ||
277 | { | ||
278 | return __blocking_notifier_call_chain(nh, val, v, -1, NULL); | ||
279 | } | ||
280 | EXPORT_SYMBOL_GPL(blocking_notifier_call_chain); | ||
281 | |||
282 | /* | ||
283 | * Raw notifier chain routines. There is no protection; | ||
284 | * the caller must provide it. Use at your own risk! | ||
285 | */ | ||
286 | |||
287 | /** | ||
288 | * raw_notifier_chain_register - Add notifier to a raw notifier chain | ||
289 | * @nh: Pointer to head of the raw notifier chain | ||
290 | * @n: New entry in notifier chain | ||
291 | * | ||
292 | * Adds a notifier to a raw notifier chain. | ||
293 | * All locking must be provided by the caller. | ||
294 | * | ||
295 | * Currently always returns zero. | ||
296 | */ | ||
297 | int raw_notifier_chain_register(struct raw_notifier_head *nh, | ||
298 | struct notifier_block *n) | ||
299 | { | ||
300 | return notifier_chain_register(&nh->head, n); | ||
301 | } | ||
302 | EXPORT_SYMBOL_GPL(raw_notifier_chain_register); | ||
303 | |||
304 | /** | ||
305 | * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain | ||
306 | * @nh: Pointer to head of the raw notifier chain | ||
307 | * @n: Entry to remove from notifier chain | ||
308 | * | ||
309 | * Removes a notifier from a raw notifier chain. | ||
310 | * All locking must be provided by the caller. | ||
311 | * | ||
312 | * Returns zero on success or %-ENOENT on failure. | ||
313 | */ | ||
314 | int raw_notifier_chain_unregister(struct raw_notifier_head *nh, | ||
315 | struct notifier_block *n) | ||
316 | { | ||
317 | return notifier_chain_unregister(&nh->head, n); | ||
318 | } | ||
319 | EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister); | ||
320 | |||
321 | /** | ||
322 | * __raw_notifier_call_chain - Call functions in a raw notifier chain | ||
323 | * @nh: Pointer to head of the raw notifier chain | ||
324 | * @val: Value passed unmodified to notifier function | ||
325 | * @v: Pointer passed unmodified to notifier function | ||
326 | * @nr_to_call: See comment for notifier_call_chain. | ||
327 | * @nr_calls: See comment for notifier_call_chain | ||
328 | * | ||
329 | * Calls each function in a notifier chain in turn. The functions | ||
330 | * run in an undefined context. | ||
331 | * All locking must be provided by the caller. | ||
332 | * | ||
333 | * If the return value of the notifier can be and'ed | ||
334 | * with %NOTIFY_STOP_MASK then raw_notifier_call_chain() | ||
335 | * will return immediately, with the return value of | ||
336 | * the notifier function which halted execution. | ||
337 | * Otherwise the return value is the return value | ||
338 | * of the last notifier function called. | ||
339 | */ | ||
340 | int __raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
341 | unsigned long val, void *v, | ||
342 | int nr_to_call, int *nr_calls) | ||
343 | { | ||
344 | return notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
345 | } | ||
346 | EXPORT_SYMBOL_GPL(__raw_notifier_call_chain); | ||
347 | |||
348 | int raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
349 | unsigned long val, void *v) | ||
350 | { | ||
351 | return __raw_notifier_call_chain(nh, val, v, -1, NULL); | ||
352 | } | ||
353 | EXPORT_SYMBOL_GPL(raw_notifier_call_chain); | ||
354 | |||
355 | /* | ||
356 | * SRCU notifier chain routines. Registration and unregistration | ||
357 | * use a mutex, and call_chain is synchronized by SRCU (no locks). | ||
358 | */ | ||
359 | |||
360 | /** | ||
361 | * srcu_notifier_chain_register - Add notifier to an SRCU notifier chain | ||
362 | * @nh: Pointer to head of the SRCU notifier chain | ||
363 | * @n: New entry in notifier chain | ||
364 | * | ||
365 | * Adds a notifier to an SRCU notifier chain. | ||
366 | * Must be called in process context. | ||
367 | * | ||
368 | * Currently always returns zero. | ||
369 | */ | ||
370 | int srcu_notifier_chain_register(struct srcu_notifier_head *nh, | ||
371 | struct notifier_block *n) | ||
372 | { | ||
373 | int ret; | ||
374 | |||
375 | /* | ||
376 | * This code gets used during boot-up, when task switching is | ||
377 | * not yet working and interrupts must remain disabled. At | ||
378 | * such times we must not call mutex_lock(). | ||
379 | */ | ||
380 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
381 | return notifier_chain_register(&nh->head, n); | ||
382 | |||
383 | mutex_lock(&nh->mutex); | ||
384 | ret = notifier_chain_register(&nh->head, n); | ||
385 | mutex_unlock(&nh->mutex); | ||
386 | return ret; | ||
387 | } | ||
388 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_register); | ||
389 | |||
390 | /** | ||
391 | * srcu_notifier_chain_unregister - Remove notifier from an SRCU notifier chain | ||
392 | * @nh: Pointer to head of the SRCU notifier chain | ||
393 | * @n: Entry to remove from notifier chain | ||
394 | * | ||
395 | * Removes a notifier from an SRCU notifier chain. | ||
396 | * Must be called from process context. | ||
397 | * | ||
398 | * Returns zero on success or %-ENOENT on failure. | ||
399 | */ | ||
400 | int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh, | ||
401 | struct notifier_block *n) | ||
402 | { | ||
403 | int ret; | ||
404 | |||
405 | /* | ||
406 | * This code gets used during boot-up, when task switching is | ||
407 | * not yet working and interrupts must remain disabled. At | ||
408 | * such times we must not call mutex_lock(). | ||
409 | */ | ||
410 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
411 | return notifier_chain_unregister(&nh->head, n); | ||
412 | |||
413 | mutex_lock(&nh->mutex); | ||
414 | ret = notifier_chain_unregister(&nh->head, n); | ||
415 | mutex_unlock(&nh->mutex); | ||
416 | synchronize_srcu(&nh->srcu); | ||
417 | return ret; | ||
418 | } | ||
419 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister); | ||
420 | |||
421 | /** | ||
422 | * __srcu_notifier_call_chain - Call functions in an SRCU notifier chain | ||
423 | * @nh: Pointer to head of the SRCU notifier chain | ||
424 | * @val: Value passed unmodified to notifier function | ||
425 | * @v: Pointer passed unmodified to notifier function | ||
426 | * @nr_to_call: See comment for notifier_call_chain. | ||
427 | * @nr_calls: See comment for notifier_call_chain | ||
428 | * | ||
429 | * Calls each function in a notifier chain in turn. The functions | ||
430 | * run in a process context, so they are allowed to block. | ||
431 | * | ||
432 | * If the return value of the notifier can be and'ed | ||
433 | * with %NOTIFY_STOP_MASK then srcu_notifier_call_chain() | ||
434 | * will return immediately, with the return value of | ||
435 | * the notifier function which halted execution. | ||
436 | * Otherwise the return value is the return value | ||
437 | * of the last notifier function called. | ||
438 | */ | ||
439 | int __srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
440 | unsigned long val, void *v, | ||
441 | int nr_to_call, int *nr_calls) | ||
442 | { | ||
443 | int ret; | ||
444 | int idx; | ||
445 | |||
446 | idx = srcu_read_lock(&nh->srcu); | ||
447 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
448 | srcu_read_unlock(&nh->srcu, idx); | ||
449 | return ret; | ||
450 | } | ||
451 | EXPORT_SYMBOL_GPL(__srcu_notifier_call_chain); | ||
452 | |||
453 | int srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
454 | unsigned long val, void *v) | ||
455 | { | ||
456 | return __srcu_notifier_call_chain(nh, val, v, -1, NULL); | ||
457 | } | ||
458 | EXPORT_SYMBOL_GPL(srcu_notifier_call_chain); | ||
459 | |||
460 | /** | ||
461 | * srcu_init_notifier_head - Initialize an SRCU notifier head | ||
462 | * @nh: Pointer to head of the srcu notifier chain | ||
463 | * | ||
464 | * Unlike other sorts of notifier heads, SRCU notifier heads require | ||
465 | * dynamic initialization. Be sure to call this routine before | ||
466 | * calling any of the other SRCU notifier routines for this head. | ||
467 | * | ||
468 | * If an SRCU notifier head is deallocated, it must first be cleaned | ||
469 | * up by calling srcu_cleanup_notifier_head(). Otherwise the head's | ||
470 | * per-cpu data (used by the SRCU mechanism) will leak. | ||
471 | */ | ||
472 | void srcu_init_notifier_head(struct srcu_notifier_head *nh) | ||
473 | { | ||
474 | mutex_init(&nh->mutex); | ||
475 | if (init_srcu_struct(&nh->srcu) < 0) | ||
476 | BUG(); | ||
477 | nh->head = NULL; | ||
478 | } | ||
479 | EXPORT_SYMBOL_GPL(srcu_init_notifier_head); | ||
480 | |||
481 | /** | ||
482 | * register_reboot_notifier - Register function to be called at reboot time | ||
483 | * @nb: Info about notifier function to be called | ||
484 | * | ||
485 | * Registers a function with the list of functions | ||
486 | * to be called at reboot time. | ||
487 | * | ||
488 | * Currently always returns zero, as blocking_notifier_chain_register() | ||
489 | * always returns zero. | ||
490 | */ | ||
491 | int register_reboot_notifier(struct notifier_block *nb) | ||
492 | { | ||
493 | return blocking_notifier_chain_register(&reboot_notifier_list, nb); | ||
494 | } | ||
495 | EXPORT_SYMBOL(register_reboot_notifier); | ||
496 | |||
497 | /** | ||
498 | * unregister_reboot_notifier - Unregister previously registered reboot notifier | ||
499 | * @nb: Hook to be unregistered | ||
500 | * | ||
501 | * Unregisters a previously registered reboot | ||
502 | * notifier function. | ||
503 | * | ||
504 | * Returns zero on success, or %-ENOENT on failure. | ||
505 | */ | ||
506 | int unregister_reboot_notifier(struct notifier_block *nb) | ||
507 | { | ||
508 | return blocking_notifier_chain_unregister(&reboot_notifier_list, nb); | ||
509 | } | ||
510 | EXPORT_SYMBOL(unregister_reboot_notifier); | ||
511 | |||
512 | static ATOMIC_NOTIFIER_HEAD(die_chain); | ||
513 | |||
514 | int notify_die(enum die_val val, const char *str, | ||
515 | struct pt_regs *regs, long err, int trap, int sig) | ||
516 | { | ||
517 | struct die_args args = { | ||
518 | .regs = regs, | ||
519 | .str = str, | ||
520 | .err = err, | ||
521 | .trapnr = trap, | ||
522 | .signr = sig, | ||
523 | |||
524 | }; | ||
525 | return atomic_notifier_call_chain(&die_chain, val, &args); | ||
526 | } | ||
527 | |||
528 | int register_die_notifier(struct notifier_block *nb) | ||
529 | { | ||
530 | vmalloc_sync_all(); | ||
531 | return atomic_notifier_chain_register(&die_chain, nb); | ||
532 | } | ||
533 | EXPORT_SYMBOL_GPL(register_die_notifier); | ||
534 | |||
535 | int unregister_die_notifier(struct notifier_block *nb) | ||
536 | { | ||
537 | return atomic_notifier_chain_unregister(&die_chain, nb); | ||
538 | } | ||
539 | EXPORT_SYMBOL_GPL(unregister_die_notifier); | ||
diff --git a/kernel/sys.c b/kernel/sys.c index bc8879c822a5..b8fcbc640193 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -106,537 +106,6 @@ EXPORT_SYMBOL(cad_pid); | |||
106 | 106 | ||
107 | void (*pm_power_off_prepare)(void); | 107 | void (*pm_power_off_prepare)(void); |
108 | 108 | ||
109 | /* | ||
110 | * Notifier list for kernel code which wants to be called | ||
111 | * at shutdown. This is used to stop any idling DMA operations | ||
112 | * and the like. | ||
113 | */ | ||
114 | |||
115 | static BLOCKING_NOTIFIER_HEAD(reboot_notifier_list); | ||
116 | |||
117 | /* | ||
118 | * Notifier chain core routines. The exported routines below | ||
119 | * are layered on top of these, with appropriate locking added. | ||
120 | */ | ||
121 | |||
122 | static int notifier_chain_register(struct notifier_block **nl, | ||
123 | struct notifier_block *n) | ||
124 | { | ||
125 | while ((*nl) != NULL) { | ||
126 | if (n->priority > (*nl)->priority) | ||
127 | break; | ||
128 | nl = &((*nl)->next); | ||
129 | } | ||
130 | n->next = *nl; | ||
131 | rcu_assign_pointer(*nl, n); | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | static int notifier_chain_unregister(struct notifier_block **nl, | ||
136 | struct notifier_block *n) | ||
137 | { | ||
138 | while ((*nl) != NULL) { | ||
139 | if ((*nl) == n) { | ||
140 | rcu_assign_pointer(*nl, n->next); | ||
141 | return 0; | ||
142 | } | ||
143 | nl = &((*nl)->next); | ||
144 | } | ||
145 | return -ENOENT; | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * notifier_call_chain - Informs the registered notifiers about an event. | ||
150 | * @nl: Pointer to head of the blocking notifier chain | ||
151 | * @val: Value passed unmodified to notifier function | ||
152 | * @v: Pointer passed unmodified to notifier function | ||
153 | * @nr_to_call: Number of notifier functions to be called. Don't care | ||
154 | * value of this parameter is -1. | ||
155 | * @nr_calls: Records the number of notifications sent. Don't care | ||
156 | * value of this field is NULL. | ||
157 | * @returns: notifier_call_chain returns the value returned by the | ||
158 | * last notifier function called. | ||
159 | */ | ||
160 | |||
161 | static int __kprobes notifier_call_chain(struct notifier_block **nl, | ||
162 | unsigned long val, void *v, | ||
163 | int nr_to_call, int *nr_calls) | ||
164 | { | ||
165 | int ret = NOTIFY_DONE; | ||
166 | struct notifier_block *nb, *next_nb; | ||
167 | |||
168 | nb = rcu_dereference(*nl); | ||
169 | |||
170 | while (nb && nr_to_call) { | ||
171 | next_nb = rcu_dereference(nb->next); | ||
172 | ret = nb->notifier_call(nb, val, v); | ||
173 | |||
174 | if (nr_calls) | ||
175 | (*nr_calls)++; | ||
176 | |||
177 | if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK) | ||
178 | break; | ||
179 | nb = next_nb; | ||
180 | nr_to_call--; | ||
181 | } | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | /* | ||
186 | * Atomic notifier chain routines. Registration and unregistration | ||
187 | * use a spinlock, and call_chain is synchronized by RCU (no locks). | ||
188 | */ | ||
189 | |||
190 | /** | ||
191 | * atomic_notifier_chain_register - Add notifier to an atomic notifier chain | ||
192 | * @nh: Pointer to head of the atomic notifier chain | ||
193 | * @n: New entry in notifier chain | ||
194 | * | ||
195 | * Adds a notifier to an atomic notifier chain. | ||
196 | * | ||
197 | * Currently always returns zero. | ||
198 | */ | ||
199 | |||
200 | int atomic_notifier_chain_register(struct atomic_notifier_head *nh, | ||
201 | struct notifier_block *n) | ||
202 | { | ||
203 | unsigned long flags; | ||
204 | int ret; | ||
205 | |||
206 | spin_lock_irqsave(&nh->lock, flags); | ||
207 | ret = notifier_chain_register(&nh->head, n); | ||
208 | spin_unlock_irqrestore(&nh->lock, flags); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_register); | ||
213 | |||
214 | /** | ||
215 | * atomic_notifier_chain_unregister - Remove notifier from an atomic notifier chain | ||
216 | * @nh: Pointer to head of the atomic notifier chain | ||
217 | * @n: Entry to remove from notifier chain | ||
218 | * | ||
219 | * Removes a notifier from an atomic notifier chain. | ||
220 | * | ||
221 | * Returns zero on success or %-ENOENT on failure. | ||
222 | */ | ||
223 | int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, | ||
224 | struct notifier_block *n) | ||
225 | { | ||
226 | unsigned long flags; | ||
227 | int ret; | ||
228 | |||
229 | spin_lock_irqsave(&nh->lock, flags); | ||
230 | ret = notifier_chain_unregister(&nh->head, n); | ||
231 | spin_unlock_irqrestore(&nh->lock, flags); | ||
232 | synchronize_rcu(); | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister); | ||
237 | |||
238 | /** | ||
239 | * __atomic_notifier_call_chain - Call functions in an atomic notifier chain | ||
240 | * @nh: Pointer to head of the atomic notifier chain | ||
241 | * @val: Value passed unmodified to notifier function | ||
242 | * @v: Pointer passed unmodified to notifier function | ||
243 | * @nr_to_call: See the comment for notifier_call_chain. | ||
244 | * @nr_calls: See the comment for notifier_call_chain. | ||
245 | * | ||
246 | * Calls each function in a notifier chain in turn. The functions | ||
247 | * run in an atomic context, so they must not block. | ||
248 | * This routine uses RCU to synchronize with changes to the chain. | ||
249 | * | ||
250 | * If the return value of the notifier can be and'ed | ||
251 | * with %NOTIFY_STOP_MASK then atomic_notifier_call_chain() | ||
252 | * will return immediately, with the return value of | ||
253 | * the notifier function which halted execution. | ||
254 | * Otherwise the return value is the return value | ||
255 | * of the last notifier function called. | ||
256 | */ | ||
257 | |||
258 | int __kprobes __atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
259 | unsigned long val, void *v, | ||
260 | int nr_to_call, int *nr_calls) | ||
261 | { | ||
262 | int ret; | ||
263 | |||
264 | rcu_read_lock(); | ||
265 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
266 | rcu_read_unlock(); | ||
267 | return ret; | ||
268 | } | ||
269 | |||
270 | EXPORT_SYMBOL_GPL(__atomic_notifier_call_chain); | ||
271 | |||
272 | int __kprobes atomic_notifier_call_chain(struct atomic_notifier_head *nh, | ||
273 | unsigned long val, void *v) | ||
274 | { | ||
275 | return __atomic_notifier_call_chain(nh, val, v, -1, NULL); | ||
276 | } | ||
277 | |||
278 | EXPORT_SYMBOL_GPL(atomic_notifier_call_chain); | ||
279 | /* | ||
280 | * Blocking notifier chain routines. All access to the chain is | ||
281 | * synchronized by an rwsem. | ||
282 | */ | ||
283 | |||
284 | /** | ||
285 | * blocking_notifier_chain_register - Add notifier to a blocking notifier chain | ||
286 | * @nh: Pointer to head of the blocking notifier chain | ||
287 | * @n: New entry in notifier chain | ||
288 | * | ||
289 | * Adds a notifier to a blocking notifier chain. | ||
290 | * Must be called in process context. | ||
291 | * | ||
292 | * Currently always returns zero. | ||
293 | */ | ||
294 | |||
295 | int blocking_notifier_chain_register(struct blocking_notifier_head *nh, | ||
296 | struct notifier_block *n) | ||
297 | { | ||
298 | int ret; | ||
299 | |||
300 | /* | ||
301 | * This code gets used during boot-up, when task switching is | ||
302 | * not yet working and interrupts must remain disabled. At | ||
303 | * such times we must not call down_write(). | ||
304 | */ | ||
305 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
306 | return notifier_chain_register(&nh->head, n); | ||
307 | |||
308 | down_write(&nh->rwsem); | ||
309 | ret = notifier_chain_register(&nh->head, n); | ||
310 | up_write(&nh->rwsem); | ||
311 | return ret; | ||
312 | } | ||
313 | |||
314 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_register); | ||
315 | |||
316 | /** | ||
317 | * blocking_notifier_chain_unregister - Remove notifier from a blocking notifier chain | ||
318 | * @nh: Pointer to head of the blocking notifier chain | ||
319 | * @n: Entry to remove from notifier chain | ||
320 | * | ||
321 | * Removes a notifier from a blocking notifier chain. | ||
322 | * Must be called from process context. | ||
323 | * | ||
324 | * Returns zero on success or %-ENOENT on failure. | ||
325 | */ | ||
326 | int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh, | ||
327 | struct notifier_block *n) | ||
328 | { | ||
329 | int ret; | ||
330 | |||
331 | /* | ||
332 | * This code gets used during boot-up, when task switching is | ||
333 | * not yet working and interrupts must remain disabled. At | ||
334 | * such times we must not call down_write(). | ||
335 | */ | ||
336 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
337 | return notifier_chain_unregister(&nh->head, n); | ||
338 | |||
339 | down_write(&nh->rwsem); | ||
340 | ret = notifier_chain_unregister(&nh->head, n); | ||
341 | up_write(&nh->rwsem); | ||
342 | return ret; | ||
343 | } | ||
344 | |||
345 | EXPORT_SYMBOL_GPL(blocking_notifier_chain_unregister); | ||
346 | |||
347 | /** | ||
348 | * __blocking_notifier_call_chain - Call functions in a blocking notifier chain | ||
349 | * @nh: Pointer to head of the blocking notifier chain | ||
350 | * @val: Value passed unmodified to notifier function | ||
351 | * @v: Pointer passed unmodified to notifier function | ||
352 | * @nr_to_call: See comment for notifier_call_chain. | ||
353 | * @nr_calls: See comment for notifier_call_chain. | ||
354 | * | ||
355 | * Calls each function in a notifier chain in turn. The functions | ||
356 | * run in a process context, so they are allowed to block. | ||
357 | * | ||
358 | * If the return value of the notifier can be and'ed | ||
359 | * with %NOTIFY_STOP_MASK then blocking_notifier_call_chain() | ||
360 | * will return immediately, with the return value of | ||
361 | * the notifier function which halted execution. | ||
362 | * Otherwise the return value is the return value | ||
363 | * of the last notifier function called. | ||
364 | */ | ||
365 | |||
366 | int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
367 | unsigned long val, void *v, | ||
368 | int nr_to_call, int *nr_calls) | ||
369 | { | ||
370 | int ret = NOTIFY_DONE; | ||
371 | |||
372 | /* | ||
373 | * We check the head outside the lock, but if this access is | ||
374 | * racy then it does not matter what the result of the test | ||
375 | * is, we re-check the list after having taken the lock anyway: | ||
376 | */ | ||
377 | if (rcu_dereference(nh->head)) { | ||
378 | down_read(&nh->rwsem); | ||
379 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, | ||
380 | nr_calls); | ||
381 | up_read(&nh->rwsem); | ||
382 | } | ||
383 | return ret; | ||
384 | } | ||
385 | EXPORT_SYMBOL_GPL(__blocking_notifier_call_chain); | ||
386 | |||
387 | int blocking_notifier_call_chain(struct blocking_notifier_head *nh, | ||
388 | unsigned long val, void *v) | ||
389 | { | ||
390 | return __blocking_notifier_call_chain(nh, val, v, -1, NULL); | ||
391 | } | ||
392 | EXPORT_SYMBOL_GPL(blocking_notifier_call_chain); | ||
393 | |||
394 | /* | ||
395 | * Raw notifier chain routines. There is no protection; | ||
396 | * the caller must provide it. Use at your own risk! | ||
397 | */ | ||
398 | |||
399 | /** | ||
400 | * raw_notifier_chain_register - Add notifier to a raw notifier chain | ||
401 | * @nh: Pointer to head of the raw notifier chain | ||
402 | * @n: New entry in notifier chain | ||
403 | * | ||
404 | * Adds a notifier to a raw notifier chain. | ||
405 | * All locking must be provided by the caller. | ||
406 | * | ||
407 | * Currently always returns zero. | ||
408 | */ | ||
409 | |||
410 | int raw_notifier_chain_register(struct raw_notifier_head *nh, | ||
411 | struct notifier_block *n) | ||
412 | { | ||
413 | return notifier_chain_register(&nh->head, n); | ||
414 | } | ||
415 | |||
416 | EXPORT_SYMBOL_GPL(raw_notifier_chain_register); | ||
417 | |||
418 | /** | ||
419 | * raw_notifier_chain_unregister - Remove notifier from a raw notifier chain | ||
420 | * @nh: Pointer to head of the raw notifier chain | ||
421 | * @n: Entry to remove from notifier chain | ||
422 | * | ||
423 | * Removes a notifier from a raw notifier chain. | ||
424 | * All locking must be provided by the caller. | ||
425 | * | ||
426 | * Returns zero on success or %-ENOENT on failure. | ||
427 | */ | ||
428 | int raw_notifier_chain_unregister(struct raw_notifier_head *nh, | ||
429 | struct notifier_block *n) | ||
430 | { | ||
431 | return notifier_chain_unregister(&nh->head, n); | ||
432 | } | ||
433 | |||
434 | EXPORT_SYMBOL_GPL(raw_notifier_chain_unregister); | ||
435 | |||
436 | /** | ||
437 | * __raw_notifier_call_chain - Call functions in a raw notifier chain | ||
438 | * @nh: Pointer to head of the raw notifier chain | ||
439 | * @val: Value passed unmodified to notifier function | ||
440 | * @v: Pointer passed unmodified to notifier function | ||
441 | * @nr_to_call: See comment for notifier_call_chain. | ||
442 | * @nr_calls: See comment for notifier_call_chain | ||
443 | * | ||
444 | * Calls each function in a notifier chain in turn. The functions | ||
445 | * run in an undefined context. | ||
446 | * All locking must be provided by the caller. | ||
447 | * | ||
448 | * If the return value of the notifier can be and'ed | ||
449 | * with %NOTIFY_STOP_MASK then raw_notifier_call_chain() | ||
450 | * will return immediately, with the return value of | ||
451 | * the notifier function which halted execution. | ||
452 | * Otherwise the return value is the return value | ||
453 | * of the last notifier function called. | ||
454 | */ | ||
455 | |||
456 | int __raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
457 | unsigned long val, void *v, | ||
458 | int nr_to_call, int *nr_calls) | ||
459 | { | ||
460 | return notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
461 | } | ||
462 | |||
463 | EXPORT_SYMBOL_GPL(__raw_notifier_call_chain); | ||
464 | |||
465 | int raw_notifier_call_chain(struct raw_notifier_head *nh, | ||
466 | unsigned long val, void *v) | ||
467 | { | ||
468 | return __raw_notifier_call_chain(nh, val, v, -1, NULL); | ||
469 | } | ||
470 | |||
471 | EXPORT_SYMBOL_GPL(raw_notifier_call_chain); | ||
472 | |||
473 | /* | ||
474 | * SRCU notifier chain routines. Registration and unregistration | ||
475 | * use a mutex, and call_chain is synchronized by SRCU (no locks). | ||
476 | */ | ||
477 | |||
478 | /** | ||
479 | * srcu_notifier_chain_register - Add notifier to an SRCU notifier chain | ||
480 | * @nh: Pointer to head of the SRCU notifier chain | ||
481 | * @n: New entry in notifier chain | ||
482 | * | ||
483 | * Adds a notifier to an SRCU notifier chain. | ||
484 | * Must be called in process context. | ||
485 | * | ||
486 | * Currently always returns zero. | ||
487 | */ | ||
488 | |||
489 | int srcu_notifier_chain_register(struct srcu_notifier_head *nh, | ||
490 | struct notifier_block *n) | ||
491 | { | ||
492 | int ret; | ||
493 | |||
494 | /* | ||
495 | * This code gets used during boot-up, when task switching is | ||
496 | * not yet working and interrupts must remain disabled. At | ||
497 | * such times we must not call mutex_lock(). | ||
498 | */ | ||
499 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
500 | return notifier_chain_register(&nh->head, n); | ||
501 | |||
502 | mutex_lock(&nh->mutex); | ||
503 | ret = notifier_chain_register(&nh->head, n); | ||
504 | mutex_unlock(&nh->mutex); | ||
505 | return ret; | ||
506 | } | ||
507 | |||
508 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_register); | ||
509 | |||
510 | /** | ||
511 | * srcu_notifier_chain_unregister - Remove notifier from an SRCU notifier chain | ||
512 | * @nh: Pointer to head of the SRCU notifier chain | ||
513 | * @n: Entry to remove from notifier chain | ||
514 | * | ||
515 | * Removes a notifier from an SRCU notifier chain. | ||
516 | * Must be called from process context. | ||
517 | * | ||
518 | * Returns zero on success or %-ENOENT on failure. | ||
519 | */ | ||
520 | int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh, | ||
521 | struct notifier_block *n) | ||
522 | { | ||
523 | int ret; | ||
524 | |||
525 | /* | ||
526 | * This code gets used during boot-up, when task switching is | ||
527 | * not yet working and interrupts must remain disabled. At | ||
528 | * such times we must not call mutex_lock(). | ||
529 | */ | ||
530 | if (unlikely(system_state == SYSTEM_BOOTING)) | ||
531 | return notifier_chain_unregister(&nh->head, n); | ||
532 | |||
533 | mutex_lock(&nh->mutex); | ||
534 | ret = notifier_chain_unregister(&nh->head, n); | ||
535 | mutex_unlock(&nh->mutex); | ||
536 | synchronize_srcu(&nh->srcu); | ||
537 | return ret; | ||
538 | } | ||
539 | |||
540 | EXPORT_SYMBOL_GPL(srcu_notifier_chain_unregister); | ||
541 | |||
542 | /** | ||
543 | * __srcu_notifier_call_chain - Call functions in an SRCU notifier chain | ||
544 | * @nh: Pointer to head of the SRCU notifier chain | ||
545 | * @val: Value passed unmodified to notifier function | ||
546 | * @v: Pointer passed unmodified to notifier function | ||
547 | * @nr_to_call: See comment for notifier_call_chain. | ||
548 | * @nr_calls: See comment for notifier_call_chain | ||
549 | * | ||
550 | * Calls each function in a notifier chain in turn. The functions | ||
551 | * run in a process context, so they are allowed to block. | ||
552 | * | ||
553 | * If the return value of the notifier can be and'ed | ||
554 | * with %NOTIFY_STOP_MASK then srcu_notifier_call_chain() | ||
555 | * will return immediately, with the return value of | ||
556 | * the notifier function which halted execution. | ||
557 | * Otherwise the return value is the return value | ||
558 | * of the last notifier function called. | ||
559 | */ | ||
560 | |||
561 | int __srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
562 | unsigned long val, void *v, | ||
563 | int nr_to_call, int *nr_calls) | ||
564 | { | ||
565 | int ret; | ||
566 | int idx; | ||
567 | |||
568 | idx = srcu_read_lock(&nh->srcu); | ||
569 | ret = notifier_call_chain(&nh->head, val, v, nr_to_call, nr_calls); | ||
570 | srcu_read_unlock(&nh->srcu, idx); | ||
571 | return ret; | ||
572 | } | ||
573 | EXPORT_SYMBOL_GPL(__srcu_notifier_call_chain); | ||
574 | |||
575 | int srcu_notifier_call_chain(struct srcu_notifier_head *nh, | ||
576 | unsigned long val, void *v) | ||
577 | { | ||
578 | return __srcu_notifier_call_chain(nh, val, v, -1, NULL); | ||
579 | } | ||
580 | EXPORT_SYMBOL_GPL(srcu_notifier_call_chain); | ||
581 | |||
582 | /** | ||
583 | * srcu_init_notifier_head - Initialize an SRCU notifier head | ||
584 | * @nh: Pointer to head of the srcu notifier chain | ||
585 | * | ||
586 | * Unlike other sorts of notifier heads, SRCU notifier heads require | ||
587 | * dynamic initialization. Be sure to call this routine before | ||
588 | * calling any of the other SRCU notifier routines for this head. | ||
589 | * | ||
590 | * If an SRCU notifier head is deallocated, it must first be cleaned | ||
591 | * up by calling srcu_cleanup_notifier_head(). Otherwise the head's | ||
592 | * per-cpu data (used by the SRCU mechanism) will leak. | ||
593 | */ | ||
594 | |||
595 | void srcu_init_notifier_head(struct srcu_notifier_head *nh) | ||
596 | { | ||
597 | mutex_init(&nh->mutex); | ||
598 | if (init_srcu_struct(&nh->srcu) < 0) | ||
599 | BUG(); | ||
600 | nh->head = NULL; | ||
601 | } | ||
602 | |||
603 | EXPORT_SYMBOL_GPL(srcu_init_notifier_head); | ||
604 | |||
605 | /** | ||
606 | * register_reboot_notifier - Register function to be called at reboot time | ||
607 | * @nb: Info about notifier function to be called | ||
608 | * | ||
609 | * Registers a function with the list of functions | ||
610 | * to be called at reboot time. | ||
611 | * | ||
612 | * Currently always returns zero, as blocking_notifier_chain_register() | ||
613 | * always returns zero. | ||
614 | */ | ||
615 | |||
616 | int register_reboot_notifier(struct notifier_block * nb) | ||
617 | { | ||
618 | return blocking_notifier_chain_register(&reboot_notifier_list, nb); | ||
619 | } | ||
620 | |||
621 | EXPORT_SYMBOL(register_reboot_notifier); | ||
622 | |||
623 | /** | ||
624 | * unregister_reboot_notifier - Unregister previously registered reboot notifier | ||
625 | * @nb: Hook to be unregistered | ||
626 | * | ||
627 | * Unregisters a previously registered reboot | ||
628 | * notifier function. | ||
629 | * | ||
630 | * Returns zero on success, or %-ENOENT on failure. | ||
631 | */ | ||
632 | |||
633 | int unregister_reboot_notifier(struct notifier_block * nb) | ||
634 | { | ||
635 | return blocking_notifier_chain_unregister(&reboot_notifier_list, nb); | ||
636 | } | ||
637 | |||
638 | EXPORT_SYMBOL(unregister_reboot_notifier); | ||
639 | |||
640 | static int set_one_prio(struct task_struct *p, int niceval, int error) | 109 | static int set_one_prio(struct task_struct *p, int niceval, int error) |
641 | { | 110 | { |
642 | int no_nice; | 111 | int no_nice; |