memory-notifier-error-inject.c 1.1 KB

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