cpu-notifier-error-inject.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/cpu.h>
  4. #include "notifier-error-inject.h"
  5. static int priority;
  6. module_param(priority, int, 0);
  7. MODULE_PARM_DESC(priority, "specify cpu notifier priority");
  8. static struct notifier_err_inject cpu_notifier_err_inject = {
  9. .actions = {
  10. { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE) },
  11. { NOTIFIER_ERR_INJECT_ACTION(CPU_UP_PREPARE_FROZEN) },
  12. { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE) },
  13. { NOTIFIER_ERR_INJECT_ACTION(CPU_DOWN_PREPARE_FROZEN) },
  14. {}
  15. }
  16. };
  17. static struct dentry *dir;
  18. static int err_inject_init(void)
  19. {
  20. int err;
  21. dir = notifier_err_inject_init("cpu", notifier_err_inject_dir,
  22. &cpu_notifier_err_inject, priority);
  23. if (IS_ERR(dir))
  24. return PTR_ERR(dir);
  25. err = register_hotcpu_notifier(&cpu_notifier_err_inject.nb);
  26. if (err)
  27. debugfs_remove_recursive(dir);
  28. return err;
  29. }
  30. static void err_inject_exit(void)
  31. {
  32. unregister_hotcpu_notifier(&cpu_notifier_err_inject.nb);
  33. debugfs_remove_recursive(dir);
  34. }
  35. module_init(err_inject_init);
  36. module_exit(err_inject_exit);
  37. MODULE_DESCRIPTION("CPU notifier error injection module");
  38. MODULE_LICENSE("GPL");
  39. MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");