cpu-notifier-error-inject.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <linux/kernel.h>
  2. #include <linux/cpu.h>
  3. #include <linux/module.h>
  4. #include <linux/notifier.h>
  5. static int priority;
  6. static int cpu_up_prepare_error;
  7. static int cpu_down_prepare_error;
  8. module_param(priority, int, 0);
  9. MODULE_PARM_DESC(priority, "specify cpu notifier priority");
  10. module_param(cpu_up_prepare_error, int, 0644);
  11. MODULE_PARM_DESC(cpu_up_prepare_error,
  12. "specify error code to inject CPU_UP_PREPARE action");
  13. module_param(cpu_down_prepare_error, int, 0644);
  14. MODULE_PARM_DESC(cpu_down_prepare_error,
  15. "specify error code to inject CPU_DOWN_PREPARE action");
  16. static int err_inject_cpu_callback(struct notifier_block *nfb,
  17. unsigned long action, void *hcpu)
  18. {
  19. int err = 0;
  20. switch (action) {
  21. case CPU_UP_PREPARE:
  22. case CPU_UP_PREPARE_FROZEN:
  23. err = cpu_up_prepare_error;
  24. break;
  25. case CPU_DOWN_PREPARE:
  26. case CPU_DOWN_PREPARE_FROZEN:
  27. err = cpu_down_prepare_error;
  28. break;
  29. }
  30. if (err)
  31. printk(KERN_INFO "Injecting error (%d) at cpu notifier\n", err);
  32. return notifier_from_errno(err);
  33. }
  34. static struct notifier_block err_inject_cpu_notifier = {
  35. .notifier_call = err_inject_cpu_callback,
  36. };
  37. static int err_inject_init(void)
  38. {
  39. err_inject_cpu_notifier.priority = priority;
  40. return register_hotcpu_notifier(&err_inject_cpu_notifier);
  41. }
  42. static void err_inject_exit(void)
  43. {
  44. unregister_hotcpu_notifier(&err_inject_cpu_notifier);
  45. }
  46. module_init(err_inject_init);
  47. module_exit(err_inject_exit);
  48. MODULE_DESCRIPTION("CPU notifier error injection module");
  49. MODULE_LICENSE("GPL");
  50. MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");