forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fault-injection: add CPU notifier error injection module
I used this module to test the series of modification to the cpu notifiers code. Example1: inject CPU offline error (-1 == -EPERM) # modprobe cpu-notifier-error-inject cpu_down_prepare_error=-1 # echo 0 > /sys/devices/system/cpu/cpu1/online bash: echo: write error: Operation not permitted Example2: inject CPU online error (-2 == -ENOENT) # modprobe cpu-notifier-error-inject cpu_up_prepare_error=-2 # echo 1 > /sys/devices/system/cpu/cpu1/online bash: echo: write error: No such file or directory [[email protected]: fix Kconfig help text] Signed-off-by: Akinobu Mita <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <linux/kernel.h> | ||
#include <linux/cpu.h> | ||
#include <linux/module.h> | ||
#include <linux/notifier.h> | ||
|
||
static int priority; | ||
static int cpu_up_prepare_error; | ||
static int cpu_down_prepare_error; | ||
|
||
module_param(priority, int, 0); | ||
MODULE_PARM_DESC(priority, "specify cpu notifier priority"); | ||
|
||
module_param(cpu_up_prepare_error, int, 0644); | ||
MODULE_PARM_DESC(cpu_up_prepare_error, | ||
"specify error code to inject CPU_UP_PREPARE action"); | ||
|
||
module_param(cpu_down_prepare_error, int, 0644); | ||
MODULE_PARM_DESC(cpu_down_prepare_error, | ||
"specify error code to inject CPU_DOWN_PREPARE action"); | ||
|
||
static int err_inject_cpu_callback(struct notifier_block *nfb, | ||
unsigned long action, void *hcpu) | ||
{ | ||
int err = 0; | ||
|
||
switch (action) { | ||
case CPU_UP_PREPARE: | ||
case CPU_UP_PREPARE_FROZEN: | ||
err = cpu_up_prepare_error; | ||
break; | ||
case CPU_DOWN_PREPARE: | ||
case CPU_DOWN_PREPARE_FROZEN: | ||
err = cpu_down_prepare_error; | ||
break; | ||
} | ||
if (err) | ||
printk(KERN_INFO "Injecting error (%d) at cpu notifier\n", err); | ||
|
||
return notifier_from_errno(err); | ||
} | ||
|
||
static struct notifier_block err_inject_cpu_notifier = { | ||
.notifier_call = err_inject_cpu_callback, | ||
}; | ||
|
||
static int err_inject_init(void) | ||
{ | ||
err_inject_cpu_notifier.priority = priority; | ||
|
||
return register_hotcpu_notifier(&err_inject_cpu_notifier); | ||
} | ||
|
||
static void err_inject_exit(void) | ||
{ | ||
unregister_hotcpu_notifier(&err_inject_cpu_notifier); | ||
} | ||
|
||
module_init(err_inject_init); | ||
module_exit(err_inject_exit); | ||
|
||
MODULE_DESCRIPTION("CPU notifier error injection module"); | ||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("Akinobu Mita <[email protected]>"); |