/*
Notifier chains are of four types:
Atomic notifier chains : run in interrupt/atomic context.
Blocking notifier chains : run in process context.
Raw notifier chains :
SRCU notifier chains :
*/
struct notifier_block
{
notifier_fn_t notifier_call;
struct notifier_block __rcu* next;
int priority;
};
内核子系统之间的信息传递;
子系统通常只在boot或者加载module时注册notifier block,即修改notification chain
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
MODULE_LICENSE("Dual BSD/GPL");
static int myreboot(struct notifier_block *self, unsigned long event, void *data)
{
printk(KERN_ALERT "Just a test! Event code: %li! System reboot now...", event);
return NOTIFY_OK;
}
static struct notifier_block myreboot_notifier = {
.notifier_call = myreboot,
};
static int myreboot_init(void)
{
register_reboot_notifier(&myreboot_notifier);
return 0;
}
static void myreboot_exit(void)
{
unregister_reboot_notifier(&myreboot_notifier);
}
module_init(myreboot_init);
module_exit(myreboot_exit);
下面给出一个简单的使用notification chain的例子。
该模块向reboot_notifier_list 注册了一个函数myreboot,该函数在系统reboot时会简单地打印一些信息;