2010-05-27 05:43:36 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2012-07-31 05:43:03 +08:00
|
|
|
#include <linux/cpu.h>
|
2010-05-27 05:43:36 +08:00
|
|
|
|
2012-07-31 05:43:03 +08:00
|
|
|
#include "notifier-error-inject.h"
|
2010-05-27 05:43:36 +08:00
|
|
|
|
2012-07-31 05:43:03 +08:00
|
|
|
static int priority;
|
2010-05-27 05:43:36 +08:00
|
|
|
module_param(priority, int, 0);
|
|
|
|
MODULE_PARM_DESC(priority, "specify cpu notifier priority");
|
|
|
|
|
2016-09-07 01:04:50 +08:00
|
|
|
#define UP_PREPARE 0
|
|
|
|
#define UP_PREPARE_FROZEN 0
|
|
|
|
#define DOWN_PREPARE 0
|
|
|
|
#define DOWN_PREPARE_FROZEN 0
|
|
|
|
|
2012-07-31 05:43:03 +08:00
|
|
|
static struct notifier_err_inject cpu_notifier_err_inject = {
|
|
|
|
.actions = {
|
2016-09-07 01:04:50 +08:00
|
|
|
{ NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE) },
|
|
|
|
{ NOTIFIER_ERR_INJECT_ACTION(UP_PREPARE_FROZEN) },
|
|
|
|
{ NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE) },
|
|
|
|
{ NOTIFIER_ERR_INJECT_ACTION(DOWN_PREPARE_FROZEN) },
|
2012-07-31 05:43:03 +08:00
|
|
|
{}
|
2010-05-27 05:43:36 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-09-07 01:04:50 +08:00
|
|
|
static int notf_err_handle(struct notifier_err_inject_action *action)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = action->error;
|
|
|
|
if (ret)
|
|
|
|
pr_info("Injecting error (%d) to %s\n", ret, action->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int notf_err_inj_up_prepare(unsigned int cpu)
|
|
|
|
{
|
|
|
|
if (!cpuhp_tasks_frozen)
|
|
|
|
return notf_err_handle(&cpu_notifier_err_inject.actions[0]);
|
|
|
|
else
|
|
|
|
return notf_err_handle(&cpu_notifier_err_inject.actions[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int notf_err_inj_dead(unsigned int cpu)
|
|
|
|
{
|
|
|
|
if (!cpuhp_tasks_frozen)
|
|
|
|
return notf_err_handle(&cpu_notifier_err_inject.actions[2]);
|
|
|
|
else
|
|
|
|
return notf_err_handle(&cpu_notifier_err_inject.actions[3]);
|
|
|
|
}
|
|
|
|
|
2012-07-31 05:43:03 +08:00
|
|
|
static struct dentry *dir;
|
|
|
|
|
2010-05-27 05:43:36 +08:00
|
|
|
static int err_inject_init(void)
|
|
|
|
{
|
2012-07-31 05:43:03 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
dir = notifier_err_inject_init("cpu", notifier_err_inject_dir,
|
|
|
|
&cpu_notifier_err_inject, priority);
|
|
|
|
if (IS_ERR(dir))
|
|
|
|
return PTR_ERR(dir);
|
|
|
|
|
2016-09-07 01:04:50 +08:00
|
|
|
err = cpuhp_setup_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE,
|
|
|
|
"cpu-err-notif:prepare",
|
|
|
|
notf_err_inj_up_prepare,
|
|
|
|
notf_err_inj_dead);
|
2012-07-31 05:43:03 +08:00
|
|
|
if (err)
|
|
|
|
debugfs_remove_recursive(dir);
|
2010-05-27 05:43:36 +08:00
|
|
|
|
2012-07-31 05:43:03 +08:00
|
|
|
return err;
|
2010-05-27 05:43:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void err_inject_exit(void)
|
|
|
|
{
|
2016-09-07 01:04:50 +08:00
|
|
|
cpuhp_remove_state_nocalls(CPUHP_NOTF_ERR_INJ_PREPARE);
|
2012-07-31 05:43:03 +08:00
|
|
|
debugfs_remove_recursive(dir);
|
2010-05-27 05:43:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(err_inject_init);
|
|
|
|
module_exit(err_inject_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("CPU notifier error injection module");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
|