1 #include <linux/kernel.h>
2 #include <linux/module.h>
5 #include "notifier-error-inject.h"
8 module_param(priority
, int, 0);
9 MODULE_PARM_DESC(priority
, "specify cpu notifier priority");
12 #define UP_PREPARE_FROZEN 0
13 #define DOWN_PREPARE 0
14 #define DOWN_PREPARE_FROZEN 0
16 static struct notifier_err_inject cpu_notifier_err_inject
= {
18 { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE
) },
19 { NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE_FROZEN
) },
20 { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE
) },
21 { NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE_FROZEN
) },
26 static int notf_err_handle(struct notifier_err_inject_action
*action
)
32 pr_info("Injecting error (%d) to %s\n", ret
, action
->name
);
36 static int notf_err_inj_up_prepare(unsigned int cpu
)
38 if (!cpuhp_tasks_frozen
)
39 return notf_err_handle(&cpu_notifier_err_inject
.actions
[0]);
41 return notf_err_handle(&cpu_notifier_err_inject
.actions
[1]);
44 static int notf_err_inj_dead(unsigned int cpu
)
46 if (!cpuhp_tasks_frozen
)
47 return notf_err_handle(&cpu_notifier_err_inject
.actions
[2]);
49 return notf_err_handle(&cpu_notifier_err_inject
.actions
[3]);
52 static struct dentry
*dir
;
54 static int err_inject_init(void)
58 dir
= notifier_err_inject_init("cpu", notifier_err_inject_dir
,
59 &cpu_notifier_err_inject
, priority
);
63 err
= cpuhp_setup_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE
,
64 "cpu-err-notif:prepare",
65 notf_err_inj_up_prepare
,
68 debugfs_remove_recursive(dir
);
73 static void err_inject_exit(void)
75 cpuhp_remove_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE
);
76 debugfs_remove_recursive(dir
);
79 module_init(err_inject_init
);
80 module_exit(err_inject_exit
);
82 MODULE_DESCRIPTION("CPU notifier error injection module");
83 MODULE_LICENSE("GPL");
84 MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");